Problem with node animation

Prophet

26-08-2008 00:08:09

Okay, I'm starting to feel real stupid, but I just can't make heads or tails out of this.
So, I have a scene with a simple box ("testBox"), which has it's position animated by auto-key. I go to oFusion->Export, saves the scene and add the animation.
Now, when I open the file in Ogre it says that the entity is not animated. Though in the .osm file, I can see the entity and all its animated keyframes.
I realise that Ogre needs a skeleton for the AnimationState part (and getAnimationState() for the entity), but how on earth do you animate nodes? (That is, I have no skeleton, but the animation is saved in the .osm file)
I feel embarrassed to ask, but I've been looking and I just can't figure it out. Sorry! :(

Edit: I might add that I copy the created scene manager to my "real" scene manager by calling getSceneManager() from my oFusion scene.

Lioric

27-08-2008 04:02:43

Node animation (the pos, rot and scale) is not in the Entity (the entity has not concept of the scene placement, that is why a node is used to place an entity in the scene), but it is in the scene nodes. You can access the node animation via the scene manager, this is some sample code to animate your scene (all animated nodes) at each frame


// We update all loaded animations each frame
SceneManager::AnimationIterator animationIt = mSceneMgr->getAnimationIterator();

while(animationIt.hasMoreElements()) {
Animation* animation = animationIt.getNext();

const Animation::NodeTrackList& trackList = animation->_getNodeTrackList();

Animation::NodeTrackList::const_iterator it = trackList.begin();
Animation::NodeTrackList::const_iterator iend = trackList.end();

for(; it != iend; ++it) {
const Ogre::NodeAnimationTrack* track = it->second;
track->getAssociatedNode()->resetToInitialState();
}

currentTime += evt.timeSinceLastFrame;
animation->apply(currentTime);
}


*This can be used in the 'frameStarted' event of a FrameListener

There are several ways to handle animation in Ogre, and this is just a sample, you might need to handle object animations individually, in that case see scene manager 'getAnimation' methods

Prophet

27-08-2008 09:53:06

Sometimes, I feel really stupid. Thanks!

elieajaltouni

02-06-2009 21:45:34

Hi guys I am facing the same problem of animation I tried to use the sample code provided but I think I have put it in the wrong place.
Lioric you have mentioned that the sample code must be set
*This can be used in the 'frameStarted' event of a FrameListener

Can you be more specific where to set the file my main code is the following:

#include "ExampleApplication.h"
#include "OgreOSMScene.h"

//#include "iostream.h"

class TutorialApplication : public ExampleApplication
{
protected:

public:
TutorialApplication()
{
}

~TutorialApplication()
{
}
protected:
void createScene(void)
{
OSMScene oScene;
oScene.initialise("ri.osm", NULL);
oScene.createScene();
mSceneMgr = oScene.getSceneManager();
mSceneMgr->setShadowTechnique(SHADOWTYPE_STENCIL_ADDITIVE);
mCamera = mSceneMgr->createCamera("PlayerCam");
// Position it at 500 in Z direction
mCamera->setPosition(Vector3(0,0,500));
// Look back along -Z
mCamera->lookAt(Vector3(0,0,-300));
mCamera->setNearClipDistance(5);
// If a viewport was not automatically created, (no cameras saved in the scene)
// create a default viewport, entire window
Viewport* vp = mWindow->addViewport(mCamera);
vp->setBackgroundColour(ColourValue(0,0,0));

// Alter the camera aspect ratio to match the viewport
mCamera->setAspectRatio(Real(vp->getActualWidth()) / Real(vp->getActualHeight()));

SceneManager::AnimationIterator animationIt = mSceneMgr->getAnimationIterator();

while(animationIt.hasMoreElements()) {
Animation* animation = animationIt.getNext();

const Animation::NodeTrackList& trackList = animation->_getNodeTrackList();

Animation::NodeTrackList::const_iterator it = trackList.begin();
Animation::NodeTrackList::const_iterator iend = trackList.end();

for(; it != iend; ++it) {
const Ogre::NodeAnimationTrack* track = it->second;
track->getAssociatedNode()->resetToInitialState();
}

currentTime += evt.timeSinceLastFrame;
animation->apply(currentTime);
}

}
void chooseSceneManager(void) {}
void createCamera(void) {}
void createViewports(void) {}
};

#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
#define WIN32_LEAN_AND_MEAN
#include "windows.h"

INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT )
#else
int main(int argc, char **argv)
#endif
{
//Create application object
TutorialApplication app;

try {
app.go();
} catch( Exception& e ) {
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
MessageBoxA( NULL, e.what(), "An exception has occured!", MB_OK | MB_ICONERROR | MB_TASKMODAL);
#else
fprintf(stderr, "An exception has occurred: %s\n",
e.what());
#endif
}

return 0;
}


I am getting an error on the currentTime and evt and timeSinceLastFrame which is reasonable since I don't have them declared.

Any suggestions please?

Lioric

03-06-2009 23:06:31

You need to create your own frame listener (used at each frame) and update the animation there, see the oScene Loader sample application for details