|
我现在又一个Creator创建的模型,包括有一个LOD节点,该节点下有三个几何节点,可以找到该LOD节点,但其子节点数总为1,且没有一个是几何节点,请教这是怎么回事呢?查找节点的代码如下:
class findNodeVisitor : public osg::NodeVisitor
{
public:
findNodeVisitor();
findNodeVisitor(const std::string &searchName);
virtual void apply(osg::Node &searchNode);
void setNameToFind(const std::string &searchName);
osg::Node* getFirst();
typedef std::vector<osg::Node*> nodeListType;
nodeListType& getNodeList() { return m_foundNodeList; }
static osg::Node* FindNamed(osg::Node* pParent,const std::string& strName);
private:
std::string m_strSearchForName;
nodeListType m_foundNodeList;
};
findNodeVisitor::findNodeVisitor(const std::string &searchName) :
osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN),
m_strSearchForName(searchName)
{
}
//The 'apply' method for 'node' type instances.
//Compare the 'searchForName' data member against the node's name.
//If the strings match, add this node to our list
void findNodeVisitor::apply(osg::Node &searchNode)
{
if (searchNode.getName() == m_strSearchForName)
{
m_foundNodeList.push_back(&searchNode);
}
traverse(searchNode);
}
// Set the searchForName to user-defined string
void findNodeVisitor::setNameToFind(const std::string &searchName)
{
m_strSearchForName = searchName;
m_foundNodeList.clear();
}
osg::Node* findNodeVisitor::getFirst()
{
if(!m_foundNodeList.empty())
{
return *(m_foundNodeList.begin());
}
else
{
return NULL;
}
}
osg::Node* findNodeVisitor::FindNamed(osg::Node* pParent,const std::string& strName)
{
if(pParent==NULL)
{
printf("ERROR(findNodeVisitor): Node to be Searched is NULL.\n");
return NULL;
}
findNodeVisitor visitor(strName);
pParent->accept(visitor);
return visitor.getFirst();
} |
|