[osg-users] How to actually play animation in osgt file
Julien Valentin
julienvalentin51 at gmail.com
Wed Oct 24 11:57:26 PDT 2018
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.
------------------------
Twirling twirling twirling toward freedom
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=75117#75117
More information about the osg-users
mailing list