Triggering Animations In Python Script?

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!

Triggering Animations In Python Script?

Postby Robert The Rebuilder » Mon Nov 03, 2008 6:12 am

I need to trigger an animation based on conditions that only a script can detect, as an alternative to triggering animations strictly through AlcScript.

I've been looking at the Kadish pillar animations and the associated Python script to see how it's done, and I've made the following observations:
  • The plATCAnim names have the form prefix_middle_anim_N where prefix is the channel name contained in plAGModifier; middle is the name passed in as a Python parameter; and N is some indicator of the animation's order in a series (or just 0 if it is a single animation).
  • The animation-related Python parameters provided to the plPythonFileMod are an AnimationName (i.e. the middle part of the animation name) followed by an Animation (that has a reference to the plAGMasterMod) - and they share the same ID/index.
  • The Python script has just one attribute for this collection of python parameters - a ptAttribAnimation instance. Somehow, the animation name and subsequent animations are all folded into this one attribute.
  • The use of the optional byObject flag seems to be when the script wants to activate each animation in the group individually. If it is specified, then all uses of the ptAttribAnimation in the script must use the byObject map to access the individual animation.
  • When not using the byObject flag, the 'value' and 'animation' members of the ptAttribAnimation seem to be interchangeable.

I tried enabling the use of animation arguments in the 1.5.X plug-in code base, where if plPythonParameter._ExportScript() detects an 'animationlist' type argument in the AlcScript argument list for the python file mod, it recurses on the references, creating a plPythonParameter with the same ID/index. For example, the AlcScript for the animationlist looks like this:

Code: Select all
              - type: animationlist
               refs:
                 - type: animationname
                  value: DoorOpen
                 - type: animation
                  ref: 006D:s111Door0


Note that the reference is to the plAGMasterMod (0x006D).

To test this, I made sure my animations followed the naming convention I've seen above. After exporting and examining the PRP file, it appears that the Python arguments were created correctly. When running in URU, the Python script does obtain a seemingly valid ptAttribAnimation. I can print out the return value of the getdef() method and animation.getFirstKey().getName(), which appear to be in order. But when I call the animation.play() method, nothing happens. I encased the call in a try-except block, but no exceptions are thrown. And no animation. :(

[And yes - I delete the .SAV file each time before firing up URU.]

Has anyone tried triggering animations from within Python scripts? Have you had any success?
Can we rebuild it? Yes, we can - here's how.

MOULagain KI# 1299

Myst Movie coming soon - spread the word!
User avatar
Robert The Rebuilder
 
Posts: 1383
Joined: Sat Sep 29, 2007 7:24 am
Location: Virginia, US

Re: Triggering Animations In Python Script?

Postby D'Lanor » Mon Nov 03, 2008 9:43 am

Hook up your animation(s) to a responder and use PtAttribResponder. That is so much easier.
"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: Triggering Animations In Python Script?

Postby Robert The Rebuilder » Tue Nov 04, 2008 11:20 am

You're right: for basic triggers of animations, even going forwards and backwards, that is the way to go.

But for the moving columns in Shell 111, there's a problem. Similar to the Kadish pillars, I want to play only a portion of the animation, depending on the settings of the buttons when the levers are pulled. Ideally, I would be able to pass the full animation for each column to the Python script, which can calculate how much of the animation to play (and whether it is forwards or backwards).

If I use responders to do this, I would first need to enable the setting of the speed, begin and end values for ptAnimCmdMsg via AlcScript (currently it doesn't support this). But the larger problem would be to create a state for each possible start/end time combination for the animation. Given 4 possible positions of a column, that would be 12 different animation states per column - repeated for each column in a separate responder. The script would then choose which state to use, depending on the button settings. It can be done, but boy - what a lot of AlcScript that would be!

Given that there's currently no alternative (unless PyPRP 2.0 comes out), maybe I'll have to do it that way.
Can we rebuild it? Yes, we can - here's how.

MOULagain KI# 1299

Myst Movie coming soon - spread the word!
User avatar
Robert The Rebuilder
 
Posts: 1383
Joined: Sat Sep 29, 2007 7:24 am
Location: Virginia, US

Re: Triggering Animations In Python Script?

Postby J'Kla » Tue Nov 04, 2008 2:39 pm

This points to where we need some help from Cyan either in the form of tools or at least instructions.

I don't think either are likely to be forthcoming.
User avatar
J'Kla
 
Posts: 1003
Joined: Wed Feb 20, 2008 3:16 pm
Location: Geordieland UK

Re: Triggering Animations In Python Script?

Postby D'Lanor » Tue Nov 04, 2008 4:07 pm

But you can play a portion of an animation. Based on the set framerate of 30 fps you can calculate the start and end times. It is one of the first things mentioned in the animations wiki, but nobody ever seems to use it that way.
"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: Triggering Animations In Python Script?

Postby Jojon » Wed Nov 05, 2008 2:24 pm

Err, isn't it just a matter of setting up one named animation definition for each distance each column travels and call the relevant four?
Jojon
 
Posts: 1116
Joined: Sun Sep 30, 2007 5:49 am


Return to Building

Who is online

Users browsing this forum: Google [Bot] and 3 guests