[SOLVED] Same mesh with different color

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.
Tranen
Posts: 34
Joined: Mon May 05, 2008 5:43 pm

[SOLVED] Same mesh with different color

Post 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
Last edited by Tranen on Fri Feb 19, 2010 1:52 pm, edited 1 time in total.
Mux
Posts: 56
Joined: Mon Feb 26, 2007 12:25 pm
Location: Stockholm

Post by Mux »

Put different textures on the instances of your mesh.
It'll only take a minute or two to debug this code...
Adler1337
Posts: 471
Joined: Sat Aug 09, 2008 6:10 pm
Location: In your base.

Post 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.
multum in parvo
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post 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.
Tranen
Posts: 34
Joined: Mon May 05, 2008 5:43 pm

Post 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
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post 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.
Bear_130278
Posts: 237
Joined: Mon Jan 16, 2006 1:18 pm
Location: Odessa,Russian Federation

Post 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.
Do you like VODKA???
Image
Image
Tranen
Posts: 34
Joined: Mon May 05, 2008 5:43 pm

Post 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
Lonesome Ducky
Competition winner
Posts: 1123
Joined: Sun Jun 10, 2007 11:14 pm

Post 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.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post 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.
Bear_130278
Posts: 237
Joined: Mon Jan 16, 2006 1:18 pm
Location: Odessa,Russian Federation

Post 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?
Do you like VODKA???
Image
Image
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post 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.
Bear_130278
Posts: 237
Joined: Mon Jan 16, 2006 1:18 pm
Location: Odessa,Russian Federation

Post 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*
Do you like VODKA???
Image
Image
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Maybe upgrade to 1.7?
Bear_130278
Posts: 237
Joined: Mon Jan 16, 2006 1:18 pm
Location: Odessa,Russian Federation

Post by Bear_130278 »

Ouch 8)
The same error on 1.7.1 8)
Do you like VODKA???
Image
Image
Post Reply