[Solved] Animation Information at RunTime

Hello dear all,

Is there a way to retrive this kind of information from an ActorNode currently playing an animation:

  • current animation played or posed
  • current frame played or posed
  • max number of frame in the current animation (or an animation i know the name?)

If such functions does exists, does they work the same in blend mode?
Also , is it possible to have a “done Event” at the end of an animation without playing the animation as specific interval (which is a bit slower at run time)?

Thanks for your help

Actor has this members:

...
getCurrentAnim
getCurrentFrame
...

Documentation:

...getCurrentAnim
def getCurrentAnim(self, partName=None)

Return the anim currently playing on the actor. If part not specified return current anim of an arbitrary part in dictionary. NOTE: only returns info for an arbitrary LOD

getCurrentFrame
def getCurrentFrame(self, animName=None, partName=None)

Return the current frame number of the anim current playing on the actor. If part not specified return current anim of first part in dictionary. NOTE: only returns info for an arbitrary LOD

If this isn’t enough you can write a class that interhits from Actor and overwrite all functions with a function thats saves the animation which should be played and calls the function from Actor.

Regards Martin

To further expand on the nitty-gritty details:

As Martin showed above, actor.getCurrentAnim() returns the animation currently playing. I don’t think it returns the posed anim though, since that’s not technically playing; and it doesn’t work in blend mode, in which case there might be multiple animations playing. But you can use actor.getAnimControls() to get a list of all playing animations; see below.

Not directly, but you can extract this from the animation’s AnimControl (see below).

As Martin showed, this one is easy: actor.getNumFrames(animName)

You can also get some of this information directly from the AnimControls associated with the Actor. The Actor class manages animations by creating an AnimControl for each animation you specify; the AnimControl actually keeps track of the frame count, play rate, current frame number, etc., for each animation. To extract the AnimControl for a particular animation, use actor.getAnimControl(animName, ‘modelRoot’); to get the list of all currently-playing animControls, use actor.getAnimControls(). In blend mode, you might want to query the control effect for a particular AnimControl. This will tell you whether the AnimControl is active or not–a 0.0 control effect means the AnimControl isn’t contributing to the final animation. For this you need the part:

part = actor.getPart().node().getBundle()
effect = part.getControlEffect(control)

But this is all pretty low-level stuff. You might be better off just keeping track of the relevent details yourself, as Martin suggested.

We used to have an interface that triggered an event when the animation finished, but we found this was always lagging by a frame, since it took a frame to generate and response to the event. It’s usually better and simpler just to set a timer at the beginning, since you know how much time it will take to play the animation:

actor.play('grab')
duration = actor.getNumFrames('grab') / actor.getPlayRate('grab')
taskMgr.doMethodLater(duration, self.finishedGrab, 'finishedGrab')

David