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?
There does exist a flavour of Wavefront's *.obj that facilitates Vertex Coloring.. I know of two applications that can export these namely "MeshLab" (free) and "MeshMixer" (also free from Autodesk).. The vertex colours is actually found just after each vertex definition as shown below..
(Piece of *.obj)
#### # # OBJ File Generated by Meshlab # #### # Object VERTEXPAINT_004_OBJ.obj # # Vertices: 284 # Faces: 281 # #### mtllib ./VERTEXPAINT_004_OBJ.obj.mtl vn 0.029683 0.730087 -0.682709 v 1220.094482 -572.500000 177.713943 0.984314 0.764706 1.000000 # "3 vals for Vert and 3 vals for Col" vn 0.000000 0.858139 -0.513418 v 1291.571533 -609.439636 -28.628490 0.921569 0.219608 1.000000 vn 0.303129 0.896367 -0.323480
Try using meshlab to generate "Vertex Based Ambient Occlusion", then open it with "MeshMixer"..
This should clarify your issue.. I think Vertex colouring is coming back with the advent of shaders.. Its funny how vertex colouring seems to be neglected when image maps were discovered.. Now we should see the the return of "Vertex Colouring"! Let me know if this was usefull!
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.