Tell me more ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

The .obj files I export are missing data for vertex colors. Is there a way to include color information in the .obj file? If not, what are the alternatives?

share|improve this question

2 Answers

up vote 2 down vote accepted

Blender can export PLY files (.ply), which are text-based, very easy to parse, and include vertices colors. The hard way is to change the OBJ exporter code so that it includes the vertices colors (thus breaking obj compatibility).

share|improve this answer
Thanks a lot for your help – Mina Samy Dec 20 '11 at 13:34
3  
The wrong way is to change the OBJ exporter. Use the right tool for the job; if you want vertex colours, Wavefront OBJ obviously isn't the tool you want to use (or abuse). – Martin Sojka Dec 20 '11 at 13:49
1  
Why is that a wrong way ? If he just takes the OBJ exporter to make his own, I really fail to see how that's "wrong". The wrong way is not doing any work because it is always the wrong way to someone. – Ravachol Dec 20 '11 at 14:33
The .obj format uses .mtl files for storing material information, but as far as I know, only supports one material per face. Also, .obj is one of the not so many topics for which the wikipedia entry is actually usefull: en.wikipedia.org/wiki/Wavefront_.obj_file – sarahm Dec 21 '11 at 2:26
1  
It's wrong because OBJ is a fixed specification. Once you start changing the exporter to do extra stuff, it is no longer an OBJ exporter, it's something else. From there, it could turn into just about any multi-headed beast. Still, good answer, I'd never heard of PLY. – Nick Wiggill Jul 21 '12 at 10:09

Wavefront OBJ supports materials, which color groups of meshes the same color.

Material statements look like this:

newmtl redMtl
Kd 1.00 0.00 0.00
Ks 0.50 0.50 0.50
Ns 18.00

So, Kd is the diffuse component, Ks specular.

These would be specified inside a .mtl file that accompanies the .obj file. Inside the .obj file are statements like

usemtl redMtl
f 1/5/1 30/39/2 20/29/3
f 20/29/4 30/39/5 31/41/6
f 35/48/7 26/35/8 2/6/9

This means the faces specified there are to use the redMtl material. When you're parsing the obj file, this translates down to per-vertex color.

If there are lots of different colors, you will have a lot of different materials, but you can do it.

Here's a video of how to assign a particular group of faces a different material. You can assign a different material to each face in a mesh if you wish.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.