[Bf-extensions-cvs] [9d7cb8d] master: Separated writeMaterial() function to its own python file

Maurice Raybaud noreply at git.blender.org
Tue Dec 29 16:54:57 CET 2015


Commit: 9d7cb8d53798944f56b044fc12efa94a229406e0
Author: Maurice Raybaud
Date:   Tue Dec 29 16:54:44 2015 +0100
Branches: master
https://developer.blender.org/rBA9d7cb8d53798944f56b044fc12efa94a229406e0

Separated writeMaterial() function to its own python file

===================================================================

M	render_povray/__init__.py
M	render_povray/render.py
A	render_povray/shading.py

===================================================================

diff --git a/render_povray/__init__.py b/render_povray/__init__.py
index 8723af1..f3f217c 100644
--- a/render_povray/__init__.py
+++ b/render_povray/__init__.py
@@ -36,7 +36,6 @@ if "bpy" in locals():
     import importlib
     importlib.reload(ui)
     importlib.reload(render)
-    importlib.reload(primitives)
     importlib.reload(update_files)
 
 else:
@@ -60,7 +59,6 @@ else:
     from . import (
             ui,
             render,
-            primitives,
             update_files,
             )
 
@@ -1479,14 +1477,6 @@ def register():
     bpy.types.Material.pov = PointerProperty(type=RenderPovSettingsMaterial)
     bpy.types.Texture.pov = PointerProperty(type=RenderPovSettingsTexture)
     bpy.types.Object.pov = PointerProperty(type=RenderPovSettingsObject)
-    #bpy.types.Object.povsuperellipsoid = CollectionProperty(type=RenderPovSettingsSuperellipsoid_add)
-    #bpy.types.Object.povsupertorus = CollectionProperty(type=RenderPovSettingsSupertorus_add)
-    #bpy.types.Object.povloft = CollectionProperty(type=RenderPovSettingsLoft_add)
-    #bpy.types.Object.povrainbow = CollectionProperty(type=RenderPovSettingsRainbow_add)
-    #bpy.types.Object.povheightfield = CollectionProperty(type=RenderPovSettingsHeightField_add)
-    #bpy.types.Object.povtorus = CollectionProperty(type=RenderPovSettingsTorus_add)
-    #bpy.types.Object.povprism = CollectionProperty(type=RenderPovSettingsPrism_add)
-    #bpy.types.Object.povpolygontocircle = CollectionProperty(type=RenderPovSettingsPolygonToCircle_add)
     bpy.types.Camera.pov = PointerProperty(type=RenderPovSettingsCamera)
     bpy.types.Text.pov = PointerProperty(type=RenderPovSettingsText)
     
@@ -1498,14 +1488,6 @@ def unregister():
     del bpy.types.Material.pov
     del bpy.types.Texture.pov
     del bpy.types.Object.pov
-    #del bpy.types.Object.povsuperellipsoid
-    #del bpy.types.Object.povsupertorus
-    #del bpy.types.Object.povloft
-    #del bpy.types.Object.povrainbow
-    #del bpy.types.Object.povheightfield
-    #del bpy.types.Object.povtorus
-    #del bpy.types.Object.povprism
-    #del bpy.types.Object.povpolygontocircle
     del bpy.types.Camera.pov
     del bpy.types.Text.pov
     
diff --git a/render_povray/render.py b/render_povray/render.py
index bb4bda6..acc27a0 100644
--- a/render_povray/render.py
+++ b/render_povray/render.py
@@ -32,6 +32,8 @@ from bpy.types import(Operator)
 
 
 from . import df3 # for smoke rendering
+from . import shading # for BI POV haders emulation
+from . import primitives # for import and export of POV specific primitives
 ##############################SF###########################
 ##############find image texture
 def imageFormat(imgF):
@@ -943,236 +945,7 @@ def write_pov(filename, scene=None, info_callback=None):
 
     materialNames = {}
     DEF_MAT_NAME = "" #or "Default"?
