Changeset View
Changeset View
Standalone View
Standalone View
render_povray/render.py
| Show First 20 Lines • Show All 2,061 Lines • ▼ Show 20 Lines | # return False | ||||
| #file.write("}\n") | #file.write("}\n") | ||||
| ob_num = 0 | ob_num = 0 | ||||
| for ob in sel: | for ob in sel: | ||||
| ob_num += 1 | ob_num += 1 | ||||
| # XXX I moved all those checks here, as there is no need to compute names | # XXX I moved all those checks here, as there is no need to compute names | ||||
| # for object we won't export here! | # for object we won't export here! | ||||
| if (ob.type in {'LAMP', 'CAMERA', #'EMPTY', #empties can bear dupligroups | if (ob.type in {'LIGHT', 'CAMERA', #'EMPTY', #empties can bear dupligroups | ||||
| 'META', 'ARMATURE', 'LATTICE'}): | 'META', 'ARMATURE', 'LATTICE'}): | ||||
| continue | continue | ||||
| smokeFlag=False | smokeFlag=False | ||||
| for mod in ob.modifiers: | for mod in ob.modifiers: | ||||
| if mod and hasattr(mod, 'smoke_type'): | if mod and hasattr(mod, 'smoke_type'): | ||||
| smokeFlag=True | smokeFlag=True | ||||
| if (mod.smoke_type == 'DOMAIN'): | if (mod.smoke_type == 'DOMAIN'): | ||||
| exportSmoke(ob.name) | exportSmoke(ob.name) | ||||
| Show All 27 Lines | # return False | ||||
| strandShape = pmaterial.strand.shape | strandShape = pmaterial.strand.shape | ||||
| else: | else: | ||||
| pmaterial = "default" # No material assigned in blender, use default one | pmaterial = "default" # No material assigned in blender, use default one | ||||
| strandStart = 0.01 | strandStart = 0.01 | ||||
| strandEnd = 0.01 | strandEnd = 0.01 | ||||
| strandShape = 0.0 | strandShape = 0.0 | ||||
| # Set the number of particles to render count rather than 3d view display | # Set the number of particles to render count rather than 3d view display | ||||
| pSys.set_resolution(scene, ob, 'RENDER') | pSys.set_resolution(scene, ob, 'RENDER') | ||||
| steps = pSys.settings.draw_step | steps = pSys.settings.display_step | ||||
| steps = 3 ** steps # or (power of 2 rather than 3) + 1 # Formerly : len(particle.hair_keys) | steps = 3 ** steps # or (power of 2 rather than 3) + 1 # Formerly : len(particle.hair_keys) | ||||
| totalNumberOfHairs = ( len(pSys.particles) + len(pSys.child_particles) ) | totalNumberOfHairs = ( len(pSys.particles) + len(pSys.child_particles) ) | ||||
| #hairCounter = 0 | #hairCounter = 0 | ||||
| file.write('#declare HairArray = array[%i] {\n' % totalNumberOfHairs) | file.write('#declare HairArray = array[%i] {\n' % totalNumberOfHairs) | ||||
| for pindex in range(0, totalNumberOfHairs): | for pindex in range(0, totalNumberOfHairs): | ||||
| #if particle.is_exist and particle.is_visible: | #if particle.is_exist and particle.is_visible: | ||||
| Show All 35 Lines | # return False | ||||
| for step in range(0, steps): | for step in range(0, steps): | ||||
| co = ob.matrix_world.inverted()*(pSys.co_hair(ob, pindex, step)) | co = ob.matrix_world.inverted()*(pSys.co_hair(ob, pindex, step)) | ||||
| #for controlPoint in particle.hair_keys: | #for controlPoint in particle.hair_keys: | ||||
| if pSys.settings.clump_factor != 0: | if pSys.settings.clump_factor != 0: | ||||
| hDiameter = pSys.settings.clump_factor / 200.0 * random.uniform(0.5, 1) | hDiameter = pSys.settings.clump_factor / 200.0 * random.uniform(0.5, 1) | ||||
| elif step == 0: | elif step == 0: | ||||
| hDiameter = strandStart | hDiameter = strandStart | ||||
| else: | else: | ||||
| hDiameter += (strandEnd-strandStart)/(pSys.settings.draw_step+1) #XXX +1 or not? | hDiameter += (strandEnd-strandStart)/(pSys.settings.display_step+1) #XXX +1 or not? | ||||
| if step == 0 and pSys.settings.use_hair_bspline: | if step == 0 and pSys.settings.use_hair_bspline: | ||||
| # Write three times the first point to compensate pov Bezier handling | # Write three times the first point to compensate pov Bezier handling | ||||
| file.write('<%.6g,%.6g,%.6g>,%.7g,\n' % (co[0], co[1], co[2], abs(hDiameter))) | file.write('<%.6g,%.6g,%.6g>,%.7g,\n' % (co[0], co[1], co[2], abs(hDiameter))) | ||||
| file.write('<%.6g,%.6g,%.6g>,%.7g,\n' % (co[0], co[1], co[2], abs(hDiameter))) | file.write('<%.6g,%.6g,%.6g>,%.7g,\n' % (co[0], co[1], co[2], abs(hDiameter))) | ||||
| #file.write('<%.6g,%.6g,%.6g>,%.7g' % (particle.location[0], particle.location[1], particle.location[2], abs(hDiameter))) # Useless because particle location is the tip, not the root. | #file.write('<%.6g,%.6g,%.6g>,%.7g' % (particle.location[0], particle.location[1], particle.location[2], abs(hDiameter))) # Useless because particle location is the tip, not the root. | ||||
| #file.write(',\n') | #file.write(',\n') | ||||
| #controlPointCounter += 1 | #controlPointCounter += 1 | ||||
| #totalNumberOfHairs += len(pSys.particles)# len(particle.hair_keys) | #totalNumberOfHairs += len(pSys.particles)# len(particle.hair_keys) | ||||
| ▲ Show 20 Lines • Show All 509 Lines • ▼ Show 20 Lines | ############################################else try to export mesh | ||||
| except: | except: | ||||
| # also happens when curves cant be made into meshes because of no-data | # also happens when curves cant be made into meshes because of no-data | ||||
| continue | continue | ||||
| importance = ob.pov.importance_value | importance = ob.pov.importance_value | ||||
| if me: | if me: | ||||
| me_materials = me.materials | me_materials = me.materials | ||||
| me_faces = me.tessfaces[:] | me_faces = me.loop_triangles[:] | ||||
| #if len(me_faces)==0: | #if len(me_faces)==0: | ||||
| #tabWrite("\n//dummy sphere to represent empty mesh location\n") | #tabWrite("\n//dummy sphere to represent empty mesh location\n") | ||||
| #tabWrite("#declare %s =sphere {<0, 0, 0>,0 pigment{rgbt 1} no_image no_reflection no_radiosity photons{pass_through collect off} hollow}\n" % povdataname) | #tabWrite("#declare %s =sphere {<0, 0, 0>,0 pigment{rgbt 1} no_image no_reflection no_radiosity photons{pass_through collect off} hollow}\n" % povdataname) | ||||
| if not me or not me_faces: | if not me or not me_faces: | ||||
| tabWrite("\n//dummy sphere to represent empty mesh location\n") | tabWrite("\n//dummy sphere to represent empty mesh location\n") | ||||
| tabWrite("#declare %s =sphere {<0, 0, 0>,0 pigment{rgbt 1} no_image no_reflection no_radiosity photons{pass_through collect off} hollow}\n" % povdataname) | tabWrite("#declare %s =sphere {<0, 0, 0>,0 pigment{rgbt 1} no_image no_reflection no_radiosity photons{pass_through collect off} hollow}\n" % povdataname) | ||||
| continue | continue | ||||
| uv_textures = me.tessface_uv_textures | uv_layers = me.uv_layers | ||||
| if len(uv_textures) > 0: | if len(uv_layers) > 0: | ||||
| if me.uv_textures.active and uv_textures.active.data: | if me.uv_layers.active and uv_layers.active.data: | ||||
| uv_layer = uv_textures.active.data | uv_layer = uv_layers.active.data | ||||
| else: | else: | ||||
| uv_layer = None | uv_layer = None | ||||
| try: | try: | ||||
| #vcol_layer = me.vertex_colors.active.data | #vcol_layer = me.vertex_colors.active.data | ||||
| vcol_layer = me.tessface_vertex_colors.active.data | vcol_layer = me.vertex_colors.active.data | ||||
| except AttributeError: | except AttributeError: | ||||
| vcol_layer = None | vcol_layer = None | ||||
| faces_verts = [f.vertices[:] for f in me_faces] | faces_verts = [f.vertices[:] for f in me_faces] | ||||
| faces_normals = [f.normal[:] for f in me_faces] | faces_normals = [f.normal[:] for f in me_faces] | ||||
| verts_normals = [v.normal[:] for v in me.vertices] | verts_normals = [v.normal[:] for v in me.vertices] | ||||
| # quads incur an extra face | |||||
| quadCount = sum(1 for f in faces_verts if len(f) == 4) | |||||
| # Use named declaration to allow reference e.g. for baking. MR | # Use named declaration to allow reference e.g. for baking. MR | ||||
| file.write("\n") | file.write("\n") | ||||
| tabWrite("#declare %s =\n" % povdataname) | tabWrite("#declare %s =\n" % povdataname) | ||||
| tabWrite("mesh2 {\n") | tabWrite("mesh2 {\n") | ||||
| tabWrite("vertex_vectors {\n") | tabWrite("vertex_vectors {\n") | ||||
| tabWrite("%d" % len(me.vertices)) # vert count | tabWrite("%d" % len(me.vertices)) # vert count | ||||
| tabStr = tab * tabLevel | tabStr = tab * tabLevel | ||||
| Show All 39 Lines | ############################################else try to export mesh | ||||
| # Vertex colors | # Vertex colors | ||||
| vertCols = {} # Use for material colors also. | vertCols = {} # Use for material colors also. | ||||
| if uv_layer: | if uv_layer: | ||||
| # Generate unique UV's | # Generate unique UV's | ||||
| uniqueUVs = {} | uniqueUVs = {} | ||||
| #n = 0 | #n = 0 | ||||
| for fi, uv in enumerate(uv_layer): | for f in me.faces: | ||||
| uvs = [uv_layer[l].uv[:] for l in f.loops] | |||||
| if len(faces_verts[fi]) == 4: | |||||
| uvs = uv_layer[fi].uv[0], uv_layer[fi].uv[1], uv_layer[fi].uv[2], uv_layer[fi].uv[3] | |||||
| else: | |||||
| uvs = uv_layer[fi].uv[0], uv_layer[fi].uv[1], uv_layer[fi].uv[2] | |||||
| for uv in uvs: | for uv in uvs: | ||||
| uniqueUVs[uv[:]] = [-1] | uniqueUVs[uv[:]] = [-1] | ||||
| tabWrite("uv_vectors {\n") | tabWrite("uv_vectors {\n") | ||||
| #print unique_uvs | #print unique_uvs | ||||
| tabWrite("%d" % len(uniqueUVs)) # vert count | tabWrite("%d" % len(uniqueUVs)) # vert count | ||||
| idx = 0 | idx = 0 | ||||
| Show All 14 Lines | ############################################else try to export mesh | ||||
| file.write(',\n\t\t<0.0, 0.0>') | file.write(',\n\t\t<0.0, 0.0>') | ||||
| ''' | ''' | ||||
| file.write("\n") | file.write("\n") | ||||
| tabWrite("}\n") | tabWrite("}\n") | ||||
| if me.vertex_colors: | if me.vertex_colors: | ||||
| #Write down vertex colors as a texture for each vertex | #Write down vertex colors as a texture for each vertex | ||||
| tabWrite("texture_list {\n") | tabWrite("texture_list {\n") | ||||
| tabWrite("%d\n" % (((len(me_faces)-quadCount) * 3 )+ quadCount * 4)) # works only with tris and quad mesh for now | tabWrite("%d\n" % (len(me_faces) * 3)) # assumes we have only triangles | ||||
| VcolIdx=0 | VcolIdx=0 | ||||
| if comments: | if comments: | ||||
| file.write("\n //Vertex colors: one simple pigment texture per vertex\n") | file.write("\n //Vertex colors: one simple pigment texture per vertex\n") | ||||
| for fi, f in enumerate(me_faces): | for fi, f in enumerate(me_faces): | ||||
| # annoying, index may be invalid | # annoying, index may be invalid | ||||
| material_index = f.material_index | material_index = f.material_index | ||||
| try: | try: | ||||
| material = me_materials[material_index] | material = me_materials[material_index] | ||||
| except: | except: | ||||
| material = None | material = None | ||||
| if material: #and material.use_vertex_color_paint: #Always use vertex color when there is some for now | if material: #and material.use_vertex_color_paint: #Always use vertex color when there is some for now | ||||
| col = vcol_layer[fi] | cols = [vcol_layer[l].color[:] for l in f.loops] | ||||
| if len(faces_verts[fi]) == 4: | |||||
| cols = col.color1, col.color2, col.color3, col.color4 | |||||
| else: | |||||
| cols = col.color1, col.color2, col.color3 | |||||
| for col in cols: | for col in cols: | ||||
| key = col[0], col[1], col[2], material_index # Material index! | key = col[0], col[1], col[2], material_index # Material index! | ||||
| VcolIdx+=1 | VcolIdx+=1 | ||||
| vertCols[key] = [VcolIdx] | vertCols[key] = [VcolIdx] | ||||
| if linebreaksinlists: | if linebreaksinlists: | ||||
| tabWrite("texture {pigment{ color srgb <%6f,%6f,%6f> }}\n" % (col[0], col[1], col[2])) | tabWrite("texture {pigment{ color srgb <%6f,%6f,%6f> }}\n" % (col[0], col[1], col[2])) | ||||
| else: | else: | ||||
| Show All 11 Lines | ############################################else try to export mesh | ||||
| diffuse_color = material.diffuse_color[:] | diffuse_color = material.diffuse_color[:] | ||||
| key = diffuse_color[0], diffuse_color[1], diffuse_color[2], \ | key = diffuse_color[0], diffuse_color[1], diffuse_color[2], \ | ||||
| material_index | material_index | ||||
| vertCols[key] = [-1] | vertCols[key] = [-1] | ||||
| tabWrite("\n}\n") | tabWrite("\n}\n") | ||||
| # Face indices | # Face indices | ||||
| tabWrite("\nface_indices {\n") | tabWrite("\nface_indices {\n") | ||||
| tabWrite("%d" % (len(me_faces) + quadCount)) # faces count | tabWrite("%d" % (len(me_faces))) # faces count | ||||
| tabStr = tab * tabLevel | tabStr = tab * tabLevel | ||||
| for fi, f in enumerate(me_faces): | for fi, f in enumerate(me_faces): | ||||
| fv = faces_verts[fi] | fv = faces_verts[fi] | ||||
| material_index = f.material_index | material_index = f.material_index | ||||
| if len(fv) == 4: | |||||
| indices = (0, 1, 2), (0, 2, 3) | |||||
| else: | |||||
| indices = ((0, 1, 2),) | |||||
| if vcol_layer: | if vcol_layer: | ||||
| col = vcol_layer[fi] | cols = [vcol_layer[l].color[:] for l in f.loops] | ||||
| 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 | if not me_materials or me_materials[material_index] is None: # No materials | ||||
| for i1, i2, i3 in indices: | |||||
| if linebreaksinlists: | if linebreaksinlists: | ||||
| file.write(",\n") | file.write(",\n") | ||||
| # vert count | # vert count | ||||
| file.write(tabStr + "<%d,%d,%d>" % (fv[i1], fv[i2], fv[i3])) | file.write(tabStr + "<%d,%d,%d>" % (fv[0], fv[1], fv[2])) | ||||
| else: | else: | ||||
| file.write(", ") | file.write(", ") | ||||
| file.write("<%d,%d,%d>" % (fv[i1], fv[i2], fv[i3])) # vert count | file.write("<%d,%d,%d>" % (fv[0], fv[1], fv[2])) # vert count | ||||
| else: | else: | ||||
| material = me_materials[material_index] | 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 | # Color per vertex - vertex color | ||||
| col1 = cols[i1] | col1 = cols[0] | ||||
| col2 = cols[i2] | col2 = cols[1] | ||||
| col3 = cols[i3] | col3 = cols[2] | ||||
| ci1 = vertCols[col1[0], col1[1], col1[2], material_index][0] | ci1 = vertCols[col1[0], col1[1], col1[2], material_index][0] | ||||
| ci2 = vertCols[col2[0], col2[1], col2[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] | ci3 = vertCols[col3[0], col3[1], col3[2], material_index][0] | ||||
| else: | else: | ||||
| # Color per material - flat material color | # Color per material - flat material color | ||||
| if material.subsurface_scattering.use: | if material.subsurface_scattering.use: | ||||
| diffuse_color = [i * j for i, j in zip(material.subsurface_scattering.color[:], material.diffuse_color[:])] | diffuse_color = [i * j for i, j in zip(material.subsurface_scattering.color[:], material.diffuse_color[:])] | ||||
| else: | else: | ||||
| diffuse_color = material.diffuse_color[:] | diffuse_color = material.diffuse_color[:] | ||||
| ci1 = ci2 = ci3 = vertCols[diffuse_color[0], diffuse_color[1], \ | ci1 = ci2 = ci3 = vertCols[diffuse_color[0], diffuse_color[1], \ | ||||
| diffuse_color[2], f.material_index][0] | diffuse_color[2], f.material_index][0] | ||||
| # ci are zero based index so we'll subtract 1 from them | # ci are zero based index so we'll subtract 1 from them | ||||
| if linebreaksinlists: | if linebreaksinlists: | ||||
| file.write(",\n") | file.write(",\n") | ||||
| file.write(tabStr + "<%d,%d,%d>, %d,%d,%d" % \ | file.write(tabStr + "<%d,%d,%d>, %d,%d,%d" % \ | ||||
| (fv[i1], fv[i2], fv[i3], ci1-1, ci2-1, ci3-1)) # vert count | (fv[0], fv[1], fv[2], ci1-1, ci2-1, ci3-1)) # vert count | ||||
| else: | else: | ||||
| file.write(", ") | file.write(", ") | ||||
| file.write("<%d,%d,%d>, %d,%d,%d" % \ | file.write("<%d,%d,%d>, %d,%d,%d" % \ | ||||
| (fv[i1], fv[i2], fv[i3], ci1-1, ci2-1, ci3-1)) # vert count | (fv[0], fv[1], fv[2], ci1-1, ci2-1, ci3-1)) # vert count | ||||
| file.write("\n") | file.write("\n") | ||||
| tabWrite("}\n") | tabWrite("}\n") | ||||
| # normal_indices indices | # normal_indices indices | ||||
| tabWrite("normal_indices {\n") | tabWrite("normal_indices {\n") | ||||
| tabWrite("%d" % (len(me_faces) + quadCount)) # faces count | tabWrite("%d" % (len(me_faces))) # faces count | ||||
| tabStr = tab * tabLevel | tabStr = tab * tabLevel | ||||
| for fi, fv in enumerate(faces_verts): | 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 me_faces[fi].use_smooth: | ||||
| if linebreaksinlists: | if linebreaksinlists: | ||||
| file.write(",\n") | file.write(",\n") | ||||
| file.write(tabStr + "<%d,%d,%d>" %\ | file.write(tabStr + "<%d,%d,%d>" %\ | ||||
| (uniqueNormals[verts_normals[fv[i1]]][0],\ | (uniqueNormals[verts_normals[fv[0]]][0],\ | ||||
| uniqueNormals[verts_normals[fv[i2]]][0],\ | uniqueNormals[verts_normals[fv[1]]][0],\ | ||||
| uniqueNormals[verts_normals[fv[i3]]][0])) # vert count | uniqueNormals[verts_normals[fv[2]]][0])) # vert count | ||||
| else: | else: | ||||
| file.write(", ") | file.write(", ") | ||||
| file.write("<%d,%d,%d>" %\ | file.write("<%d,%d,%d>" %\ | ||||
| (uniqueNormals[verts_normals[fv[i1]]][0],\ | (uniqueNormals[verts_normals[fv[0]]][0],\ | ||||
| uniqueNormals[verts_normals[fv[i2]]][0],\ | uniqueNormals[verts_normals[fv[1]]][0],\ | ||||
| uniqueNormals[verts_normals[fv[i3]]][0])) # vert count | uniqueNormals[verts_normals[fv[2]]][0])) # vert count | ||||
| else: | else: | ||||
| idx = uniqueNormals[faces_normals[fi]][0] | idx = uniqueNormals[faces_normals[fi]][0] | ||||
| if linebreaksinlists: | if linebreaksinlists: | ||||
| file.write(",\n") | file.write(",\n") | ||||
| file.write(tabStr + "<%d,%d,%d>" % (idx, idx, idx)) # vert count | file.write(tabStr + "<%d,%d,%d>" % (idx, idx, idx)) # vert count | ||||
| else: | else: | ||||
| file.write(", ") | file.write(", ") | ||||
| file.write("<%d,%d,%d>" % (idx, idx, idx)) # vert count | file.write("<%d,%d,%d>" % (idx, idx, idx)) # vert count | ||||
| file.write("\n") | file.write("\n") | ||||
| tabWrite("}\n") | tabWrite("}\n") | ||||
| if uv_layer: | if uv_layer: | ||||
| tabWrite("uv_indices {\n") | tabWrite("uv_indices {\n") | ||||
| tabWrite("%d" % (len(me_faces) + quadCount)) # faces count | tabWrite("%d" % (len(me_faces))) # faces count | ||||
| tabStr = tab * tabLevel | tabStr = tab * tabLevel | ||||
| for fi, fv in enumerate(faces_verts): | for f in me_faces: | ||||
| uvs = [uv_layer[l].uv[:] for l in f.loops] | |||||
| 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 linebreaksinlists: | if linebreaksinlists: | ||||
| file.write(",\n") | file.write(",\n") | ||||
| file.write(tabStr + "<%d,%d,%d>" % ( | file.write(tabStr + "<%d,%d,%d>" % ( | ||||
| uniqueUVs[uvs[i1]][0],\ | uniqueUVs[uvs[0]][0],\ | ||||
| uniqueUVs[uvs[i2]][0],\ | uniqueUVs[uvs[1]][0],\ | ||||
| uniqueUVs[uvs[i3]][0])) | uniqueUVs[uvs[2]][0])) | ||||
| else: | else: | ||||
| file.write(", ") | file.write(", ") | ||||
| file.write("<%d,%d,%d>" % ( | file.write("<%d,%d,%d>" % ( | ||||
| uniqueUVs[uvs[i1]][0],\ | uniqueUVs[uvs[0]][0],\ | ||||
| uniqueUVs[uvs[i2]][0],\ | uniqueUVs[uvs[1]][0],\ | ||||
| uniqueUVs[uvs[i3]][0])) | uniqueUVs[uvs[2]][0])) | ||||
| file.write("\n") | file.write("\n") | ||||
| tabWrite("}\n") | tabWrite("}\n") | ||||
| #XXX BOOLEAN | #XXX BOOLEAN | ||||
| onceCSG = 0 | onceCSG = 0 | ||||
| for mod in ob.modifiers: | for mod in ob.modifiers: | ||||
| if onceCSG == 0: | if onceCSG == 0: | ||||
| ▲ Show 20 Lines • Show All 106 Lines • ▼ Show 20 Lines | ############################################else try to export mesh | ||||
| file.write("\n texture{%s}\n" % faceMaterial) | file.write("\n texture{%s}\n" % faceMaterial) | ||||
| # END!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | # END!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||||
| else: | else: | ||||
| file.write(" texture{}\n") | file.write(" texture{}\n") | ||||
| tabWrite("}\n") | tabWrite("}\n") | ||||
| # Face indices | # Face indices | ||||
| tabWrite("face_indices {\n") | tabWrite("face_indices {\n") | ||||
| tabWrite("%d" % (len(me_faces) + quadCount)) # faces count | tabWrite("%d" % (len(me_faces))) # faces count | ||||
| tabStr = tab * tabLevel | tabStr = tab * tabLevel | ||||
| for fi, f in enumerate(me_faces): | for fi, f in enumerate(me_faces): | ||||
| fv = faces_verts[fi] | fv = faces_verts[fi] | ||||
| material_index = f.material_index | material_index = f.material_index | ||||
| if len(fv) == 4: | |||||
| indices = (0, 1, 2), (0, 2, 3) | |||||
| else: | |||||
| indices = ((0, 1, 2),) | |||||
| if vcol_layer: | if vcol_layer: | ||||
| col = vcol_layer[fi] | cols = [vcol_layer[l].color[:] for l in f.loops] | ||||
| 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 | if not me_materials or me_materials[material_index] is None: # No materials | ||||
| for i1, i2, i3 in indices: | |||||
| if linebreaksinlists: | if linebreaksinlists: | ||||
| file.write(",\n") | file.write(",\n") | ||||
| # vert count | # vert count | ||||
| file.write(tabStr + "<%d,%d,%d>" % (fv[i1], fv[i2], fv[i3])) | file.write(tabStr + "<%d,%d,%d>" % (fv[0], fv[1], fv[2])) | ||||
| else: | else: | ||||
| file.write(", ") | file.write(", ") | ||||
| file.write("<%d,%d,%d>" % (fv[i1], fv[i2], fv[i3])) # vert count | file.write("<%d,%d,%d>" % (fv[0], fv[1], fv[2])) # vert count | ||||
| else: | else: | ||||
| material = me_materials[material_index] | material = me_materials[material_index] | ||||
| for i1, i2, i3 in indices: | |||||
| ci1 = ci2 = ci3 = f.material_index | ci1 = ci2 = ci3 = f.material_index | ||||
| 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 | # Color per vertex - vertex color | ||||
| col1 = cols[i1] | col1 = cols[0] | ||||
| col2 = cols[i2] | col2 = cols[1] | ||||
| col3 = cols[i3] | col3 = cols[2] | ||||
| ci1 = vertCols[col1[0], col1[1], col1[2], material_index][0] | ci1 = vertCols[col1[0], col1[1], col1[2], material_index][0] | ||||
| ci2 = vertCols[col2[0], col2[1], col2[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] | ci3 = vertCols[col3[0], col3[1], col3[2], material_index][0] | ||||
| elif material.pov.material_use_nodes: | elif material.pov.material_use_nodes: | ||||
| ci1 = ci2 = ci3 = 0 | ci1 = ci2 = ci3 = 0 | ||||
| else: | else: | ||||
| # Color per material - flat material color | # Color per material - flat material color | ||||
| if material.subsurface_scattering.use: | if material.subsurface_scattering.use: | ||||
| diffuse_color = [i * j for i, j in | diffuse_color = [i * j for i, j in | ||||
| zip(material.subsurface_scattering.color[:], | zip(material.subsurface_scattering.color[:], | ||||
| material.diffuse_color[:])] | material.diffuse_color[:])] | ||||
| else: | else: | ||||
| diffuse_color = material.diffuse_color[:] | diffuse_color = material.diffuse_color[:] | ||||
| ci1 = ci2 = ci3 = vertCols[diffuse_color[0], diffuse_color[1], \ | ci1 = ci2 = ci3 = vertCols[diffuse_color[0], diffuse_color[1], \ | ||||
| diffuse_color[2], f.material_index][0] | diffuse_color[2], f.material_index][0] | ||||
| if linebreaksinlists: | if linebreaksinlists: | ||||
| file.write(",\n") | file.write(",\n") | ||||
| file.write(tabStr + "<%d,%d,%d>, %d,%d,%d" % \ | file.write(tabStr + "<%d,%d,%d>, %d,%d,%d" % \ | ||||
| (fv[i1], fv[i2], fv[i3], ci1, ci2, ci3)) # vert count | (fv[0], fv[1], fv[2], ci1, ci2, ci3)) # vert count | ||||
| else: | else: | ||||
| file.write(", ") | file.write(", ") | ||||
| file.write("<%d,%d,%d>, %d,%d,%d" % \ | file.write("<%d,%d,%d>, %d,%d,%d" % \ | ||||
| (fv[i1], fv[i2], fv[i3], ci1, ci2, ci3)) # vert count | (fv[0], fv[1], fv[2], ci1, ci2, ci3)) # vert count | ||||
| file.write("\n") | file.write("\n") | ||||
| tabWrite("}\n") | tabWrite("}\n") | ||||
| # normal_indices indices | # normal_indices indices | ||||
| tabWrite("normal_indices {\n") | tabWrite("normal_indices {\n") | ||||
| tabWrite("%d" % (len(me_faces) + quadCount)) # faces count | tabWrite("%d" % (len(me_faces))) # faces count | ||||
| tabStr = tab * tabLevel | tabStr = tab * tabLevel | ||||
| for fi, fv in enumerate(faces_verts): | 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 me_faces[fi].use_smooth: | ||||
| if linebreaksinlists: | if linebreaksinlists: | ||||
| file.write(",\n") | file.write(",\n") | ||||
| file.write(tabStr + "<%d,%d,%d>" %\ | file.write(tabStr + "<%d,%d,%d>" %\ | ||||
| (uniqueNormals[verts_normals[fv[i1]]][0],\ | (uniqueNormals[verts_normals[fv[0]]][0],\ | ||||
| uniqueNormals[verts_normals[fv[i2]]][0],\ | uniqueNormals[verts_normals[fv[1]]][0],\ | ||||
| uniqueNormals[verts_normals[fv[i3]]][0])) # vert count | uniqueNormals[verts_normals[fv[2]]][0])) # vert count | ||||
| else: | else: | ||||
| file.write(", ") | file.write(", ") | ||||
| file.write("<%d,%d,%d>" %\ | file.write("<%d,%d,%d>" %\ | ||||
| (uniqueNormals[verts_normals[fv[i1]]][0],\ | (uniqueNormals[verts_normals[fv[0]]][0],\ | ||||
| uniqueNormals[verts_normals[fv[i2]]][0],\ | uniqueNormals[verts_normals[fv[1]]][0],\ | ||||
| uniqueNormals[verts_normals[fv[i3]]][0])) # vert count | uniqueNormals[verts_normals[fv[2]]][0])) # vert count | ||||
| else: | else: | ||||
| idx = uniqueNormals[faces_normals[fi]][0] | idx = uniqueNormals[faces_normals[fi]][0] | ||||
| if linebreaksinlists: | if linebreaksinlists: | ||||
| file.write(",\n") | file.write(",\n") | ||||
| file.write(tabStr + "<%d,%d,%d>" % (idx, idx, idx)) # vertcount | file.write(tabStr + "<%d,%d,%d>" % (idx, idx, idx)) # vertcount | ||||
| else: | else: | ||||
| file.write(", ") | file.write(", ") | ||||
| file.write("<%d,%d,%d>" % (idx, idx, idx)) # vert count | file.write("<%d,%d,%d>" % (idx, idx, idx)) # vert count | ||||
| file.write("\n") | file.write("\n") | ||||
| tabWrite("}\n") | tabWrite("}\n") | ||||
| if uv_layer: | if uv_layer: | ||||
| tabWrite("uv_indices {\n") | tabWrite("uv_indices {\n") | ||||
| tabWrite("%d" % (len(me_faces) + quadCount)) # faces count | tabWrite("%d" % (len(me_faces))) # faces count | ||||
| tabStr = tab * tabLevel | tabStr = tab * tabLevel | ||||
| for fi, fv in enumerate(faces_verts): | for f in me_faces: | ||||
| uvs = [uv_layer[l].uv[:] for l in f.loops] | |||||
| 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 linebreaksinlists: | if linebreaksinlists: | ||||
| file.write(",\n") | file.write(",\n") | ||||
| file.write(tabStr + "<%d,%d,%d>" % ( | file.write(tabStr + "<%d,%d,%d>" % ( | ||||
| uniqueUVs[uvs[i1]][0],\ | uniqueUVs[uvs[0]][0],\ | ||||
| uniqueUVs[uvs[i2]][0],\ | uniqueUVs[uvs[1]][0],\ | ||||
| uniqueUVs[uvs[i3]][0])) | uniqueUVs[uvs[2]][0])) | ||||
| else: | else: | ||||
| file.write(", ") | file.write(", ") | ||||
| file.write("<%d,%d,%d>" % ( | file.write("<%d,%d,%d>" % ( | ||||
| uniqueUVs[uvs[i1]][0],\ | uniqueUVs[uvs[0]][0],\ | ||||
| uniqueUVs[uvs[i2]][0],\ | uniqueUVs[uvs[1]][0],\ | ||||
| uniqueUVs[uvs[i3]][0])) | uniqueUVs[uvs[2]][0])) | ||||
| file.write("\n") | file.write("\n") | ||||
| tabWrite("}\n") | tabWrite("}\n") | ||||
| #XXX BOOLEAN | #XXX BOOLEAN | ||||
| onceCSG = 0 | onceCSG = 0 | ||||
| for mod in ob.modifiers: | for mod in ob.modifiers: | ||||
| if onceCSG == 0: | if onceCSG == 0: | ||||
| ▲ Show 20 Lines • Show All 408 Lines • ▼ Show 20 Lines | #http://news.pov.org/pov.newusers/thread/%3Cweb.4a5cddf4e9c9822ba2f93e20@news.pov.org%3E/ | ||||
| if csg_list != []: | if csg_list != []: | ||||
| csg = False | csg = False | ||||
| sel = no_renderable_objects(scene) | sel = no_renderable_objects(scene) | ||||
| exportMeshes(scene, sel, csg) | exportMeshes(scene, sel, csg) | ||||
| csg = True | csg = True | ||||
| sel = renderable_objects(scene) | sel = renderable_objects(scene) | ||||
| exportLamps([L for L in sel if (L.type == 'LAMP' and L.pov.object_as != 'RAINBOW')]) | exportLamps([L for L in sel if (L.type == 'LIGHT' and L.pov.object_as != 'RAINBOW')]) | ||||
| if comments: | if comments: | ||||
| file.write("\n//--Rainbows--\n\n") | file.write("\n//--Rainbows--\n\n") | ||||
| exportRainbows([L for L in sel if (L.type == 'LAMP' and L.pov.object_as == 'RAINBOW')]) | exportRainbows([L for L in sel if (L.type == 'LIGHT' and L.pov.object_as == 'RAINBOW')]) | ||||
| if comments: | if comments: | ||||
| file.write("\n//--Special Curves--\n\n") | file.write("\n//--Special Curves--\n\n") | ||||
| for c in sel: | for c in sel: | ||||
| if c.is_modified(scene, 'RENDER'): | if c.is_modified(scene, 'RENDER'): | ||||
| continue #don't export as pov curves objects with modifiers, but as mesh | continue #don't export as pov curves objects with modifiers, but as mesh | ||||
| elif c.type == 'CURVE' and (c.pov.curveshape in {'lathe','sphere_sweep','loft','birail'}): | elif c.type == 'CURVE' and (c.pov.curveshape in {'lathe','sphere_sweep','loft','birail'}): | ||||
| ▲ Show 20 Lines • Show All 790 Lines • Show Last 20 Lines | |||||