Hi William, On Tue, Sep 28, 2010 at 9:24 AM, william nily <william.n...@gmail.com> wrote: > Since the StateSet inherits from Object,so i can setName to a specific > StateSet.Then can I find the StateSet by its name?Is there any way to do > this such like to find a Node through its name?
The tool for the job is a custom NodeVisitor, which does the traversal of the scene graph for you and then picks out the StateSet's on all the Node and Drawables. Something like: class MyFindStateSet : public osg::NodeVisitor { public: std::string _name; MyFindStateSet(const std::string& name): osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN), _name(name) {} void checkStateSet(const osg::StateSate* stateset) { if (node.getStateSet() && node.getStateSet()->getName()==_name) { // found a node with a the correct stateset, now do what you want... } } void apply(osg::Node& node) { checkStateSet(node.getStateSet()); // must traverse children otherwise we want descend scene graph traverse(node); } void apply(osg::Geode& geode) { checkStateSet(geode.getStateSet()); // traverse the drawables of the geode. for(unsigned int i = 0; i<geode.getNumChildren(); ++i) { checkStateSet(geode.getDrawable(i)->getStateSet()); } } }; .. { .. // now create the visitor and pass it to the scene graph to do the traversal MyFindStateSet mfss("mystateset"); myscenegraph->accept(mffs); .. } For further examples of NodeVisitor's in action just do a search of the OSG code base, you'll find many of them all over the place. It's one of the most useful classes in the OSG. Robert. _______________________________________________ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org