[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [4040] contrib/py/scripts/addons/ online_mat_lib/__init__.py: OSL script nodes now save options.

Peter Cassetta peter at fingertipsoft.com
Wed Dec 12 10:22:30 CET 2012


Revision: 4040
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=4040
Author:   petercassetta
Date:     2012-12-12 09:22:30 +0000 (Wed, 12 Dec 2012)
Log Message:
-----------
OSL script nodes now save options.

Also fixed a small bug with adding OSL scripts, and updated the link to the Blender Material Preview Scene.

Modified Paths:
--------------
    contrib/py/scripts/addons/online_mat_lib/__init__.py

Modified: contrib/py/scripts/addons/online_mat_lib/__init__.py
===================================================================
--- contrib/py/scripts/addons/online_mat_lib/__init__.py	2012-12-12 02:27:08 UTC (rev 4039)
+++ contrib/py/scripts/addons/online_mat_lib/__init__.py	2012-12-12 09:22:30 UTC (rev 4040)
@@ -245,7 +245,7 @@
                 row.operator("wm.url_open", text="All materials are CC0 - learn more.", emboss=False).url = "http://creativecommons.org/publicdomain/zero/1.0/"
                 
                 row = layout.row()
-                row.operator("wm.url_open", text="Material previews generated with B.M.P.S.", emboss=False).url = "https://svn.blender.org/svnroot/bf-blender/trunk/lib/tests/rendering/cycles/bmps.blend"
+                row.operator("wm.url_open", text="Material previews generated with B.M.P.S.", emboss=False).url = "https://svn.blender.org/svnroot/bf-blender/trunk/lib/tests/rendering/cycles/blend_files/bmps.blend"
                 row = layout.row()
                 row.operator("wm.url_open", text="B.M.P.S. created by Robin \"tuqueque\" Marín", emboss=False).url = "http://blenderartists.org/forum/showthread.php?151903-b.m.p.s.-1.5!"
             
@@ -1663,6 +1663,7 @@
         
         #Create internal OSL scripts
         scripts = dom.getElementsByTagName("script")
+        osl_scripts = []
         for s in scripts:
             osl_datablock = bpy.data.texts.new(name=s.attributes['name'].value)
             osl_text = s.toxml()[s.toxml().index(">"):s.toxml().rindex("<")]
@@ -1844,6 +1845,7 @@
         
         #Create internal OSL scripts
         scripts = dom.getElementsByTagName("script")
+        osl_scripts = []
         for s in scripts:
             osl_datablock = bpy.data.texts.new(name=s.attributes['name'].value)
             osl_text = s.toxml()[s.toxml().index(">"):s.toxml().rindex("<")]
@@ -1917,7 +1919,7 @@
         #Parse file
         dom = xml.dom.minidom.parseString(material_file_contents)
         
-        #Create internal OSL scripts and cache image textures
+        #Create external OSL scripts and cache image textures
         nodes = dom.getElementsByTagName("node")
         for node in nodes:
             node_data = node.attributes
@@ -2087,7 +2089,7 @@
         material_file_contents = bcm_file.read()
         bcm_file.close()
         
-        #Create internal OSL scripts and cache image textures
+        #Create external OSL scripts and cache image textures
         nodes = dom.getElementsByTagName("node")
         for node in nodes:
             node_data = node.attributes
@@ -2958,7 +2960,24 @@
             else:
                 if 'script' in node_data:
                     node.script = osl_scripts[int(node_data['script'].value)]
-            
+            if node.inputs:
+                for input in node.inputs:
+                    if input.name.lower() in node_data:
+                        if input.type == 'RGBA':
+                            input.default_value = color(node_data[input.name.lower()].value)
+                        elif input.type == 'VECTOR':
+                            input.default_value = vector(node_data[input.name.lower()].value)
+                        elif input.type == 'VALUE':
+                            input.default_value = float(node_data[input.name.lower()].value)
+                        elif input.type == 'INT':
+                            input.default_value = int(node_data[input.name.lower()].value)
+                        elif input.type == 'BOOL':
+                            input.default_value = boolean(node_data[input.name.lower()].value)
+                        else:
+                            input.default_value = str(node_data[input.name.lower()].value)
+                    else:
+                        node_message = ['WARNING', "There was no value specified for input \"%s\", leaving at default." % input.name]
+                
         else:
             node_message = ['ERROR', """The material file contains the node name \"%s\", which is not known.
 The material file may contain an error, or you may need to check for updates to this add-on.""" % node_type]
@@ -3598,7 +3617,22 @@
             if node.script:
                 write(" script=\"%s\"" % len(script_stack))
                 script_stack.append(node.script.name)
-        
+        if node.inputs:
+            for input in node.inputs:
+                if input.type == 'RGBA':
+                    input_value = rgba(input.default_value)
+                elif input.type == 'VECTOR':
+                    input_value = smallVector(input.default_value)
+                elif input.type == 'VALUE':
+                    input_value = smallFloat(input.default_value)
+                elif input.type == 'INT':
+                    input_value = str(input.default_value)
+                elif input.type == 'BOOL':
+                    input_value = str(input.default_value)
+                else:
+                    input_value = str(input.default_value)
+                
+                write(" %s=\"%s\"" % (input.name.lower(), input_value))
     else:
         write(" ERROR: UNKNOWN NODE TYPE. ")
         return



More information about the Bf-extensions-cvs mailing list