OpenSceneGraph Forum Forum Index OpenSceneGraph Forum
Official forum which mirrors the existent OSG mailing lists. Messages posted here are forwarded to the mailing list and vice versa.
 
   FAQFAQ    SearchSearch    MemberlistMemberlist    RulesRules    UsergroupsUsergroups    RegisterRegister 
 Mail2Forum SettingsMail2Forum Settings  ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
   AlbumAlbum  OpenSceneGraph IRC ChatOpenSceneGraph IRC Chat   SmartFeedSmartFeed 

How to actually play animation in osgt file


 
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General
View previous topic :: View next topic  
Author Message
Warren93
Newbie


Joined: 23 Oct 2018
Posts: 2

PostPosted: Tue Oct 23, 2018 1:23 pm    Post subject:
How to actually play animation in osgt file
Reply with quote

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.
Back to top
View user's profile Send private message
mp3butcher (Julien Valentin)
Appreciator


Joined: 17 Feb 2010
Posts: 484
Location: France

PostPosted: Wed Oct 24, 2018 6:57 pm    Post subject:
Re: How to actually play animation in osgt file
Reply with quote

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
Back to top
View user's profile Send private message Visit poster's website
Warren93
Newbie


Joined: 23 Oct 2018
Posts: 2

PostPosted: Wed Oct 24, 2018 8:09 pm    Post subject:
Re: How to actually play animation in osgt file
Reply with quote

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. Setting OPTION(BUILD_OSG_EXAMPLES "Enable to build OSG Examples" ON) in the root CMakeLists file does not change this. 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.)
Back to top
View user's profile Send private message
mp3butcher (Julien Valentin)
Appreciator


Joined: 17 Feb 2010
Posts: 484
Location: France

PostPosted: Wed Oct 24, 2018 8:34 pm    Post subject:
Re: How to actually play animation in osgt file
Reply with quote

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

Warren93 wrote:
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.)

_________________
Twirling twirling twirling toward freedom
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum

Similar Topics
Topic Author Forum Replies Posted
No new posts Change color of node read from dxf file dhhabyc General 1 Sat Nov 17, 2018 12:58 pm View latest post
No new posts Load an obj file and mapping a given ... aaa3d General 3 Mon Aug 06, 2018 2:27 pm View latest post
No new posts osgconv osgjs bug file not found memory_thrasher Plugins [osgPlugins] 2 Tue Jul 31, 2018 5:21 pm View latest post
No new posts error while loading .iv file in opens... Rj@123 General 0 Wed Jun 20, 2018 10:52 am View latest post
No new posts DXF file with text crashes on Intersect brianh General 4 Tue May 29, 2018 3:15 pm View latest post


Board Security Anti Bot Question MOD - phpBB MOD against Spam Bots
Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP