Animation frame callbacks

Discussion area about developing or extending OGRE, adding plugins for it or building applications on it. No newbie questions please, use the Help forum for that.
Post Reply
Crashy
Google Summer of Code Student
Google Summer of Code Student
Posts: 1005
Joined: Wed Jan 08, 2003 9:15 pm
Location: Lyon, France
x 49
Contact:

Animation frame callbacks

Post by Crashy »

Hi,
I need for personnal purpoise to develop an animation frame callback system, and I've seen that is a requested feature for Ogre( http://www.ogre3d.org/tikiwiki/Help+Req ... _callbacks) , so why may I develop it only for myself while it is a needed feature.
So the needs are, according to the wiki:

* Enhance the .skeleton format to include frame events in animations
* Allow listeners to be registered on AnimationState to receive event notifications
* Events raised must be aware of interpolation (skipping over the event, time distances)

The implementation basis I've seen is to add

Code: Select all

 addAnimationFrameListener(AnimationListener*)
addAnimationTimeListener( AnimationListener*)
to the AnimationStateclass, and

Code: Select all

addFrameEvent(ogre::string& animName,int frame)
addTimeEvent(ogre::string &animName,float frame)

to the skeleton class with the AnimationListener having two methods:

Code: Select all

AnimationListener::frameEventRaised(Ogre::string &animname,int frame)
AnimationListener::timeEventRaised(Ogre::string &animname,float time)
While the animation is running, there are some possible ways to wake-up listeners:
-if the current frame/time is listened or if there was a listened frame/time during the last time increment, wake up listener. It somehow a backward looking system.
-if the current frame/time is listened, or if there is a listened frame/time during the next estimated time increment, wake up listener. A forward looking system.
-if the current frame/time is listened, or if there is a listened frame/time in the [currentFrame-delta, currentFrame+delta] intervall, delta beeing given by the user while registering the listener, wake up the listener.

I don't know which one to choose, maybe let the user choose it having different type of listeners.
Any other thought on this feature?
Follow la Moustache on Twitter or on Facebook
Image
User avatar
Praetor
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 3335
Joined: Tue Jun 21, 2005 8:26 pm
Location: Rochester, New York, US
x 3
Contact:

Re: Animation frame callbacks

Post by Praetor »

I do this externally to the animation system. I associate a callback to a time position, and then during game updates I check if I crossed that time "boundary" and call the callback. You could store the callback information in a separate file and load it alongside the .skeleton file.

Events are really just a listener that gets called with a "key" (a string) attached to the real time position of the animation.
Game Development, Engine Development, Porting
http://www.darkwindmedia.com
Crashy
Google Summer of Code Student
Google Summer of Code Student
Posts: 1005
Joined: Wed Jan 08, 2003 9:15 pm
Location: Lyon, France
x 49
Contact:

Re: Animation frame callbacks

Post by Crashy »

So, do you think this could be a core addition?

I'm gonna start coding this, using time position and not the frame count, which are not really reliable for this.
Events are really just a listener that gets called with a "key" (a string) attached to the real time position of the animation.
What is the key for? Just to know which event has called the listener?
Follow la Moustache on Twitter or on Facebook
Image
User avatar
Klaim
Old One
Posts: 2565
Joined: Sun Sep 11, 2005 1:04 am
Location: Paris, France
x 56
Contact:

Re: Animation frame callbacks

Post by Klaim »

I have a maybe very naive suggestion but you'll tell me if it is :

Couldn't this system be implemented in templates to make this system only implemented/generated if it's used?
That would limit the run-time cost of adding the checks in the core system?

That said, I don't know the real cost if there is no usage so maybe it's juste premature optimiaztion.
User avatar
Kojack
OGRE Moderator
OGRE Moderator
Posts: 7157
Joined: Sun Jan 25, 2004 7:35 am
Location: Brisbane, Australia
x 534

Re: Animation frame callbacks

Post by Kojack »

What is the key for? Just to know which event has called the listener?
There could be multiple different events within one animation, so you'd want a way to identify which was triggered.

I was thinking about this the other day. What I would want from an animation trigger system would be not only different trigger keys, but also the ability to query how long until the next trigger of a specified type. Imagine an animation of a drummer. You could have a trigger on the moment of drum hit. Now when playing a song you can scan ahead to detect beats, query how long the animation has to play to reach a drum hit, then adjust the playback speed of the animation so the drum hit happens right on the beat. This would let you put any animation with the drum trigger with any song, without hard coding the timing. (I had the ogre ninja head banging (crouch animation) to daft punk recently, so it got me thinking about how to sync the animation to the sound better).

Also I was thinking a range trigger would be useful. So you can ask the animation if it is currently within the activation region of a trigger. This would let you do things like flag the period of the animation where the left foot is touching the ground, not just an instantaneous trigger when it first touches the ground.
Crashy
Google Summer of Code Student
Google Summer of Code Student
Posts: 1005
Joined: Wed Jan 08, 2003 9:15 pm
Location: Lyon, France
x 49
Contact:

Re: Animation frame callbacks

Post by Crashy »

There could be multiple different events within one animation, so you'd want a way to identify which was triggered.
Okay, personally I'd prefer to use biteflag to identify an event, but it is another problem.
What I would want from an animation trigger system would be not only different trigger keys, but also the ability to query how long until the next trigger of a specified type.
Yeah, this is a cool idea to querry how many time is remaining until the event point is reached.
Something like a getEstimatedTimeToEvent(string animname, string eventType);
Also I was thinking a range trigger would be useful. So you can ask the animation if it is currently within the activation region of a trigger.
Yup, good idea too.
That said, I don't know the real cost if there is no usage so maybe it's juste premature optimiaztion.
Mmhh, I don't think testing that a listenerList is empty costs that much.

You could store the callback information in a separate file and load it alongside the .skeleton file.
I missed this. I personally planned to enhance the .skeleton format to add a new parameter in the keyframe description. It will be also easy to modify exporters to add this feature.

This make me think that it could be cool to add event not on a fixed time on an animation, but also to specify a track name, so that it becomes possible to have a different trigger for each bone.
Follow la Moustache on Twitter or on Facebook
Image
Post Reply