can't get skeletal animation to work [solved]


07-01-2007 08:07:42

i hve done test animation with bones and exported it with oFusion, so i went to the Mogre tutorials and my surprise is that doesn't have tutorial or a snippet or something showing how to run the animations of the loaded meshes... so anybody can point me to a tutorial o something.... i have seen the c++ version but it changes in c#..

in just in case my animation is not working i loaded a mesh that has an animation and that already comes with the sample models in the media folder and is the "fish.mesh"... so by now i have this code in the createScene() ....

SceneManager mgr = win.SceneManager;
mgr.AmbientLight = new ColourValue(1, 1, 1);
mgr.ShadowTechnique = ShadowTechnique.SHADOWTYPE_STENCIL_ADDITIVE;

Entity ent = mgr.CreateEntity("Fish", "fish.mesh");
SceneNode node = mgr.RootSceneNode.CreateChildSceneNode("FISHNode");

Animation.DefaultInterpolationMode = Animation.InterpolationMode.IM_LINEAR;
Animation.DefaultRotationInterpolationMode = Animation.RotationInterpolationMode.RIM_LINEAR;

AnimationState ae = ent.GetAnimationState("swim");
ae.Enabled = true;
ae.Loop = true;

the fish mesh loads perfect, but i don't see any animation, what am i missing???... i'm a really noob at OGRE..


07-01-2007 13:24:49

You need to subscribe to FrameStarted event.
Inside this You must update fish animation, something like this:

this.m_CurrentAnimationState.AddTime(frameEvent.timeSinceLastFrame * speed);

m_CurrentAnimationState is the animation state that You set to play.
speed - with this You can control the animation speed. Let's say if it is 2 then animation will be player twice of the normal speed while if it is 0.5 it will be player halfo of the speed.

That's actually all You have to do to play animations either skeletal, node and I suppose vertex(didn't try that tho).

Hope I helped a bit, see Ya.


07-01-2007 15:36:31

And check out the SkeletalAnimation demo. It just loads 10 robots and animates them at random speeds.


08-01-2007 21:11:10

thanks crodude, Bekas...

yeah that's what it was missing.. ichecked out the example that comes with the MOGRE SDK as Bekas point me and of course crodude snippet whas a great help cose the code in the SkeletalAnimation project has some issues that i will hightlight....

the example inherits from the ExampleApplication class so it overrides a method to register the event listener for the animation like this...

public override void CreateFrameListener()
root.FrameStarted += new FrameListener.FrameStartedHandler(Skeletal_FrameStarted);

notice the syntax for registering the event...

for my app what i do is the following:

at my SceneCreating method (this method loads the scene with the OSMLoder and setups some lights and stuff like that) i register the event:

Root.Singleton.FrameStarted += new FrameListener.FrameStartedHandler(SkeletalFrameStarted);

"SkeletalFrameStarted" is the function that will be called each time the event shows... as you can see the syntax is a lil bit different

finally in my function SkeletalFrameStarted i coded the following:

ae.AddTime(evt.timeSinceLastFrame * AnimationSpeed);
return true;

where "ae" comes from the sceneCreating method where i registered the event, and then loaded the scene with the OSMLoader, and since this might be helpful for those using the OSMLoader i will show you the snippet from where the "ae" variable comes...

first i declared the AnimationState variable "ae", and the animation speed

AnimationState ae = null;
float AnimationSpeed = 0.25f;

and then in the creteScene method :

Entity ent2 = mgr.GetEntity("Cylinder01");
ae = ent2.GetAnimationState("anim1");
ae.Enabled = true;
ae.Loop = true;

where "Cylinder01" is the mesh i loaded with the bone animation and "anim1" is how i named the animation in the oFusion exporter

everything else is just as in the skeletal animation example.

so that's it i just wanted to show you guys since it is lil bit different the code since i'm using the osm loader if u load directly an *.mesh file then the ae.ent2.GetAnimationState method souldn't be used the equivalent c++ sould be a reference to a pointer of the element loaded.. anyway hope this helps someone that is starting like me :)

happy coding :)