#include "stdafx.h"
#include <windows.h>
#include <osgViewer/Viewer>
#include <osg/Node>
#include <osg/Geode>
#include <osg/Geometry>
#include <osg/Group>
#include <osg/Switch>
#include <osg/Billboard>
#include <osg/Texture2D>
#include <osg/Image>
#include <osg/Vec3>
#include <osg/Vec2>
#include <osg/PositionAttitudeTransform>
#include <osg/MatrixTransform>
#include <osgDB/ReadFile>
#include <osgDB/WriteFile>
#include <osgUtil/Optimizer>
#include <osg/PagedLOD>
#include <osgSim/Impostor>
#include <osgViewer/ViewerEventHandlers> //事件监听
#include <osgGA/StateSetManipulator> //事件响应类,对渲染状态进行控制
#include <osgUtil/Simplifier> //简化几何体
#pragma comment(lib, "OpenThreadsd.lib")
#pragma comment(lib, "osgd.lib")
#pragma comment(lib, "osgDBd.lib")
#pragma comment(lib, "osgUtild.lib")
#pragma comment(lib, "osgGAd.lib")
#pragma comment(lib, "osgViewerd.lib")
#pragma comment(lib, "osgTextd.lib")
#pragma comment(lib, "osgSimd.lib")
osg::ref_ptr<osg::Group> createPagedLOD()
{
osg::ref_ptr<osg::PagedLOD> page = new osg::PagedLOD();
page->setCenter(osg::Vec3(0.0f, 0.0f, 0.0f));
page->setFileName(0, "cow.osg");
page->setRange(0, 0.0f, 50.0f);
page->setFileName(1, "glider.osg");
page->setRange(1, 50.0f, 100.0f);
page->setFileName(2, "cessna.osg");
page->setRange(2, 100.0f, 200.0f);
return page.get();
}
int main()
{
osg::ref_ptr<osgViewer::Viewer> viewer = new osgViewer::Viewer();
osg::ref_ptr<osg::Group> root = new osg::Group();
osg::ref_ptr<osg::MatrixTransform> mt = new osg::MatrixTransform();
mt->addChild(createPagedLOD());
osg::Matrix m;
m.makeRotate(60.0f, 0.0f, 0.0f, 1.0f);
mt->setMatrix(m);
root->addChild(mt.get());
osgDB::writeNodeFile(*root, "page.osg");
osgUtil::Optimizer optimizer;
optimizer.optimize(root.get());
viewer->setSceneData(root.get());
viewer->realize();
viewer->run();
return 0;
}
比较遗憾的是,在VS2017下PagedLOD分页细节层次节点实例代码无法正常运行,OSG版本3.6.4 ,希望有大神告知为何?
已经解决:模型太大,用滚轮调好角度不停的放大即可找到模型!