在osg库类中场景节点中查找geometry类型的节点,需要对场景中的所有节点做一个遍历,以下为osg中Geode类型的节点中遍历查出geometry类型的简约代码。
代码封装在一个函数里面。
void apply(osg::Geode& geode)
{int Num = 0;
for (unsigned int i = 0; i < geode.getNumDrawables(); ++i)
{
osg::Geometry* geom = dynamic_cast<osg::Geometry*>(geode.getDrawable(i));
if (geom)
Num ++;
}
traverse(geode);
}