diff options
author | Maurice Raybaud <mauriceraybaud@hotmail.fr> | 2013-11-11 22:13:40 +0400 |
---|---|---|
committer | Maurice Raybaud <mauriceraybaud@hotmail.fr> | 2013-11-11 22:13:40 +0400 |
commit | bfa70771ded56cc2a0eb5332f1b9a662701c49e7 (patch) | |
tree | 72a9e1cea26aa8b01f55abf35920b2ae6f1ea711 /render_povray | |
parent | 3d71a0995decd1c74b088e4007a1c2fe310b0301 (diff) |
Fixed: objects with Vertex color were not rendering
added: now vertex colors get written as a simple pigment per vertex anytime there is some vertex color layer regardless of the vertex color paint or vertex color light toggles.
Diffstat (limited to 'render_povray')
-rw-r--r-- | render_povray/render.py | 172 |
1 files changed, 163 insertions, 9 deletions
diff --git a/render_povray/render.py b/render_povray/render.py index 9923e3d6..0fbeb410 100644 --- a/render_povray/render.py +++ b/render_povray/render.py @@ -314,7 +314,7 @@ def write_pov(filename, scene=None, info_callback=None): comments = scene.pov.comments_enable if material: - # If saturation(.s) is not zero, then color is not grey, and has a tint + # If saturation(.s) is not zero, then color is not grey, and has a tint colored_specular_found = (material.specular_color.s > 0.0) ################## @@ -1027,7 +1027,8 @@ def write_pov(filename, scene=None, info_callback=None): uv_layer = None try: - vcol_layer = me.vertex_colors.active.data + #vcol_layer = me.vertex_colors.active.data + vcol_layer = me.tessface_vertex_colors.active.data except AttributeError: vcol_layer = None @@ -1127,7 +1128,10 @@ def write_pov(filename, scene=None, info_callback=None): tabWrite("}\n") if me.vertex_colors: - + #Write down vertex colors as a texture for each vertex + tabWrite("texture_list {\n") + tabWrite("%d\n" % (((len(me_faces)-quadCount) * 3 )+ quadCount * 4)) # works only with tris and quad mesh for now + VcolIdx=0 for fi, f in enumerate(me_faces): # annoying, index may be invalid material_index = f.material_index @@ -1135,9 +1139,8 @@ def write_pov(filename, scene=None, info_callback=None): material = me_materials[material_index] except: material = None - - if material and material.use_vertex_color_paint: - + if material: #and material.use_vertex_color_paint: #Always use vertex color when there is some for now + col = vcol_layer[fi] if len(faces_verts[fi]) == 4: @@ -1147,8 +1150,10 @@ def write_pov(filename, scene=None, info_callback=None): for col in cols: key = col[0], col[1], col[2], material_index # Material index! - vertCols[key] = [-1] - + VcolIdx+=1 + vertCols[key] = [VcolIdx] + tabWrite("texture {pigment{ color rgb <%6f,%6f,%6f> }}" % (col[0], col[1], col[2])) + tabStr = tab * tabLevel else: if material: # Multiply diffuse with SSS Color @@ -1163,6 +1168,155 @@ def write_pov(filename, scene=None, info_callback=None): material_index vertCols[key] = [-1] + tabWrite("\n}\n") + # Face indices + tabWrite("\nface_indices {\n") + tabWrite("%d" % (len(me_faces) + quadCount)) # faces count + tabStr = tab * tabLevel + + for fi, f in enumerate(me_faces): + fv = faces_verts[fi] + material_index = f.material_index + if len(fv) == 4: + indices = (0, 1, 2), (0, 2, 3) + else: + indices = ((0, 1, 2),) + + if vcol_layer: + col = vcol_layer[fi] + + if len(fv) == 4: + cols = col.color1, col.color2, col.color3, col.color4 + else: + cols = col.color1, col.color2, col.color3 + + if not me_materials or me_materials[material_index] is None: # No materials + for i1, i2, i3 in indices: + if not scene.pov.tempfiles_enable and scene.pov.list_lf_enable: + file.write(",\n") + # vert count + file.write(tabStr + "<%d,%d,%d>" % (fv[i1], fv[i2], fv[i3])) + else: + file.write(", ") + file.write("<%d,%d,%d>" % (fv[i1], fv[i2], fv[i3])) # vert count + else: + material = me_materials[material_index] + for i1, i2, i3 in indices: + if me.vertex_colors: #and material.use_vertex_color_paint: + # Color per vertex - vertex color + + col1 = cols[i1] + col2 = cols[i2] + col3 = cols[i3] + + ci1 = vertCols[col1[0], col1[1], col1[2], material_index][0] + ci2 = vertCols[col2[0], col2[1], col2[2], material_index][0] + ci3 = vertCols[col3[0], col3[1], col3[2], material_index][0] + else: + # Color per material - flat material color + if material.subsurface_scattering.use: + diffuse_color = [i * j for i, j in zip(material.subsurface_scattering.color[:], material.diffuse_color[:])] + else: + diffuse_color = material.diffuse_color[:] + ci1 = ci2 = ci3 = vertCols[diffuse_color[0], diffuse_color[1], \ + diffuse_color[2], f.material_index][0] + # ci are zero based index so we'll subtract 1 from them + if not scene.pov.tempfiles_enable and scene.pov.list_lf_enable: + file.write(",\n") + file.write(tabStr + "<%d,%d,%d>, %d,%d,%d" % \ + (fv[i1], fv[i2], fv[i3], ci1-1, ci2-1, ci3-1)) # vert count + else: + file.write(", ") + file.write("<%d,%d,%d>, %d,%d,%d" % \ + (fv[i1], fv[i2], fv[i3], ci1-1, ci2-1, ci3-1)) # vert count + + file.write("\n") + tabWrite("}\n") + + # normal_indices indices + tabWrite("normal_indices {\n") + tabWrite("%d" % (len(me_faces) + quadCount)) # faces count + tabStr = tab * tabLevel + for fi, fv in enumerate(faces_verts): + + if len(fv) == 4: + indices = (0, 1, 2), (0, 2, 3) + else: + indices = ((0, 1, 2),) + + for i1, i2, i3 in indices: + if me_faces[fi].use_smooth: + if not scene.pov.tempfiles_enable and scene.pov.list_lf_enable: + file.write(",\n") + file.write(tabStr + "<%d,%d,%d>" %\ + (uniqueNormals[verts_normals[fv[i1]]][0],\ + uniqueNormals[verts_normals[fv[i2]]][0],\ + uniqueNormals[verts_normals[fv[i3]]][0])) # vert count + else: + file.write(", ") + file.write("<%d,%d,%d>" %\ + (uniqueNormals[verts_normals[fv[i1]]][0],\ + uniqueNormals[verts_normals[fv[i2]]][0],\ + uniqueNormals[verts_normals[fv[i3]]][0])) # vert count + else: + idx = uniqueNormals[faces_normals[fi]][0] + if not scene.pov.tempfiles_enable and scene.pov.list_lf_enable: + file.write(",\n") + file.write(tabStr + "<%d,%d,%d>" % (idx, idx, idx)) # vert count + else: + file.write(", ") + file.write("<%d,%d,%d>" % (idx, idx, idx)) # vert count + + file.write("\n") + tabWrite("}\n") + + if uv_layer: + tabWrite("uv_indices {\n") + tabWrite("%d" % (len(me_faces) + quadCount)) # faces count + tabStr = tab * tabLevel + for fi, fv in enumerate(faces_verts): + + if len(fv) == 4: + indices = (0, 1, 2), (0, 2, 3) + else: + indices = ((0, 1, 2),) + + uv = uv_layer[fi] + if len(faces_verts[fi]) == 4: + uvs = uv.uv[0][:], uv.uv[1][:], uv.uv[2][:], uv.uv[3][:] + else: + uvs = uv.uv[0][:], uv.uv[1][:], uv.uv[2][:] + + for i1, i2, i3 in indices: + if not scene.pov.tempfiles_enable and scene.pov.list_lf_enable: + file.write(",\n") + file.write(tabStr + "<%d,%d,%d>" % ( + uniqueUVs[uvs[i1]][0],\ + uniqueUVs[uvs[i2]][0],\ + uniqueUVs[uvs[i3]][0])) + else: + file.write(", ") + file.write("<%d,%d,%d>" % ( + uniqueUVs[uvs[i1]][0],\ + uniqueUVs[uvs[i2]][0],\ + uniqueUVs[uvs[i3]][0])) + + file.write("\n") + tabWrite("}\n") + + if me.materials: + try: + material = me.materials[0] # dodgy + writeObjectMaterial(material, ob) + except IndexError: + print(me) + + #Importance for radiosity sampling added here: + tabWrite("radiosity { \n") + tabWrite("importance %3g \n" % importance) + tabWrite("}\n") + + tabWrite("}\n") # End of mesh block else: # No vertex colors, so write material colors as vertex colors for i, material in enumerate(me_materials): @@ -1661,7 +1815,7 @@ def write_pov(filename, scene=None, info_callback=None): else: material = me_materials[material_index] for i1, i2, i3 in indices: - if me.vertex_colors and material.use_vertex_color_paint: + if me.vertex_colors: #and material.use_vertex_color_paint: # Color per vertex - vertex color col1 = cols[i1] |