Get mesh from Octree

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
SSG
Posts: 33
Joined: Sun Jan 11, 2009 1:16 pm

Get mesh from Octree

Post by SSG »

I created an IrrEdit scene with an octree scene node. The problem is that I want to retrieve its mesh. I tried exactly as in tutorial 15, but it failed at runtime because the node can't be cast to an IMeshSceneNode.

Code: Select all

case scene::ESNT_OCT_TREE:
			selector = smgr->createOctTreeTriangleSelector(((scene::IMeshSceneNode*)(node))->getMesh(), node);
			break;
The scene from tutorial 15 doesn't even contain an octree so I suspect this code is actually untested.

Is there any scene node type I can cast the node to to get its mesh? If not, is there any other way of getting the mesh, short of loading it again?
SSG
Posts: 33
Joined: Sun Jan 11, 2009 1:16 pm

Post by SSG »

Bump.

Any ideas why the tutorial is wrong? It would be good if there was a common base class for all geometric scene nodes, then triangle selectors could be created directly from them. IMeshSceneNode, IAnimatedMeshSceneNode and IOctreeSceneNode would inherit from, let's say, IGeometricSceneNode, then a triangle selector could be created directly from any IGeometricSceneNode without necessarily requiring the original mesh from which the geometric scene node was loaded.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

The Octree does not have an IMesh base, hence it cannot be used as an IMeshSceneNode directly. However, getMesh should return an IMesh with which you can work.
The common base is not that easily possible, because we need to know the exact type and act depending on the actual implementation behind the interface.
SSG
Posts: 33
Joined: Sun Jan 11, 2009 1:16 pm

Post by SSG »

Do you mean something like this?

Code: Select all

irr::io::IAttributes attribs = device->getFileSystem()->createEmptyAttributes();
node->serializeAttributes(attribs.get());
irr::core::stringc name = attribs->getAttributeAsString("Mesh");
selector = smgr->createOctTreeTriangleSelector(smgr->getMesh(name.c_str()), node);
That seems like a lot of work just to get a triangle selector from an octree scene node, but it works so i'll just accept it until it's simplified.

Can someone please correct tutorial 15 so it works with octrees?
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

hybrid wrote:The Octree does not have an IMesh base, hence it cannot be used as an IMeshSceneNode directly. However, getMesh should return an IMesh with which you can work.
The common base is not that easily possible, because we need to know the exact type and act depending on the actual implementation behind the interface.
Presumably the IMesh passed to COctTreeSceneNode::createTree(IMesh* mesh) is going to come from an octtree, so can we just derive COctTreeSceneNode from IMeshSceneNode, store the provided IMesh and return it in getMesh()? Looking at example 7, we're building the oct tree triangle selector from the same mesh that we're buildling the oct tree scene node from, so I'm not sure that we need to do anything other than store the IMesh given to createTree().

I've got that implemented locally, and tested with a slightly modified example 07 (and example 15 should work with its current code). Is there anything obvious that I'm missing?
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

I'm not sure if getMesh would have to return the octree organized mesh, or the original mesh. For now, it would probably be sufficient to return the original mesh.
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

OK, I've committed that to the trunk in SVN 2173. I stepped through what was happening in example 07, and the pertinent code is:

Code: Select all

scene::IAnimatedMesh* q3levelmesh = smgr->getMesh("20kdm2.bsp");

q3node = smgr->addOctTreeSceneNode(q3levelmesh->getMesh(0));

selector = smgr->createOctTreeTriangleSelector(q3levelmesh->getMesh(0), q3node, 128);
So it looks like we're just using whatever mesh data is in the IMesh that's got from loading the .bsp. I've just stored a reference to that IMesh in the COctTreeSceneNode so that it can be recovered later.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Post Reply