How to get an entity without know its name

CorPetit09

20-10-2010 11:24:53

Hi,

My problem is this, I have access to an object mesh (which I think is made through an Entity). The fact is that I load the scene from a .scene file and I don't know the names of each of the Entities. With Ogre, I did through all the nodes of the scene and cast the sons of the nodes to Entities (the code below is the one that did this):


Ogre::Node::ChildNodeIterator iterator = scene->GetRootNode()->getChildIterator();

while(iterator.hasMoreElements()){
Ogre::SceneNode* child = (Ogre::SceneNode *)iterator.getNext();
Ogre::SceneNode::ObjectIterator oi = child->getAttachedObjectIterator();

child->setPosition(child->getPosition()*50);
child->translate(0,2400,0);
while(oi.hasMoreElements()){
Ogre::Entity* ent = (Ogre::Entity *)oi.getNext(); // This is the important line
// blablabla
}
}


But with Mogre I can't, as it give me an error when I try to cast a Node to an Entity. If someone can tell me how you can access to an Entity without knowing its name, it would be perfect,
Regards

smiley80

20-10-2010 18:13:21

private static void GetAllMovableObjects(IEnumerable<Node> iterator)
{
foreach (var node in iterator)
{
var sceneNode = node as SceneNode;
if (sceneNode != null)
{
foreach (var movObj in sceneNode.GetAttachedObjectIterator())
{
// do something with movObj
}
}

GetAllMovableObjects(node.GetChildIterator());
}
}

Get all MovableObjects of a SceneManager:
GetAllMovableObjects(sceneMgr.RootSceneNode.GetChildIterator());

CorPetit09

21-10-2010 12:06:45

Thanks a lot smiley80 :D