Page 1 of 1
Get mesh from Octree
Posted: Wed Jan 21, 2009 3:57 am
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?
Posted: Sun Jan 25, 2009 5:25 am
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.
Posted: Sun Jan 25, 2009 1:26 pm
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.
Posted: Sat Jan 31, 2009 6:52 am
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?
Posted: Sat Jan 31, 2009 10:55 am
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?
Posted: Sat Jan 31, 2009 3:01 pm
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.
Posted: Sat Jan 31, 2009 4:02 pm
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.