Animation not working after first frame

Problems building or running the engine, queries about how to use features etc.
Post Reply
mehwoot
Bronze Sponsor
Bronze Sponsor
Posts: 6
Joined: Fri Feb 22, 2013 5:19 pm

Animation not working after first frame

Post by mehwoot »

I have a problem with animations not updating properly. What is weird is that when I set up the animation before the first frame is rendered, it steps fine- but after the first frame is rendered, it doesn't update anymore.

Code: Select all

auto currentAnimation = entity->getAnimationState("Walking");
currentAnimation->setTimePosition(0.0f);
currentAnimation->setWeight(1);
currentAnimation->setLoop(true);
currentAnimation->setEnabled(true);
And then each frame I do

Code: Select all

currentAnimation->addTime(0.05f);
currentAnimation->getTimePosition() is being updated as it should, currentAnimation->getWeight() equals 1, currentAnimation->hasEnded() is false and currentAnimation->getEnabled() is true each update. However the animation is still stuck having advanced only 0.05f in the actual render window.

I can manually make it step more than once before the first render by doing

Code: Select all

entity->getSkeleton()->_notifyManualBonesDirty();
currentAnimation->addTime(0.05f);
and that updates it multiple times, but after the first render it doesn't work anymore.

Using Ogre 1.9.1, also I am using SDL 2.0 so my render loop looks like

Code: Select all

window->update(false);
window->swapBuffers();
Ogre::WindowEventUtilities::messagePump();
SDL_GL_SwapWindow(sdlWindow);
Possibilities...
entity->hasSkeleton() returns true, but I am not using skeleton animation (I thought?) I am using vertex based animation (I think). But it animates fine the first time so I don't see how this could cause it to fail in this way.
I do see a message "WARNING: Person.mesh is an older format ([MeshSerializer_v1.41]); you should upgrade it as soon as possible using the OgreMeshUpgrade tool." So I guess I should do that, but I can't see how it could cause this issue.
User avatar
Kojack
OGRE Moderator
OGRE Moderator
Posts: 7157
Joined: Sun Jan 25, 2004 7:35 am
Location: Brisbane, Australia
x 534

Re: Animation not working after first frame

Post by Kojack »

It looks like the problem is that you are bypassing part of the Ogre render process by updating the window directly.
The Ogre Root system has a member mNextFrame which tracks the frame number for rendering. The scene manager only updates animations if the frame number is different to when it was last called (this is so if you have multiple viewports, it won't update animations multiple times, since they are shared in a frame).
But when you call window->update() directly you skip over the code that increments the mNextFrame value, so it permanently sits at zero and the scene manager thinks it's never time to update animations.

The increment happens in Root::_fireFrameRenderingQueued
This is done for you if you use the typical Root::renderOneFrame to do all rendering, but you could probably call Root::_fireFrameRenderingQueued manually (all it will do is increment the frame number and call any frame listener frameRenderingQueued callbacks). (I've never tried doing that though, I just use renderOneFrame)
mehwoot
Bronze Sponsor
Bronze Sponsor
Posts: 6
Joined: Fri Feb 22, 2013 5:19 pm

Re: Animation not working after first frame

Post by mehwoot »

Brilliant, that was exactly it. Thanks heaps!
Post Reply