[osg-users] fbx animation

178 views
Skip to first unread message

Josue Hernandez

unread,
Mar 23, 2011, 12:48:07 PM3/23/11
to osg-...@lists.openscenegraph.org
Hi, everybody:

anyone know how to activate an animation. fbx?

...

Thank you!

Cheers,
Josue

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

_______________________________________________
osg-users mailing list
osg-...@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Mourad Boufarguine

unread,
Mar 23, 2011, 2:30:31 PM3/23/11
to osg-...@lists.openscenegraph.org
Hi Josue,

take a look at osganimationviewer example.

Mourad

Mr Alji

unread,
Mar 24, 2011, 8:47:51 AM3/24/11
to OpenSceneGraph Users
Hi Josue & Morad,

Here is a newbie explanation :
  • First time, you need to know that the osgDB library provides access to a lot of 2D and 3D files ( like .fbx ), by managing several osg plugins.
  • You intend to use an fbx file, so you need to check if the plugin "FBX reader/writer" is correctly installed.
  • In second, the following snippet enable to load the scene graph of an fbx file:
osg::ref_ptr<osg::Node> root = osgDB::readNodeFile( fbxFile )   
  • Then, locate the AnimationManager you want to use either Basic or Timeline, according to your necessity.
 a02292.png
  • the best way is to use the design pattern Visitor, already implemented in osg::NodeVisitor.
struct AnimationManagerFinder : public osg::NodeVisitor
{
    osg::ref_ptr<osgAnimation::BasicAnimationManager> _am;
   
    AnimationManagerFinder() {setTraversalMode(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN); }
   
    void apply(osg::Node& node) {
   
        if (_am.valid())
            return;
   
        if (node.getUpdateCallback()) {       
            _am = dynamic_cast<osgAnimation::BasicAnimationManager*>(node.getUpdateCallback());
            return;
        }
       
        traverse(node);
    }
};

  • In the previous code snippet, the BasicAnimationManager, if it is found, will be stored on the variable '_am' located at finder._am.
  • in your main function:
AnimationManagerFinder finder;
root->accept(finder);
  • then you can recuperate the AnimationList avalaible in your fbx file like this:
const osgAnimation::AnimationList& animations = finder._am->getAnimationList();
  • Finally, you can do what ever you want: play the animation on the osgViewer, get the Duration, the StartTime, the Name of the animation... specify the PlayMode..
finder._am->playAnimation( animations[an].get() );
 ...
std::cout << "name animation: " << animations[an]->getName() << std::endl;   

I hope I helped :) please feel free to respond to this topic to ameliorate it.
 
Have a nice day
--
M. ALJI Mohamed


a02292.png

Josue Hernandez

unread,
Mar 25, 2011, 12:03:50 PM3/25/11
to osg-...@lists.openscenegraph.org
ok, but what means "an" in the follow line?:

finder._am->playAnimation( animations[an].get() );

and where i can see how can i do this:

Finally, you can do what ever you want: play the animation on the osgViewer, get the Duration, the StartTime, the Name of the animation... specify the PlayMode..

PD the fbx load ok
PD2: sorry if my english is not good

------------------
Read this topic online here:

http://forum.openscenegraph.org/viewtopic.php?p=37887#37887

Josue Hernandez

unread,
Mar 25, 2011, 12:09:49 PM3/25/11
to osg-...@lists.openscenegraph.org
forget what i say about the "an" jeje

------------------
Read this topic online here:

http://forum.openscenegraph.org/viewtopic.php?p=37888#37888

Josue Hernandez

unread,
Mar 30, 2011, 11:37:25 AM3/30/11
to osg-...@lists.openscenegraph.org
good, now i can see my .fbx with animations, but now: how can i separate the different animations the model?

------------------
Read this topic online here:

http://forum.openscenegraph.org/viewtopic.php?p=38077#38077

Thomas Hogarth

unread,
Mar 30, 2011, 7:48:41 PM3/30/11
to osg-...@lists.openscenegraph.org
Hi Josue 
 
>>how can i separate the different animations the model?

When you say seperate animations I assume you mean split one long animation into multiple sub animations. I've written a little tool to help with this. I've attached the source and an example config.

You can use the config file to specify the input and output file, then specify sub animations using start and end frames.

