Skip to content
Snippets Groups Projects
render.py 184 KiB
Newer Older
  • Learn to ignore specific revisions
  •                                 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 linebreaksinlists:
    
                                    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 linebreaksinlists:
    
                                    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
    
    Luca Bonavita's avatar
    Luca Bonavita committed
                else:
    
                    # No vertex colors, so write material colors as vertex colors
    
    Luca Bonavita's avatar
    Luca Bonavita committed
                    for i, material in enumerate(me_materials):
    
                        if material:
    
                            # Multiply diffuse with SSS Color
                            if material.subsurface_scattering.use:
    
    Campbell Barton's avatar
    Campbell Barton committed
                                diffuse_color = [i * j for i, j in zip(material.subsurface_scattering.color[:], material.diffuse_color[:])]
    
                                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]
    
    Luca Bonavita's avatar
    Luca Bonavita committed
    
    
                            LocalMaterialNames = []                       
    
                            for col, index in vertCols.items():
                                #if me_materials:
    
                                if me_materials is None: #XXX working?
    
                                    material_finish = DEF_MAT_NAME  # not working properly,
                                    trans = 0.0
    
                                    material_finish = materialNames[mater.name]                        
                                    if mater.use_transparency:
                                        trans = 1.0 - mater.alpha
    
                                    if (mater.specular_color.s == 0.0):
    
                                        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
    
                                    else:
                                        povFilter = 0.0
                                        
                                    ##############SF
                                    texturesDif = ""
                                    texturesSpec = ""
                                    texturesNorm = ""
                                    texturesAlpha = ""
    
                                        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)
    
                                            # 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
    
                                            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])
    
                                    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':
    
                                        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)))
    
                                    if mater.diffuse_shader == 'FRESNEL':
    
                                        # 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)))
    
                                            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)
    
                                            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))
    
                                                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")
    
                                                tabWrite("pigment {rgbft<%.3g, %.3g, %.3g, %.3g, %.3g>}\n" % \
                                                         (col[0], col[1], col[2], povFilter, trans))
    
                                            if texturesSpec != "":
                                                # Level 1 is no specular
                                                tabWrite("finish {%s}\n" % (safety(material_finish, Level=1)))
    
                                            else:
                                                # Level 2 is translated spec
                                                tabWrite("finish {%s}\n" % (safety(material_finish, Level=2)))
    
                                            mappingDif = imgMapTransforms(t_dif)
    
    
                                                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)
    
                                                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))
    
                                                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)                                                          
    
                                                if texturesAlpha and texturesAlpha.startswith("PAT_"):
                                                    tabWrite("}\n")
    
                                                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))
    
                                            if texturesSpec != "":
                                                # Level 1 is no specular
                                                tabWrite("finish {%s}\n" % (safety(material_finish, Level=1)))
    
                                            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)
    
                                            #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))
    
                                        if texturesSpec != "":
                                            tabWrite("]\n")
                                        ##################Second index for mapping specular max value###############
                                            tabWrite("[1 \n")
    
    
                                    if texturesDif == "" and mater.pov.replacement_text == "":
    
                                        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))
    
                                            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")
    
                                        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)))
    
                                        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))
    
                                        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))
    
                                            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)
    
                                            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")
    
                                              
                                        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 == "":
    
                                        ## 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))
    
                                        #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 == "":
    
                                        tabWrite("]\n")
    
                                        tabWrite("}\n")
    
                                    #End of slope/ior texture_map
    
                                    if mater.diffuse_shader == 'MINNAERT' and mater.pov.replacement_text == "":
    
                                    if mater.diffuse_shader == 'FRESNEL' and mater.pov.replacement_text == "":
    
                                        c = 1
                                        while (c <= lampCount):
                                            tabWrite("]\n")
                                            tabWrite("}\n")
                                            c += 1
    
    
                                    # Close first layer of POV "texture" (Blender material)
                                    tabWrite("}\n")
    
                                        
                                    # Write another layered texture using invisible diffuse and metallic trick 
                                    # to emulate colored specular highlights
                                    special_texture_found = False
    
                                        if(t and t.use and ((t.texture.type == 'IMAGE' and t.texture.image) or t.texture.type != 'IMAGE') and
    
                                           (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")
    
                                        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]))
    
                                        tabWrite("finish {%s}\n" % (safety(material_finish, Level=2))) # Level 2 is translated spec
    
                                        texturesNorm = ""
    
    
                                            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 
    
                                                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))
                                                                      
    
                                        tabWrite("}\n") # THEN IT CAN CLOSE LAST LAYER OF TEXTURE   --MR
    
    
                                ####################################################################################
                                index[0] = idx
                                idx += 1
                                
    
                    # 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)
    
                        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
    
    Luca Bonavita's avatar
    Luca Bonavita committed
                    else:
    
                        file.write(" texture{}\n")                
    
    Luca Bonavita's avatar
    Luca Bonavita committed
    
    
                    # Face indices
                    tabWrite("face_indices {\n")
                    tabWrite("%d" % (len(me_faces) + quadCount))  # faces count
                    tabStr = tab * tabLevel
    
    Luca Bonavita's avatar
    Luca Bonavita committed
    
    
                    for fi, f in enumerate(me_faces):
                        fv = faces_verts[fi]
                        material_index = f.material_index
    
    Luca Bonavita's avatar
    Luca Bonavita committed
                        if len(fv) == 4:
    
    Luca Bonavita's avatar
    Luca Bonavita committed
                        else:
    
    Luca Bonavita's avatar
    Luca Bonavita committed
    
    
    Luca Bonavita's avatar
    Luca Bonavita committed
    
    
                            if len(fv) == 4:
                                cols = col.color1, col.color2, col.color3, col.color4
    
                                cols = col.color1, col.color2, col.color3
    
    Luca Bonavita's avatar
    Luca Bonavita committed
    
    
                        if not me_materials or me_materials[material_index] is None:  # No materials
                            for i1, i2, i3 in indices:
    
                                if linebreaksinlists:
    
                                    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:
    
    Luca Bonavita's avatar
    Luca Bonavita committed
    
    
    Luca Bonavita's avatar
    Luca Bonavita 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]
    
    
                                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
                                else:
                                    file.write(", ")
                                    file.write("<%d,%d,%d>, %d,%d,%d" % \
                                               (fv[i1], fv[i2], fv[i3], ci1, ci2, ci3))  # vert count
    
    Luca Bonavita's avatar
    Luca Bonavita committed
    
    
    Luca Bonavita's avatar
    Luca Bonavita committed
    
    
                    # normal_indices indices
                    tabWrite("normal_indices {\n")
    
                    tabWrite("%d" % (len(me_faces) + quadCount))  # faces count
    
    Luca Bonavita's avatar
    Luca Bonavita committed
                    for fi, fv in enumerate(faces_verts):
    
                        if len(fv) == 4:
    
                            indices = (0, 1, 2), (0, 2, 3)
    
    Luca Bonavita's avatar
    Luca Bonavita committed
                        else:
    
                            indices = ((0, 1, 2),)
    
    Luca Bonavita's avatar
    Luca Bonavita committed
    
    
                        for i1, i2, i3 in indices:
    
                                if linebreaksinlists:
    
                                    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
    
                                idx = uniqueNormals[faces_normals[fi]][0]
    
                                if linebreaksinlists:
    
                                    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
    
    Luca Bonavita's avatar
    Luca Bonavita 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:
    
                                if linebreaksinlists:
    
                                    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's avatar
    Maurice Raybaud committed
    
    
    Luca Bonavita's avatar
    Luca Bonavita committed
    
                bpy.data.meshes.remove(me)
    
    
            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")
    
    
    Luca Bonavita's avatar
    Luca Bonavita committed
        def exportWorld(world):
    
            render = scene.render
    
    Maurice Raybaud's avatar
    Maurice Raybaud committed
            camera = scene.camera
    
            matrix = global_matrix * camera.matrix_world
    
    Luca Bonavita's avatar
    Luca Bonavita committed
            if not world:
                return
    
            #############Maurice####################################
    
    Maurice Raybaud's avatar
    Maurice Raybaud committed
            #These lines added to get sky gradient (visible with PNG output)
            if world:
                #For simple flat background:
                if not world.use_sky_blend:
    
                    # Non fully transparent background could premultiply alpha and avoid anti-aliasing
                    # display issue:
    
                    if render.alpha_mode == 'TRANSPARENT':
    
                        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[:]))
    
                worldTexCount = 0
    
    Maurice Raybaud's avatar
    Maurice Raybaud committed
                #For Background image textures
    
                for t in world.texture_slots:  # risk to write several sky_spheres but maybe ok.
    
                    if t and t.texture.type is not None:
    
                        worldTexCount += 1
    
                    # 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':
    
    Campbell Barton's avatar
    Campbell Barton committed
                        image_filename = path_image(t.texture.image)
    
                        if t.texture.image.filepath != image_filename:
                            t.texture.image.filepath = image_filename
    
                        if image_filename != "" and t.use_map_blend:
    
    Maurice Raybaud's avatar
    Maurice Raybaud committed
                            texturesBlend = image_filename
                            #colvalue = t.default_value
                            t_blend = t
    
                        # 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))
    
    Maurice Raybaud's avatar
    Maurice Raybaud committed
                        #using camera rotation valuesdirectly from blender seems much easier
    
                        if t_blend.texture_coords == 'ANGMAP':
                            mappingBlend = ""
    
                            # 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)
    
    
                            # 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")
    
                        tabWrite("image_map{%s \"%s\" %s}\n" % \
                                 (imageFormat(texturesBlend), texturesBlend, imgMapBG(t_blend)))
    
                        tabWrite("}\n")
                        tabWrite("%s\n" % (mappingBlend))
    
                        # The following layered pigment opacifies to black over the texture for
                        # transmit below 1 or otherwise adds to itself
    
                        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:
    
    Maurice Raybaud's avatar
    Maurice Raybaud committed
                    if world.use_sky_blend:
    
                        tabWrite("sky_sphere {\n")
                        tabWrite("pigment {\n")
    
                        # maybe Should follow the advice of POV doc about replacing gradient
                        # for skysphere..5.5
                        tabWrite("gradient y\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[:]))
    
                            # 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")
    
                        # Sky_sphere alpha (transmit) is not translating into image alpha the same
                        # way as 'background'
    
                #if world.light_settings.use_indirect_light:
    
                # 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?
    
    Maurice Raybaud's avatar
    Maurice Raybaud committed
    
            ###############################################################
    
    Luca Bonavita's avatar
    Luca Bonavita committed
    
    
    Campbell Barton's avatar
    Campbell Barton committed
            mist = world.mist_settings
    
    Luca Bonavita's avatar
    Luca Bonavita committed
    
            if mist.use_mist:
    
                tabWrite("fog {\n")
                tabWrite("distance %.6f\n" % mist.depth)
    
                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")
    
                tabWrite("scattering { 1, rgb <%.4g, %.4g, %.4g>}\n" % scene.pov.media_color[:])
                tabWrite("samples %.d\n" % scene.pov.media_samples)
    
    Luca Bonavita's avatar
    Luca Bonavita committed
    
        def exportGlobalSettings(scene):
    
    
            tabWrite("global_settings {\n")
            tabWrite("assumed_gamma 1.0\n")
    
            tabWrite("max_trace_level %d\n" % scene.pov.max_trace_level)
    
    Luca Bonavita's avatar
    Luca Bonavita 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)
    
    Maurice Raybaud's avatar
    Maurice Raybaud committed
            for material in bpy.data.materials:
    
                if material.subsurface_scattering.use and onceSss:
    
                    # 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))
    
                    # In POV-Ray, the scale factor for all subsurface shaders needs to be the same
    
    Maurice Raybaud's avatar
    Maurice Raybaud committed
                    sslt_samples = (11 - material.subsurface_scattering.error_threshold) * 10 # formerly ...*100
    
    Campbell Barton's avatar
    Campbell Barton committed
                    tabWrite("subsurface { samples %d, %d }\n" % (sslt_samples, sslt_samples / 10))
    
    Luca Bonavita's avatar
    Luca Bonavita committed
    
    
                    tabWrite("ambient_light rgb<%.3g, %.3g, %.3g>\n" % world.ambient_color[:])
    
                if (material.pov.refraction_type == "2" or material.pov.photons_reflection == True) and oncePhotons:
    
                    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")
    
    Luca Bonavita's avatar
    Luca Bonavita committed
    
    
    Luca Bonavita's avatar
    Luca Bonavita committed
    
    
            # 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")
    
                    # Why are the newlines needed?
                    file.write("\n")
                    file.write(txt.as_string())
                    file.write("\n")
    
        sel = renderable_objects()
    
            file.write("//----------------------------------------------\n" \
                       "//--Exported with POV-Ray exporter for Blender--\n" \
                       "//----------------------------------------------\n\n")
    
            file.write("\n//--Global settings--\n\n")
    
    Maurice Raybaud's avatar
    Maurice Raybaud committed
        exportGlobalSettings(scene)