Hi, 
 
The nodevisitor seems cannot reach the leaf node when I add two layers of 
groups. like this: 
 
                             root (group)
                            /   |  \
                          group ... group
                        / |  \
                     geode. 
my code is like this, basiclly this is the example of texture2D example: 
virtual void apply(osg::Geode& geode)
{
apply(geode.getStateSet());
for(unsigned int i=0;i<geode.getNumDrawables();++i)
{
apply(geode.getDrawable(i)->getStateSet());
}

traverse(geode);
}
 
//////////////////////////////////////////////////////////////////////////////////////////
 
virtual void apply(osg::Group& group)
{
apply(group.getStateSet());
for(unsigned int i = 0; i < group.getNumChildren(); ++i)
{
apply(*(group.getChild(i)));        // here is the code for group maybe get 
trouble.  
}
traverse(group); 
}
 
/////////////////////////////////////////////////////////////////////////////////////////////////////
 
virtual void apply(osg::Node& node)
{

apply((osg::Geode &)(node));             // this is nothing. 

apply(node.getStateSet());
traverse(node);
}
 
 

inline void apply(osg::StateSet* stateset)
{
if (!stateset) return;

osg::StateAttribute* attr = 
stateset->getTextureAttribute(0,osg::StateAttribute::TEXTURE);
if (attr)
{
osg::Texture2D* texture2D = dynamic_cast<osg::Texture2D*>(attr);
if (texture2D) apply(dynamic_cast<osg::ImageStream*>(texture2D->getImage()));
osg::TextureRectangle* textureRec = dynamic_cast<osg::TextureRectangle*>(attr);
if (textureRec) apply(dynamic_cast<osg::ImageStream*>(textureRec->getImage()));
}
}
 
 
// and when create scene as: 
 
osg::Node* createZYloadWall(osg::BoundingBox& bb)
{
 
// then the original code use a group then add geode by addchild 
// then return the first layer group. 
 
// osg::Group* group = new osg::Group;

osg::Geometry* geom = new osg::Geometry;
 
osg::Geode* geom_geode = new osg::Geode;
geom_geode->addDrawable(geom);
 
// group->addChild(geom); 
 

return geom_geode;

//return group;

}
 
 
// then later add another layer of root. 
{
  
osg::Group* root = new osg::Group();
 
root->addchild(createZYloadWall(osg::BoundingBox& bb)); 
}
 
 
// the problem is that if do it with two layer group, the nodevisitor still can 
go to geod 
by code: 
virtual void apply(osg::Group& group)
{
apply(group.getStateSet());
for(unsigned int i = 0; i < group.getNumChildren(); ++i)
{
apply(*(group.getChild(i)));        // here is the code for group maybe get 
trouble.  
traverse(group); 
}
 
// but the geode looks not right. 
I finally remove one group layer then directly add geode into root, 
then it works, 
So my question is how to traverse with two layer of group, is my code right?
 
Thanks. 
 
Hui


      
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to