It works in most cases, it does however trip over occasionally, the best bet is to ensure you have a key per frame. If your using 3D Studio you can collapse trajectories to do this for you. This does create bigger files though so I plan to improve it at some points

Cheers
Tom 


anisplit.cpp
splitConfig.xml

Josue Hernandez

unread,
Apr 1, 2011, 11:58:48 AM4/1/11
to osg-...@lists.openscenegraph.org
thank you so much for this, but now i have a problem: how I can get the library osgDB/XmlParser?

another custion: the argument of AnimationSplitter is my .fbx or is something else?

------------------
Read this topic online here:

http://forum.openscenegraph.org/viewtopic.php?p=38166#38166

Thomas Hogarth

unread,
Apr 2, 2011, 9:12:23 AM4/2/11
to osg-...@lists.openscenegraph.org
Hi

I beleive osgDB/XmlPaser is part of osg 2.9.x and higher, the argument passed to the spliter class is an xml file, but for some reason this forum blocks them. Here is the content of the splitConfig.xml file I use.

<?xml version="1.0" encoding="ISO-8859-15"?>
<OsgAnimationTools sourceFile='./Data/BookModel/bookPage.FBX' destinationFile='./Data/BookModel/bookPage.osgb' fps='30'>
<AnimationSplit sourceAnimation='Take 001'>
<NewAnimation name='IdleClosed' startFrame='0' endFrame='1'/>
<NewAnimation name='AnimateOpen' startFrame='2' endFrame='30'/>
<NewAnimation name='IdleRightOpen' startFrame='31' endFrame='34'/>
<NewAnimation name='RightPageTurn' startFrame='36' endFrame='49'/>
<NewAnimation name='IdleLeftOpen' startFrame='50' endFrame='53'/>
<NewAnimation name='LeftPageTurn' startFrame='55' endFrame='70'/>
<NewAnimation name='AnimateClosed' startFrame='71' endFrame='104'/>
</AnimationSplit>
</OsgAnimationTools>

Hope that helps
Tom

------------------
Read this topic online here:

http://forum.openscenegraph.org/viewtopic.php?p=38173#38173

Josue Hernandez

unread,
Apr 4, 2011, 4:24:11 PM4/4/11
to osg-...@lists.openscenegraph.org
ok, now i have osg 2.9.11 and no longer mark error, but where i can specific my .fbx file?, i try to find it, but I could not

------------------
Read this topic online here:

http://forum.openscenegraph.org/viewtopic.php?p=38204#38204

Melanie Presa

unread,
Apr 4, 2011, 10:09:46 PM4/4/11
to osg-...@lists.openscenegraph.org
I've made a model in 3Ds Max 2011 and animated it. After seeking help I was told to re-export the model, cooking the animations into the .fbx file.
My problem now is that I don't know how to access the animations within Visual Studio/XNA in order to play them as my character walks/runs..

------------------
Read this topic online here:

http://forum.openscenegraph.org/viewtopic.php?p=38209#38209

Josue Hernandez

unread,
Apr 6, 2011, 10:40:05 AM4/6/11
to osg-...@lists.openscenegraph.org
well, with this file you can see the animation of your .fbx,

------------------
Read this topic online here:

http://forum.openscenegraph.org/viewtopic.php?p=38260#38260


Attachments:
http://forum.openscenegraph.org//files/animacionfbx_575.cpp

Josue Hernandez

unread,
Apr 6, 2011, 1:38:21 PM4/6/11
to osg-...@lists.openscenegraph.org
thank you, now i can separate the animations, but when i change the destinationFile in .fbx file, the animation were not created. why?

------------------
Read this topic online here:

http://forum.openscenegraph.org/viewtopic.php?p=38264#38264

Thomas Hogarth

unread,
Apr 6, 2011, 3:01:25 PM4/6/11
to osg-...@lists.openscenegraph.org
Hi

There is no write functionality for the fbx plugin, this is why you need to use .osgb. Once converted there is no difference to using fbx other then you can't re open it in 3ds max etc.

Cheers
Tom

Josue Hernandez

unread,
Apr 6, 2011, 4:05:09 PM4/6/11
to osg-...@lists.openscenegraph.org
i understend, but how i can change that?, because i need do this but the file should remain as .fbx

------------------
Read this topic online here:

http://forum.openscenegraph.org/viewtopic.php?p=38272#38272

Josue Hernandez

