[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [1406] trunk/py/scripts/addons/ render_povray: By Constantin Rahn:

Maurice Raybaud mauriceraybaud at hotmail.fr
Sat Jan 15 14:15:06 CET 2011


Revision: 1406
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-extensions&revision=1406
Author:   mauriceraybaud
Date:     2011-01-15 13:15:05 +0000 (Sat, 15 Jan 2011)
Log Message:
-----------
By Constantin Rahn:
-POV file formatting improvement with UI option and function to handle all tabs/spaces indentation (big clean up)
-use of quote characters made more consistent.

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 01:48:20 UTC (rev 1405)
+++ trunk/py/scripts/addons/render_povray/__init__.py	2011-01-15 13:15:05 UTC (rev 1406)
@@ -69,6 +69,22 @@
             name="Enable Baking",
             description="Enable povrays texture baking",
             default=False)
+    Scene.pov_indentation_character = EnumProperty(
+            name="Indentation",
+            description="Select the indentation type",
+            items=(("0", "None", "No indentation"),
+               ("1", "Tabs", "Indentation with tabs"),
+               ("2", "Spaces", "Indentation with spaces")),
+            default="1")
+    Scene.pov_indentation_spaces = IntProperty(
+            name="Quantity of spaces",
+            description="The number of spaces for indentation",
+            min=1, max=10, default=3)
+    
+    Scene.pov_comments_enable = BoolProperty(
+            name="Enable Comments",
+            description="Add comments to pov and ini files",
+            default=True)
 
     # Real pov options
     Scene.pov_max_trace_level = IntProperty(
@@ -257,6 +273,9 @@
     del Scene.pov_media_color # MR
     del Scene.pov_baking_enable # MR
     del Scene.pov_max_trace_level # MR
+    del Scene.pov_indentation_character # CR
+    del Scene.pov_indentation_spaces #CR
+    del Scene.pov_comments_enable #CR
     del Mat.pov_irid_enable # MR
     del Mat.pov_mirror_use_IOR # MR
     del Mat.pov_mirror_metallic # MR    

Modified: trunk/py/scripts/addons/render_povray/render.py
===================================================================
--- trunk/py/scripts/addons/render_povray/render.py	2011-01-15 01:48:20 UTC (rev 1405)
+++ trunk/py/scripts/addons/render_povray/render.py	2011-01-15 13:15:05 UTC (rev 1406)
@@ -41,7 +41,7 @@
 
 
 def imageFormat(imgF):
-    ext = ""
+    ext = ''
     ext_orig = splitExt(imgF)
     if ext_orig == 'JPG' or ext_orig == 'JPEG': ext='jpeg'
     if ext_orig == 'GIF': ext = 'gif'
@@ -64,7 +64,7 @@
     if ts.mapping=='TUBE':image_map= ' map_type 2 '
     #if ts.mapping=='?':image_map= ' map_type 3 '# map_type 3 and 4 in development (?) for Povray, currently they just seem to default back to Flat (type 0)
     #if ts.mapping=='?':image_map= ' map_type 4 '# map_type 3 and 4 in development (?) for Povray, currently they just seem to default back to Flat (type 0)
-    if ts.texture.use_interpolation: image_map+= " interpolate 2 "
+    if ts.texture.use_interpolation: image_map+= ' interpolate 2 '
     if ts.texture.extension == 'CLIP': image_map+=' once '
     #image_map+='}'
     #if ts.mapping=='CUBE':image_map+= 'warp { cubic } rotate <-90,0,180>' #no direct cube type mapping. Though this should work in POV 3.7 it doesn't give that good results(best suited to environment maps?)
@@ -76,7 +76,7 @@
     if wts.texture_coords== 'VIEW':image_mapBG= ' map_type 0 ' #texture_coords refers to the mapping of world textures
     if wts.texture_coords=='ANGMAP':image_mapBG= ' map_type 1 '
     if wts.texture_coords=='TUBE':image_mapBG= ' map_type 2 '
-    if wts.texture.use_interpolation: image_mapBG+= " interpolate 2 "
+    if wts.texture.use_interpolation: image_mapBG+= ' interpolate 2 '
     if wts.texture.extension == 'CLIP': image_mapBG+=' once '
     #image_mapBG+='}'
     #if wts.mapping=='CUBE':image_mapBG+= 'warp { cubic } rotate <-90,0,180>' #no direct cube type mapping. Though this should work in POV 3.7 it doesn't give that good results(best suited to environment maps?)
@@ -87,7 +87,7 @@
     idx = path.rfind('/')
     if idx == -1:
         idx = path.rfind('\\')
-    return path[idx:].replace("/", "").replace("\\", "")
+    return path[idx:].replace('/', '').replace('\\', '')
 
 def splitPath(path):
     idx = path.rfind('/')
@@ -152,9 +152,21 @@
 ##############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
+
+
 def write_pov(filename, scene=None, info_callback=None):
     import mathutils
-    file = open(filename, 'w')
+    #file = filename
+    file = open(filename.name, 'w')
 
     # Only for testing
     if not scene:
@@ -163,7 +175,8 @@
     render = scene.render
     world = scene.world
     global_matrix = mathutils.Matrix.Rotation(-pi / 2.0, 4, 'X')
-
+    Tab = setTab(scene.pov_indentation_character, scene.pov_indentation_spaces)
+    
     def uniqueName(name, nameSeq):
 
         if name not in nameSeq:
@@ -177,8 +190,12 @@
         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):
