[osg-users] How to actually play animation in osgt file
Warren Schwartz
warrens95 at gmail.com
Tue Oct 23 06:23:20 PDT 2018
I am trying to render an animated model in an X-Plane 11 plugin using OSG 3.6.3 (using Viewer::setUpViewerAsEmbeddedInWindow and glEnableClientState). I can see the model, but the animation does not play. (The model was exported from Blender using the osgexport plugin).
This is the code I have to verify that there actually is an animation in the exported .osgt model:
Code:
osg::ref_ptr<osg::Group> osgModelGroup = dynamic_cast<osg::Group*>( osgModelNode.get() );
if (osgModelGroup) {
osgAnimation::BasicAnimationManager* animationManager = dynamic_cast<osgAnimation::BasicAnimationManager*>(osgModelGroup->getUpdateCallback());
if (animationManager) {
std::cout << "got animation manager\n";
const osgAnimation::AnimationList& animations = animationManager->getAnimationList();
for (int i = 0; i < animations.size(); i++) {
anim = animations[i].get();
animDuration = anim->getDuration();
osg::Object* animObj = dynamic_cast<osg::Object*>(anim);
std::string animName = "";
if (animObj)
animName = animObj->getName();
std::cout << "found an animation '" << animName << "' with duration " << animDuration << "\n";
animationManager->playAnimation(anim); // does nothing
std::cout << "animation has " << anim->getChannels().size() << "channels\n";
}
}
else {
std::cout << "no animation manager\n";
}
}
else {
std::cout << "no group for osgModelNode\n";
}
The output is:
got animation manager
found an animation 'ArmatureAction' with duration 5.96667
animation has 198channels
And in X-Plane's draw loop, there is code to manually update the animation:
Code:
std::cout << "Rendering OSG scene...\n";
if (anim) {
animTime += 1 / 60.0f; // assuming osg interprets time as seconds and not frames...
if (animTime > animDuration);
animTime = 0;
anim->update(animTime);
std::cout << "updated animation\n";
}
mViewer->frame();
This also prints the expected output. What am I doing wrong here?
Thanks for any info.
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=75110#75110
More information about the osg-users
mailing list