unread,
Apr 11, 2011, 1:36:55 PM4/11/11
to osg-...@lists.openscenegraph.org
Hi, this is the code that i'm using:

#include <osg/Node>
#include <osg/MatrixTransform>
#include <osg/Group>
#include <osg/Timer>
#include <osgGA/TrackBallManipulator>
#include <osgDB/ReadFile>
#include <osgDB/WriteFile>
#include <osgViewer/Viewer>
#include <iostream>
#include <osgViewer/ViewerEventHandlers>
#include <osgAnimation/BasicAnimationManager>
using namespace std;

static osg::Timer_t old_tick,new_tick;
int bandera=0;
static double delta;

class tankControll: public osgGA::GUIEventHandler{
public:
tankControll(){
acc=0;
};
virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa){
if(ea.getEventType()==osgGA::GUIEventAdapter::KEYDOWN && (ea.getKey()=='q' || ea.getKey()=='Q')){
bandera=0;
bandera=1;
return true;
}else if(ea.getEventType()==osgGA::GUIEventAdapter::KEYDOWN && (ea.getKey()=='w' || ea.getKey()=='W')){
bandera=0;
bandera=2;
return true;
}else if(ea.getEventType()==osgGA::GUIEventAdapter::KEYDOWN && (ea.getKey()=='e' || ea.getKey()=='E')){
bandera=0;
bandera=3;
return true;
}else if(ea.getEventType()==osgGA::GUIEventAdapter::KEYDOWN && (ea.getKey()=='a' || ea.getKey()=='A')){
bandera=0;
bandera=4;
return true;
}else if(ea.getEventType()==osgGA::GUIEventAdapter::KEYDOWN && (ea.getKey()=='s' || ea.getKey()=='S')){
bandera=0;
bandera=5;
return true;
}else if(ea.getEventType()==osgGA::GUIEventAdapter::KEYDOWN && (ea.getKey()=='d' || ea.getKey()=='D')){
bandera=0;
bandera=6;
return true;
}else{
return false;
}
}
private:
int acc;
};

struct AnimationManagerFinder : public osg::NodeVisitor
{
osg::ref_ptr<osgAnimation::BasicAnimationManager> _am;

AnimationManagerFinder() {setTraversalMode(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN); }

void apply(osg::Node& node) {

if (_am.valid())
return;

if (node.getUpdateCallback()) {
_am = dynamic_cast<osgAnimation::BasicAnimationManager*>(node.getUpdateCallback());
return;
}

traverse(node);
}
};


int main()
{
osg::ref_ptr<osg::Node> escena = osgDB::readNodeFile("Lerpz.osgb");
if (!escena){
cout<<"I´m not reading"<<endl;
//exit(0);
}

AnimationManagerFinder finder;
escena->accept(finder);

const osgAnimation::AnimationList& animations = finder._am->getAnimationList();

tankControll *eh=new tankControll();

osgViewer::Viewer visor;

visor.setSceneData(escena);
visor.addEventHandler(eh);
/*if(bandera==1)
finder._am->playAnimation( animations[1].get() );
else if(bandera==2)
finder._am->playAnimation( animations[2].get() );
else if(bandera==3)
finder._am->playAnimation( animations[3].get() );*/

visor.setCameraManipulator(new osgGA::TrackballManipulator);

visor.realize();
while ( !visor.done()){
//while (bandera!=6){

if (bandera==1)
finder._am->playAnimation( animations[1].get() );
else
if (bandera==2)
finder._am->playAnimation( animations[2].get() );
else
if (bandera==3)
finder._am->playAnimation( animations[3].get() );
else
printf("%i",bandera);

visor.frame();

}

return visor.run();

}

the problem is the follow: when i press the w after the q, or e, it seems that animations are one over the other, why it happens?

...

Thank you!

Cheers,
Josue

------------------


Read this topic online here:

http://forum.openscenegraph.org/viewtopic.php?p=38406#38406

Josue Hernandez

unread,
Apr 13, 2011, 11:42:34 AM4/13/11
to osg-...@lists.openscenegraph.org

tomhog wrote:
> Hi
>
> how I can stop an animation?
>
>
> Cheers
> Tom
>
> ------------------
> Post generated by Mail2Forum


------------------
Read this topic online here:

http://forum.openscenegraph.org/viewtopic.php?p=38444#38444

Reply all
Reply to author
Forward
0 new messages