[osg-users] Animation of shared model

65 views
Skip to first unread message

Thilo Weigel

unread,
Aug 15, 2012, 5:01:18 PM8/15/12
to osg-...@lists.openscenegraph.org
Hi,

I'd like to place several instances of the same model in a scene and play the model's animation individually on each instance - just like having several nathans standing around and letting each one scratch his head asynchronously to the others.

The model is loaded once and assigned to a osg::Group. The model's instances are placed by attaching the osg::Group to different PositionAttitudeTransforms. Similar code as in the osganimationviewer is used to retrieve the model's osgAnimation::BasicAnimationManager which is then added as an UpdateCallback for each PositionAttitudeTransform.

Obviously, the animations can now only be played synchronously on all instances. How could I achieve being able to start the animation of each instance individually - for example to let each nathan start scratching its head for a few seconds after clicking on it?

Thanks a lot for any hints,

Cheers,
Thilo

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





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

Sergey Polischuk

unread,
Aug 16, 2012, 4:42:54 AM8/16/12
to osg-...@lists.openscenegraph.org
Hi, Thilo.

I believe you can achieve this by creating new top-nodes of animated model (nodes which contain animation manager callback), sharing model itself, and attaching new animation managers to them (sharing existing animations).

Cheers,
Sergey.

16.08.2012, 01:01, "Thilo Weigel" <thilo....@atrics.de>:

Thilo Weigel

unread,
Aug 17, 2012, 6:14:42 AM8/17/12
to osg-...@lists.openscenegraph.org
Hi Sergey,

Thanks for your advice! Unfortunately I'm not sure if I completely understood your solution. Would you mind to help me a little bit further?

Suppose I retrieved the model and the animation manager as follows:
osg::ref_ptr< osg::Node > model = osgDB::readNodeFile("nathan.osg");
osgAnimation::BasicAnimationManager* modelManager = dynamic_cast < osgAnimation::BasicAnimationManager* > (model->getUpdateCallback());

Now I add one of several transforms:
osg::ref_ptr < osg::PositionAttitudeTransform > transform = new PositionAttitudeTransform();
transform->addChild(model);
transform->addUpdateCallback(modelManager.get());

And finally play all animations of the model:
const osgAnimation::AnimationList& animations = modelManager->getAnimationList();
for (unsigned int i=0; i < animations.size(); ++i )
{
modelManager->playAnimation( animations[i].get() );
}

After reading your post I tried not to add the modelManager to the transform but a new animation manger using the existing animations:
osg::ref_ptr < osgAnimation::BasicAnimationManager > manager = new osgAnimation::BasicAnimationManager;
for (unsigned int i = 0; i < modelManager->getAnimationList().size(); ++i)
{
osgAnimation::Animation* animation = new osgAnimation::Animation(*modelManager->getAnimationList()[i]);
// alternatively: osgAnimation::Animation* animation = modelManager->getAnimationList()[i];
manager->registerAnimation(animation);
}
transform->addUpdateCallback(manager);

But with this approach also all animations off all instances are playing in parallel. What am I missing?

Thank you!

Cheers,
Thilo

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

Sergey Polischuk

unread,
Aug 17, 2012, 6:58:52 AM8/17/12
to osg-...@lists.openscenegraph.org
Hi

your transforms(with animation managers) contain original model, which itself have another animation manager, you should move it out
so get original animation manager and keep it, while removing it from original model, then add copy of it to your transforms. If it dont work out well - try to copy animations instead of using shared, i'm not sure if they have different targets and not overriding each other.

Cheers.

17.08.2012, 14:14, "Thilo Weigel" <thilo....@atrics.de>:

Thilo Weigel

unread,
Aug 17, 2012, 10:41:03 AM8/17/12
to osg-...@lists.openscenegraph.org
Hi Sergey,

I removed the animation manager from the original model:
model->removeUpdateCallback(model->getUpdateCallback());
and created a new animation manager with clones of the original animations:
osg::ref_ptr < osgAnimation::BasicAnimationManager > manager = new osgAnimation::BasicAnimationManager;
for (unsigned int i = 0; i < modelManager->getAnimationList().size(); ++i)
{
osgAnimation::Animation* animation = dynamic_cast < osgAnimation::Animation* >(modelManager->getAnimationList()[i]->clone(osg::CopyOp::DEEP_COPY_ALL));
manager->registerAnimation(animation);
}
transform->addUpdateCallback(manager);

The animations are still played on all instances - even if I add the animation manager to only the first transform.
Do I have to remove more than just the updateCallback of the original model? How is it possible that the animation is played on the second instance even if there is no (animation) updateCallback added to it?

Thank you!

Cheers,
Thilo

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

Sergey Polischuk

unread,
Aug 17, 2012, 11:12:31 AM8/17/12
to osg-...@lists.openscenegraph.org
Hi

I checked osgAnimation sources, and it looks like what you want can be done that easy. Animation calculation happens in update traversal, and directly changes RigGeometry vertex data, so with shared rig geometry all instances will look same. So i believe you need at least to create different RigGeometries in order to have different animations(though you can share source geometry between them).

Cheers.

17.08.2012, 18:41, "Thilo Weigel" <thilo....@atrics.de>:

Thilo Weigel

unread,
Aug 18, 2012, 3:32:48 PM8/18/12
to osg-...@lists.openscenegraph.org
Hi Sergey,

Ok, thanks. I'll do that.

Cheers,
Thilo

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=49323#49323
Reply all
Reply to author
Forward
0 new messages