[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [4824] trunk/py/scripts/addons/ render_povray/render.py: Fixed: objects with Vertex color were not rendering

Maurice Raybaud mauriceraybaud at hotmail.fr
Mon Nov 11 19:13:40 CET 2013


Revision: 4824
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=4824
Author:   mauriceraybaud
Date:     2013-11-11 18:13:40 +0000 (Mon, 11 Nov 2013)
Log Message:
-----------
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.

Modified Paths:
--------------
    trunk/py/scripts/addons/render_povray/render.py

Modified: trunk/py/scripts/addons/render_povray/render.py
===================================================================
--- trunk/py/scripts/addons/render_povray/render.py	2013-11-10 13:28:24 UTC (rev 4823)
+++ trunk/py/scripts/addons/render_povray/render.py	2013-11-11 18:13:40 UTC (rev 4824)
@@ -314,7 +314,7 @@
         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 @@
                 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 @@
                 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 @@
                         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 @@
 
                         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 @@
                                       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")
+

@@ Diff output truncated at 10240 characters. @@


More information about the Bf-extensions-cvs mailing list