Page 1 of 2

[SOLVED] Same mesh with different color

Posted: Tue Feb 16, 2010 1:35 pm
by Tranen
Hi what is the best way to have the same mesh with different color. I create my mesh in blender but I need to create different instance of the same mesh with different color (for example I have a cube and I want to create a red cube a blue cube and so on)

What is the best and fast way?
Thanks a lot.
regards
Tranen

Posted: Tue Feb 16, 2010 2:10 pm
by Mux
Put different textures on the instances of your mesh.

Posted: Tue Feb 16, 2010 2:12 pm
by Adler1337
There is an easy way. It goes something like this:
node->getMaterial(num).diffuse

Can't remember if that is the exact code, but you can take a look at the API.

Posted: Tue Feb 16, 2010 2:51 pm
by hybrid
If you need vertex colors (the other color values are only taken if the cube is lit) you have to copy the mesh (e.g. by using the mesh manipulator). Because the vertex colors are directly attached to the mesh, not the scene node.

Posted: Tue Feb 16, 2010 3:59 pm
by Tranen
I'm sorry if it's a stupid question, but i'm a bit confused.
I don't want to load the mesh n times.
I want to export my mesh from blender and load it then share the mesh definition (maybe SSharedMeshBuffer?)

It is possible to use the same Mesh to create multiple objects whit different colors?

How can I do that? using n texture, mofifying the vertex color?

Thanks
Tranen

Posted: Tue Feb 16, 2010 9:27 pm
by hybrid
Since you seem to lack the necessary knowledge about the different 3d rendering techniques, it might be better to explain in detail what you want to achieve. Don't use technical details such as textures, but numbers and effects you want to see.

Posted: Wed Feb 17, 2010 12:07 pm
by Bear_130278
Image

Hello there guys.
I got almost the same question.
Look at the shot.
It is a mesh with 3 different materials.There is no maps on them just colors.
How can i change each of the colors??
I've tried
getMaterial(0).DiffuseColor.set(0,255,0,0);
and
getMaterial(0).AmbientColor.set(0,255,0,0);
with all 3 materials and
meter->setMaterialFlag(EMF_LIGHTING, true\false);

The color in material is changing, i've checked... but the image stays the same....

I've also tried to set the vertex colors, it worked but it sets all the colors in the mesh, when i need to change 3 materials separate.

And BTW. I've checked the colors in the materials before the change... they 100% correspond to those we see on picture, but after the change the colors do not correspond to the picture.

Posted: Wed Feb 17, 2010 6:28 pm
by Tranen
Hi Hybrid, my problem is that I create an object in blender and import it into irrlicht (the format is obj):

Image

and I want to make n instances of this objects with different color:

Image

I'have done this in irredit cloning the object and setting different values of emissive color after enable the lighting on the object. I guess I can do this also changing vertex color or assigning a diffenent texture to every object.

There is another/better way to do this?
Is possible to store just once the vertex coordinates for all the objects since they are always the same?

Thanks for your patience and help.
Cheers
Tranen

Posted: Wed Feb 17, 2010 8:07 pm
by Lonesome Ducky
To bear: Irrlicht stores parts of a mesh with different materials in separate mesh buffers. So try setting the vertex colors of each mesh buffer instead of the whole mesh.

Posted: Wed Feb 17, 2010 8:58 pm
by hybrid
Tranen, if you do so in irrEdit, you should also be able to do so in Irrlicht. You can simply instantiate as many mesh scene nodes with the same mesh as you want. If you set the hardware mapping hint of that mesh to EHM_STATIC, it's also not uploaded to the GPU for each node, but only once. Using a color material for the coloring is pretty cheap, so it's a good idea.

Posted: Thu Feb 18, 2010 7:37 am
by Bear_130278
Ducky, i see your point...
But i do not see the way to set the vertex colors of the mesh buffer.
Did you mean, to get the array of vertices and set the colors of each vertex?

Posted: Thu Feb 18, 2010 8:20 am
by hybrid
You can use the mesh manipulator interface to alter the colors of meshes and meshbuffers. Simply use getMeshBuffer(i) and pass it to the vertexcolor method.

Posted: Thu Feb 18, 2010 8:52 am
by Bear_130278
Really? 8)))

irr::scene::IMeshManipulator::setVertexColors' : cannot convert parameter 1 from 'irr::scene::IMeshBuffer *' to 'irr::scene::IMesh *'

I'm doing it like this:

Code: Select all

Core.smgr->getMeshManipulator()->setVertexColors(meter->getMesh()->getMeshBuffer(0),(0,255,0,0));
Doc says:
virtual void irr::scene::IMeshManipulator::setVertexColors ( IMesh * mesh,
video::SColor color ) There is only one method.... and it is for IMesh*

Posted: Thu Feb 18, 2010 11:30 am
by hybrid
Maybe upgrade to 1.7?

Posted: Thu Feb 18, 2010 1:17 pm
by Bear_130278
Ouch 8)
The same error on 1.7.1 8)