|
for(unsigned int k=0; k< mt2->getNumChildren(); k++)
{
osg::ref_ptr<osg::Node> s_node = mt2->getChild(k);
osg::BoundingSphere bs=s_node->computeBound();
float radius = bs.radius();
osg::Vec3f center = bs.center();
mt2->removeChild(s_node);
osg::ref_ptr<osg::Geode> box = new osg::Geode();
box->addDrawable(new osg::ShapeDrawable(new osg::Box(center,radius)));
mt2->addChild( box.get() );
}
mt下的全是小球,现在把sphere 换成box, 为什么是隔一个处理一个
我觉得问题出在 mt2->removeChild(s_node);
mt2->addChild( box.get() );
虽然现在用replaceChild已经解决问题,但是还想研究一下,
如果现在mt2有4个结点,
osg::ref_ptr<osg::Node> s_node = mt2->getChild(1);
mt2->removeChild(s_node);
mt2->addChild( box.get() );
这时mt2的子结点序号? |
|