[Bf-extensions-cvs] [5417a6c0] master: Dynamic Sky: Cleanup, Fixes

lijenstina noreply at git.blender.org
Fri Jun 16 00:22:48 CEST 2017


Commit: 5417a6c0c27aae1fba137a0f24bdac87e886987c
Author: lijenstina
Date:   Fri Jun 16 00:21:55 2017 +0200
Branches: master
https://developer.blender.org/rBA5417a6c0c27aae1fba137a0f24bdac87e886987c

Dynamic Sky: Cleanup, Fixes

Bumped version to 1.0.2
Pep8 cleanup
add several checks to prevent crashes
add a scene prop to store the world name
avoid hardcoding the name
add some warnings in the Panel

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

M	lighting_dynamic_sky.py

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

diff --git a/lighting_dynamic_sky.py b/lighting_dynamic_sky.py
index de125529..85b57ce0 100644
--- a/lighting_dynamic_sky.py
+++ b/lighting_dynamic_sky.py
@@ -1,25 +1,27 @@
 # Dynamic Sky.py (c) 2015 Pratik Solanki (Draguu)
+
+# ##### BEGIN GPL LICENSE BLOCK #####
 #
-#    This program is free software: you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation, either version 3 of the License, or
-#    (at your option) any later version.
-
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-
-#    You should have received a copy of the GNU General Public License
-#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#  This program is free software; you can redistribute it and/or
+#  modify it under the terms of the GNU General Public License
+#  as published by the Free Software Foundation; either version 2
+#  of the License, or (at your option) any later version.
 #
