• 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;
    };

  • 相关阅读:
    工具类--map 转成xml xml转成map
    工具类--MD5Utils
    工具类--敏感信息掩码规则
    spring--Springmvc中@Autowired注解与@Resource注解的区别
    工具类--发送验证码短信
    工具类--日期工具类
    工具类--Excel 导出poi
    Jquery mobile中的 checkbox和radio的设置问题
    ASP和JS读写Cookie的问题
    js获取当前用户IP
  • 原文地址:https://www.cnblogs.com/coolbear/p/4587744.html
Copyright © 2020-2023  润新知