[osg-users] How to correctly manage animations?

185 views
Skip to first unread message

alessandro terenzi

unread,
Jun 1, 2010, 5:22:33 PM6/1/10
to OpenSceneGraph Users
I'm trying to manage animations in my application and I'm looking at the osganimationviewer example to try to understand how to do it. So far I have done something like this:

1) I use a node visitor that looks for an AnimationManagerBase
2) if the visitor manage to find an AnimationManagerBase then I get its AnimationList
4) then I create a new BasicAnimationManager from the AnimationManagerBase
3) and for each animation in AnimationList I call setPlayMode(osgAnimation::Animation::LOOP) and the playAnimation() method for the BasicAnimationManager

but animations do not start. Am I missing something?

Thanks.
Alessandro

Cedric Pinson

unread,
Jun 1, 2010, 6:06:05 PM6/1/10
to OpenSceneGraph Users
Hi Alessandro,

Which version of osg are you using ?
do you have a small sample code that reproduce the problem ?

Cheers
Cedric

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

--
Provide OpenGL, WebGL and OpenSceneGraph services
+33 659 598 614 Cedric Pinson mailto:cedric...@plopbyte.net
http://www.plopbyte.net

signature.asc

alessandro terenzi

unread,
Jun 1, 2010, 6:12:47 PM6/1/10
to cedric...@plopbyte.net, OpenSceneGraph Users
Hi Cedric,
I'm using OSG 2.9.6 (61) but with the latest osgAnimation from svn (2.9.8). I added these lines to osgviewer (just before setting scene data):

AnimationManagerFinder finder;
loadedModel->accept(finder);
if(finder._am.valid())
{
    osg::notify(osg::WARN) << "osgAnimation::AnimationManagerBase found in the subgraph..." << std::endl;
    loadedModel->setUpdateCallback(finder._am.get());
}
else
{
    osg::notify(osg::WARN) << "no osgAnimation::AnimationManagerBase found in the subgraph, no animations available" << std::endl;
}

and I defined the visitor like this:

struct AnimationManagerFinder : public osg::NodeVisitor
{
    osg::ref_ptr<osgAnimation::BasicAnimationManager> _am;
    AnimationManagerFinder() : osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN) {}

    void apply(osg::Node& node)
    {
        if (_am.valid())
            return;

        if (node.getUpdateCallback())
        {
            osgAnimation::AnimationManagerBase* b = dynamic_cast<osgAnimation::AnimationManagerBase*>(node.getUpdateCallback());
            if (b)
            {
                osg::notify(osg::FATAL)<<"found AnimationManagerBase..."<<std::endl;
                _am = new osgAnimation::BasicAnimationManager(*b);

                int i=0;
                osgAnimation::AnimationList animations = b->getAnimationList();
                for (osgAnimation::AnimationList::iterator it = animations.begin(); it != animations.end(); ++it)
                {               
                    osg::notify(osg::FATAL)<<"playing animation: "<<i<<std::endl;
                    (*it)->setPlayMode(osgAnimation::Animation::LOOP);
                    _am->playAnimation(*it);
                    osg::notify(osg::FATAL)<<"animation name: "<<(*it)->getName()<<std::endl;
                    osg::notify(osg::FATAL)<<"animation duration: "<<(*it)->getDuration()<<std::endl;

                    i++;
                }

                return;
            }
        }
        traverse(node);
    }
};

And tried with a simple FBX model, but animation do not play.

Thanks.
Alessandro

Cedric Pinson

unread,
Jun 1, 2010, 7:37:38 PM6/1/10
to alessandro terenzi, OpenSceneGraph Users
Hi Alessandro,

Is it possible the problem could be from the fbx file ?
Could you try with nathan.osg from osg-data and tell me if you have the
same problem ?

Cheers,
Cedric

signature.asc

Cedric Pinson

unread,
Jun 2, 2010, 5:55:42 PM6/2/10
to alessandro terenzi, OpenSceneGraph Users
Hi Alessandro,

Yeah the list of animation is copied. Good to know it works now. I added
this to the mailing list for log for other users.

Cheers,
Cedric

On Wed, 2010-06-02 at 23:30 +0200, alessandro terenzi wrote:
> Ok, I think I found where the problem was...I was doing something like
> this:
>
> // in the apply method...
> ...
> osgAnimation::AnimationManagerBase* b = ...
> ...
> osgAnimation::BasicAnimationManager _am;


> _am = new osgAnimation::BasicAnimationManager(*b);

> osgAnimation::AnimationList animations = b->getAnimationList();
> for (osgAnimation::AnimationList::iterator it = animations.begin();
> it != animations.end(); ++it)
> {

> _am->playAnimation(*it);
> }
> ...
>
> and animations were not played during the update traversal. Then I
> replaced b with _am this solved the problem, so I did something like
> this:
>
> // in the apply method...
> ...
> osgAnimation::AnimationManagerBase* b = ...
> ...
> osgAnimation::BasicAnimationManager _am;


