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<osg::Group> group =
dynamic_cast<osg::Group*>(*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<osg::Node*> 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
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org