Hi,

I think you record key in global space and replaying in a a sub tree
node that is not in the same space.

I can't help more without a sample code ready to build and data that
produce the problem. Just some remarks. I am not sure you need skinning,
then use only an UpdateTransform callback you will not need skeleton and
bone, so it will be easier to setup (there are example in osg)

Cheers,
Cedric
-  
+33 659 598 614  Cedric Pinson mailto:[email protected]
http://www.plopbyte.net


On Sun, 2009-08-30 at 20:07 +0000, Bao-Anh Dang-Vu wrote:
> Hi,
> 
> Thank you for your reply.
> I have attached a sample of code, that presents how I create my
> animation.
> 
> Cheers,
> Bao-Anh.
> 
> --8<---------------cut here---------------start------------->8---
> // The Callback that refreshes the animation and creates frames.
> class codaNodeCallback : public osg::NodeCallback
> {
> public:
>  codaNodeCallback(unsigned id, osgAnimation::Vec3KeyframeContainer* key)
>    : id_(id), key_(key), frame_nb_(0)
>  {}
> 
>  virtual void operator()(osg::Node* node, osg::NodeVisitor* nv)
>  {
>    osg::ref_ptr<osg::Geode> codaData = node->asGeode();
>    if (codaData)
>    {
>      osg::Vec3 position(getPositionX(id_),
>                         getPositionY(id_),
>                         getPositionZ(id_));
> 
>      // Add a frame to the animation.
>      key_->push_back(osgAnimation::Vec3Keyframe(++frame_nb_, position));
> 
>      // Also display the Sphere in real-time.  We got the expected behavior.
>      osg::Sphere* s = new osg::Sphere(position, RAYON);
>      codaData->replaceDrawable(codaData->getDrawable(0),
>                                new osg::ShapeDrawable(s));
> 
>    }
>    traverse(node, nv);
>  }
> 
> private:
>  unsigned id_;
>  osgAnimation::Vec3KeyframeContainer* key_;
>  unsigned frame_nb_;
> };
> 
> 
> // The creation of the animation.
> 
> osg::ref_ptr<osgAnimation::Skeleton> skelroot = new osgAnimation::Skeleton;
> skelroot->setDefaultUpdateCallback();
> 
>  // The bone that follows some positions.
> osg::ref_ptr<osgAnimation::Bone> bone = new osgAnimation::Bone;
> bone->setBindMatrixInBoneSpace(osg::Matrix::translate(1,0,0));
> bone->setName("a bone");
> bone->setDefaultUpdateCallback("a bone");
> skelroot->addChild(bone.get());
> 
> osg::Node* sphereNode = createSphere(osg::Vec3(0, 0, 0), RAYON);
> bone->addChild(sphereNode);
> 
> osgAnimation::Vec3KeyframeContainer* key = new
> osgAnimation::Vec3KeyframeContainer;
> 
> // We also display the position in realtime.  Hence, the callback records
> // the animation.
> 
> sphereNode_realtime->addUpdateCallback(new codaNodeCallback(0, key));
> root_realtime->addChild(sphereNode);
> viewer.setSceneData(root_realtime);
> viewer.run();
> 
> // When the view is done, we save the animation.
> 
> osg::Group* scene = new osg::Group;
> osg::ref_ptr<osgAnimation::BasicAnimationManager> manager =
>       new osgAnimation::BasicAnimationManager;
> scene->setUpdateCallback(manager.get());
> 
> osgAnimation::Animation* anim = new osgAnimation::Animation;
> 
> osgAnimation::Vec3LinearSampler* sampler = new 
> osgAnimation::Vec3LinearSampler;
> sampler->setKeyframeContainer(key);
> 
> osgAnimation::Vec3LinearChannel* channel = new
> osgAnimation::Vec3LinearChannel(sampler);
> channel->setName("position");
> channel->setTargetName("a bone");
> 
> anim->addChannel(channel);
> 
> manager->registerAnimation(anim);
> manager->buildTargetReference();
> 
> // Then, we add some root nodes, it comes from the example
> // “osganimationskinning” and stay a little bit fuzzy.
> 
> osg::MatrixTransform* trueroot = new osg::MatrixTransform;
> trueroot->setMatrix(osg::Matrix(osg::Matrix::translate(50,50,20).ptr()));
> trueroot->addChild(skelroot.get());
> trueroot->setDataVariance(osg::Object::DYNAMIC);
> rootTransform->addChild(trueroot);
> scene->addChild(rootTransform);
> 
> // We save the scene.
> osgDB::writeNodeFile(*scene, "scene.osg");
> --8<---------------cut here---------------end--------------->8---
> 
> ------------------
> Read this topic online here:
> http://forum.openscenegraph.org/viewtopic.php?p=16854#16854
> 
> 
> 
> 
> 
> _______________________________________________
> osg-users mailing list
> [email protected]
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Attachment: signature.asc
Description: This is a digitally signed message part

_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to