Shared mesh buffers?

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
bob
Posts: 57
Joined: Fri Jun 08, 2007 4:17 am
Location: Jacksonville, Fl (USA)
Contact:

Shared mesh buffers?

Post by bob »

It seems when I use addAnimatedMeshSceneNode() to load multiple instances of the same model, the actual mesh buffers are shared. That's normally just swell, but when I apply vertex shading it applies it to all of them.

Is there a simple way to over-ride this behavior and specify that each should have it's own buffer?
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

You can create q copy of the mesh and use that one for the next scene node. there is no automatic way for doing this.
Why do shaders create a problem here? The vertex buffers are uploaded for each mesh separately. This should create a new temporary copy each time. So I'm wondering what interferes here.
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

The root of the problem is that the meshes are cached, and once they are loaded you get a pointer to the same mesh every time you ask for it. One way to get around this is to remove the mesh from the mesh cache after loading it. By removing it from the cache, you prevent the next scene node from trying to share the vertex data. Each scene node will have its own mesh data.

Code: Select all

scene::IAnimatedMesh* am1 = smgr->getMesh("../../media/dwarf.x");
scene::IAnimatedMeshSceneNode* amNode1 = 
    smgr->addAnimatedMeshSceneNode(am1);
smgr->getMeshCache()->removeMesh(am1);

// modify vertex colors of am1

scene::IAnimatedMesh* am2 = smgr->getMesh("../../media/dwarf.x");
scene::IAnimatedMeshSceneNode* amNode2 = 
    smgr->addAnimatedMeshSceneNode(am2);
smgr->getMeshCache()->removeMesh(am2);

// modify vertex colors of am2
The big problem with this is that you are potentially duplicating lots of data. If it becomes a problem, you could use a shader or even a texture to modify the color of the nodes.

Travis
bob
Posts: 57
Joined: Fri Jun 08, 2007 4:17 am
Location: Jacksonville, Fl (USA)
Contact:

Post by bob »

smgr->getMeshCache()->removeMesh(am1);
AHHHHH!!! :evil:

That's it, after reading your post vitek, I realized I've ran across this before on the forum, I was looking everywhere for some kind of flag. Many thanks and sorry to slow you down. :D

@hybrid

I was actually using m_pSm->getMeshManipulator()->setVertexColors(), I dropped the phrase vertex shading because I don't know what I'm talking about. :roll:
Post Reply