Playing animation (IPO) from Python? [Solved]

If you feel like you're up to the challenge of building your own Ages in Blender or 3ds Max, this is the place for you!

Playing animation (IPO) from Python? [Solved]

Postby tachzusamm » Wed Jul 20, 2011 5:45 am

Well, I'm trying to play an animation (animated object, not an avatar animation) from a Python script.

Snippet of the Python code:
Code: Select all
actSubEnter = ptAttribActivator(1, 'Enter region activator')
actSubExit = ptAttribActivator(2, 'Exit region activator')
animSubRamp = ptAttribAnimation(3, 'Ramp Animation', netForce=1)
...
    def OnNotify(self, state, id, events):
        if (not PtWasLocallyNotified(self.key)):
            return
        if ((id == actSubEnter.id) and state):
            animSubRamp.value.backwards(0)
            animSubRamp.value.speed(1)
            animSubRamp.value.playRange(0, 5)



Snippet of the AlcScript:
Code: Select all
SubWorld_02:
    type: subworld
    animations:
      - name: SubRampAnim_02
        autostart: 0
        loop: 0

Region_Anim_Start:
    logic:
        modifiers:
          - name: logMod_TrigAniStart
            flags:
              - multitrigger
            conditions:
              - type: volumesensor
                satisfied: true
                direction: enter
                trignum: -1
            activators:
              - type: objectinvolume
                remote: Region_Anim_Start
            actions:
              - type: pythonfile
                ref: :SubWorld_02_PFM
         
        actions:
          - type: pythonfile
            name: SubWorld_02_PFM
            pythonfile:
                file: aniSubTest
                parameters:
                  - type: activator
                    ref: logicmod:logMod_TrigAniStart
                  - type: activator
                    ref: logicmod:logMod_TrigAniStop
               
                # This is what I assume is wrong:
                  - type: animation
                    ref: :SubRampAnim_02   # (already tried without ":")



Now, the proper section in OnNotify gets called as expected (put some "print" in the code and checked the Python0.log),
BUT: The log reports:
"AttributeError: 'NoneType' object has no attribute 'backwards' "
on the line "animSubRamp.value.backwards(0)"

So I'm guessing that the animation gets not properly passed as a parameter to python, because the ptAttribAnimation animSubRamp has value of "None".
Actually, I don't really know how to pass an animation.
By name of the animation, by the animation, by object, by ... (responder?)

Or do I simply use a wrong syntax?


Solution: There's a modified prp_LogicClasses.py on page 2 of this thread; explanations in the thread itself. ;)
Last edited by tachzusamm on Thu Jul 21, 2011 1:40 pm, edited 1 time in total.
User avatar
tachzusamm
 
Posts: 575
Joined: Thu May 29, 2008 2:03 am
Location: Germany

Re: Playing animation (IPO) from Python?

Postby D'Lanor » Wed Jul 20, 2011 12:50 pm

AlcScript does not recognize "animation" as a valid Python parameter. In the trunk version of prp_logicClasses.py it has been commented out under class plPythonParameter. No idea if it is there with good reason or simply overlooked when animations were implemented. I suggest you remove the # character and try. ;)
"It is in self-limitation that a master first shows himself." - Goethe
User avatar
D'Lanor
 
Posts: 1980
Joined: Sat Sep 29, 2007 4:24 am

Re: Playing animation (IPO) from Python?

Postby tachzusamm » Thu Jul 21, 2011 2:30 am

Thanks, I tried that.
Well, it gave a bit of progress; but since the mentioned line did not set a default, I tried writing the AlcScript this way:
Code: Select all
                  - type: animation
                    ref: 006D:SubRampAnim_02

and that at least wrote an entry for the animation in the PRP, which was not the case earlier (it was just empty before).

Then I tried to include some changes from GPNMilano's PyPRP contrib (which seems a lot more complete by the way, but unfortunatelly handles materials/textures in a very different way, which makes my age look extremly ugly), and that exported it even without the 006D prefix.

But, still, the animation does not play finally. Evereything seems right and logical, but comparing the final entries in the PRP reveals that in Cyan's ages the parameters look quite different - the animation parameter gets exported, but without an animation name (which has the *same* id as the animation; seems strange, but seems to be right or better):
Animation_Compare.png
Animation_Compare.png (26.47 KiB) Viewed 3324 times


Now I guess the next step would be to find in PyPRP where exporting the animation name as well can be added... :roll:


EDIT: Oh, another difference. No "<PrivateAnims>" in my case.
AniComp_2.png
AniComp_2.png (23.47 KiB) Viewed 3315 times

This is strange, because PyPRP *DOES* have code for including this part (as far as I understand it).
It's in "class plSceneObject()", in prp_ObjClasses.py. Assumed this is the right place where it should be. Seems it does not make it to the PRP finally.
This could be it... well, something to munch on.
User avatar
tachzusamm
 
Posts: 575
Joined: Thu May 29, 2008 2:03 am
Location: Germany

Re: Playing animation (IPO) from Python?

Postby D'Lanor » Thu Jul 21, 2011 5:35 am