-# ***** END GPL LICENCE BLOCK *****
-
+#  This program is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#  GNU General Public License for more details.
+#
+#  You should have received a copy of the GNU General Public License
+#  along with this program; if not, write to the Free Software Foundation,
+#  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# ##### END GPL LICENSE BLOCK #####
 
 bl_info = {
     "name": "Dynamic Sky",
     "author": "Pratik Solanki",
-    "version": (1, 0, 1),
+    "version": (1, 0, 2),
     "blender": (2, 78, 0),
     "location": "View3D > Tools",
     "description": "Creates Dynamic Sky for Cycles",
@@ -27,29 +29,59 @@ bl_info = {
     "wiki_url": "http://www.dragoneex.com/downloads/dynamic-skyadd-on",
     "category": "Lighting",
     }
-import bpy
-
-
-class dsky(bpy.types.Operator):
 
+import bpy
+from bpy.props import StringProperty
+from bpy.types import (
+        Operator,
+        Panel,
+        )
+
+
+# Handle error notifications
+def error_handlers(self, error, reports="ERROR"):
+    if self and reports:
+        self.report({'WARNING'}, reports + " (See Console for more info)")
+
+    print("\n[Dynamic Sky]\nError: {}\n".format(error))
+
+
+def check_world_name(name_id="Dynamic"):
+    # check if the new name pattern is in world data
+    name_list = []
+    suffix = 1
+    try:
+        name_list = [world.name for world in bpy.data.worlds if name_id in world.name]
+        new_name = "{}_{}".format(name_id, len(name_list) + suffix)
+        if new_name in name_list:
+            # KISS failed - numbering is not sequential
+            # try harvesting numbers in world names, find the rightmost ones
+            test_num = []
+            from re import findall
+            for words in name_list:
+                test_num.append(findall("\d+", words))
+
+            suffix += max([int(l[-1]) for l in test_num])
+            new_name = "{}_{}".format(name_id, suffix)
+        return new_name
+    except Exception as e:
+        error_handlers(False, e)
+        pass
+    return name_id
+
+
+class dsky(Operator):
     bl_idname = "sky.dyn"
-    bl_label = "Make a Procidural sky"
-
+    bl_label = "Make a Procedural sky"
+    bl_description = "Make a Procedural Sky"
 
     def execute(self, context):
+        try:
+            get_name = check_world_name()
+            context.scene.dynamic_sky_name = get_name
+            bpy.context.scene.render.engine = 'CYCLES'
 
-        def clean_node_tree(node_tree):
-            nodes = node_tree.nodes
-            for node in nodes:
-                if not node.type == 'OUTPUT_WORLD':
-                    nodes.remove(node)
-            return node_tree.nodes[0]
-        bpy.context.scene.render.engine = 'CYCLES'
-
-
-        def dynamic():
-
-            world = bpy.data.worlds.new('Dynamic')
+            world = bpy.data.worlds.new(get_name)
             world.cycles.sample_as_light = True
             world.cycles.sample_map_resolution = 2048
             world.use_nodes = True
@@ -66,110 +98,110 @@ class dsky(bpy.types.Operator):
 
             nor = nt.nodes.new(type="ShaderNodeNormal")
 
-            cr1 = nt.nodes.new(type ="ShaderNodeValToRGB")
+            cr1 = nt.nodes.new(type="ShaderNodeValToRGB")
             cr1.color_ramp.elements[0].position = 0.969
             cr1.color_ramp.interpolation = 'EASE'
-            cr2 = nt.nodes.new(type ="ShaderNodeValToRGB")
+            cr2 = nt.nodes.new(type="ShaderNodeValToRGB")
             cr2.color_ramp.elements[0].position = 0.991
             cr2.color_ramp.elements[1].position = 1
             cr2.color_ramp.interpolation = 'EASE'
-            cr3 = nt.nodes.new(type ="ShaderNodeValToRGB")
+            cr3 = nt.nodes.new(type="ShaderNodeValToRGB")
             cr3.color_ramp.elements[0].position = 0.779
             cr3.color_ramp.elements[1].position = 1
             cr3.color_ramp.interpolation = 'EASE'
 
-            mat1 = nt.nodes.new(type ="ShaderNodeMath")
+            mat1 = nt.nodes.new(type="ShaderNodeMath")
             mat1.operation = 'MULTIPLY'
             mat1.inputs[1].default_value = 0.2
-            mat2 = nt.nodes.new(type ="ShaderNodeMath")
+            mat2 = nt.nodes.new(type="ShaderNodeMath")
             mat2.operation = 'MULTIPLY'
             mat2.inputs[1].default_value = 2
-            mat3 = nt.nodes.new(type ="ShaderNodeMath")
+            mat3 = nt.nodes.new(type="ShaderNodeMath")
             mat3.operation = 'MULTIPLY'
             mat3.inputs[1].default_value = 40.9
-            mat4 = nt.nodes.new(type ="ShaderNodeMath")
+            mat4 = nt.nodes.new(type="ShaderNodeMath")
             mat4.operation = 'SUBTRACT'
             mat4.inputs[1].default_value = 1
-            ntl(mat2.inputs[0],mat1.outputs[0])
-            ntl(mat4.inputs[0],mat3.outputs[0])
-            ntl(mat1.inputs[0],cr3.outputs[0])
-            ntl(mat3.inputs[0],cr2.outputs[0])
+            ntl(mat2.inputs[0], mat1.outputs[0])
+            ntl(mat4.inputs[0], mat3.outputs[0])
+            ntl(mat1.inputs[0], cr3.outputs[0])
+            ntl(mat3.inputs[0], cr2.outputs[0])
 
-            soft = nt.nodes.new(type = "ShaderNodeMixRGB")
-            soft_1 = nt.nodes.new(type = "ShaderNodeMixRGB")
+            soft = nt.nodes.new(type="ShaderNodeMixRGB")
+            soft_1 = nt.nodes.new(type="ShaderNodeMixRGB")
             soft.inputs[0].default_value = 1
             soft_1.inputs[0].default_value = 0.466
-            ntl(soft.inputs[1],mat2.outputs[0])
-            ntl(soft.inputs[2],mat4.outputs[0])
-            ntl(soft_1.inputs[1],mat2.outputs[0])
-            ntl(soft_1.inputs[2],cr2.outputs[0])
+            ntl(soft.inputs[1], mat2.outputs[0])
+            ntl(soft.inputs[2], mat4.outputs[0])
+            ntl(soft_1.inputs[1], mat2.outputs[0])
+            ntl(soft_1.inputs[2], cr2.outputs[0])
 
-            mix1 = nt.nodes.new(type = "ShaderNodeMixRGB")
+            mix1 = nt.nodes.new(type="ShaderNodeMixRGB")
             mix1.blend_type = 'MULTIPLY'
             mix1.inputs[0].default_value = 1
-            mix1_1 = nt.nodes.new(type = "ShaderNodeMixRGB")
+            mix1_1 = nt.nodes.new(type="ShaderNodeMixRGB")
             mix1_1.blend_type = 'MULTIPLY'
             mix1_1.inputs[0].default_value = 1
 
-            mix2 = nt.nodes.new(type = "ShaderNodeMixRGB")
-            mix2_1 = nt.nodes.new(type = "ShaderNodeMixRGB")
+            mix2 = nt.nodes.new(type="ShaderNodeMixRGB")
+            mix2_1 = nt.nodes.new(type="ShaderNodeMixRGB")
             mix2.inputs[1].default_value = (0, 0, 0, 1)
             mix2.inputs[2].default_value = (32, 22, 14, 200)
             mix2_1.inputs[1].default_value = (0, 0, 0, 1)
-            mix2_1.inputs[2].default_value = (1, 0.820, 0.650,1)
+            mix2_1.inputs[2].default_value = (1, 0.820, 0.650, 1)
 
-            ntl(mix1.inputs[1],soft.outputs[0])
-            ntl(mix1_1.inputs[1],soft_1.outputs[0])
-            ntl(mix2.inputs[0],mix1.outputs[0])
-            ntl(mix2_1.inputs[0],mix1_1.outputs[0])
+            ntl(mix1.inputs[1], soft.outputs[0])
+            ntl(mix1_1.inputs[1], soft_1.outputs[0])
+            ntl(mix2.inputs[0], mix1.outputs[0])
+            ntl(mix2_1.inputs[0], mix1_1.outputs[0])
 
-            gam = nt.nodes.new(type = "ShaderNodeGamma")
+            gam = nt.nodes.new(type="ShaderNodeGamma")
             gam.inputs[1].default_value = 2.3
-            gam2 = nt.nodes.new(type = "ShaderNodeGamma")
+            gam2 = nt.nodes.new(type="ShaderNodeGamma")
             gam2.inputs[1].default_value = 1
-            gam3 = nt.nodes.new(type = "ShaderNodeGamma")
+            gam3 = nt.nodes.new(type="ShaderNodeGamma")
             gam3.inputs[1].default_value = 1
 
-            sunopa = nt.nodes.new(type = "ShaderNodeMixRGB")
+            sunopa = nt.nodes.new(type="ShaderNodeMixRGB")
             sunopa.blend_type = 'ADD'
             sunopa.inputs[0].default_value = 1
-            sunopa_1 = nt.nodes.new(type = "ShaderNodeMixRGB")
+            sunopa_1 = nt.nodes.new(type="ShaderNodeMixRGB")
             sunopa_1.blend_type = 'ADD'
             sunopa_1.inputs[0].default_value = 1
 
-            combine = nt.nodes.new(type = "ShaderNodeMixRGB")
-            ntl(combine.inputs[1],sunopa.outputs[0])
-            ntl(combine.inputs[2],sunopa_1.outputs[0])
-            lp = nt.nodes.new(type = "ShaderNodeLightPath")
-            ntl(combine.inputs[0],lp.outputs[0])
+            combine = nt.nodes.new(type="ShaderNodeMixRGB")
+            ntl(combine.inputs[1], sunopa.outputs[0])
+            ntl(combine.inputs[2], sunopa_1.outputs[0])
+            lp = nt.nodes.new(type="ShaderNodeLightPath")
+            ntl(combine.inputs[0], lp.outputs[0])
 
-            ntl(gam2.inputs[0],gam.outputs[0])
-            ntl(gam.inputs[0],mix2.outputs[0])
-            ntl(bg.inputs[0],combine.outputs[0])

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list