|
本帖最后由 1162810317 于 2013-4-22 21:03 编辑
- class FillEmptyNode :
- public osg::NodeVisitor
- {
- public:
- int count;
- //所有的顶点
- osg::ref_ptr<osg::Node> childrenNode;
- //构造函数,选择向下遍历全孩子的方式
- FillEmptyNode() : osg::NodeVisitor(osg::NodeVisitor ::TRAVERSE_ALL_CHILDREN)
- {
- childrenNode = new osg::Node;
- count=0;
- // Modelinfoconfig = new Config("MTNode.ini");
- osg::ref_ptr<osg::Node> songshu=osgDB::readNodeFile("songshu.ive");
- osg::ref_ptr<osg::Node> wutong=osgDB::readNodeFile("wutong.ive");
- osg::ref_ptr<osg::Node> yushu= osgDB::readNodeFile("yushu.ive");
- osg::ref_ptr<osg::Node> liushu= osgDB::readNodeFile("liushu.ive");
- lodsong = new osg::LOD ;
- lodsong->addChild(songshu,0,500);
- lodyu = new osg::LOD ;
- lodyu->addChild(yushu,0,500);
- lodliu = new osg::LOD ;
- lodliu->addChild(liushu,0,500);
- lodwu = new osg::LOD ;
- lodwu->addChild(wutong,0,500);
- lodsushe = new osg::LOD ;
- lodsushe->addChild(osgDB::readNodeFile("sushe.ive"),0,500);
- map.insert(pair<std::string,osg::ref_ptr<osg::LOD>>("liush",lodliu));
- map.insert(pair<std::string,osg::ref_ptr<osg::LOD>>("songs",lodsong));
- map.insert(pair<std::string,osg::ref_ptr<osg::LOD>>("wuton",lodwu));
- map.insert(pair<std::string,osg::ref_ptr<osg::LOD>>("yushu",lodyu));
- map.insert(pair<std::string,osg::ref_ptr<osg::LOD>>("sushe",lodsushe));
- }
- osg::Matrix getMatrix(){return wMatrix;}
- //apply
- void apply( osg::Transform & node );
- ~FillEmptyNode(void);
- std::map< std::string, int> modelmap;
- std::map<std::string,osg::ref_ptr<osg::LOD>> map ;
- std::map<std::string,osg::ref_ptr<osg::LOD>>::iterator ite;
- //const std::string configfile = "MTNode.ini";
- Config * Modelinfoconfig ;
- public:
- osg::ref_ptr<osg::LOD> lodsong;
- osg::ref_ptr<osg::LOD> lodyu;
- osg::ref_ptr<osg::LOD> lodliu;
- osg::ref_ptr<osg::LOD> lodwu;
- osg::ref_ptr<osg::LOD> lodsushe;
- private:
- osg::Matrix wMatrix;
- };
- void FillEmptyNode::apply( osg::Transform & node ) //我试过osg::node ,也没用,,不知道有什么区别没?
- {
-
- {
- std::string str = node.getName();
- std::string strf;
-
- if(str!=""&&str.length()<10)
- {
- strf= str.substr(0,5);
- count++;
- ite=map.find(strf);
- if (ite!=map.end())
- {
- node.asGroup()->addChild(ite->second);
- }
- }
- }
- traverse( node);
- }
复制代码
我在地形优化中添加了MT节点。然后读取这个地形,想通过遍历节点给MT挂上模型,,,但不知道为什么程序运行后出错,请大神们指教!
谢谢! |
|