5,保存4个一级节点

前面是一个牛和一个滑翔机,位置都在原点,

远处是牛,近处是滑翔机,可以自然而然地把牛当作0级节点,滑翔机作为一级节点,那么,能不能输出四个不同位置的滑翔机,类似于四叉树一样。

没有什么不可以。

输出四个不同位置的osg::MatrixTransform即可。

复制代码
for (int childIndex = 0; childIndex < 4; childIndex++)
{

	std::string strOutputName = strOutputDir + 
		"root_" + std::to_string(rootIndex) +
		"_level_" + std::to_string(level) + 
		"_child_" + std::to_string(childIndex) +".osg";
	osg::Vec3 center = centerVector[childIndex];
	osg::Matrix mat;
	mat.setTrans(center);
	osg::ref_ptr<osg::MatrixTransform> trans = new osg::MatrixTransform();
	trans->setMatrix(mat);
	trans->addChild(node);
	osgDB::writeNodeFile(*trans, strOutputName);
}

代码如下:

#include <osgViewer/Viewer>

#include <osg/Node>

#include <osgdb/ReadFile>

#include <osgDB/WriteFile>

#include <osg/PagedLod>

#include <osgGA/TrackballManipulator>

#include <osg/MatrixTransform>

#include <osg/Matrix>

int main()

{

int rootIndex = 0;

int level = 1;

std::string strOutputDir = "d:/test/1/";

osg::Vec3 center_child0(-5, 0, -5);

osg::Vec3 center_child1(-5, 0, 5);

osg::Vec3 center_child2(5, 0, -5);

osg::Vec3 center_child3(5, 0, 5);

复制代码
std::vector<osg::Vec3> centerVector;
centerVector.clear();
centerVector.push_back(center_child0);
centerVector.push_back(center_child1);
centerVector.push_back(center_child2);
centerVector.push_back(center_child3);
std::string strInputName = "D:/install/osg365_oe210_vs2019/OpenSceneGraph-Data/glider.osg";
osg::ref_ptr<osg::Node> node = osgDB::readNodeFile(strInputName);

for (int childIndex = 0; childIndex < 4; childIndex++)
{

	std::string strOutputName = strOutputDir + 
		"root_" + std::to_string(rootIndex) +
		"_level_" + std::to_string(level) + 
		"_child_" + std::to_string(childIndex) +".osg";
	osg::Vec3 center = centerVector[childIndex];
	osg::Matrix mat;
	mat.setTrans(center);
	osg::ref_ptr<osg::MatrixTransform> trans = new osg::MatrixTransform();
	trans->setMatrix(mat);
	trans->addChild(node);
	osgDB::writeNodeFile(*trans, strOutputName);
}

}

相关推荐
directx3d_beginner7 小时前
1, pagedlod和lod
osg
CHPCWWHSU1 个月前
pointCloudExtractor:一个基于 osgPotree 的 Potree 点云数据提取工具
目标识别·osg·potree·点云提取
CHPCWWHSU2 个月前
CesiumforUnreal环境准备
c++·cesium·unreal·osg
妙为2 个月前
osgEarth中文显示乱码
中文乱码·osgearth·osg
CHPCWWHSU3 个月前
osg中文字的使用
osg·osgtext·text3d
CHPCWWHSU5 个月前
osg中相机矩阵到vsg相机矩阵的转换
opengl·osg·投影矩阵·vulkan·vsg
幽迷狂7 个月前
AFSIM入门教程03.03:更新所有依赖库版本
c++·qt·仿真·osgearth·osg·军事·afsim
星火撩猿10 个月前
如何配置osg编译使支持png图标加载显示
osgearth·osg·地图图标添加
xiyangxiaoguo10 个月前
使用OpenSceneGraph (osg)实现一个星系漫游
osg