getParentalNodePaths、osg::NodePathList、osg::NodePath详解
osg::NodePathList、osg::NodePath在osg的osg\Node頭文件中定義如下:
可以看到NodePath 是以osg::Node為元素的vector容器,osg::NodePathList是以NodePath為元素的容器。具體說明如下:
類似的,從父節點(或祖宗節點)到當前節點可以有好多路徑。OSG允許一個節點具有多個父節點,在osg::Node類中:
如下圖,假定我們有如下一個場景圖:
從Root節點到Child4節點,共有兩條路徑。分別為:
上面的兩條路徑就是osg::NodePathList容器的元素,即osg::NodePathList[0]就是上面的條目1;osg::NodePathList[1]就是上面的條目2.
osg::NodePathList[0][0]、osg::NodePathList[0][1]、osg::NodePathList[0][2]、osg::NodePathList[0][3]、osg::NodePathList[0][4]對應上面條目1中的Root 、L_Child1、L_Child2?、L_Child3?、 Child4。
osg::NodePathList[1][0]、osg::NodePathList[1][1]、osg::NodePathList[1][2]、osg::NodePathList[1][3]、osg::NodePathList[1][4]對應上面條目1中的Root 、R_Child1、R_Child2?、R_Child3?、Child4 。
如下代碼:
int main(int argc, char** argv) {osg::ref_ptr<osgViewer::Viewer> spViewer = new osgViewer::Viewer();spViewer->setName("Viewer");osg::Camera* pCamera = spViewer->getCamera();pCamera->setName("Camera");osg::ref_ptr<osg::Group> spRoot = new osg::Group();spRoot->setName("Root");osg::ref_ptr<osg::Node>spNode = osgDB::readNodeFile("cow.osg");spNode->setName("Node");spRoot->addChild(spNode.get());spViewer->setSceneData(spRoot);osg::NodePathList lstPath = spNode->getParentalNodePaths();int m = lstPath.size();cout << "Path size:" << m << "\r\n";for (size_t iPathIndex = 0; iPathIndex < lstPath.size(); ++iPathIndex){size_t iNodeSize = lstPath[iPathIndex].size();cout << iPathIndex << "----> size:" << iNodeSize << "\r\n";for (size_t iNodeIndex = 0; iNodeIndex < iNodeSize; ++iNodeIndex){string strName = lstPath[iPathIndex][iNodeIndex]->getName();cout << "Node Name:" << strName << "\r\n";}}return spViewer->run(); }按照上面畫出父子關系圖如下:
結合上面對osg::NodePathList、osg::NodePath、getParentalNodePaths講解,應該能明白程序輸出如下:
總結
以上是生活随笔為你收集整理的getParentalNodePaths、osg::NodePathList、osg::NodePath详解的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 可转债研报阅读笔记
- 下一篇: OSG与opengl的shader结合