-        file.write('\tmatrix <%.6f, %.6f, %.6f,  %.6f, %.6f, %.6f,  %.6f, %.6f, %.6f,  %.6f, %.6f, %.6f>\n' %\
+        fileWriteTab(1, '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):
@@ -189,34 +206,37 @@
         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
-                file.write('\tinterior {\n\t\tior %.6f\n' % material.subsurface_scattering.ior)
+                fileWriteTab(1, 'interior {\n')
+                fileWriteTab(2, '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
-                file.write('\tinterior {\n\t\tior %.6f\n' % material.raytrace_transparency.ior)
+                fileWriteTab(1, 'interior {\n')
+                fileWriteTab(2, 'ior %.6f\n' % material.raytrace_transparency.ior)
             else:
-                file.write('\tinterior {\n\t\tior %.6f\n' % material.raytrace_transparency.ior)
+                fileWriteTab(1, 'interior {\n')
+                fileWriteTab(2, 'ior %.6f\n' % material.raytrace_transparency.ior)
                 
             pov_fake_caustics = False
             pov_photons_refraction = False
             pov_photons_reflection = False
                 
-            if material.pov_refraction_type=="0":
+            if material.pov_refraction_type=='0':
                 pov_fake_caustics = False
                 pov_photons_refraction = False
                 pov_photons_reflection = True #should respond only to proper checkerbox
-            elif material.pov_refraction_type=="1":
+            elif material.pov_refraction_type=='1':
                 pov_fake_caustics = True
                 pov_photons_refraction = False
-            elif material.pov_refraction_type=="2":
+            elif material.pov_refraction_type=='2':
                 pov_fake_caustics = False
                 pov_photons_refraction = True
 
-            #If only Raytrace transparency is set, its IOR will be used for refraction, but user can set up "un-physical" fresnel reflections in raytrace mirror parameters. 
-            #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 only Raytrace transparency is set, its IOR will be used for refraction, but user can set up 'un-physical' fresnel reflections in raytrace mirror parameters. 
+            #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:
-                    file.write('\t\tcaustics %.3g\n' % material.pov_fake_caustics_power)
+                    fileWriteTab(2, 'caustics %.3g\n' % material.pov_fake_caustics_power)
                 if pov_photons_refraction:
-                    file.write('\t\tdispersion %.3g\n' % material.pov_photons_dispersion) #Default of 1 means no dispersion
+                    fileWriteTab(2, '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':
@@ -225,41 +245,46 @@
             # fade_color
 
             # (variable) dispersion_samples (constant count for now)
-            file.write('\t}\n')
+            fileWriteTab(1, '}\n')
             if pov_photons_refraction or pov_photons_reflection:
-                file.write('\tphotons{\n')
-                file.write('\t\ttarget\n')
+                fileWriteTab(1, 'photons{\n')
+                fileWriteTab(2, 'target\n')
                 if pov_photons_refraction:
-                    file.write('\t\trefraction on\n')
+                    fileWriteTab(2, 'refraction on\n')
                 if pov_photons_reflection:
-                    file.write('\t\treflection on\n')
-                file.write('\t}\n')
+                    fileWriteTab(2, 'reflection on\n')
+                fileWriteTab(1, '}\n')
                 
     materialNames = {}
     DEF_MAT_NAME = 'Default'
 
     def writeMaterial(material):
         # Assumes only called once on each material
-
         if material:
             name_orig = material.name
         else:
             name_orig = DEF_MAT_NAME
 
         name = materialNames[name_orig] = uniqueName(bpy.path.clean_name(name_orig), materialNames)
+        comments = scene.pov_comments_enable
 
-
         ##################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

@@ Diff output truncated at 10240 characters. @@


More information about the Bf-extensions-cvs mailing list