|
书中简化几何体的例子,编译成功,但是没东西显示
#include<osgViewer/Viewer>
#include<osgViewer/ViewerEventHandlers>
#include<osg/Node>
#include<osg/Geode>
#include<osg/Group>
#include<osg/PositionAttitudeTransform>
#include<osgDB/ReadFile>
#include<osgDB/WriteFile>
#include<osgGA/StateSetManipulator>
#include<osgUtil/Optimizer>
#include<osgUtil/Simplifier>
int main()
{
//osg::ref_ptr<osgViewer::Viewer> viewer=new osgViewer::Viewer();
osgViewer::Viewer viewer;
//切换网格模型,方便比较模型
viewer.addEventHandler(new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet()));
osg::ref_ptr<osg::Group> root=new osg::Group();
//设置样本比率,样本比率越大,简化越少,样本比率越小,简化越多
float sampleRatio=0.3f;
//设置点的最大误差
float maxError=4.0f;
//创建简化对象
osgUtil::Simplifier simplifier(sampleRatio,maxError);
osg::ref_ptr<osg::Node> node1=osgDB::readNodeFile("cow.osg");
//深拷贝牛的模型到node2节点
osg::ref_ptr<osg::Node> node2=(osg::Node*)(node1->clone(osg::CopyOp:EEP_COPY_ALL));
osg::ref_ptr<osg:ositionAttitudeTransform> pat=new osg::PositionAttitudeTransform();
pat->setPosition(osg::Vec3(10.0f,0.0f,0.0f));
//添加子节点
pat->addChild(node2.get());
//简化处理
pat->accept(simplifier);
//添加到场景
root->addChild(node1.get());
root->addChild(pat.get());
//优化场景数据
osgUtil::Optimizer optimizer;
optimizer.optimize(root.get());
viewer.setSceneData(root.get());
return viewer.run();
}
当我把 pat->accept(simplifier);注释之后,可以显示。
是不是简化几何体还要设置什么东西的? |
|