|
楼主 |
发表于 2011-3-22 09:55:32
|
显示全部楼层
回复 15# aya_daxiang
我不知道您导过flt格式的模型没有,我这儿写了程序试了一下,如果您有时间,请帮忙看看,程序的问题出在哪儿,为什么只能找到g232,而不能找到o232?
程序代码不多,我用的是vs2008,include路径和library目录可能需要改一下,findNodeVisitor.h和findNodeVisitor.cpp没有贴出来,我没办法上传附件!!!
- #include <osgDB/ReadFile>
- #include <osgViewer/Viewer>
- #include <osg/ComputeBoundsVisitor>
- #include "findNodeVisitor.h"
- #include <iostream>
- int main(int argc,char** argv)
- {
- osgViewer::Viewer viewer;
- osg::ref_ptr<osg::Node> root=osgDB::readNodeFile("test2.flt");
- /* Test: just get the boundingbox of the whole model*/
- osg::ComputeBoundsVisitor boundvisitor;
- root->accept(boundvisitor);
- osg::BoundingBox bb;
- bb=boundvisitor.getBoundingBox();
- std::cout<<"root's name: "<<root->getName()<<std::endl;
- std::cout<<bb.xMin()<<" "<<bb.yMin()<<" "<<bb.zMin()<<std::endl
- <<bb.xMax()<<" "<<bb.yMax()<<" "<<bb.zMax()<<std::endl;
- /* get the specified node's bounding box */
- osg::ref_ptr<osg::Node> node=new osg::Node;
- osg::ref_ptr<osg::Group> group=new osg::Group;
- group=root->asGroup();
- //您能找到o232这个模型么?
- findNodeVisitor findNode("g232");
- group->accept(findNode);
-
- for (std::vector<osg::Node*>::iterator itr=findNode.getNodeList().begin();
- itr != findNode.getNodeList().end(); ++itr)
- {
- osg::ComputeBoundsVisitor bv;
- (*itr)->accept(bv);
- osg::BoundingBox bb1;
- bb1=bv.getBoundingBox();
- std::cout<<"the node's name: "<<(*itr)->getName()<<std::endl;
- std::cout<<bb1.xMin()<<" "<<bb1.yMin()<<" "<<bb1.zMin()<<std::endl
- <<bb1.xMax()<<" "<<bb1.yMax()<<" "<<bb1.zMax()<<std::endl;
- }
- viewer.setSceneData(root);
- return viewer.run();
- }
复制代码 |
|