Discussion:
[osg-users] How to actually play animation in osgt file
Warren Schwartz
2018-10-23 13:23:20 UTC
Permalink
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
Julien Valentin
2018-10-24 18:57:26 UTC
Permalink
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
Post by Warren Schwartz
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).
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";
}
got animation manager
found an animation 'ArmatureAction' with duration 5.96667
animation has 198channels
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
Warren Schwartz
2018-10-24 20:09:26 UTC
Permalink
Post by Julien Valentin
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
Post by Warren Schwartz
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).
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";
}
got animation manager
found an animation 'ArmatureAction' with duration 5.96667
animation has 198channels
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
Julien Valentin
2018-10-24 20:34:21 UTC
Permalink
okay you're really new to c++:
use cmake-gui to check OSG_BUILD_EXAMPLES check box
make example_osganimationviewer
next time try to find yourself: this kind of thing is not osg related...
Cheers
Post by Warren Schwartz
Post by Julien Valentin
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
Post by Warren Schwartz
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).
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";
}
got animation manager
found an animation 'ArmatureAction' with duration 5.96667
animation has 198channels
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.
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.)
------------------------
Twirling twirling twirling toward freedom

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

Loading...