zoukankan      html  css  js  c++  java
  • OSG中找到特定节点的方法(转)

    OSG中找到特定节点的方法

    为了在OSG中找到需要的节点并对节点做出相应的操作,可以从NodeVisitor类中继承一个类,NPS的教程下载文件

    [download id="14"]
    阐述了这个问题。下面是我写的一个类,找到指定名字、指定类型的节点:
    class findGeoNamedNode:
    public osg::NodeVisitor
    {
    public:
    findGeoNamedNode();
    findGeoNamedNode(const std::string name):
    osg::NodeVisitor(TRAVERSE_ALL_CHILDREN) //Set traverse mode
    {
    resultNode=NULL;
    this->name=name;
    }

    virtual void apply(osg::Node &searchNode)
    {
    if(searchNode.getName()==name)
    {
    osg::Geode* dynamicTry=dynamic_cast(&searchNode);

    if(dynamicTry)
    {
    resultNode=dynamicTry;
    }
    }
    traverse(searchNode);
    }

    osg::Geode* getNode()
    {
    return resultNode;
    }
    private:
    osg::Geode* resultNode;
    std::string name;
    };
    使用这个VISITOR类只需要调用以下的一些函数
    osg::Node* testNode=NULL;
    testNode=dynamic_cast(osgDB::readNodeFile("d:\1.3ds"));

    findGeoNamedNode* visitor=new findGeoNamedNode("Box01");
    testNode->accept(*visitor);
    用起来很方便,得益于visitor模式的正确应用。
  • 相关阅读:
    ES6 变量的解构赋值
    【js重学系列】new
    【js面试系列】手写常见js方法
    【js重学系列】this
    js-继承
    【js重学系列】数组高阶函数
    【js面试系列】数组去重
    云服务器部署项目-基本使用流程
    mongodb-基本使用
    移动端适配
  • 原文地址:https://www.cnblogs.com/mazhenyu/p/4111313.html
Copyright © 2011-2022 走看看