Hello Trajce,
I have osg file and I am doing traversal to get nodes with given
name. In the osg file, I see the Geode with the name, however the
visitor never gets there
[...]
virtual void apply(osg::Group& node)
{
for (unsigned int i=0; i<node.getNumChildren(); ++i)
{
traverse(*node.getChild(i));
}
}
Well first of all, you don't need this, the osg::NodeVisitor base class
version of apply(osg::Group&) will traverse all children of a group already.
virtual void apply(osg::Geode& node)
{
osg::Node::DescriptionList& dl = node.getDescriptions();
osg::Node::DescriptionList::iterator itr = dl.begin();
for (; itr != dl.end(); ++itr)
{
if (itr->find_first_of("#MIRROR") != std::string::npos)
{
std::cout << "Never gets here !" << std::endl;
}
}
traverse(node);
}
Here, you're not checking the node's name, you're checking its
description list... In addition, find_first_of doesn't do what you think
it does. It finds the first occurence of *any* of the characters in the
string you pass (so the first occurence of either '#' 'M' 'I'...). Try
this instead:
virtual void apply(osg::Geode& node)
{
if (node.getName().find("#MIRROR") != std::string::npos)
{
std::cout << "Should get here if one of the Geodes' name has
#MIRROR in it" << std::endl;
}
traverse(node);
}
std::string::find returns the first occurrence of the argument within
the string object you call it on, or std::string::npos if not found.
Also note that you're only checking Geodes here... If you want to find
any node that has #MIRROR in its name, you might want to override the
apply(osg::Node& node), which will be called for all types of nodes (as
long as you don't override other versions of apply() ).
And a little tip I imagine you know, but just in case: you can write
your scene graph to a .osg file (either with osgDB::writeNodeFile() in
code or with osgconv on the command line) and then inspect it with a
text editor to make sure one of the nodes really has #MIRROR in its name.
Hope this helps,
J-S
--
______________________________________________________
Jean-Sebastien Guay [email protected]
http://www.cm-labs.com/
http://whitestar02.webhop.org/
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org