tachzusamm wrote:Now I guess the next step would be to find in PyPRP where exporting the animation name as well can be added... :roll:

It is right below animation in prp_logicClasses.py and appears to be a simple string. You could try this.
Code: Select all
                  - type: animationname
                    value: SubRampAnim_02
"It is in self-limitation that a master first shows himself." - Goethe
User avatar
D'Lanor
 
Posts: 1980
Joined: Sat Sep 29, 2007 4:24 am

Re: Playing animation (IPO) from Python?

Postby tachzusamm » Thu Jul 21, 2011 7:39 am

You mean it could be so obvious? But wouldn't this create a different ID for the animation name?
Exactly this is confusing me, why in Cyan's Ages the animation name and the animation get the same ID. Maybe that was not done intentially, a small mistake in Plasma, and they made the Max exporter to do it the same way, and later they never changed it - but I'm just guessing here.
And the name itself is not used in any of Cyan's belonging python scripts, oh well... maybe Plasma itself needs it internally.
I wish I could understand the whole engine.

But however, I'll try this.
User avatar
tachzusamm
 
Posts: 575
Joined: Thu May 29, 2008 2:03 am
Location: Germany

Re: Playing animation (IPO) from Python?

Postby tachzusamm » Thu Jul 21, 2011 9:21 am

Okay, I got it working. :D

First, and here I feel a bit dumb, the <PrivateAnims> DO make it into the PRP of course - BUT only if you set the ref: in the type: animation block to the animated OBJECT, not the animation name.
I got this idea when I saw that you suggested to use "SubRampAnim_02" as the animation name (which of course is just a name / string).
So let's scratch the "No <PrivateAnims>" in the third post. Everything is fine here.

Then, I did what you suggested with the animationname, but as expected, the parameter got a different ID.

Snippet of code until now:
Code: Select all
                  - type: animationname      # id 7
                    value: SubRampAnim_02
                  - type: animation         # id 8
                    ref: :SubWorld_02         # <= here goes the animated object, NOT its animation name!


So, I changed the animationname ID with PrpShop to 8 as well after export, and voilá, the animation works and can be controlled from a Python script. (Much better than setting up an endless bunch of responders, if you ask me. Not to talk about complex state machines with crazy key/msg, waiton and user shuffling. And tach crying and scratching his head. Did I mention that I love Python?)

So, here's what made the difference:
Anim-Name_ID_match.png
Anim-Name_ID_match.png (15.33 KiB) Viewed 3295 times
Checked it twice. Isn't that strange?


Unfortunatelly, I don't think this is finally solved - because I still believe that PyPRP needs the option to export the animation name with the same ID as the animated object.
Doing it with PrpShop works, but slows down the process. (I export my age very often, especially when I want to get complex animations right)

Maybe some of the original PyPRP developers could give a hint where to have a look at?
Oh, please.
User avatar
tachzusamm
 
Posts: 575
Joined: Thu May 29, 2008 2:03 am
Location: Germany

Re: Playing animation (IPO) from Python?

Postby D'Lanor » Thu Jul 21, 2011 9:45 am

When Python parameters show up with the same ID in PrpShop they are usually part of a list. In this case it seems we need a list of mixed types but I don't think PyPRP currently supports that. :?
"It is in self-limitation that a master first shows himself." - Goethe
User avatar
D'Lanor
 
Posts: 1980
Joined: Sat Sep 29, 2007 4:24 am

Re: Playing animation (IPO) from Python?

Postby tachzusamm » Thu Jul 21, 2011 10:02 am

Hm, I see...
What about just getting the animation name from the object inside PyPRP automatically? Instead of explicitly putting it as a parameter again. The name is already defined there at the object in AlcScript.
(Could work witch animation lists as well - as long as PyPRP supports animation lists. I guess no. But this does not matter that much - as long as one animation (one IPO) can be passed, one could do the splitting into part inside the Python script.)

Or, one could simply avoid the ID incrementing if "animationname" is followed by "animation".

Well, I think I will have again a deeper look into the code.
User avatar
tachzusamm
 
Posts: 575
Joined: Thu May 29, 2008 2:03 am
Location: Germany

Re: Playing animation (IPO) from Python?

Postby D'Lanor » Thu Jul 21, 2011 10:22 am

btw, Paradox has a modification in his contrib which allows forcing the index of Python parameters.
"It is in self-limitation that a master first shows himself." - Goethe
User avatar
D'Lanor
 
Posts: 1980
Joined: Sat Sep 29, 2007 4:24 am

Re: Playing animation (IPO) from Python?

Postby tachzusamm » Thu Jul 21, 2011 11:58 am

Great.
Are you sure it was Paradox?

I've compared each of his scripts with those in trunk with CSDiff now, and read the differing lines carefully, but I don't find any change which smells like what you described.
Browsing the logs in the svn did not give me an idea as well.
User avatar
tachzusamm
 
Posts: 575
Joined: Thu May 29, 2008 2:03 am
Location: Germany

Next

Return to Building

Who is online

Users browsing this forum: No registered users and 3 guests