Re: [osg-users] Noob question: how to change osg::Group to osg::Switch
Hi, OSG is very powerful toolkit so I wirte simple nodevisitor class ReplaceGrouptoSwitchVisitor: public osg::NodeVisitor { public: ReplaceGrouptoSwitchVisitor(const std::string& name) : osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN), _name(name) { } virtual void apply(osg::Group& group) { if (group.getName() == _name) { _GroupNodeList.insert(&group); } traverse(group); } virtual void replace() { for(NodeList::iterator itr=_redundantNodeList.begin(); itr!=_redundantNodeList.end(); ++itr) { osg::ref_ptr group = dynamic_cast(*itr); if (group.valid()) { osg::Node::ParentList parents = group->getParents(); for(osg::Node::ParentList::iterator pitr=parents.begin(); pitr!=parents.end(); ++pitr) { osg::Switch* switch2 = new osg::Switch(); for (unsigned int i = 0; i < group->getNumChildren(); ++i) { switch2->addChild(group->getChild(i)); } (*pitr)->replaceChild(group.get(),switch2); switch2->setSingleChildOn(0); } } } } typedef std::set NodeList; NodeList _GroupNodeList; std::string _name; }; in code you can simply use it by ReplaceGrouptoSwitchVisitor findflame("Flame"); model->accept(findflame); findflame.remove(); ... Thank you! Cheers, Roman -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=29108#29108 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Noob question: how to change osg::Group to osg::Switch
have a look at osg::Group::replaceChild. Get the parents list from the group you want to replace and call parent->replaceChild(group,switch) -Nick On Thu, Jun 17, 2010 at 2:11 PM, Vincent Bourdier < vincent.bourd...@gmail.com> wrote: > Hi, > > You just have to create a new Switch, attach the geodes to it, and get the > parent of the group to attach the switch and remove the group. > Next just check that the geode only have one parent, but I think this would > be enought > > Regards, >Vincent. > > Le 17/06/2010 12:58, Roman Grigoriev a écrit : > > Hi, >> Sorry for noob question but maybe there is example how to change >> this scenegraph >> group -| >> |-geode >> |-geode >> to >> switch-| >> |-geode >> |-geode >> >> ... >> >> Thank you! >> >> Cheers, >> Roman >> >> -- >> Read this topic online here: >> http://forum.openscenegraph.org/viewtopic.php?p=29074#29074 >> >> >> >> >> >> ___ >> 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 > ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Noob question: how to change osg::Group to osg::Switch
Hi, You just have to create a new Switch, attach the geodes to it, and get the parent of the group to attach the switch and remove the group. Next just check that the geode only have one parent, but I think this would be enought Regards, Vincent. Le 17/06/2010 12:58, Roman Grigoriev a écrit : Hi, Sorry for noob question but maybe there is example how to change this scenegraph group -| |-geode |-geode to switch-| |-geode |-geode ... Thank you! Cheers, Roman -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=29074#29074 ___ 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
[osg-users] Noob question: how to change osg::Group to osg::Switch
Hi, Sorry for noob question but maybe there is example how to change this scenegraph group -| |-geode |-geode to switch-| |-geode |-geode ... Thank you! Cheers, Roman -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=29074#29074 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org