[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [1407] trunk/py/scripts/addons/ render_povray: - mktemp is Deprecated since version 2.3, replaced with NamedTemporaryFile()

Constantin Rahn conz at vrchannel.de
Sat Jan 15 18:19:21 CET 2011


Revision: 1407
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-extensions&revision=1407
Author:   conz
Date:     2011-01-15 17:19:20 +0000 (Sat, 15 Jan 2011)
Log Message:
-----------
- mktemp is Deprecated since version 2.3, replaced with NamedTemporaryFile()
- Automatic indentation in Pov file
- Added "command line switch". (Option to set some command line parameter)

Modified Paths:
--------------
    trunk/py/scripts/addons/render_povray/__init__.py
    trunk/py/scripts/addons/render_povray/render.py
    trunk/py/scripts/addons/render_povray/ui.py

Modified: trunk/py/scripts/addons/render_povray/__init__.py
===================================================================
--- trunk/py/scripts/addons/render_povray/__init__.py	2011-01-15 13:15:05 UTC (rev 1406)
+++ trunk/py/scripts/addons/render_povray/__init__.py	2011-01-15 17:19:20 UTC (rev 1407)
@@ -16,10 +16,10 @@
 #
 # ##### END GPL LICENSE BLOCK #####
 
-bl_info = {
+bl_addon_info = {
     "name": "PovRay 3.7",
     "author": "Campbell Barton, Silvio Falcinelli, Maurice Raybaud, Constantin Rahn",
-    "version": (0, 0, 4),
+    "version": (0, 0, 6),
     "blender": (2, 5, 6),
     "api": 31667,
     "location": "Info Header (engine dropdown)",
@@ -83,10 +83,14 @@
     
     Scene.pov_comments_enable = BoolProperty(
             name="Enable Comments",
-            description="Add comments to pov and ini files",
+            description="Add comments to pov file",
             default=True)
 
     # Real pov options
+    Scene.pov_command_line_switches = StringProperty(name="Command Line Switches",
+            description="Command line switches consist of a + (plus) or - (minus) sign, followed by one or more alphabetic characters and possibly a numeric value.",
+            default="", maxlen=500)
+    
     Scene.pov_max_trace_level = IntProperty(
             name="Max Trace Level", description="Number of reflections/refractions allowed on ray path",
             min=1, max=256, default=5)
@@ -273,6 +277,7 @@
     del Scene.pov_media_color # MR
     del Scene.pov_baking_enable # MR
     del Scene.pov_max_trace_level # MR
+    del Scene.pov_command_line_switches #CR
     del Scene.pov_indentation_character # CR
     del Scene.pov_indentation_spaces #CR
     del Scene.pov_comments_enable #CR

Modified: trunk/py/scripts/addons/render_povray/render.py
===================================================================
--- trunk/py/scripts/addons/render_povray/render.py	2011-01-15 13:15:05 UTC (rev 1406)
+++ trunk/py/scripts/addons/render_povray/render.py	2011-01-15 17:19:20 UTC (rev 1407)
@@ -30,6 +30,7 @@
 else:
     bitness = 32
 
+
 ##############################SF###########################
 ##############find image texture 
 def splitExt(path):
@@ -152,17 +153,8 @@
 ##############end safety string name material
 ##############################EndSF###########################
 
-def setTab(tabtype, spaces):
-    TabStr = ''
-    if tabtype == '0':
-        TabStr = ''
-    elif tabtype == '1': 
-        TabStr = '\t'
-    elif tabtype == '2':
-        TabStr = spaces * ' '
-    return TabStr
+TabLevel = 0
 
-
 def write_pov(filename, scene=None, info_callback=None):
     import mathutils
     #file = filename
@@ -175,8 +167,33 @@
     render = scene.render
     world = scene.world
     global_matrix = mathutils.Matrix.Rotation(-pi / 2.0, 4, 'X')
+
+    def setTab(tabtype, spaces):
+        TabStr = ''
+        if tabtype == '0':
+            TabStr = ''
+        elif tabtype == '1': 
+            TabStr = '\t'
+        elif tabtype == '2':
+            TabStr = spaces * ' '
+        return TabStr
+
     Tab = setTab(scene.pov_indentation_character, scene.pov_indentation_spaces)
-    
+
+    def tabWrite(str_o):
+        global TabLevel
+        brackets = str_o.count('{') - str_o.count('}')
+        if brackets < 0:
+            TabLevel = TabLevel + brackets 
+        if TabLevel < 0:
+            print('Indentation Warning: TabLevel = %s' % TabLevel)
+            TabLevel = 0
+        if TabLevel >= 1: 
+            file.write('%s' % Tab * TabLevel)
+        file.write(str_o)
+        if brackets > 0:
+            TabLevel = TabLevel + brackets 
+
     def uniqueName(name, nameSeq):
 
         if name not in nameSeq:
@@ -190,12 +207,8 @@
         name = splitHyphen(name)
         return name
 
-    def fileWriteTab(Tabcount, str_o):
-        if Tabcount >= 1: file.write('%s' % Tab*Tabcount)
-        file.write(str_o)
-
     def writeMatrix(matrix):
-        fileWriteTab(1, 'matrix <%.6f, %.6f, %.6f,  %.6f, %.6f, %.6f,  %.6f, %.6f, %.6f,  %.6f, %.6f, %.6f>\n' %\
+        tabWrite('matrix <%.6f, %.6f, %.6f,  %.6f, %.6f, %.6f,  %.6f, %.6f, %.6f,  %.6f, %.6f, %.6f>\n' %\
         (matrix[0][0], matrix[0][1], matrix[0][2], matrix[1][0], matrix[1][1], matrix[1][2], matrix[2][0], matrix[2][1], matrix[2][2], matrix[3][0], matrix[3][1], matrix[3][2]))
 
     def writeObjectMaterial(material):
@@ -206,14 +219,14 @@
         if material: #and material.transparency_method == 'RAYTRACE':#Commented out: always write IOR to be able to use it for SSS, Fresnel reflections...
             #But there can be only one!
             if material.subsurface_scattering.use:#SSS IOR get highest priority
-                fileWriteTab(1, 'interior {\n')
-                fileWriteTab(2, 'ior %.6f\n' % material.subsurface_scattering.ior)
+                tabWrite('interior {\n')
+                tabWrite('ior %.6f\n' % material.subsurface_scattering.ior)
             elif material.pov_mirror_use_IOR:#Then the raytrace IOR taken from raytrace transparency properties and used for reflections if IOR Mirror option is checked
-                fileWriteTab(1, 'interior {\n')
-                fileWriteTab(2, 'ior %.6f\n' % material.raytrace_transparency.ior)
+                tabWrite('interior {\n')
+                tabWrite('ior %.6f\n' % material.raytrace_transparency.ior)
             else:
-                fileWriteTab(1, 'interior {\n')
-                fileWriteTab(2, 'ior %.6f\n' % material.raytrace_transparency.ior)
+                tabWrite('interior {\n')
+                tabWrite('ior %.6f\n' % material.raytrace_transparency.ior)
                 
             pov_fake_caustics = False
             pov_photons_refraction = False
@@ -234,9 +247,9 @@
             #Last, if none of the above is specified, user can set up 'un-physical' fresnel reflections in raytrace mirror parameters. And pov IOR defaults to 1. 
             if material.pov_caustics_enable:
                 if pov_fake_caustics:
-                    fileWriteTab(2, 'caustics %.3g\n' % material.pov_fake_caustics_power)
+                    tabWrite('caustics %.3g\n' % material.pov_fake_caustics_power)
                 if pov_photons_refraction:
-                    fileWriteTab(2, 'dispersion %.3g\n' % material.pov_photons_dispersion) #Default of 1 means no dispersion
+                    tabWrite('dispersion %.3g\n' % material.pov_photons_dispersion) #Default of 1 means no dispersion
             #TODO        
             # Other interior args
             # if material.use_transparency and material.transparency_method == 'RAYTRACE':
@@ -245,15 +258,15 @@
             # fade_color
 
             # (variable) dispersion_samples (constant count for now)
-            fileWriteTab(1, '}\n')
+            tabWrite('}\n')
             if pov_photons_refraction or pov_photons_reflection:
-                fileWriteTab(1, 'photons{\n')
-                fileWriteTab(2, 'target\n')
+                tabWrite('photons{\n')
+                tabWrite('target\n')
                 if pov_photons_refraction:
-                    fileWriteTab(2, 'refraction on\n')
+                    tabWrite('refraction on\n')
                 if pov_photons_reflection:
-                    fileWriteTab(2, 'reflection on\n')
-                fileWriteTab(1, '}\n')
+                    tabWrite('reflection on\n')
+                tabWrite('}\n')
                 
     materialNames = {}
     DEF_MAT_NAME = 'Default'
@@ -274,17 +287,17 @@
         # Level=3 Means Maximum Spec and Mirror 
         def povHasnoSpecularMaps(Level):
             if Level == 1:
-                fileWriteTab(0, '#declare %s = finish {' % safety(name, Level = 1))
+                tabWrite('#declare %s = finish {' % safety(name, Level = 1))
                 if comments: file.write('  //No specular nor Mirror reflection\n')
-                else: fileWriteTab(0, '\n')
+                else: tabWrite('\n')
             elif Level == 2:
-                fileWriteTab(0, '#declare %s = finish {' % safety(name, 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: fileWriteTab(0, '\n')
+                else: tabWrite('\n')
             elif Level == 3:
-                fileWriteTab(0, '#declare %s = finish {' % safety(name, Level = 3))
+                tabWrite('#declare %s = finish {' % safety(name, Level = 3))
                 if comments: file.write('  //Maximum Spec and Mirror\n')
-                else: fileWriteTab(0, '\n')
+                else: tabWrite('\n')
 
 
             if material:
@@ -316,87 +329,87 @@
                 #####################################Diffuse Shader######################################
                 # Not used for Full spec (Level=3) of the shader
                 if material.diffuse_shader == 'OREN_NAYAR' and Level != 3:
-                    fileWriteTab(1, 'brilliance %.3g\n' % (0.9+material.roughness))#blender roughness is what is generally called oren nayar Sigma, and brilliance in povray
+                    tabWrite('brilliance %.3g\n' % (0.9+material.roughness))#blender roughness is what is generally called oren nayar Sigma, and brilliance in povray
 
                 if material.diffuse_shader == 'TOON' and Level != 3:
-                    fileWriteTab(1, 'brilliance %.3g\n' % (0.01+material.diffuse_toon_smooth*0.25))
+                    tabWrite('brilliance %.3g\n' % (0.01+material.diffuse_toon_smooth*0.25))
                     frontDiffuse*=0.5 #Lower diffuse and increase specular for toon effect seems to look better in povray
                 
                 if material.diffuse_shader == 'MINNAERT' and Level != 3:
-                    #fileWriteTab(1, 'aoi %.3g\n' % material.darkness)
+                    #tabWrite('aoi %.3g\n' % material.darkness)
                     pass #let's keep things simple for now
                 if material.diffuse_shader == 'FRESNEL' and Level != 3:
-                    #fileWriteTab(1, 'aoi %.3g\n' % material.diffuse_fresnel_factor)
+                    #tabWrite('aoi %.3g\n' % material.diffuse_fresnel_factor)
                     pass #let's keep things simple for now
                 if material.diffuse_shader == 'LAMBERT' and Level != 3:

@@ Diff output truncated at 10240 characters. @@


More information about the Bf-extensions-cvs mailing list