|
class VertexVisitor : public osg::NodeVisitor
{
public:
osg::ref_ptr<osg::Vec3Array> extracted_verts; //保存顶点数据
VertexVisitor() : osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN)
{
extracted_verts = new osg::Vec3Array();
}
void apply(osg::Geode& geode) //重载apply方法
{
//得到每一个drawables
for (unsigned int i=0; i<geode.getNumDrawables(); ++i)
{
//得到几何体
osg::Geometry* geom = dynamic_cast<osg::Geometry*>(geode.getDrawable(i));
if(!geom)
{
std::cout<<"几何体错误!"<<std::endl;
continue;
}
//得到顶点数组
osg::Vec3Array* verts = dynamic_cast<osg::Vec3Array*>(geom->getVertexArray());
if(!verts)
{
std::cout<<"顶点数组错误!"<<std::endl;
continue;
}
//添加到extracted_verts
extracted_verts->insert(extracted_verts->end(), verts->begin(), verts->end());
}
}
};
附上测试的ive文件 |
-
-
puget.ive
260.74 KB, 下载次数: 2, 下载积分: 威望 1
测试文件
|