Loading seperate meshes from same file[SOLVED]

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
nikoomba
Competition winner
Posts: 22
Joined: Wed Mar 09, 2011 11:35 am

Loading seperate meshes from same file[SOLVED]

Post by nikoomba »

Hello everyone.

I'm having some trouble changing the colour of an individual mesh with the mesh manipulator.

What happens is that I have two seperate objects tied to two seperate meshes; where both meshes are loaded from the same file.

Essentially they have the same mesh, but I'm assigning them to different variables. When I change the colours of one of the meshes, the other one - which should be unrelated to the other - also changes its colour.

Example:

object_1:

Code: Select all

 
IMesh* m_Mesh = m_Smgr->getMesh("Media//mesh.x");
IMeshSceneNode* m_Node...etc
 
object_2:

Code: Select all

 
IMesh* m_Mesh = m_Smgr->getMesh("Media//mesh.x");
IMeshSceneNode* m_Node...etc
 
main.cpp:

Code: Select all

 
Object object_1;
Object object_2;
 
smgr->getMeshManipulator()->setVertexColors([b]object_1[/b].m_Node->getMesh(), SColor(0, rand() % 255, rand() % 255, rand() % 255));
 
Even though I'm changing only object_1's mesh's colours, object2's mesh's colours have changed as well.
This also happens when referring to the mesh directly, instead of using 'm_Node->getMesh().'
I've also tried setting the mesh again with 'm_Node->setMesh()' after changing the colour, but this does not work either.

This isn't completely illogical, it's just that I want to know how to make irrlicht think the mesh is a seperate one.

Since there's lots of different files I'm dealing with, I can't just make copies of the file for each individual mesh / colour combination.

Thanks in advance,
Sjors
Last edited by nikoomba on Fri Aug 26, 2011 12:19 pm, edited 1 time in total.
mongoose7
Posts: 1227
Joined: Wed Apr 06, 2011 12:13 pm

Re: Loading seperate meshes from same file

Post by mongoose7 »

Irrlicht has a mesh cache based on the filename. The second mesh has the same filename as the first and so the same mesh is returned.

BTW You wouldn't normally write '//' as one '/' is correct. You have to double '\' because it is a 'C' escape.
nikoomba
Competition winner
Posts: 22
Joined: Wed Mar 09, 2011 11:35 am

Re: Loading seperate meshes from same file

Post by nikoomba »

mongoose7 wrote:Irrlicht has a mesh cache based on the filename. The second mesh has the same filename as the first and so the same mesh is returned.

BTW You wouldn't normally write '//' as one '/' is correct. You have to double '\' because it is a 'C' escape.
Thanks for your quick reply. Is there any way to work around this, other than to create a new file?

I've actually already solved the issue by just making seperate texture files and applying those.

I think it's strange that I can apply a different texture to each model, but not a different colour.

There should be a workaround for this kind of stuff.

Also, I know about the '//'; I actually meant to type '\\.'
SGH
Posts: 13
Joined: Wed Aug 24, 2011 2:53 pm

Re: Loading seperate meshes from same file

Post by SGH »

I think you are able to create a Mesh Clone ( scene::IMeshSceneNode->createClone i think... )
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Re: Loading seperate meshes from same file

Post by hybrid »

Yes, vertex colors and textures are related to different objects. Vertex colors are directly bound to the vertices, which are part of the mesh. Textures, however, are related to materials. A mesh has a default material, but each scene node copies the material and hence can override the settings on a per-node base. This would not make too much sense for vertex information, as this would mean that the whole mesh would already be cloned into the scene node and occupy quite a lot of RAM. So if you really need this, you can manually clone the mesh. This tells Irrlicht that you really want to spend RAM on this. You can even clone the meshes as many times as you want, if you need even more variations. But keep in mind that this also means that you occupy this RAM also on your GPU. And that rendering the same mesh with different textures is way faster than rendering different meshes.
nikoomba
Competition winner
Posts: 22
Joined: Wed Mar 09, 2011 11:35 am

Re: Loading seperate meshes from same file

Post by nikoomba »

OK, thanks for your replies everyone. I think I'll stick with just applying different textures then.

It's good to know the possibility is there, though :).

Have a good one ladies and gents :).
Post Reply