[Bf-extensions-cvs] [7f70ce3] master: Node Wrangler - Updates and new features

Greg Zaal noreply at git.blender.org
Thu Mar 13 20:09:53 CET 2014


Commit: 7f70ce3d54c9473135374733b1cf88138bc0ac34
Author: Greg Zaal
Date:   Thu Mar 13 21:06:31 2014 +0200
https://developer.blender.org/rBA7f70ce3d54c9473135374733b1cf88138bc0ac34

Node Wrangler - Updates and new features

Updates:
* Better positions for new Mix nodes
* Replace Swap Outputs with a generic Swap Links function: It works the same if two nodes are selected. If one node with one input linked is selected, the link is cycled through the available inputs. If one node with two inputs linked is selected, the two links are swapped (useful if you want to swap the inputs of a Mix node for example)
* Lazy functions now work on nodes that are in frames

New features:
* Add Image Sequence - just a speedy way to select just one image from a sequence in the file browser and have it automatically detect the length of the sequence and set the node appropriately
* Add Multiple Images - simply allows you to select more than one image and adds a node for each (useful for importing multiple render passes or renders for image stacking)

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

M	node_efficiency_tools.py

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

diff --git a/node_efficiency_tools.py b/node_efficiency_tools.py
index 9d53e77..7d6661f 100644
--- a/node_efficiency_tools.py
+++ b/node_efficiency_tools.py
@@ -19,8 +19,8 @@
 bl_info = {
     'name': "Node Wrangler (aka Nodes Efficiency Tools)",
     'author': "Bartek Skorupa, Greg Zaal",
-    'version': (3, 2),
-    'blender': (2, 69, 0),
+    'version': (3, 3),
+    'blender': (2, 70, 0),
     'location': "Node Editor Properties Panel  or  Ctrl-SPACE",
     'description': "Various tools to enhance and speed up node-based workflow",
     'warning': "",
@@ -32,9 +32,11 @@ bl_info = {
 
 import bpy, blf, bgl
 from bpy.types import Operator, Panel, Menu
-from bpy.props import FloatProperty, EnumProperty, BoolProperty, IntProperty, StringProperty, FloatVectorProperty
+from bpy.props import FloatProperty, EnumProperty, BoolProperty, IntProperty, StringProperty, FloatVectorProperty, CollectionProperty
+from bpy_extras.io_utils import ImportHelper
 from mathutils import Vector
 from math import cos, sin, pi, sqrt
+from os import listdir
 
 #################
 # rl_outputs:
@@ -540,32 +542,50 @@ def node_at_pos(nodes, context, event):
     # Will be sorted to find nearest point and thus nearest node
     node_points_with_dist = []
     for node in nodes:
-        locx = node.location.x
-        locy = node.location.y
-        dimx = node.dimensions.x/dpifac()
-        dimy = node.dimensions.y/dpifac()
-        node_points_with_dist.append([node, sqrt((x - locx) ** 2 + (y - locy) ** 2)])  # Top Left
-        node_points_with_dist.append([node, sqrt((x - (locx+dimx)) ** 2 + (y - locy) ** 2)])  # Top Right
-        node_points_with_dist.append([node, sqrt((x - locx) ** 2 + (y - (locy-dimy)) ** 2)])  # Bottom Left
-        node_points_with_dist.append([node, sqrt((x - (locx+dimx)) ** 2 + (y - (locy-dimy)) ** 2)])  # Bottom Right
-
-        node_points_with_dist.append([node, sqrt((x - (locx+(dimx/2))) ** 2 + (y - locy) ** 2)])  # Mid Top
-        node_points_with_dist.append([node, sqrt((x - (locx+(dimx/2))) ** 2 + (y - (locy-dimy)) ** 2)])  # Mid Bottom
-        node_points_with_dist.append([node, sqrt((x - locx) ** 2 + (y - (locy-(dimy/2))) ** 2)])  # Mid Left
-        node_points_with_dist.append([node, sqrt((x - (locx+dimx)) ** 2 + (y - (locy-(dimy/2))) ** 2)])  # Mid Right
-
-        #node_points_with_dist.append([node, sqrt((x - (locx+(dimx/2))) ** 2 + (y - (locy-(dimy/2))) ** 2)])  # Center
+        skipnode = False
+        if node.type != 'FRAME':  # no point trying to link to a frame node
+            locx = node.location.x
+            locy = node.location.y
+            dimx = node.dimensions.x/dpifac()
+            dimy = node.dimensions.y/dpifac()
+            if node.parent:
+                locx += node.parent.location.x
+                locy += node.parent.location.y
+                if node.parent.parent:
+                    locx += node.parent.parent.location.x
+                    locy += node.parent.parent.location.y
+                    if node.parent.parent.parent:
+                        locx += node.parent.parent.parent.location.x
+                        locy += node.parent.parent.parent.location.y
+                        if node.parent.parent.parent.parent:
+                            # Support three levels or parenting
+                            # There's got to be a better way to do this...
+                            skipnode = True
+            if not skipnode:
+                node_points_with_dist.append([node, sqrt((x - locx) ** 2 + (y - locy) ** 2)])  # Top Left
+                node_points_with_dist.append([node, sqrt((x - (locx+dimx)) ** 2 + (y - locy) ** 2)])  # Top Right
+                node_points_with_dist.append([node, sqrt((x - locx) ** 2 + (y - (locy-dimy)) ** 2)])  # Bottom Left
+                node_points_with_dist.append([node, sqrt((x - (locx+dimx)) ** 2 + (y - (locy-dimy)) ** 2)])  # Bottom Right
+
+                node_points_with_dist.append([node, sqrt((x - (locx+(dimx/2))) ** 2 + (y - locy) ** 2)])  # Mid Top
+                node_points_with_dist.append([node, sqrt((x - (locx+(dimx/2))) ** 2 + (y - (locy-dimy)) ** 2)])  # Mid Bottom
+                node_points_with_dist.append([node, sqrt((x - locx) ** 2 + (y - (locy-(dimy/2))) ** 2)])  # Mid Left
+                node_points_with_dist.append([node, sqrt((x - (locx+dimx)) ** 2 + (y - (locy-(dimy/2))) ** 2)])  # Mid Right
 
     nearest_node = sorted(node_points_with_dist, key=lambda k: k[1])[0][0]
 
     for node in nodes:
-        locx = node.location.x
-        locy = node.location.y
-        dimx = node.dimensions.x/dpifac()
-        dimy = node.dimensions.y/dpifac()
-        if (locx <= x <= locx + dimx) and \
-           (locy - dimy <= y <= locy):
-            nodes_under_mouse.append(node)
+        if node.type != 'FRAME' and skipnode == False:
+            locx = node.location.x
+            locy = node.location.y
+            dimx = node.dimensions.x/dpifac()
+            dimy = node.dimensions.y/dpifac()
+            if node.parent:
+                locx += node.parent.location.x
+                locy += node.parent.location.y
+            if (locx <= x <= locx + dimx) and \
+               (locy - dimy <= y <= locy):
+                nodes_under_mouse.append(node)
 
     if len(nodes_under_mouse) == 1:
         if nodes_under_mouse[0] != nearest_node:
@@ -630,6 +650,16 @@ def draw_rounded_node_border(node, radius=8, colour=[1.0, 1.0, 1.0, 0.7]):
     nlocy = (node.location.y+1)*dpifac()
     ndimx = node.dimensions.x
     ndimy = node.dimensions.y
+    if node.parent:
+        nlocx += node.parent.location.x
+        nlocy += node.parent.location.y
+        if node.parent.parent:
+            nlocx += node.parent.parent.location.x
+            nlocy += node.parent.parent.location.y
+            if node.parent.parent.parent:
+                nlocx += node.parent.parent.parent.location.x
+                nlocy += node.parent.parent.parent.location.y
+
 
     bgl.glBegin(bgl.GL_TRIANGLE_FAN)
     mx, my = bpy.context.region.view2d.view_to_region(nlocx, nlocy)
@@ -1124,17 +1154,17 @@ class NWDeleteUnused(Operator, NWBase):
         return context.window_manager.invoke_confirm(self, event)
 
 
-class NWSwapOutputs(Operator, NWBase):
-    """Swap the output connections of the two selected nodes"""
-    bl_idname = 'node.nw_swap_outputs'
-    bl_label = 'Swap Outputs'
+class NWSwapLinks(Operator, NWBase):
+    """Swap the output connections of the two selected nodes, or two similar inputs of a single node"""
+    bl_idname = 'node.nw_swap_links'
+    bl_label = 'Swap Links'
     bl_options = {'REGISTER', 'UNDO'}
 
     @classmethod
     def poll(cls, context):
         snode = context.space_data
         if context.selected_nodes:
-            return len(context.selected_nodes) == 2
+            return len(context.selected_nodes) <= 2
         else:
             return False
 
@@ -1142,36 +1172,96 @@ class NWSwapOutputs(Operator, NWBase):
         nodes, links = get_nodes_links(context)
         selected_nodes = context.selected_nodes
         n1 = selected_nodes[0]
-        n2 = selected_nodes[1]
-        n1_outputs = []
-        n2_outputs = []
-
-        out_index = 0
-        for output in n1.outputs:
-            if output.links:
-                for link in output.links:
-                    n1_outputs.append([out_index, link.to_socket])
-                    links.remove(link)
-            out_index += 1
-
-        out_index = 0
-        for output in n2.outputs:
-            if output.links:
-                for link in output.links:
-                    n2_outputs.append([out_index, link.to_socket])
-                    links.remove(link)
-            out_index += 1
-
-        for connection in n1_outputs:
-            try:
-                links.new(n2.outputs[connection[0]], connection[1])
-            except:
-                self.report({'WARNING'}, "Some connections have been lost due to differing numbers of output sockets")
-        for connection in n2_outputs:
-            try:
-                links.new(n1.outputs[connection[0]], connection[1])
-            except:
-                self.report({'WARNING'}, "Some connections have been lost due to differing numbers of output sockets")
+
+        # Swap outputs
+        if len(selected_nodes) == 2:
+            n2 = selected_nodes[1]
+            if n1.outputs and n2.outputs:
+                n1_outputs = []
+                n2_outputs = []
+
+                out_index = 0
+                for output in n1.outputs:
+                    if output.links:
+                        for link in output.links:
+                            n1_outputs.append([out_index, link.to_socket])
+                            links.remove(link)
+                    out_index += 1
+
+                out_index = 0
+                for output in n2.outputs:
+                    if output.links:
+                        for link in output.links:
+                            n2_outputs.append([out_index, link.to_socket])
+                            links.remove(link)
+                    out_index += 1
+
+                for connection in n1_outputs:
+                    try:
+                        links.new(n2.outputs[connection[0]], connection[1])
+                    except:
+                        self.report({'WARNING'}, "Some connections have been lost due to differing numbers of output sockets")
+                for connection in n2_outputs:
+                    try:
+                        links.new(n1.outputs[connection[0]], connection[1])
+                    except:
+                        self.report({'WARNING'}, "Some connections have been lost due to differing numbers of output sockets")
+            else:
+                if n1.outputs or n2.outputs:
+                    self.report({'WARNING'}, "One of the nodes has no outputs!")
+                else:
+                    self.report({'WARNING'}, "Neither of the nodes have outputs!")
+
+        # Swap Inputs
+        elif len(selected_nodes) == 1:
+            if n1.inputs:
+                types = []
+                i=0
+                for i1 in n1.inputs:
+                    if i1.is_linked:
+                        simila

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list