[osg-users] How to actually play animation in osgt file

Warren Schwartz warrens95 at gmail.com
Wed Oct 24 13:09:26 PDT 2018


mp3butcher wrote:
> Hi
> Have a look at osganimationviewer example
> You can use it to check import have worked as expected and it's code tell you how to use AnimationManager
> Cheers
> 
> 
> Warren93 wrote:
> > 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.
> 


Thanks for the reply. Any tips on how to build that example? To build OSG, in the root OSG directory I just did:

cmake -DCMAKE_INSTALL_PREFIX:PATH=~/usr . && make all install

(I don't have root access to the machine I'm on, hence the prefix above). The OSG .so libraries build just fine but the examples don't seem to get built. Is there anything special I have to do to get them to build? (I don't know much about cmake, and am therefore hesitant to manually edit the cmakelists files.)

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=75119#75119







More information about the osg-users mailing list