-
-    def writeMaterial(material):
-        # Assumes only called once on each material
-        if material:
-            name_orig = material.name
-            name = materialNames[name_orig] = uniqueName(bpy.path.clean_name(name_orig), materialNames)
-        else:
-            name = name_orig = DEF_MAT_NAME
-
-
-        if material:
-            # If saturation(.s) is not zero, then color is not grey, and has a tint
-            colored_specular_found = (material.specular_color.s > 0.0)
-
-        ##################
-        # Several versions of the finish: Level conditions are variations for specular/Mirror
-        # texture channel map with alternative finish of 0 specular and no mirror reflection.
-        # Level=1 Means No specular nor Mirror reflection
-        # Level=2 Means translation of spec and mir levels for when no map influences them
-        # Level=3 Means Maximum Spec and Mirror
-
-        def povHasnoSpecularMaps(Level):
-            if Level == 1:
-                tabWrite("#declare %s = finish {" % safety(name, Level=1))
-                if comments:
-                    file.write("  //No specular nor Mirror reflection\n")
-                else:
-                    tabWrite("\n")
-            elif Level == 2:
-                tabWrite("#declare %s = finish {" % safety(name, Level=2))
-                if comments:
-                    file.write("  //translation of spec and mir levels for when no map " \
-                               "influences them\n")
-                else:
-                    tabWrite("\n")
-            elif Level == 3:
-                tabWrite("#declare %s = finish {" % safety(name, Level=3))
-                if comments:
-                    file.write("  //Maximum Spec and Mirror\n")
-                else:
-                    tabWrite("\n")
-
-            if material:
-                # POV-Ray 3.7 now uses two diffuse values respectively for front and back shading
-                # (the back diffuse is like blender translucency)
-                frontDiffuse = material.diffuse_intensity
-                backDiffuse = material.translucency
-
-                if material.pov.conserve_energy:
-
-                    #Total should not go above one
-                    if (frontDiffuse + backDiffuse) <= 1.0:
-                        pass
-                    elif frontDiffuse == backDiffuse:
-                        # Try to respect the user's 'intention' by comparing the two values but
-                        # bringing the total back to one.
-                        frontDiffuse = backDiffuse = 0.5
-                    # Let the highest value stay the highest value.
-                    elif frontDiffuse > backDiffuse:
-                        # clamps the sum below 1
-                        backDiffuse = min(backDiffuse, (1.0 - frontDiffuse))
-                    else:
-                        frontDiffuse = min(frontDiffuse, (1.0 - backDiffuse))
-
-                # map hardness between 0.0 and 1.0
-                roughness = ((1.0 - ((material.specular_hardness - 1.0) / 510.0)))
-                ## scale from 0.0 to 0.1
-                roughness *= 0.1
-                # add a small value because 0.0 is invalid.
-                roughness += (1.0 / 511.0)
-
-                ################################Diffuse Shader######################################
-                # Not used for Full spec (Level=3) of the shader.
-                if material.diffuse_shader == 'OREN_NAYAR' and Level != 3:
-                    # Blender roughness is what is generally called oren nayar Sigma,
-                    # and brilliance in POV-Ray.
-                    tabWrite("brilliance %.3g\n" % (0.9 + material.roughness))
-
-                if material.diffuse_shader == 'TOON' and Level != 3:
-                    tabWrite("brilliance %.3g\n" % (0.01 + material.diffuse_toon_smooth * 0.25))
-                    # Lower diffuse and increase specular for toon effect seems to look better
-                    # in POV-Ray.
-                    frontDiffuse *= 0.5
-
-                if material.diffuse_shader == 'MINNAERT' and Level != 3:
-                    #tabWrite("aoi %.3g\n" % material.darkness)
-                    pass  # let's keep things simple for now
-                if material.diffuse_shader == 'FRESNEL' and Level != 3:
-                    #tabWrite("aoi %.3g\n" % material.diffuse_fresnel_factor)
-                    pass  # let's keep things simple for now
-                if material.diffuse_shader == 'LAMBERT' and Level != 3:
-                    # trying to best match lambert attenuation by that constant brilliance value
-                    tabWrite("brilliance 1.8\n")
-
-                if Level == 2:
-                    ###########################Specular Shader######################################
-                    # No difference between phong and cook torrence in blender HaHa!
-                    if (material.specular_shader == 'COOKTORR' or
-                        material.specular_shader == 'PHONG'):
-                        tabWrite("phong %.3g\n" % (material.specular_intensity))
-                        tabWrite("phong_size %.3g\n" % (material.specular_hardness / 2 + 0.25))
-
-                    # POV-Ray 'specular' keyword corresponds to a Blinn model, without the ior.
-                    elif material.specular_shader == 'BLINN':
-                        # Use blender Blinn's IOR just as some factor for spec intensity
-                        tabWrite("specular %.3g\n" % (material.specular_intensity *
-                                                      (material.specular_ior / 4.0)))
-                        tabWrite("roughness %.3g\n" % roughness)
-                        #Could use brilliance 2(or varying around 2 depending on ior or factor) too.
-
-                    elif material.specular_shader == 'TOON':
-                        tabWrite("phong %.3g\n" % (material.specular_intensity * 2.0))
-                        # use extreme phong_size
-                        tabWrite("phong_size %.3g\n" % (0.1 + material.specular_toon_smooth / 2.0))
-
-                    elif material.specular_shader == 'WARDISO':
-                        # find best suited default constant for brilliance Use both phong and
-                        # specular for some values.
-                        tabWrite("specular %.3g\n" % (material.specular_intensity /
-                                                      (material.specular_slope + 0.0005)))
-                        # find best suited default constant for brilliance Use both phong and
-                        # specular for some values.
-                        tabWrite("roughness %.4g\n" % (0.0005 + material.specular_slope / 10.0))
-                        # find best suited default constant for brilliance Use both phong and
-                        # specular for some values.
-                        tabWrite("brilliance %.4g\n" % (1.8 - material.specular_slope * 1.8))
-
-                ####################################################################################
-                elif Level == 1:
-                    tabWrite("specular 0\n")
-                elif Level == 3:
-                    tabWrite("specular 1\n")
-                tabWrite("diffuse %.3g %.3g\n" % (frontDiffuse, backDiffuse))
-
-                tabWrite("ambie

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list