在osgearth程序的开发过程中,为了提高系统的帧率和运行效率,需要对三维模型进行LOD优化处理,通过使用OSG的osg::LOD类来实现。
如果在osgEarth中直接加载三维模型,当三维模型的数量很多时,会消耗大量的计算机内存,这是个不可取的做法。使用LOD方法处理大量三维模型时,能提升系统的帧率和运行效率,使用LOD加载三维模型如图1所示,使用LOD卸载三维模型如图2所示。
图1 LOD加载三维模型(帧率2.53)
图2 LOD卸载三维模型(帧率31.21)
关键代码如下:
lodmodel ->addChild(model,0,5000);
scale_model ->setMatrix(osg::Matrix::scale(1.0,1.0,1.0));
scale_model ->addChild(lodmodel );
const osg::Matrix model_matrix = scale_model ->getMatrix();
const osg::BoundingSphere model_box = scale_model ->getBound();
osg::Matrix modelMat = osg::Matrix::translate(-model_box .center()) ;
osg::Matrix modelmatrix1 = model_matrix * modelMat ;
osg::Matrix modelmatrix2 = modelmatrix1 * osg::Matrix::rotate(osg::DegreesToRadians(0.0), 1, 0, 0) * osg::Matrix::rotate(osg::DegreesToRadians(0.0), 0, 0, 1)* osg::Matrix::rotate(osg::DegreesToRadians(0.0), 0, 1, 0);
scale_model ->setMatrix(modelmatrix2 ) ;
model_locator = new osgEarth::Util::ObjectLocatorNode( mapNode->getMap());
model_locator ->getLocator()->setPosition(osg::Vec3d(116.823925, 28.753795, 29));
model_locator ->addChild(scale_model );
最近一段时间一直在研究osgEarth和OSG渲染引擎,收获颇多,欢迎志同道合的小伙伴一起交流与合作(QQ:1628271050,请备注OSG开发交流)。另外,相关OSG/osgEarth小项目代码的github存储地址如下:
1、https://github.com/SheyWang/flight_simulation
2、https://github.com/SheyWang/roaming_system
自己在开发系统之前,成功编译了OSG和osgearth,并整理和学习了一些OSG的资料。需要相关资料的小伙伴可以下载,下载地址如下:
1、https://download.csdn.net/download/xiaoyuwang1994/12049698
OSG资料大全,该资源包括了一些入门OSG(OpenSceneGraph)三维图形渲染引擎必看的文档书籍,对三维开发非常有帮助。
2、https://download.csdn.net/download/xiaoyuwang1994/10177254
osgearth2.8帮助文档,自己使用doxygen_1.8.6和htmlhelp.exe编译的osgearth2.8的帮助文档,希望能够帮助到大家。
3、https://download.csdn.net/download/xiaoyuwang1994/10176063
osg完整配置过程(vs2010,win7,win10),本人经过自己的实践成功编译了osg3.4,步骤详尽,编译后自己总结的文档,希望对大家有帮助。