Hi,
Well, I found a solution, a little sloppy but it works!
The idea is to create a MorphGeometry for each morph, and link these to an
animation with a single channel. Then we will create a main MorphGeometry,
adding each previous MorphGeometrys. This we will associate to an animation
with an equal number of channels than MorphGeometrys.
Do not know why but I had to add one more channel to main MorphGeometry
animation.
Code:
bam = new osgAnimation::BasicAnimationManager;
osg::Group* grp = new osg::Group();
std::string morpths[3] = {"morph0","morph1","morph2"};
for(int i=0;i<3;i++){
osgAnimation::Animation* animation = new
osgAnimation::Animation;
osgAnimation::FloatLinearChannel* channel0 = new
osgAnimation::FloatLinearChannel;
channel0->getOrCreateSampler()->getOrCreateKeyframeContainer()->push_back(osgAnimation::FloatKeyframe(0,0.0));
channel0->getOrCreateSampler()->getOrCreateKeyframeContainer()->push_back(osgAnimation::FloatKeyframe(0.5,1.0));
channel0->getOrCreateSampler()->getOrCreateKeyframeContainer()->push_back(osgAnimation::FloatKeyframe(1.0,0.0));
channel0->setTargetName(morpths[i]);
channel0->setName("0");
animation->addChannel(channel0);
animation->setName(morpths[i]);
animation->computeDuration();
animation->setPlayMode(osgAnimation::Animation::ONCE);
bam->registerAnimation(animation);
// initialize with the first shape
morphGeometrys.push_back(new
osgAnimation::MorphGeometry(*geometryBase));
morphGeometrys[i]->addMorphTarget(geoms[i].get());
osg::Geode* geodeMorph = new osg::Geode ;
geodeMorph->addDrawable( morphGeometrys[i]) ;
geodeMorph->addUpdateCallback( new
osgAnimation::UpdateMorph(morpths[i]) ) ;
grp->addChild(geodeMorph);
}
grp->setCullCallback(new FilterCullCallback());
osgAnimation::Animation* animation = new osgAnimation::Animation;
osgAnimation::MorphGeometry* morphGeometry = new
osgAnimation::MorphGeometry(*geometryBase);
morphGeometry->addMorphTarget(morphGeometrys[0]);
osgAnimation::FloatLinearChannel* channel0 = new
osgAnimation::FloatLinearChannel;
channel0->getOrCreateSampler()->getOrCreateKeyframeContainer()->push_back(osgAnimation::FloatKeyframe(0,0.0));
channel0->getOrCreateSampler()->getOrCreateKeyframeContainer()->push_back(osgAnimation::FloatKeyframe(0.5,1.0));
channel0->getOrCreateSampler()->getOrCreateKeyframeContainer()->push_back(osgAnimation::FloatKeyframe(1.0,0.0));
channel0->setTargetName("playMorphs");
channel0->setName("0");
animation->addChannel(channel0);
for(int i=0;i<morphGeometrys.size();i++){
morphGeometry->addMorphTarget(morphGeometrys[i]);
osgAnimation::FloatLinearChannel* channel0 = new
osgAnimation::FloatLinearChannel;
channel0->getOrCreateSampler()->getOrCreateKeyframeContainer()->push_back(osgAnimation::FloatKeyframe(0,0.0));
channel0->getOrCreateSampler()->getOrCreateKeyframeContainer()->push_back(osgAnimation::FloatKeyframe(0.5,1.0));
channel0->getOrCreateSampler()->getOrCreateKeyframeContainer()->push_back(osgAnimation::FloatKeyframe(1.0,0.0));
channel0->setTargetName("playMorphs");
channel0->setName("0");
animation->addChannel(channel0);
}
animation->setName("playMorphs");
animation->computeDuration();
animation->setPlayMode(osgAnimation::Animation::LOOP);
osg::Geode* geodeMorph = new osg::Geode ;
geodeMorph->addDrawable( morphGeometry) ;
geodeMorph->addUpdateCallback( new
osgAnimation::UpdateMorph("playMorphs") ) ;
grp->addChild(geodeMorph);
bam->registerAnimation(animation);
geom0->setSourceGeometry( morphGeometry);
osg::Group* scene = new osg::Group;
scene->addUpdateCallback(bam);
shape0->addChild( grp ) ;
scene->addChild(shape0);
Thank you!
Cheers,
Aitor
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=39508#39508
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org