//DEMO20
//功能:输出模型所有的顶点
#include <osgDB/ReadFile>
#include <osgViewer/Viewer>
#include <osg/NodeVisitor>
#include <osg/Geometry>
#include <fstream>
#include <iostream>
//定义一个定点访问的nodevisitor,名字自己取
class VertexExtractor:public osg::NodeVisitor
{
public :
//所有的顶点
osg::ref_ptr<osg::Vec3Array>extracted_verts;
//构造函数,选择向下遍历全孩子的方式
VertexExtractor():osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN)
{
extracted_verts = new osg::Vec3Array;
}
//apply
void apply(osg::Geode& geode)
{
//看看有多少可绘制节点
for(unsigned int i=0;i<geode.getNumDrawables();++i)
{
osg::Geometry* geom = dynamic_cast<osg::Geometry*>(geode.getDrawable(i));
if(!geom)
continue;
//得到可绘制节点的定点序列
osg::Vec3Array * verts =dynamic_cast<osg::Vec3Array*>(geom->getVertexArray());
if(!verts)
continue;
//把顶点序列插入到顶点集中以便输出
extracted_verts->i
osg demo20 输出模型所有结点
最新推荐文章于 2022-11-14 15:57:11 发布
该示例展示了如何使用osg库输出模型的所有顶点。通过定义一个名为VertexExtractor的NodeVisitor类,遍历并提取模型中的顶点信息。在主函数中,加载模型文件,创建并应用VertexExtractor,最后将顶点数据写入到文件中。
摘要由CSDN通过智能技术生成