[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [4414] contrib/py/scripts/addons/ node_efficiency_tools.py: Added several options and changed some keyboard shortcuts:

Bartek Skorupa bartekskorupa at bartekskorupa.com
Fri Mar 22 22:52:52 CET 2013


Revision: 4414
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=4414
Author:   bartekskorupa
Date:     2013-03-22 21:52:52 +0000 (Fri, 22 Mar 2013)
Log Message:
-----------
Added several options and changed some keyboard shortcuts:

Swap Nodes (Shift-S):
This allows to replace selected nodes with nodes of a different type.
Previously only exchanging between 'REROUTE' and 'SWITCH' nodes were possible.
This commit adds options to change some nodes' types to:
'MIX_RGB', 'MATH, 'ALPHAOVER', 'SWITCH' and 'REROUTE'.
I'm planning to add option to change shaders to other shaders.

Link Active To Selected (Shift-F, Ctrl-Shift-F, Alt-F):
This allows to link active node to all selected nodes.
It's possible to link without replacing existing links (Shift-F). First input of the same type as active node's output will be linked if it's free.
To replace existing links - use (Ctrl-Shift-F).
This behavior is similiar to standard (F) or (Ctrl-F), but links active to selected instead of basing on nodes' location.
(Alt-F) will link active to selected basing on names. Menu is called and user can select option to use active node's name/label and compare it with selected nodes' names,
or base on outputs' names. This option can be useful when user decides to replace input Render Layers node with pre-rendered MultiLayerOpenEXR.

Add Reroutes to Selected Nodes' Outputs (Slash) or (Numpad Slash):
This adds 'REROUTE' nodes and links them to all outputs of selected nodes.
Option to add them to all outputs no matter if they are linked or not.
If adding reroutes to already linked outputs - newly added reroutes are inserted into link. Behaves exactly as if we dropped node onto the link.
In this function I changed spacing between newly added reroutes to match latest changes in displaying outputs of nodes. They are now a bit more apart from one another.

The addon is almost ready to go to trunk. Only one thing left to do: Adding option to swap shaders.

Modified Paths:
--------------
    contrib/py/scripts/addons/node_efficiency_tools.py

Modified: contrib/py/scripts/addons/node_efficiency_tools.py
===================================================================
--- contrib/py/scripts/addons/node_efficiency_tools.py	2013-03-22 18:44:53 UTC (rev 4413)
+++ contrib/py/scripts/addons/node_efficiency_tools.py	2013-03-22 21:52:52 UTC (rev 4414)
@@ -19,7 +19,7 @@
 bl_info = {
     'name': "Nodes Efficiency Tools",
     'author': "Bartek Skorupa",
-    'version': (2, 0.11),
+    'version': (2, 0.12),
     'blender': (2, 6, 6),
     'location': "Node Editor Properties Panel (Ctrl-SPACE)",
     'description': "Nodes Efficiency Tools",
@@ -30,7 +30,7 @@
     }
 
 import bpy
-from bpy.props import EnumProperty, StringProperty
+from bpy.props import EnumProperty, StringProperty, BoolProperty, FloatProperty
 
 #################
 # rl_outputs:
@@ -310,8 +310,10 @@
     bl_label = "Change Factors of Mix Nodes and Mix Shader Nodes"
     bl_options = {'REGISTER', 'UNDO'}
     
-    # option: string indicating factor change. Example: '0.1'
-    option = StringProperty()
+    # option: Change factor.
+    # If option is 1.0 or 0.0 - set to 1.0 or 0.0
+    # Else - change factor by option value.
+    option = FloatProperty()
     
     @classmethod
     def poll(cls, context):
@@ -320,7 +322,7 @@
     
     def execute(self, context):
         set_convenience_variables(context)
-        option = float(self.option)
+        option = self.option
         selected = []  # entry = index
         for si, node in enumerate(nodes):
             if node.select:
@@ -592,7 +594,7 @@
                 x = node.location.x + width + 20.0
                 if node.type != 'REROUTE':
                     y -= 35.0
-                y_offset = -20.0
+                y_offset = -21.0
                 loc = [x, y]
             reroutes_count = 0  # will be used when aligning reroutes added to hidden nodes
             for out_i, output in enumerate(node.outputs):
@@ -639,63 +641,102 @@
         return {'FINISHED'}
     
 
-class NodesReroutesSwitchesSwap(bpy.types.Operator):
-    bl_idname = "node.reroutes_switches_swap"
+class NodesSwap(bpy.types.Operator):
+    bl_idname = "node.swap_nodes"
     bl_label = "Swap Reroutes and Switches"
     bl_options = {'REGISTER', 'UNDO'}
     
-    # option: 'CompositorNodeSwitch', 'NodeReroute'
+    # option: 'CompositorNodeSwitch', 'NodeReroute', 'NodeMixRGB', 'NodeMath', 'CompositorNodeAlphaOver'
     # 'CompositorNodeSwitch' - change selected reroutes to switches
     # 'NodeReroute' - change selected switches to reroutes
+    # 'NodeMixRGB' - change selected switches to MixRGB (prefix 'Compositor' or 'Shader' will be added
+    # 'NodeMath' - change selected switches to Math (prefix 'Compositor' or 'Shader' will be added
+    # 'CompositorNodeAlphaOver'
     option = StringProperty()
     
     @classmethod
     def poll(cls, context):
         space = context.space_data
-        valid = False
-        if space.type == 'NODE_EDITOR':
-            if space.tree_type == 'CompositorNodeTree' and space.node_tree is not None:
-                valid = True
-        return valid
+        return space.type == 'NODE_EDITOR' and space.node_tree is not None
     
     def execute(self, context):
         set_convenience_variables(context)
+        tree_type = context.space_data.tree_type
+        if tree_type == 'CompositorNodeTree':
+            prefix = 'Compositor'
+        elif tree_type == 'ShaderNodeTree':
+            prefix = 'Shader'
         option = self.option
         selected = [n for n in nodes if n.select]
         reselect = []
-        # If change to switches - replace reroutes
+        mode = None  # will be used to set proper operation or blend type in new Math or Mix nodes.
         if option == 'CompositorNodeSwitch':
-            replace_type = 'REROUTE'
-        # If change to reroutes - replace switches
+            replace_types = ('REROUTE', 'MIX_RGB', 'MATH', 'ALPHAOVER')
+            new_type = option
         elif option == 'NodeReroute':
-            replace_type = 'SWITCH'
+            replace_types = ('SWITCH')
+            new_type = option
+        elif option == 'NodeMixRGB':
+            replace_types = ('REROUTE', 'SWITCH', 'MATH', 'ALPHAOVER')
+            new_type = prefix + option
+        elif option == 'NodeMath':
+            replace_types = ('REROUTE', 'SWITCH', 'MIX_RGB', 'ALPHAOVER')
+            new_type = prefix + option
+        elif option == 'CompositorNodeAlphaOver':
+            replace_types = ('REROUTE', 'SWITCH', 'MATH', 'MIX_RGB')
+            new_type = option
         for node in selected:
-            if node.type == replace_type:
-                valid = True
-                if option == 'NodeReroute':
-                    # If something is linked to second input of switch - don't replace.
-                    if node.inputs[1].links:
-                        valid = False
-                if valid:
-                    new_node = nodes.new(option)
-                    in_link = None
-                    if node.inputs[0].is_linked:
-                        in_link = node.inputs[0].links[0]
-                    if in_link:
-                        links.new(in_link.from_socket, new_node.inputs[0])
-                    for out_link in node.outputs[0].links:
-                        links.new(new_node.outputs[0], out_link.to_socket)
-                    new_node.location = node.location
-                    new_node.label = node.label
-                    new_node.hide = True
-                    new_node.width_hidden = 100.0
-                    nodes.active = new_node
-                    reselect.append(new_node)
-                    bpy.ops.node.select_all(action = "DESELECT")
-                    node.select = True
-                    bpy.ops.node.delete()
-                else:
-                    reselect.append(node)
+            if node.type in replace_types:
+                hide = node.hide
+                if node.type == 'REROUTE':
+                    hide = True
+                new_node = nodes.new(new_type)
+                # if swap Mix to Math of vice-verca - try to set blend type or operation accordingly
+                if new_node.type == 'MIX_RGB':
+                    if node.type == 'MATH':
+                        if node.operation in blend_types:
+                            new_node.blend_type = node.operation
+                elif new_node.type == 'MATH':
+                    if node.type == 'MIX_RGB':
+                        if node.blend_type in operations:
+                            new_node.operation = node.blend_type
+                old_inputs_count = len(node.inputs)
+                new_inputs_count = len(new_node.inputs)
+                if new_inputs_count == 1:
+                    replace = [[0, 0]]  # old input 0 (first of the entry) will be replaced by new input 0.
+                elif new_inputs_count == 2:
+                    if old_inputs_count == 1:
+                        replace = [[0, 0]]
+                    elif old_inputs_count == 2:
+                        replace = [[0, 0], [1, 1]]
+                    elif old_inputs_count == 3:
+                        replace = [[1, 0], [2, 1]]
+                elif new_inputs_count == 3:
+                    if old_inputs_count == 1:
+                        replace = [[0, 1]]
+                    elif old_inputs_count == 2:
+                        replace = [[0, 1], [1, 2]]
+                    elif old_inputs_count == 3:
+                        replace = [[0, 0], [1, 1], [2, 2]]
+                for [old, new] in replace:
+                    if node.inputs[old].links:
+                        in_link = node.inputs[old].links[0]
+                        links.new(in_link.from_socket, new_node.inputs[new])
+                for out_link in node.outputs[0].links:
+                    links.new(new_node.outputs[0], out_link.to_socket)
+                new_node.location = node.location
+                new_node.label = node.label
+                new_node.hide = hide
+                new_node.mute = node.mute
+                new_node.show_preview = node.show_preview
+                new_node.width_hidden = node.width_hidden
+                nodes.active = new_node
+                reselect.append(new_node)
+                bpy.ops.node.select_all(action = "DESELECT")
+                node.select = True
+                bpy.ops.node.delete()
+            else:
+                reselect.append(node)
         for node in reselect:
             node.select = True
             
@@ -707,9 +748,8 @@
     bl_label = "Link Active Node to Selected"
     bl_options = {'REGISTER', 'UNDO'}
     
-    # option: 'True/Nodes Names', 'True/Nodes Location', 'True/First Output Only'
-    #         'False/Nodes Names', 'False/Nodes Location', 'False/First Output Only'
-    option = StringProperty()    
+    # option: 'bool bool bool' - replace, use node's name, use outputs' names
+    option = StringProperty()
     
     @classmethod
     def poll(cls, context):
@@ -717,114 +757,71 @@
         valid = False
         if space.type == 'NODE_EDITOR':
             if space.node_tree is not None and context.active_node is not None:
-                valid = True
+                if context.active_node.select:
+                    valid = True
         return valid
     
     def execute(self, context):
         set_convenience_variables(context)
-        splitted_option = self.option.split('/')
-        # Will replace existing links or not
-        replace = eval(splitted_option[0])  # True or False
-        # basis for linking: 'Nodes Names', 'Nodes Location', 'First Output Only'
-        option = splitted_option[1]
-        # Links will be made from active node
+        option_split = self.option.split( )
+        replace = eval(option_split[0])
+        use_node_name = eval(option_split[1])
+        use_outputs_names = eval(option_split[2])
         active = nodes.active
-        # create list of selected nodes. Links will be made to those nodes
-        selected = []  # entry = [node index, node locacion.x, node.location.y]
-        for i, node in enumerate(nodes):
-            is_selected = node.select
-            is_not_active = node != active
-            has_inputs = len(node.inputs) > 0
-            is_valid = is_selected and is_not_active and has_inputs
-            if is_valid:
-                selected.append([i, node.location.x, node.location.y])

@@ Diff output truncated at 10240 characters. @@


More information about the Bf-extensions-cvs mailing list