zoukankan      html  css  js  c++  java
  • NodeVisitor的使用-遍历Geode节点并在它与父节点之间添加一个LOD节点

    #include <osgNodeVisitor>
    #include <osgMatrixTransform>
    #include <osgPagedLOD>
    #include <osgDBFileNameUtils>
    #include <osgGeode>
    #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;
    };

  • 相关阅读:
    171-滑动窗口问题
    170-133. 克隆图
    169-150. 逆波兰表达式求值
    windows相对路径设置与取消小工具[提效]
    Sword 38
    Sword 33
    Sword 28
    Sword 26
    Sword 12
    Sword 07
  • 原文地址:https://www.cnblogs.com/coolbear/p/4587744.html
Copyright © 2011-2022 走看看