> _am = new osgAnimation::BasicAnimationManager(*b);

> osgAnimation::AnimationList animations = _am->getAnimationList();


> for (osgAnimation::AnimationList::iterator it = animations.begin();
> it != animations.end(); ++it)
> {

> _am->playAnimation(*it);
> }
> ...
>
> I realized that in the 1st case the animation was not found in the
> list of animations of the BasicAnimationManager _am, so it was not
> actually played. I thought that the list was the same of the
> AnimationManagerBase b, but actually it is not (or, at least, it is
> not the same for the comparison carried on inside playAnimation(.)).
>
> Alessandro
>
>
> On Wed, Jun 2, 2010 at 5:33 PM, alessandro terenzi
> <a.te...@gmail.com> wrote:
> No progress on my side...
>
> I'm attacching the OSG model converted from FBX...
>
> Alessandro
>
>
>
> On Wed, Jun 2, 2010 at 4:09 PM, Cedric Pinson
> <cedric...@plopbyte.net> wrote:
> Hi,
> I dont have fbx plugin could you convert the fbx file
> to .osg , I would
> like to check if your fbx file converted to osg works
> in
> osganimationviewer.
>
> Any progress about your problem ?
>
> Cheers,
> Cedric
>
> On Wed, 2010-06-02 at 12:18 +0200, alessandro terenzi
> wrote:
>
>
> > By the way, here is a sample FBX model to test if
> you need it...please
> > note that this require the latest fix by Michael
> Platings in order to
> > work.
> >
> > Alessandro
> >
> > On Wed, Jun 2, 2010 at 11:49 AM, alessandro terenzi
> > <a.te...@gmail.com> wrote:
> > Yes, same thing, but while the FBX animation
> is played, the
> > nathan.osg files doesn't show any geometry,
> just the xyz axes.
> > So just to be clear:
> >
> > osganimationviewer:
> >
> > - plays FBX animations
> > - doesn't display nathan.osg model
> >
> > osgviewer (with the modifications I sent
> earlier and that I
> > took from osganimationviewer example):
> >
> > - doesn't play animation (FBX)
> > - doesn't display nathan.osg model
> >
> > I'm using OSG 2.9.6 with osgAnimation from
> OSG 2.9.8. Finally,
> > the same happens if I use osgviewer from OSG
> 2.9.8 with my
> > modifications.
> >
> > Regards.
> > Alessandro
> >
> >
> >
> > On Wed, Jun 2, 2010 at 11:28 AM, Cedric


> Pinson
> > <cedric...@plopbyte.net> wrote:
> > Hi Alessandro,
> >

> > Same thing with osganimationviewer ?
> I will have a
> > look this afternoon
> >
> > Cheers,
> > Cedric
> >
> >
> > On Wed, 2010-06-02 at 10:27 +0200,
> alessandro terenzi
> > wrote:
> > > I've tried also with osg 2.9.8 and
> nathan.osg but
> > animation is not
> > > played...looking at the console I
> see lots of errors
> > like this:
> > >
> > > ...
> > > 0192CFB8 RigTransformSoftware no
> source geometry
> > found on RigGeometry
> > > ...
> > >
> > > Alessandro
> > >
> > > On Wed, Jun 2, 2010 at 9:53 AM,
> alessandro terenzi
> > > <a.te...@gmail.com> wrote:
> > > I've tried to load
> nathan.osg but nothing is
> > displayed at
> > > all...also I tried
> avatar.osg and again no
> > geometry is
> > > displayed. On the other
> hand the cow.osg
> > model is displayed
> > > correctly. Do I need any
> "wrapper" to read
> > osg models with
> > > animations even if I'm
> using osg 2.9.6 (61)?


> > >
> > > Alessandro
> > >
> > >
> > >
> > > On Wed, Jun 2, 2010 at

> 1:37 AM, Cedric

signature.asc

alessandro terenzi

unread,
Jun 3, 2010, 10:29:36 AM6/3/10
to cedric...@plopbyte.net, OpenSceneGraph Users
I'd like to understand how to use animations more in depth, so I still have a question about their management. Looking at the examples and our previous discussions, I understand that I have to:

1) create a visitor that looks for an AnimationManagerBase object
2) from the found AnimationManagerBase object I have to create a BasicAnimationManager object that is the one that allow me to play/stop animations...
3) finally set the UpdateCallback (of the model containing the animations) to the newly created BasicAnimationManager

I realized that if I skip step 3, there is no mean to play animations later. Now my question is:

is it possible to replace the found AnimationManagerBase callback with the BasicAnimationManager during the visitor traversal instead of setting the UpdateCallback of the node where the search started from?

Actually this is what I did and seems to work, but I wonder if there could be some side-effect that I cannot imagine right now.

Thanks.
Alessandro
Reply all
Reply to author
Forward
0 new messages