Cleanups suggested by Campbell Barton:
*reduced dictionary lookups for comments and linebreaks in lists *Better tabWrite function to speed up when using tempfiles
This commit is contained in:
parent
c50944e808
commit
2bfbbe4182
|
@ -165,7 +165,8 @@ def write_pov(filename, scene=None, info_callback=None):
|
|||
render = scene.render
|
||||
world = scene.world
|
||||
global_matrix = mathutils.Matrix.Rotation(-pi / 2.0, 4, 'X')
|
||||
|
||||
comments = scene.pov.comments_enable and not scene.pov.tempfiles_enable
|
||||
linebreaksinlists= scene.pov.list_lf_enable and not scene.pov.tempfiles_enable
|
||||
def setTab(tabtype, spaces):
|
||||
TabStr = ""
|
||||
if tabtype == 'NONE':
|
||||
|
@ -177,9 +178,8 @@ def write_pov(filename, scene=None, info_callback=None):
|
|||
return TabStr
|
||||
|
||||
tab = setTab(scene.pov.indentation_character, scene.pov.indentation_spaces)
|
||||
|
||||
def tabWrite(str_o):
|
||||
if not scene.pov.tempfiles_enable:
|
||||
if not scene.pov.tempfiles_enable:
|
||||
def tabWrite(str_o):
|
||||
global tabLevel
|
||||
brackets = str_o.count("{") - str_o.count("}") + str_o.count("[") - str_o.count("]")
|
||||
if brackets < 0:
|
||||
|
@ -192,7 +192,8 @@ def write_pov(filename, scene=None, info_callback=None):
|
|||
file.write(str_o)
|
||||
if brackets > 0:
|
||||
tabLevel = tabLevel + brackets
|
||||
else:
|
||||
else:
|
||||
def tabWrite(str_o):
|
||||
file.write(str_o)
|
||||
|
||||
def uniqueName(name, nameSeq):
|
||||
|
@ -311,8 +312,6 @@ def write_pov(filename, scene=None, info_callback=None):
|
|||
name = name_orig = DEF_MAT_NAME
|
||||
|
||||
|
||||
comments = scene.pov.comments_enable
|
||||
|
||||
if material:
|
||||
# If saturation(.s) is not zero, then color is not grey, and has a tint
|
||||
colored_specular_found = (material.specular_color.s > 0.0)
|
||||
|
@ -327,20 +326,20 @@ def write_pov(filename, scene=None, info_callback=None):
|
|||
def povHasnoSpecularMaps(Level):
|
||||
if Level == 1:
|
||||
tabWrite("#declare %s = finish {" % safety(name, Level=1))
|
||||
if not scene.pov.tempfiles_enable and comments:
|
||||
if comments:
|
||||
file.write(" //No specular nor Mirror reflection\n")
|
||||
else:
|
||||
tabWrite("\n")
|
||||
elif Level == 2:
|
||||
tabWrite("#declare %s = finish {" % safety(name, Level=2))
|
||||
if not scene.pov.tempfiles_enable and comments:
|
||||
if comments:
|
||||
file.write(" //translation of spec and mir levels for when no map " \
|
||||
"influences them\n")
|
||||
else:
|
||||
tabWrite("\n")
|
||||
elif Level == 3:
|
||||
tabWrite("#declare %s = finish {" % safety(name, Level=3))
|
||||
if not scene.pov.tempfiles_enable and comments:
|
||||
if comments:
|
||||
file.write(" //Maximum Spec and Mirror\n")
|
||||
else:
|
||||
tabWrite("\n")
|
||||
|
@ -661,7 +660,7 @@ def write_pov(filename, scene=None, info_callback=None):
|
|||
|
||||
# TODO - blenders 'motherball' naming is not supported.
|
||||
|
||||
if not scene.pov.tempfiles_enable and scene.pov.comments_enable and len(metas) >= 1:
|
||||
if comments and len(metas) >= 1:
|
||||
file.write("//--Blob objects--\n\n")
|
||||
|
||||
for ob in metas:
|
||||
|
@ -735,7 +734,7 @@ def write_pov(filename, scene=None, info_callback=None):
|
|||
|
||||
tabWrite("}\n") # End of Metaball block
|
||||
|
||||
if not scene.pov.tempfiles_enable and scene.pov.comments_enable and len(metas) >= 1:
|
||||
if comments and len(metas) >= 1:
|
||||
file.write("\n")
|
||||
|
||||
# objectNames = {}
|
||||
|
@ -1048,7 +1047,7 @@ def write_pov(filename, scene=None, info_callback=None):
|
|||
|
||||
tabStr = tab * tabLevel
|
||||
for v in me.vertices:
|
||||
if not scene.pov.tempfiles_enable and scene.pov.list_lf_enable:
|
||||
if linebreaksinlists:
|
||||
file.write(",\n")
|
||||
file.write(tabStr + "<%.6f, %.6f, %.6f>" % v.co[:]) # vert count
|
||||
else:
|
||||
|
@ -1076,7 +1075,7 @@ def write_pov(filename, scene=None, info_callback=None):
|
|||
idx = 0
|
||||
tabStr = tab * tabLevel
|
||||
for no, index in uniqueNormals.items():
|
||||
if not scene.pov.tempfiles_enable and scene.pov.list_lf_enable:
|
||||
if linebreaksinlists:
|
||||
file.write(",\n")
|
||||
file.write(tabStr + "<%.6f, %.6f, %.6f>" % no) # vert count
|
||||
else:
|
||||
|
@ -1110,7 +1109,7 @@ def write_pov(filename, scene=None, info_callback=None):
|
|||
idx = 0
|
||||
tabStr = tab * tabLevel
|
||||
for uv, index in uniqueUVs.items():
|
||||
if not scene.pov.tempfiles_enable and scene.pov.list_lf_enable:
|
||||
if linebreaksinlists:
|
||||
file.write(",\n")
|
||||
file.write(tabStr + "<%.6f, %.6f>" % uv)
|
||||
else:
|
||||
|
@ -1152,8 +1151,13 @@ def write_pov(filename, scene=None, info_callback=None):
|
|||
key = col[0], col[1], col[2], material_index # Material index!
|
||||
VcolIdx+=1
|
||||
vertCols[key] = [VcolIdx]
|
||||
tabWrite("texture {pigment{ color rgb <%6f,%6f,%6f> }}" % (col[0], col[1], col[2]))
|
||||
tabStr = tab * tabLevel
|
||||
if comments:
|
||||
file.write("\n //Vertex colors: one simple pigment texture per vertex\n")
|
||||
if linebreaksinlists:
|
||||
tabWrite("texture {pigment{ color rgb <%6f,%6f,%6f> }}\n" % (col[0], col[1], col[2]))
|
||||
else:
|
||||
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
|
||||
|
@ -1192,7 +1196,7 @@ def write_pov(filename, scene=None, info_callback=None):
|
|||
|
||||
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:
|
||||
if linebreaksinlists:
|
||||
file.write(",\n")
|
||||
# vert count
|
||||
file.write(tabStr + "<%d,%d,%d>" % (fv[i1], fv[i2], fv[i3]))
|
||||
|
@ -1221,7 +1225,7 @@ def write_pov(filename, scene=None, info_callback=None):
|
|||
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:
|
||||
if linebreaksinlists:
|
||||
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
|
||||
|
@ -1246,7 +1250,7 @@ def write_pov(filename, scene=None, info_callback=None):
|
|||
|
||||
for i1, i2, i3 in indices:
|
||||
if me_faces[fi].use_smooth:
|
||||
if not scene.pov.tempfiles_enable and scene.pov.list_lf_enable:
|
||||
if linebreaksinlists:
|
||||
file.write(",\n")
|
||||
file.write(tabStr + "<%d,%d,%d>" %\
|
||||
(uniqueNormals[verts_normals[fv[i1]]][0],\
|
||||
|
@ -1260,7 +1264,7 @@ def write_pov(filename, scene=None, info_callback=None):
|
|||
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:
|
||||
if linebreaksinlists:
|
||||
file.write(",\n")
|
||||
file.write(tabStr + "<%d,%d,%d>" % (idx, idx, idx)) # vert count
|
||||
else:
|
||||
|
@ -1288,7 +1292,7 @@ def write_pov(filename, scene=None, info_callback=None):
|
|||
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:
|
||||
if linebreaksinlists:
|
||||
file.write(",\n")
|
||||
file.write(tabStr + "<%d,%d,%d>" % (
|
||||
uniqueUVs[uvs[i1]][0],\
|
||||
|
@ -1728,7 +1732,7 @@ def write_pov(filename, scene=None, info_callback=None):
|
|||
special_texture_found = True
|
||||
|
||||
if colored_specular_found and not special_texture_found:
|
||||
if not scene.pov.tempfiles_enable and scene.pov.comments_enable:
|
||||
if comments:
|
||||
file.write(" //Emulating colored highlights with a metallic layer\n")
|
||||
else:
|
||||
tabWrite("\n")
|
||||
|
@ -1805,7 +1809,7 @@ def write_pov(filename, scene=None, info_callback=None):
|
|||
|
||||
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:
|
||||
if linebreaksinlists:
|
||||
file.write(",\n")
|
||||
# vert count
|
||||
file.write(tabStr + "<%d,%d,%d>" % (fv[i1], fv[i2], fv[i3]))
|
||||
|
@ -1834,7 +1838,7 @@ def write_pov(filename, scene=None, info_callback=None):
|
|||
ci1 = ci2 = ci3 = vertCols[diffuse_color[0], diffuse_color[1], \
|
||||
diffuse_color[2], f.material_index][0]
|
||||
|
||||
if not scene.pov.tempfiles_enable and scene.pov.list_lf_enable:
|
||||
if linebreaksinlists:
|
||||
file.write(",\n")
|
||||
file.write(tabStr + "<%d,%d,%d>, %d,%d,%d" % \
|
||||
(fv[i1], fv[i2], fv[i3], ci1, ci2, ci3)) # vert count
|
||||
|
@ -1859,7 +1863,7 @@ def write_pov(filename, scene=None, info_callback=None):
|
|||
|
||||
for i1, i2, i3 in indices:
|
||||
if me_faces[fi].use_smooth:
|
||||
if not scene.pov.tempfiles_enable and scene.pov.list_lf_enable:
|
||||
if linebreaksinlists:
|
||||
file.write(",\n")
|
||||
file.write(tabStr + "<%d,%d,%d>" %\
|
||||
(uniqueNormals[verts_normals[fv[i1]]][0],\
|
||||
|
@ -1873,7 +1877,7 @@ def write_pov(filename, scene=None, info_callback=None):
|
|||
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:
|
||||
if linebreaksinlists:
|
||||
file.write(",\n")
|
||||
file.write(tabStr + "<%d,%d,%d>" % (idx, idx, idx)) # vert count
|
||||
else:
|
||||
|
@ -1901,7 +1905,7 @@ def write_pov(filename, scene=None, info_callback=None):
|
|||
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:
|
||||
if linebreaksinlists:
|
||||
file.write(",\n")
|
||||
file.write(tabStr + "<%d,%d,%d>" % (
|
||||
uniqueUVs[uvs[i1]][0],\
|
||||
|
@ -2145,39 +2149,38 @@ def write_pov(filename, scene=None, info_callback=None):
|
|||
file.write("\n")
|
||||
|
||||
sel = renderable_objects(scene)
|
||||
comments = scene.pov.comments_enable
|
||||
if not scene.pov.tempfiles_enable and comments:
|
||||
if comments:
|
||||
file.write("//----------------------------------------------\n" \
|
||||
"//--Exported with POV-Ray exporter for Blender--\n" \
|
||||
"//----------------------------------------------\n\n")
|
||||
file.write("#version 3.7;\n")
|
||||
|
||||
if not scene.pov.tempfiles_enable and comments:
|
||||
if comments:
|
||||
file.write("\n//--Global settings--\n\n")
|
||||
|
||||
exportGlobalSettings(scene)
|
||||
|
||||
|
||||
if not scene.pov.tempfiles_enable and comments:
|
||||
if comments:
|
||||
file.write("\n//--Custom Code--\n\n")
|
||||
exportCustomCode()
|
||||
|
||||
if not scene.pov.tempfiles_enable and comments:
|
||||
if comments:
|
||||
file.write("\n//--Background--\n\n")
|
||||
|
||||
exportWorld(scene.world)
|
||||
|
||||
if not scene.pov.tempfiles_enable and comments:
|
||||
if comments:
|
||||
file.write("\n//--Cameras--\n\n")
|
||||
|
||||
exportCamera()
|
||||
|
||||
if not scene.pov.tempfiles_enable and comments:
|
||||
if comments:
|
||||
file.write("\n//--Lamps--\n\n")
|
||||
|
||||
exportLamps([l for l in sel if l.type == 'LAMP'])
|
||||
|
||||
if not scene.pov.tempfiles_enable and comments:
|
||||
if comments:
|
||||
file.write("\n//--Material Definitions--\n\n")
|
||||
|
||||
# Convert all materials to strings we can access directly per vertex.
|
||||
|
@ -2186,12 +2189,12 @@ def write_pov(filename, scene=None, info_callback=None):
|
|||
for material in bpy.data.materials:
|
||||
if material.users > 0:
|
||||
writeMaterial(material)
|
||||
if not scene.pov.tempfiles_enable and comments:
|
||||
if comments:
|
||||
file.write("\n")
|
||||
|
||||
exportMeta([l for l in sel if l.type == 'META'])
|
||||
|
||||
if not scene.pov.tempfiles_enable and comments:
|
||||
if comments:
|
||||
file.write("//--Mesh objects--\n")
|
||||
|
||||
exportMeshes(scene, sel)
|
||||
|
|
Loading…
Reference in New Issue