码迷,mamicode.com
首页 > 其他好文 > 详细

NodeVisitor的使用-遍历Geode节点并在它与父节点之间添加一个LOD节点

时间:2015-06-19 10:06:52      阅读:165      评论:0      收藏:0      [点我收藏+]

标签:

#include <osg\NodeVisitor>
#include <osg\MatrixTransform>
#include <osg\PagedLOD>
#include <osgDB\FileNameUtils>
#include <osg\Geode>
#include <strstream>

//只能处理osgExp插件导出的单个ive文件
class InsideLODVisitor : public osg::NodeVisitor
{
public:
InsideLODVisitor(float_rangeScale=50):rangeScale(_rangeScale),
osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN)
{
}
virtual void apply(osg::Geode& geode)
{
//检测是否处理过
if (markedGeode.find(&geode)!=markedGeode.end())
{
return;
}
//记录已经处理
markedGeode.insert(&geode);
//在geode的父节点和geode之间插入一个LOD节点
unsigned int parentNum=geode.getNumParents();
osg::Node::ParentList parents=geode.getParents();
for (osg::Node::ParentList::iterator itr =parents.begin(); itr<parents.end(); itr++)
{
osg::ref_ptr<osg::LOD> lod=new osg::LOD;
lod->addChild(&geode, 0, geode.getBound().radius()*rangeScale);
//osg::ref_ptr<osg::Geode> tmpGeode=dynamic_cast<osg::Geode*>(geode.clone(osg::CopyOp::DEEP_COPY_ALL));
//osgUtil::Simplifier simplifier(0.5);
//tmpGeode->accept(simplifier);
//lod->addChild(tmpGeode, geode.getBound().radius()*rangeScale, FLT_MAX);
(*itr)->replaceChild(&geode, lod);
}
}
private:
std::set<osg::Geode*> markedGeode;
float rangeScale;
};

NodeVisitor的使用-遍历Geode节点并在它与父节点之间添加一个LOD节点

标签:

原文地址:http://www.cnblogs.com/coolbear/p/4587744.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!