I am writing a FLT loader, which has sub groups/nodes. The nodes are named, so I want to be able to load the model and then be able to get a specific sub-node by name from the scene manager.
//!Returns the first scene node with the specified Name.
ISceneNode* getSceneNodeFromName(ISceneManager* smgr, ISceneNode* root, stringw Name)
{
ISceneNode* resultNode =0;
if(root ==0)
root = smgr->getRootSceneNode();
const core::list<ISceneNode*>& children = root->getChildren();
core::list<ISceneNode*>::Iterator it = children.begin();
for (; it != children.end(); ++it)
{
ISceneNode* current = *(it);
if(stringw(current->getName()) == Name)
{
resultNode = current;
return resultNode;
}
// if any node has a children apply this function for children by recursion
if(!current->getChildren().empty())
{
getSceneNodeFromName(smgr, current, Name);
}
}
return resultNode;
}
You can use it, only difference is that you must ponit smgr like parameter.
//!Returns scene node with these ID and Name
ISceneNode* getSceneNodeFromNameAndId(ISceneManager* smgr, ISceneNode* root, stringw Name, s32 id)
{
ISceneNode* resultNode =0;
if(root ==0)
root = smgr->getRootSceneNode();
const core::list<ISceneNode*>& children = root->getChildren();
core::list<ISceneNode*>::Iterator it = children.begin();
for (; it != children.end(); ++it)
{
ISceneNode* current = *(it);
if(stringw(current->getName()) == Name && current->getID() == id)
{
resultNode = current;
return resultNode;
}
// if any node has a children apply this function for children by recursion
if(!current->getChildren().empty())
{
getSceneNodeFromNameAndId(smgr, current, Name, id);
}
}
return resultNode;
}
Enjoy.
Site development -Rock and metal online --- etcaptor.com ------freenetlife.com
//!Returns the first scene node with the specified Name.
// if any node has a children apply this function for children by recursion
if(!current->getChildren().empty())
{
getSceneNodeFromName(smgr, current, Name);
}
}
return resultNode;
}
//!Returns the first scene node with the specified Name.
// if any node has a children apply this function for children by recursion
if(!current->getChildren().empty())
{
resultNode = getSceneNodeFromName(smgr, current, Name);
if(resultNode != 0)
return resultNode;
}
}
return resultNode;
}
Thanks for the info! I hope this is put into the new version.
DrAnonymous wrote:I think there is an error in your code. You aren't keeping track of the return from the recursive call.
I'm not full agree with this addition, because you will never get executing of this additional line after recursion.
After recussion you have a two return states:
- if name was found /rturns node/
- if name was not found /returns null/[/quote]
Site development -Rock and metal online --- etcaptor.com ------freenetlife.com