Is that possible to assign colors to individual triangles in a mesh?

Hi,



I have a mesh, of which each triangle is associated with a uniform color. For example, two neighboring triangles may have completely two different colors. I tried to visualize this mesh in JME using TriMesh. But TriMesh assigns colors to vertices, not triangles.



Could you please shed some light on this problem? I really appreciate it!



Best Regards,

Dan

hi, no way you can assign colors to triangles, ever. If any program lets you do this it is just a convenience method for this: what you can do is break up two neighboring triangles and copy the two vertices in common and then just set the same color for all three vertices of the new triangles.

You could use a large texuture with different colorued blocks, and then change the texture coordinates manually for each triangle, but thats a bit  work.

How many triangles are you talking about?



Maybe you could use a 3D modelling package (Blender?), and map it to a UV image. You'll have complete control then over the colours (or anything you like) of each triangle. It's a long-winded way round, but it will give you lots of flexibility at least. I've been using the hottbj exporter with some success on this.



Hope this helps.

Thanks, guys! This is very helpful. At least I know that there is no direct ways to do that.



I was thinking of creating multiple meshes, each of which is assigned a uniform color. This is similar to dhdd's idea.



The model which I have consists of hundreds of triangles. It was automatically created. I guess I am able to generate a texture and use it to color the triangles.



Again, thanks a lot!



Sincerely,

Dan

guodah said:

I was thinking of creating multiple meshes, each of which is assigned a uniform color. This is similar to dhdd's idea.

No its not even similar. 500 meshes a 1 triangle will perform MUCH worse than 1 mesh with 500 individual triangles. All you need is use a triangle list with duplicate vertices instead of, for example, a triangle strip or fan.

dhdd: I see the difference! Thanks!