Re: [osg-users] Node callback without being included in the scenegraph
Ok! I managed to do it by putting them in a osg:: Switch and calling morphsGrp- setAllChildrenOff (); But I have performance problems ... to manage various morphs I have followed this model: Code: std::vectorosg::ref_ptrosg::Geometry geoms; morphsGrp = new osg::Switch(); std::vectorosgAnimation::MorphGeometry* morphGeometrys; int morphsCont = 0; for(int i=0;ianimations.size();i++) { if(!animations[i].type.compare(animation)){ ... } else if(!animations[i].type.compare(morph)){ osg::notify(osg::WARN) ...reading morph animations[i].callName std::endl; osg::ref_ptrosg::Node shape0 = osgDB::readNodeFile(animations[i].loadDir); if (!shape0) { std::cerr can't read morphtarget std::endl; } else{ osg::Geometry* geom = osgGenerals::findGeometryNode(shape0)-asGeode()-getDrawable(0)-asGeometry(); if(!geom) { std::cerr can't read geometry std::endl; } else{ geoms.push_back(geom); 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(animations[i].callName); channel0-setName(0); animation-addChannel(channel0); animation-setName(animations[i].callName); animation-computeDuration(); animation-setPlayMode(osgAnimation::Animation::ONCE); m_morphManager-registerAnimation(animation); // initialize with the first shape morphGeometrys.push_back(new osgAnimation::MorphGeometry(*geometryBase)); morphGeometrys[morphsCont]-addMorphTarget(geoms[morphsCont].get()); osg::Geode* geodeMorph = new osg::Geode ; geodeMorph-setName(animations[i].callName); geodeMorph-addDrawable( morphGeometrys[morphsCont]) ; osgAnimation::UpdateMorph* updateMorph = new osgAnimation::UpdateMorph(animations[i].callName); geodeMorph-setUpdateCallback(updateMorph) ; morphsGrp-addChild(geodeMorph); morphsCont++; } } } } 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;imorphGeometrys.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::ONCE); m_morphManager-registerAnimation(animation); osg::Geode* geodeMorph = new osg::Geode ; geodeMorph-addDrawable( morphGeometry) ; geodeMorph-setUpdateCallback( new osgAnimation::UpdateMorph(playMorphs) ) ; morphsGrp-addChild(geodeMorph); morphsGrp-setAllChildrenOff(); morphsGrp-setUpdateCallback(m_morphManager); if(morphGeometry){ geom0-setSourceGeometry( morphGeometry); modelNode-addChild( morphsGrp ) ; return true; } Now I load about 15 morphs and the performance is about 17 frames per second. Loading 3, the performance goes
[osg-users] Node callback without being included in the scenegraph
Hi, I need to update a node that is not included in the scene graph. I define it as follows: Code: for... osg::Geode* geodeMorph = new osg::Geode ; geodeMorph-setName(animations[i].callName); geodeMorph-addDrawable( morphGeometrys[morphsCont]) ; geodeMorph-setUpdateCallback( new osgAnimation::UpdateMorph(animations[i].callName) ) ; grp-addChild(geodeMorph); ... morphsGrp-addChild(geodeMorph); morphsGrp-addChild(grp); morphsGrp-setUpdateCallback(m_morphManager); if(morphGeometry){ geom0-setSourceGeometry( morphGeometry); //modelNode-addChild( morphsGrp ) ; return true; } I only need to update morphGeometry, and I do it with the osg morphing animation system... but if I didn't include morphsGrp in scene, fails to call the callbacks... Is there any other way to do this? Thank you! Cheers, Aitor -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=40528#40528 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Node callback without being included in the scenegraph
Hi, The update callback are called by a visitor (cullvisitor ?) so if the node is not in the scene graph you won't get any chance to have your callback traversed, and called. But you can call the updatevisitor (cullvisitor?) by yourself on a scenegraph you made if I'm not wrong. Hope this helps you Regards, Vincent Le 15/06/2011 15:56, Aitor Ardanza a écrit : Hi, I need to update a node that is not included in the scene graph. I define it as follows: Code: for... osg::Geode* geodeMorph = new osg::Geode ; geodeMorph-setName(animations[i].callName); geodeMorph-addDrawable( morphGeometrys[morphsCont]) ; geodeMorph-setUpdateCallback( new osgAnimation::UpdateMorph(animations[i].callName) ) ; grp-addChild(geodeMorph); ... morphsGrp-addChild(geodeMorph); morphsGrp-addChild(grp); morphsGrp-setUpdateCallback(m_morphManager); if(morphGeometry){ geom0-setSourceGeometry( morphGeometry); //modelNode-addChild( morphsGrp ) ; return true; } I only need to update morphGeometry, and I do it with the osg morphing animation system... but if I didn't include morphsGrp in scene, fails to call the callbacks... Is there any other way to do this? Thank you! Cheers, Aitor -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=40528#40528 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Node callback without being included in the scenegraph
Hi, The callbacks are only performed if it's assigned action is performed and the visitor visits the node where your callback si registered(In your case: the update traversal). But updating a node means not neccesarily that this node must be included in the scenegraph. If you register your update function not your anaimation node, but on any scenegraph node (for exampe the camera) your callback will be invoked and your node be updated, even if it is outside the scenegraph. Cheers, Torben -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=40531#40531 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Node callback without being included in the scenegraph
Hi Torben, But if I register callback in other nodes like this... Code: for(...){ morphGeometrys.push_back(new osgAnimation::MorphGeometry(*geometryBase)); morphGeometrys[morphsCont]-addMorphTarget(geoms[morphsCont].get()); osg::Geode* geodeMorph = new osg::Geode ; geodeMorph-setName(animations[i].callName); geodeMorph-addDrawable( morphGeometrys[morphsCont]) ; osgAnimation::UpdateMorph* updateMorph = new osgAnimation::UpdateMorph(animations[i].callName); geodeMorph-setUpdateCallback(updateMorph) ; morphsGrp-addUpdateCallback(updateMorph); grp-addChild(geodeMorph); } ... morphsGrp-setUpdateCallback(m_morphManager); if(morphGeometry){ geom0-setSourceGeometry( morphGeometry); modelNode-addChild( morphsGrp ) ; return true; } It do the same... nothing... -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=40534#40534 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Node callback without being included in the scenegraph
I can't use morphsGrp-setNodeMask(false)? UpdateMorph does not calculate when Geode is hidden? -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=40535#40535 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org