Newer
Older
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]
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
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:
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
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
# No vertex colors, so write material colors as vertex colors
for i, material in enumerate(me_materials):
if material:
Maurice Raybaud
committed
# Multiply diffuse with SSS Color
if material.subsurface_scattering.use:
diffuse_color = [i * j for i, j in zip(material.subsurface_scattering.color[:], material.diffuse_color[:])]
Maurice Raybaud
committed
key = diffuse_color[0], diffuse_color[1], diffuse_color[2], i # i == f.mat
vertCols[key] = [-1]
else:
diffuse_color = material.diffuse_color[:]
key = diffuse_color[0], diffuse_color[1], diffuse_color[2], i # i == f.mat
vertCols[key] = [-1]
Maurice Raybaud
committed
idx = 0
LocalMaterialNames = []
Maurice Raybaud
committed
for col, index in vertCols.items():
#if me_materials:
mater = me_materials[col[3]]
Maurice Raybaud
committed
material_finish = DEF_MAT_NAME # not working properly,
trans = 0.0
Maurice Raybaud
committed
else:
material_finish = materialNames[mater.name]
if mater.use_transparency:
trans = 1.0 - mater.alpha
Maurice Raybaud
committed
else:
trans = 0.0
if (mater.specular_color.s == 0.0):
Maurice Raybaud
committed
colored_specular_found = False
else:
colored_specular_found = True
if mater.use_transparency and mater.transparency_method == 'RAYTRACE':
povFilter = mater.raytrace_transparency.filter * (1.0 - mater.alpha)
trans = (1.0 - mater.alpha) - povFilter
Maurice Raybaud
committed
else:
povFilter = 0.0
##############SF
texturesDif = ""
texturesSpec = ""
texturesNorm = ""
texturesAlpha = ""
#proceduralFlag=False
for t in mater.texture_slots:
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
if t and t.use and t.texture.type != 'IMAGE' and t.texture.type != 'NONE':
proceduralFlag=True
image_filename = "PAT_%s"%string_strip_hyphen(bpy.path.clean_name(t.texture.name))
if image_filename:
if t.use_map_color_diffuse:
texturesDif = image_filename
# colvalue = t.default_value # UNUSED
t_dif = t
if t_dif.texture.pov.tex_gamma_enable:
imgGamma = (" gamma %.3g " % t_dif.texture.pov.tex_gamma_value)
if t.use_map_specular or t.use_map_raymir:
texturesSpec = image_filename
# colvalue = t.default_value # UNUSED
t_spec = t
if t.use_map_normal:
texturesNorm = image_filename
# colvalue = t.normal_factor * 10.0 # UNUSED
#textNormName=t.texture.image.name + ".normal"
#was the above used? --MR
t_nor = t
if t.use_map_alpha:
texturesAlpha = image_filename
# colvalue = t.alpha_factor * 10.0 # UNUSED
#textDispName=t.texture.image.name + ".displ"
#was the above used? --MR
t_alpha = t
if t and t.texture.type == 'IMAGE' and t.use and t.texture.image and t.texture.pov.tex_pattern_type == 'emulator':
proceduralFlag=False
if t.texture.image.packed_file:
orig_image_filename=t.texture.image.filepath_raw
workDir=os.path.dirname(__file__)
previewDir=os.path.join(workDir, "preview")
unpackedfilename= os.path.join(previewDir,("unpacked_img_"+(string_strip_hyphen(bpy.path.clean_name(t.texture.name)))))
if not os.path.exists(unpackedfilename):
# record which images that were newly copied and can be safely
# cleaned up
unpacked_images.append(unpackedfilename)
t.texture.image.filepath_raw=unpackedfilename
t.texture.image.save()
image_filename = unpackedfilename
t.texture.image.filepath_raw=orig_image_filename
else:
image_filename = path_image(t.texture.image)
Maurice Raybaud
committed
# IMAGE SEQUENCE BEGINS
if image_filename:
if bpy.data.images[t.texture.image.name].source == 'SEQUENCE':
korvaa = "." + str(bpy.data.textures[t.texture.name].image_user.frame_offset + 1).zfill(3) + "."
image_filename = image_filename.replace(".001.", korvaa)
print(" seq debug ")
print(image_filename)
# IMAGE SEQUENCE ENDS
Maurice Raybaud
committed
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
imgGamma = ""
if image_filename:
if t.use_map_color_diffuse:
texturesDif = image_filename
# colvalue = t.default_value # UNUSED
t_dif = t
if t_dif.texture.pov.tex_gamma_enable:
imgGamma = (" gamma %.3g " % t_dif.texture.pov.tex_gamma_value)
if t.use_map_specular or t.use_map_raymir:
texturesSpec = image_filename
# colvalue = t.default_value # UNUSED
t_spec = t
if t.use_map_normal:
texturesNorm = image_filename
# colvalue = t.normal_factor * 10.0 # UNUSED
#textNormName=t.texture.image.name + ".normal"
#was the above used? --MR
t_nor = t
if t.use_map_alpha:
texturesAlpha = image_filename
# colvalue = t.alpha_factor * 10.0 # UNUSED
#textDispName=t.texture.image.name + ".displ"
#was the above used? --MR
t_alpha = t
####################################################################################
file.write("\n")
# THIS AREA NEEDS TO LEAVE THE TEXTURE OPEN UNTIL ALL MAPS ARE WRITTEN DOWN.
# --MR
currentMatName = string_strip_hyphen(materialNames[mater.name])
Maurice Raybaud
committed
LocalMaterialNames.append(currentMatName)
file.write("\n #declare MAT_%s = \ntexture{\n" % currentMatName)
################################################################################
if mater.pov.replacement_text != "":
file.write("%s\n" % mater.pov.replacement_text)
#################################################################################
if mater.diffuse_shader == 'MINNAERT':
Maurice Raybaud
committed
tabWrite("\n")
tabWrite("aoi\n")
tabWrite("texture_map {\n")
tabWrite("[%.3g finish {diffuse %.3g}]\n" % \
(mater.darkness / 2.0, 2.0 - mater.darkness))
tabWrite("[%.3g\n" % (1.0 - (mater.darkness / 2.0)))
Maurice Raybaud
committed
if mater.diffuse_shader == 'FRESNEL':
Maurice Raybaud
committed
# For FRESNEL diffuse in POV, we'll layer slope patterned textures
# with lamp vector as the slope vector and nest one slope per lamp
# into each texture map's entry.
c = 1
while (c <= lampCount):
tabWrite("slope { lampTarget%s }\n" % (c))
tabWrite("texture_map {\n")
# Diffuse Fresnel value and factor go up to five,
# other kind of values needed: used the number 5 below to remap
tabWrite("[%.3g finish {diffuse %.3g}]\n" % \
((5.0 - mater.diffuse_fresnel) / 5,
(mater.diffuse_intensity *
((5.0 - mater.diffuse_fresnel_factor) / 5))))
tabWrite("[%.3g\n" % ((mater.diffuse_fresnel_factor / 5) *
(mater.diffuse_fresnel / 5.0)))
Maurice Raybaud
committed
c += 1
# if shader is a 'FRESNEL' or 'MINNAERT': slope pigment pattern or aoi
# and texture map above, the rest below as one of its entry
if texturesSpec != "" or texturesAlpha != "":
if texturesSpec != "":
# tabWrite("\n")
tabWrite("pigment_pattern {\n")
if texturesSpec and texturesSpec.startswith("PAT_"):
tabWrite("function{f%s(x,y,z).grey}" %texturesSpec)
else:
# POV-Ray "scale" is not a number of repetitions factor, but its
# inverse, a standard scale factor.
# Offset seems needed relatively to scale so probably center of the
# scale is not the same in blender and POV
mappingSpec =imgMapTransforms(t_spec)
# mappingSpec = "translate <%.4g,%.4g,%.4g> scale <%.4g,%.4g,%.4g>\n" % \
# (-t_spec.offset.x, t_spec.offset.y, t_spec.offset.z,
# 1.0 / t_spec.scale.x, 1.0 / t_spec.scale.y,
# 1.0 / t_spec.scale.z)
tabWrite("uv_mapping image_map{%s \"%s\" %s}\n" % \
(imageFormat(texturesSpec), texturesSpec, imgMap(t_spec)))
tabWrite("%s\n" % mappingSpec)
Maurice Raybaud
committed
tabWrite("}\n")
tabWrite("texture_map {\n")
tabWrite("[0 \n")
if texturesDif == "":
if texturesAlpha != "":
tabWrite("\n")
if texturesAlpha and texturesAlpha.startswith("PAT_"):
tabWrite("function{f%s(x,y,z).transmit}\n" %texturesAlpha)
else:
# POV-Ray "scale" is not a number of repetitions factor, but its
# inverse, a standard scale factor.
# Offset seems needed relatively to scale so probably center of the
# scale is not the same in blender and POV
mappingAlpha = imgMapTransforms(t_alpha)
# mappingAlpha = " translate <%.4g, %.4g, %.4g> " \
# "scale <%.4g, %.4g, %.4g>\n" % \
# (-t_alpha.offset.x, -t_alpha.offset.y,
# t_alpha.offset.z, 1.0 / t_alpha.scale.x,
# 1.0 / t_alpha.scale.y, 1.0 / t_alpha.scale.z)
tabWrite("pigment {pigment_pattern {uv_mapping image_map" \
"{%s \"%s\" %s}%s" % \
(imageFormat(texturesAlpha), texturesAlpha,
imgMap(t_alpha), mappingAlpha))
Maurice Raybaud
committed
tabWrite("}\n")
tabWrite("pigment_map {\n")
tabWrite("[0 color rgbft<0,0,0,1,1>]\n")
tabWrite("[1 color rgbft<%.3g, %.3g, %.3g, %.3g, %.3g>]\n" % \
(col[0], col[1], col[2], povFilter, trans))
tabWrite("}\n")
tabWrite("}\n")
Maurice Raybaud
committed
else:
Maurice Raybaud
committed
Maurice Raybaud
committed
tabWrite("pigment {rgbft<%.3g, %.3g, %.3g, %.3g, %.3g>}\n" % \
(col[0], col[1], col[2], povFilter, trans))
Maurice Raybaud
committed
Maurice Raybaud
committed
if texturesSpec != "":
# Level 1 is no specular
tabWrite("finish {%s}\n" % (safety(material_finish, Level=1)))
Maurice Raybaud
committed
Maurice Raybaud
committed
else:
# Level 2 is translated spec
tabWrite("finish {%s}\n" % (safety(material_finish, Level=2)))
Maurice Raybaud
committed
else:
mappingDif = imgMapTransforms(t_dif)
Maurice Raybaud
committed
if texturesAlpha != "":
mappingAlpha = imgMapTransforms(t_alpha)
# mappingAlpha = " translate <%.4g,%.4g,%.4g> " \
# "scale <%.4g,%.4g,%.4g>" % \
# (-t_alpha.offset.x, -t_alpha.offset.y,
# t_alpha.offset.z, 1.0 / t_alpha.scale.x,
# 1.0 / t_alpha.scale.y, 1.0 / t_alpha.scale.z)
Maurice Raybaud
committed
tabWrite("pigment {\n")
tabWrite("pigment_pattern {\n")
if texturesAlpha and texturesAlpha.startswith("PAT_"):
tabWrite("function{f%s(x,y,z).transmit}\n" %texturesAlpha)
else:
tabWrite("uv_mapping image_map{%s \"%s\" %s}%s}\n" % \
(imageFormat(texturesAlpha), texturesAlpha,
imgMap(t_alpha), mappingAlpha))
Maurice Raybaud
committed
tabWrite("pigment_map {\n")
tabWrite("[0 color rgbft<0,0,0,1,1>]\n")
#if texturesAlpha and texturesAlpha.startswith("PAT_"):
#tabWrite("[1 pigment{%s}]\n" %texturesDif)
if texturesDif and not texturesDif.startswith("PAT_"):
tabWrite("[1 uv_mapping image_map {%s \"%s\" %s} %s]\n" % \
(imageFormat(texturesDif), texturesDif,
(imgGamma + imgMap(t_dif)), mappingDif))
elif texturesDif and texturesDif.startswith("PAT_"):
tabWrite("[1 %s]\n" %texturesDif)
Maurice Raybaud
committed
tabWrite("}\n")
tabWrite("}\n")
if texturesAlpha and texturesAlpha.startswith("PAT_"):
tabWrite("}\n")
Maurice Raybaud
committed
else:
if texturesDif and texturesDif.startswith("PAT_"):
tabWrite("pigment{%s}\n" %texturesDif)
else:
tabWrite("pigment {uv_mapping image_map {%s \"%s\" %s}%s}\n" % \
(imageFormat(texturesDif), texturesDif,
(imgGamma + imgMap(t_dif)), mappingDif))
Maurice Raybaud
committed
if texturesSpec != "":
# Level 1 is no specular
tabWrite("finish {%s}\n" % (safety(material_finish, Level=1)))
Maurice Raybaud
committed
else:
# Level 2 is translated specular
tabWrite("finish {%s}\n" % (safety(material_finish, Level=2)))
## scale 1 rotate y*0
#imageMap = ("{image_map {%s \"%s\" %s }\n" % \
# (imageFormat(textures),textures,imgMap(t_dif)))
#tabWrite("uv_mapping pigment %s} %s finish {%s}\n" % \
# (imageMap,mapping,safety(material_finish)))
#tabWrite("pigment {uv_mapping image_map {%s \"%s\" %s}%s} " \
# "finish {%s}\n" % \
# (imageFormat(texturesDif), texturesDif, imgMap(t_dif),
# mappingDif, safety(material_finish)))
if texturesNorm != "":
## scale 1 rotate y*0
# POV-Ray "scale" is not a number of repetitions factor, but its
# inverse, a standard scale factor.
# Offset seems needed relatively to scale so probably center of the
# scale is not the same in blender and POV
mappingNor =imgMapTransforms(t_nor)
# mappingNor = " translate <%.4g,%.4g,%.4g> scale <%.4g,%.4g,%.4g>" % \
# (-t_nor.offset.x, -t_nor.offset.y, t_nor.offset.z,
# 1.0 / t_nor.scale.x, 1.0 / t_nor.scale.y,
# 1.0 / t_nor.scale.z)
Maurice Raybaud
committed
#imageMapNor = ("{bump_map {%s \"%s\" %s mapping}" % \
# (imageFormat(texturesNorm),texturesNorm,imgMap(t_nor)))
#We were not using the above maybe we should?
if texturesNorm and texturesNorm.startswith("PAT_"):
tabWrite("normal{function{f%s(x,y,z).grey} bump_size %.4g}\n" %(texturesNorm, t_nor.normal_factor * 10))
else:
tabWrite("normal {uv_mapping bump_map " \
"{%s \"%s\" %s bump_size %.4g }%s}\n" % \
(imageFormat(texturesNorm), texturesNorm, imgMap(t_nor),
t_nor.normal_factor * 10, mappingNor))
Maurice Raybaud
committed
if texturesSpec != "":
tabWrite("]\n")
##################Second index for mapping specular max value###############
tabWrite("[1 \n")
if texturesDif == "" and mater.pov.replacement_text == "":
Maurice Raybaud
committed
if texturesAlpha != "":
# POV-Ray "scale" is not a number of repetitions factor, but its inverse,
# a standard scale factor.
# Offset seems needed relatively to scale so probably center of the scale
# is not the same in blender and POV
# Strange that the translation factor for scale is not the same as for
# translate.
# TODO: verify both matches with blender internal.
mappingAlpha = imgMapTransforms(t_alpha)
# mappingAlpha = " translate <%.4g,%.4g,%.4g> scale <%.4g,%.4g,%.4g>\n" % \
# (-t_alpha.offset.x, -t_alpha.offset.y, t_alpha.offset.z,
# 1.0 / t_alpha.scale.x, 1.0 / t_alpha.scale.y,
# 1.0 / t_alpha.scale.z)
if texturesAlpha and texturesAlpha.startswith("PAT_"):
tabWrite("function{f%s(x,y,z).transmit}\n" %texturesAlpha)
else:
tabWrite("pigment {pigment_pattern {uv_mapping image_map" \
"{%s \"%s\" %s}%s}\n" % \
(imageFormat(texturesAlpha), texturesAlpha, imgMap(t_alpha),
mappingAlpha))
Maurice Raybaud
committed
tabWrite("pigment_map {\n")
tabWrite("[0 color rgbft<0,0,0,1,1>]\n")
tabWrite("[1 color rgbft<%.3g, %.3g, %.3g, %.3g, %.3g>]\n" % \
(col[0], col[1], col[2], povFilter, trans))
tabWrite("}\n")
tabWrite("}\n")
Maurice Raybaud
committed
else:
tabWrite("pigment {rgbft<%.3g, %.3g, %.3g, %.3g, %.3g>}\n" % \
(col[0], col[1], col[2], povFilter, trans))
if texturesSpec != "":
# Level 3 is full specular
tabWrite("finish {%s}\n" % (safety(material_finish, Level=3)))
elif colored_specular_found:
# Level 1 is no specular
tabWrite("finish {%s}\n" % (safety(material_finish, Level=1)))
Maurice Raybaud
committed
else:
# Level 2 is translated specular
tabWrite("finish {%s}\n" % (safety(material_finish, Level=2)))
elif mater.pov.replacement_text == "":
mappingDif = imgMapTransforms(t_dif)
# mappingDif = ("scale <%.4g,%.4g,%.4g> translate <%.4g,%.4g,%.4g>" % \
# ( 1.0 / t_dif.scale.x,
# 1.0 / t_dif.scale.y,
# 1.0 / t_dif.scale.z,
# 0.5-(0.5/t_dif.scale.x) + t_dif.offset.x,
# 0.5-(0.5/t_dif.scale.y) + t_dif.offset.y,
# 0.5-(0.5/t_dif.scale.z) + t_dif.offset.z))
Maurice Raybaud
committed
if texturesAlpha != "":
# Strange that the translation factor for scale is not the same as for
# translate.
# TODO: verify both matches with blender internal.
mappingAlpha = imgMapTransforms(t_alpha)
# mappingAlpha = "translate <%.4g,%.4g,%.4g> scale <%.4g,%.4g,%.4g>" % \
# (-t_alpha.offset.x, -t_alpha.offset.y, t_alpha.offset.z,
# 1.0 / t_alpha.scale.x, 1.0 / t_alpha.scale.y,
# 1.0 / t_alpha.scale.z)
if texturesAlpha and texturesAlpha.startswith("PAT_"):
tabWrite("pigment{pigment_pattern {function{f%s(x,y,z).transmit}}\n" %texturesAlpha)
else:
tabWrite("pigment {pigment_pattern {uv_mapping image_map" \
"{%s \"%s\" %s}%s}\n" % \
(imageFormat(texturesAlpha), texturesAlpha, imgMap(t_alpha),
mappingAlpha))
Maurice Raybaud
committed
tabWrite("pigment_map {\n")
tabWrite("[0 color rgbft<0,0,0,1,1>]\n")
if texturesAlpha and texturesAlpha.startswith("PAT_"):
tabWrite("[1 function{f%s(x,y,z).transmit}]\n" %texturesAlpha)
elif texturesDif and not texturesDif.startswith("PAT_"):
tabWrite("[1 uv_mapping image_map {%s \"%s\" %s} %s]\n" % \
(imageFormat(texturesDif), texturesDif,
(imgMap(t_dif) + imgGamma), mappingDif))
elif texturesDif and texturesDif.startswith("PAT_"):
tabWrite("[1 %s]\n" %texturesDif)
Maurice Raybaud
committed
tabWrite("}\n")
tabWrite("}\n")
Maurice Raybaud
committed
Maurice Raybaud
committed
else:
if texturesDif and texturesDif.startswith("PAT_"):
tabWrite("pigment{%s}\n" %texturesDif)
else:
tabWrite("pigment {\n")
tabWrite("uv_mapping image_map {\n")
#tabWrite("%s \"%s\" %s}%s\n" % \
# (imageFormat(texturesDif), texturesDif,
# (imgGamma + imgMap(t_dif)),mappingDif))
tabWrite("%s \"%s\" \n" % (imageFormat(texturesDif), texturesDif))
tabWrite("%s\n" % (imgGamma + imgMap(t_dif)))
tabWrite("}\n")
tabWrite("%s\n" % mappingDif)
tabWrite("}\n")
Maurice Raybaud
committed
if texturesSpec != "":
# Level 3 is full specular
tabWrite("finish {%s}\n" % (safety(material_finish, Level=3)))
else:
# Level 2 is translated specular
tabWrite("finish {%s}\n" % (safety(material_finish, Level=2)))
## scale 1 rotate y*0
#imageMap = ("{image_map {%s \"%s\" %s }" % \
# (imageFormat(textures), textures,imgMap(t_dif)))
#file.write("\n\t\t\tuv_mapping pigment %s} %s finish {%s}" % \
# (imageMap, mapping, safety(material_finish)))
#file.write("\n\t\t\tpigment {uv_mapping image_map " \
# "{%s \"%s\" %s}%s} finish {%s}" % \
# (imageFormat(texturesDif), texturesDif,imgMap(t_dif),
# mappingDif, safety(material_finish)))
if texturesNorm != "" and mater.pov.replacement_text == "":
Maurice Raybaud
committed
## scale 1 rotate y*0
# POV-Ray "scale" is not a number of repetitions factor, but its inverse,
# a standard scale factor.
# Offset seems needed relatively to scale so probably center of the scale is
# not the same in blender and POV
mappingNor =imgMapTransforms(t_nor)
# mappingNor = (" translate <%.4g,%.4g,%.4g> scale <%.4g,%.4g,%.4g>" % \
# (-t_nor.offset.x, -t_nor.offset.y, t_nor.offset.z,
# 1.0 / t_nor.scale.x, 1.0 / t_nor.scale.y, 1.0 / t_nor.scale.z))
Maurice Raybaud
committed
#imageMapNor = ("{bump_map {%s \"%s\" %s mapping}" % \
# (imageFormat(texturesNorm),texturesNorm,imgMap(t_nor)))
#We were not using the above maybe we should?
if texturesNorm and texturesNorm.startswith("PAT_"):
tabWrite("normal{function{f%s(x,y,z).grey} bump_size %.4g}\n" %(texturesNorm, t_nor.normal_factor * 10))
else:
tabWrite("normal {uv_mapping bump_map {%s \"%s\" %s bump_size %.4g }%s}\n" % \
(imageFormat(texturesNorm), texturesNorm, imgMap(t_nor),
t_nor.normal_factor * 10.0, mappingNor))
if texturesSpec != "" and mater.pov.replacement_text == "":
Maurice Raybaud
committed
tabWrite("]\n")
tabWrite("}\n")
#End of slope/ior texture_map
if mater.diffuse_shader == 'MINNAERT' and mater.pov.replacement_text == "":
Maurice Raybaud
committed
tabWrite("]\n")
tabWrite("}\n")
if mater.diffuse_shader == 'FRESNEL' and mater.pov.replacement_text == "":
Maurice Raybaud
committed
c = 1
while (c <= lampCount):
tabWrite("]\n")
tabWrite("}\n")
c += 1
Maurice Raybaud
committed
Maurice Raybaud
committed
Maurice Raybaud
committed
# Close first layer of POV "texture" (Blender material)
tabWrite("}\n")
Maurice Raybaud
committed
Maurice Raybaud
committed
if (mater.specular_color.s > 0.0):
Maurice Raybaud
committed
colored_specular_found = True
Maurice Raybaud
committed
else:
colored_specular_found = False
Maurice Raybaud
committed
# Write another layered texture using invisible diffuse and metallic trick
# to emulate colored specular highlights
special_texture_found = False
for t in mater.texture_slots:
if(t and t.use and ((t.texture.type == 'IMAGE' and t.texture.image) or t.texture.type != 'IMAGE') and
Maurice Raybaud
committed
(t.use_map_specular or t.use_map_raymir)):
# Specular mapped textures would conflict with colored specular
# because POV can't layer over or under pigment patterned textures
special_texture_found = True
if colored_specular_found and not special_texture_found:
file.write(" // colored highlights with a stransparent metallic layer\n")
Maurice Raybaud
committed
else:
tabWrite("\n")
tabWrite("texture {\n")
tabWrite("pigment {rgbft<%.3g, %.3g, %.3g, 0, 1>}\n" % \
(mater.specular_color[0], mater.specular_color[1], mater.specular_color[2]))
Maurice Raybaud
committed
tabWrite("finish {%s}\n" % (safety(material_finish, Level=2))) # Level 2 is translated spec
texturesNorm = ""
for t in mater.texture_slots:
if t and t.texture.pov.tex_pattern_type != 'emulator':
proceduralFlag=True
image_filename = string_strip_hyphen(bpy.path.clean_name(t.texture.name))
if t and t.texture.type == 'IMAGE' and t.use and t.texture.image and t.texture.pov.tex_pattern_type == 'emulator':
proceduralFlag=False
Maurice Raybaud
committed
image_filename = path_image(t.texture.image)
imgGamma = ""
if image_filename:
if t.use_map_normal:
texturesNorm = image_filename
# colvalue = t.normal_factor * 10.0 # UNUSED
#textNormName=t.texture.image.name + ".normal"
#was the above used? --MR
t_nor = t
if proceduralFlag:
tabWrite("normal{function{f%s(x,y,z).grey} bump_size %.4g}\n" %(texturesNorm, t_nor.normal_factor * 10))
else:
tabWrite("normal {uv_mapping bump_map " \
"{%s \"%s\" %s bump_size %.4g }%s}\n" % \
(imageFormat(texturesNorm), texturesNorm, imgMap(t_nor),
t_nor.normal_factor * 10, mappingNor))
Maurice Raybaud
committed
tabWrite("}\n") # THEN IT CAN CLOSE LAST LAYER OF TEXTURE --MR
####################################################################################
index[0] = idx
idx += 1
Maurice Raybaud
committed
# Vert Colors
tabWrite("texture_list {\n")
# In case there's is no material slot, give at least one texture (empty so it uses pov default)
if len(vertCols)==0:
file.write(tabStr + "1")
else:
file.write(tabStr + "%s" % (len(vertCols))) # vert count
if material is not None:
if material.pov.replacement_text != "":
file.write("\n")
file.write(" texture{%s}\n" % material.pov.replacement_text)
Constantin Rahn
committed
else:
# Loop through declared materials list
for cMN in LocalMaterialNames:
if material != "Default":
file.write("\n texture{MAT_%s}\n" % cMN)#string_strip_hyphen(materialNames[material])) # Something like that
file.write(" texture{}\n")
Maurice Raybaud
committed
tabWrite("}\n")
Maurice Raybaud
committed
# Face indices
tabWrite("face_indices {\n")
tabWrite("%d" % (len(me_faces) + quadCount)) # faces count
tabStr = tab * tabLevel
Maurice Raybaud
committed
for fi, f in enumerate(me_faces):
fv = faces_verts[fi]
material_index = f.material_index
Maurice Raybaud
committed
indices = (0, 1, 2), (0, 2, 3)
Maurice Raybaud
committed
indices = ((0, 1, 2),)
Maurice Raybaud
committed
if vcol_layer:
col = vcol_layer[fi]
Maurice Raybaud
committed
if len(fv) == 4:
cols = col.color1, col.color2, col.color3, col.color4
Maurice Raybaud
committed
cols = col.color1, col.color2, col.color3
Maurice Raybaud
committed
if not me_materials or me_materials[material_index] is None: # No materials
for i1, i2, i3 in indices:
Maurice Raybaud
committed
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:
Maurice Raybaud
committed
# Color per vertex - vertex color
Maurice Raybaud
committed
col1 = cols[i1]
col2 = cols[i2]
col3 = cols[i3]
Maurice Raybaud
committed
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]
Maurice Raybaud
committed
file.write(",\n")
file.write(tabStr + "<%d,%d,%d>, %d,%d,%d" % \
(fv[i1], fv[i2], fv[i3], ci1, ci2, ci3)) # vert count
else:
file.write(", ")
file.write("<%d,%d,%d>, %d,%d,%d" % \
(fv[i1], fv[i2], fv[i3], ci1, ci2, ci3)) # vert count
Maurice Raybaud
committed
file.write("\n")
tabWrite("}\n")
Maurice Raybaud
committed
# normal_indices indices
tabWrite("normal_indices {\n")
tabWrite("%d" % (len(me_faces) + quadCount)) # faces count
Constantin Rahn
committed
tabStr = tab * tabLevel
for fi, fv in enumerate(faces_verts):
if len(fv) == 4:
indices = (0, 1, 2), (0, 2, 3)
indices = ((0, 1, 2),)
for i1, i2, i3 in indices:
Maurice Raybaud
committed
if me_faces[fi].use_smooth:
Maurice Raybaud
committed
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
Maurice Raybaud
committed
idx = uniqueNormals[faces_normals[fi]][0]
Maurice Raybaud
committed
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")
Maurice Raybaud
committed
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:
Maurice Raybaud
committed
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
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")
Maurice Raybaud
committed
tabWrite("}\n") # End of mesh block
Bastien Montagne
committed
for data_name, inst in data_ref.items():
for ob_name, matrix_str in inst:
tabWrite("//----Blender Object Name:%s----\n" % ob_name)
tabWrite("object { \n")
tabWrite("%s\n" % data_name)
tabWrite("%s\n" % matrix_str)
tabWrite("}\n")
render = scene.render
matrix = global_matrix * camera.matrix_world
#############Maurice####################################
#These lines added to get sky gradient (visible with PNG output)
if world:
#For simple flat background:
if not world.use_sky_blend:
Bastien Montagne
committed
# Non fully transparent background could premultiply alpha and avoid anti-aliasing
# display issue:
if render.alpha_mode == 'TRANSPARENT':
Bastien Montagne
committed
tabWrite("background {rgbt<%.3g, %.3g, %.3g, 0.75>}\n" % \
(world.horizon_color[:]))
#Currently using no alpha with Sky option:
elif render.alpha_mode == 'SKY':
tabWrite("background {rgbt<%.3g, %.3g, %.3g, 0>}\n" % (world.horizon_color[:]))
# XXX Does not exists anymore
#else:
#tabWrite("background {rgbt<%.3g, %.3g, %.3g, 1>}\n" % (world.horizon_color[:]))
for t in world.texture_slots: # risk to write several sky_spheres but maybe ok.
if t and t.texture.type is not None:
Bastien Montagne
committed
# XXX No enable checkbox for world textures yet (report it?)
#if t and t.texture.type == 'IMAGE' and t.use:
if t and t.texture.type == 'IMAGE':
if t.texture.image.filepath != image_filename:
t.texture.image.filepath = image_filename
if image_filename != "" and t.use_map_blend:
texturesBlend = image_filename
#colvalue = t.default_value
t_blend = t
Bastien Montagne
committed
Bastien Montagne
committed
# Commented below was an idea to make the Background image oriented as camera
# taken here:
#http://news.povray.org/povray.newusers/thread/%3Cweb.4a5cddf4e9c9822ba2f93e20@news.povray.org%3E/
# Replace 4/3 by the ratio of each image found by some custom or existing
# function
#mappingBlend = (" translate <%.4g,%.4g,%.4g> rotate z*degrees" \
# "(atan((camLocation - camLookAt).x/(camLocation - " \
# "camLookAt).y)) rotate x*degrees(atan((camLocation - " \
# "camLookAt).y/(camLocation - camLookAt).z)) rotate y*" \
# "degrees(atan((camLocation - camLookAt).z/(camLocation - " \
# "camLookAt).x)) scale <%.4g,%.4g,%.4g>b" % \
# (t_blend.offset.x / 10 , t_blend.offset.y / 10 ,
# t_blend.offset.z / 10, t_blend.scale.x ,
# t_blend.scale.y , t_blend.scale.z))
#using camera rotation valuesdirectly from blender seems much easier
if t_blend.texture_coords == 'ANGMAP':
mappingBlend = ""
Maurice Raybaud
committed
else:
# POV-Ray "scale" is not a number of repetitions factor, but its
# inverse, a standard scale factor.
# 0.5 Offset is needed relatively to scale because center of the
# UV scale is 0.5,0.5 in blender and 0,0 in POV
# Further Scale by 2 and translate by -1 are
# required for the sky_sphere not to repeat
mappingBlend = "scale 2 scale <%.4g,%.4g,%.4g> translate -1 translate <%.4g,%.4g,%.4g> " \
"rotate<0,0,0> " % \
((1.0 / t_blend.scale.x),
(1.0 / t_blend.scale.y),
(1.0 / t_blend.scale.z),
0.5-(0.5/t_blend.scale.x)- t_blend.offset.x,
0.5-(0.5/t_blend.scale.y)- t_blend.offset.y,
t_blend.offset.z)
Bastien Montagne
committed
# The initial position and rotation of the pov camera is probably creating
# the rotation offset should look into it someday but at least background
# won't rotate with the camera now.
# Putting the map on a plane would not introduce the skysphere distortion and
# allow for better image scale matching but also some waay to chose depth and
# size of the plane relative to camera.
tabWrite("sky_sphere {\n")
tabWrite("pigment {\n")
Bastien Montagne
committed
tabWrite("image_map{%s \"%s\" %s}\n" % \
(imageFormat(texturesBlend), texturesBlend, imgMapBG(t_blend)))
tabWrite("}\n")
tabWrite("%s\n" % (mappingBlend))
Bastien Montagne
committed
# The following layered pigment opacifies to black over the texture for
# transmit below 1 or otherwise adds to itself
Maurice Raybaud
committed
tabWrite("pigment {rgb 0 transmit %s}\n" % (t.texture.intensity))
tabWrite("}\n")
#tabWrite("scale 2\n")
#tabWrite("translate -1\n")
#For only Background gradient
if worldTexCount == 0:
tabWrite("sky_sphere {\n")
tabWrite("pigment {\n")
Bastien Montagne
committed
# maybe Should follow the advice of POV doc about replacing gradient
# for skysphere..5.5
tabWrite("gradient y\n")
tabWrite("color_map {\n")
# XXX Does not exists anymore
#if render.alpha_mode == 'STRAIGHT':
#tabWrite("[0.0 rgbt<%.3g, %.3g, %.3g, 1>]\n" % (world.horizon_color[:]))
#tabWrite("[1.0 rgbt<%.3g, %.3g, %.3g, 1>]\n" % (world.zenith_color[:]))
if render.alpha_mode == 'TRANSPARENT':
tabWrite("[0.0 rgbt<%.3g, %.3g, %.3g, 0.99>]\n" % (world.horizon_color[:]))
Bastien Montagne
committed
# aa premult not solved with transmit 1
tabWrite("[1.0 rgbt<%.3g, %.3g, %.3g, 0.99>]\n" % (world.zenith_color[:]))
tabWrite("[0.0 rgbt<%.3g, %.3g, %.3g, 0>]\n" % (world.horizon_color[:]))
tabWrite("[1.0 rgbt<%.3g, %.3g, %.3g, 0>]\n" % (world.zenith_color[:]))
tabWrite("}\n")
tabWrite("}\n")
tabWrite("}\n")
Bastien Montagne
committed
# Sky_sphere alpha (transmit) is not translating into image alpha the same
# way as 'background'
Maurice Raybaud
committed
#if world.light_settings.use_indirect_light:
Bastien Montagne
committed
# scene.pov.radio_enable=1
Bastien Montagne
committed
# Maybe change the above to a funtion copyInternalRenderer settings when
# user pushes a button, then:
#scene.pov.radio_enable = world.light_settings.use_indirect_light
# and other such translations but maybe this would not be allowed either?
###############################################################
tabWrite("fog {\n")
tabWrite("distance %.6f\n" % mist.depth)
Bastien Montagne
committed
tabWrite("color rgbt<%.3g, %.3g, %.3g, %.3g>\n" % \
(world.horizon_color[:] + (1.0 - mist.intensity,)))
#tabWrite("fog_offset %.6f\n" % mist.start)
#tabWrite("fog_alt 5\n")
#tabWrite("turbulence 0.2\n")
#tabWrite("turb_depth 0.3\n")
tabWrite("fog_type 1\n")
tabWrite("}\n")
Bastien Montagne
committed
if scene.pov.media_enable:
tabWrite("media {\n")
Bastien Montagne
committed
tabWrite("scattering { 1, rgb <%.4g, %.4g, %.4g>}\n" % scene.pov.media_color[:])
tabWrite("samples %.d\n" % scene.pov.media_samples)
tabWrite("}\n")
tabWrite("global_settings {\n")
tabWrite("assumed_gamma 1.0\n")
Bastien Montagne
committed
tabWrite("max_trace_level %d\n" % scene.pov.max_trace_level)
Bastien Montagne
committed
if scene.pov.radio_enable:
tabWrite("radiosity {\n")
Bastien Montagne
committed
tabWrite("adc_bailout %.4g\n" % scene.pov.radio_adc_bailout)
tabWrite("always_sample %d\n" % scene.pov.radio_always_sample)
tabWrite("brightness %.4g\n" % scene.pov.radio_brightness)
tabWrite("count %d\n" % scene.pov.radio_count)
tabWrite("error_bound %.4g\n" % scene.pov.radio_error_bound)
tabWrite("gray_threshold %.4g\n" % scene.pov.radio_gray_threshold)
tabWrite("low_error_factor %.4g\n" % scene.pov.radio_low_error_factor)
tabWrite("media %d\n" % scene.pov.radio_media)
tabWrite("minimum_reuse %.4g\n" % scene.pov.radio_minimum_reuse)
tabWrite("nearest_count %d\n" % scene.pov.radio_nearest_count)
tabWrite("normal %d\n" % scene.pov.radio_normal)
tabWrite("pretrace_start %.3g\n" % scene.pov.radio_pretrace_start)
tabWrite("pretrace_end %.3g\n" % scene.pov.radio_pretrace_end)
tabWrite("recursion_limit %d\n" % scene.pov.radio_recursion_limit)
tabWrite("}\n")
Bastien Montagne
committed
onceSss = 1
onceAmbient = 1
oncePhotons = 1
if material.subsurface_scattering.use and onceSss:
Bastien Montagne
committed
# In pov, the scale has reversed influence compared to blender. these number
# should correct that
tabWrite("mm_per_unit %.6f\n" % \
(material.subsurface_scattering.scale * 1000.0))# formerly ...scale * (-100.0) + 15.0))
Bastien Montagne
committed
# In POV-Ray, the scale factor for all subsurface shaders needs to be the same
sslt_samples = (11 - material.subsurface_scattering.error_threshold) * 10 # formerly ...*100
tabWrite("subsurface { samples %d, %d }\n" % (sslt_samples, sslt_samples / 10))
Bastien Montagne
committed
onceSss = 0
Bastien Montagne
committed
if world and onceAmbient:
Maurice Raybaud
committed
tabWrite("ambient_light rgb<%.3g, %.3g, %.3g>\n" % world.ambient_color[:])
Bastien Montagne
committed
onceAmbient = 0
Maurice Raybaud
committed
if (material.pov.refraction_type == "2" or material.pov.photons_reflection == True) and oncePhotons:
Maurice Raybaud
committed
tabWrite("photons {\n")
tabWrite("spacing %.6f\n" % scene.pov.photon_spacing)
tabWrite("max_trace_level %d\n" % scene.pov.photon_max_trace_level)
tabWrite("adc_bailout %.3g\n" % scene.pov.photon_adc_bailout)
tabWrite("gather %d, %d\n" % (scene.pov.photon_gather_min, scene.pov.photon_gather_max))
tabWrite("}\n")
Bastien Montagne
committed
oncePhotons = 0
tabWrite("}\n")
Maurice Raybaud
committed
def exportCustomCode():
# Write CurrentAnimation Frame for use in Custom POV Code
file.write("#declare CURFRAMENUM = %d;\n" % bpy.context.scene.frame_current)
#Change path and uncomment to add an animated include file by hand:
file.write("//#include \"/home/user/directory/animation_include_file.inc\"\n")
Campbell Barton
committed
for txt in bpy.data.texts:
Bastien Montagne
committed
if txt.pov.custom_code:
Campbell Barton
committed
# Why are the newlines needed?
file.write("\n")
file.write(txt.as_string())
file.write("\n")
Maurice Raybaud
committed
sel = renderable_objects()
Bastien Montagne
committed
file.write("//----------------------------------------------\n" \
"//--Exported with POV-Ray exporter for Blender--\n" \
"//----------------------------------------------\n\n")
file.write("#version 3.7;\n")
file.write("\n//--Global settings--\n\n")