osg demo20 输出模型所有结点

该示例展示了如何使用osg库输出模型的所有顶点。通过定义一个名为VertexExtractor的NodeVisitor类,遍历并提取模型中的顶点信息。在主函数中,加载模型文件,创建并应用VertexExtractor,最后将顶点数据写入到文件中。
摘要由CSDN通过智能技术生成
//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
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值