[Bf-extensions-cvs] [d883ddc] master: Node Wrangler: Add more specific Lazy connection

Greg Zaal noreply at git.blender.org
Tue Feb 18 18:53:26 CET 2014


Commit: d883ddcd26fc31faaf8c3d5a9e54b28f4333eca8
Author: Greg Zaal
Date:   Tue Feb 18 19:11:04 2014 +0200
https://developer.blender.org/rBAd883ddcd26fc31faaf8c3d5a9e54b28f4333eca8

Node Wrangler: Add more specific Lazy connection

The original Lazy Connect works the same (Ctrl+RMB drag to make a new connection between guessed sockets) - this new function can be accessed with Ctrl+Shift+RMB drag and will show a menu for the user to choose exactly which sockets to connect. This can be useful when dealing with a large node tree, users want to make some connections without repeatedly zooming in and out or trying to click the exact socket they want. Just like with the normal Lazy Connect, you don't need to click on a no [...]

Included in this update are:
- More accurate nearest-node detection
- Auto-linkage (used in Lazy Connect) now matches sockets by name first
- Account for DPI settings other than 72

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

M	node_efficiency_tools.py

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

diff --git a/node_efficiency_tools.py b/node_efficiency_tools.py
index 3f2aeeb..9d53e77 100644
--- a/node_efficiency_tools.py
+++ b/node_efficiency_tools.py
@@ -19,7 +19,7 @@
 bl_info = {
     'name': "Node Wrangler (aka Nodes Efficiency Tools)",
     'author': "Bartek Skorupa, Greg Zaal",
-    'version': (3, 1),
+    'version': (3, 2),
     'blender': (2, 69, 0),
     'location': "Node Editor Properties Panel  or  Ctrl-SPACE",
     'description': "Various tools to enhance and speed up node-based workflow",
@@ -32,7 +32,7 @@ bl_info = {
 
 import bpy, blf, bgl
 from bpy.types import Operator, Panel, Menu
-from bpy.props import FloatProperty, EnumProperty, BoolProperty, StringProperty, FloatVectorProperty
+from bpy.props import FloatProperty, EnumProperty, BoolProperty, IntProperty, StringProperty, FloatVectorProperty
 from mathutils import Vector
 from math import cos, sin, pi, sqrt
 
@@ -459,6 +459,10 @@ def hack_force_update(context, nodes):
     return False
 
 
+def dpifac():
+    return bpy.context.user_preferences.system.dpi/72
+
+
 def is_end_node(node):
     bool = True
     for output in node.outputs:
@@ -480,6 +484,14 @@ def node_mid_pt(node, axis):
 
 def autolink(node1, node2, links):
     link_made = False
+
+    for outp in node1.outputs:
+        for inp in node2.inputs:
+            if not inp.is_linked and inp.name == outp.name:
+                link_made = True
+                links.new(outp, inp)
+                return True
+
     for outp in node1.outputs:
         for inp in node2.inputs:
             if not inp.is_linked and inp.type == outp.type:
@@ -521,22 +533,47 @@ def node_at_pos(nodes, context, event):
 
     store_mouse_cursor(context, event)
     x, y = context.space_data.cursor_location
+    x = x
+    y = y
+
+    # Make a list of each corner (and middle of border) for each node.
+    # 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
 
-    # nearest node
-    nodes_near_mouse = sorted(nodes, key=lambda k: sqrt((x - node_mid_pt(k, 'x')) ** 2 + (y - node_mid_pt(k, 'y')) ** 2))
+    nearest_node = sorted(node_points_with_dist, key=lambda k: k[1])[0][0]
 
     for node in nodes:
-        if (node.location.x <= x <= node.location.x + node.dimensions.x) and \
-           (node.location.y - node.dimensions.y <= y <= node.location.y):
+        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 len(nodes_under_mouse) == 1:
-        if nodes_under_mouse[0] != nodes_near_mouse[0]:
+        if nodes_under_mouse[0] != nearest_node:
             target_node = nodes_under_mouse[0]  # use the node under the mouse if there is one and only one
         else:
-            target_node = nodes_near_mouse[0]  # else use the nearest node
+            target_node = nearest_node  # else use the nearest node
     else:
-        target_node = nodes_near_mouse[0]
+        target_node = nearest_node
     return target_node
 
 
@@ -554,16 +591,19 @@ def store_mouse_cursor(context, event):
 
 def draw_line(x1, y1, x2, y2, size, colour=[1.0, 1.0, 1.0, 0.7]):
     bgl.glEnable(bgl.GL_BLEND)
-    bgl.glColor4f(colour[0], colour[1], colour[2], colour[3])
     bgl.glLineWidth(size)
+    bgl.glShadeModel(bgl.GL_SMOOTH)
 
     bgl.glBegin(bgl.GL_LINE_STRIP)
     try:
+        bgl.glColor4f(colour[0]+(1.0-colour[0])/4, colour[1]+(1.0-colour[1])/4, colour[2]+(1.0-colour[2])/4, colour[3]+(1.0-colour[3])/4)
         bgl.glVertex2f(x1, y1)
+        bgl.glColor4f(colour[0], colour[1], colour[2], colour[3])
         bgl.glVertex2f(x2, y2)
     except:
         pass
     bgl.glEnd()
+    bgl.glShadeModel(bgl.GL_FLAT)
 
 
 def draw_circle(mx, my, radius, colour=[1.0, 1.0, 1.0, 0.7]):
@@ -578,41 +618,152 @@ def draw_circle(mx, my, radius, colour=[1.0, 1.0, 1.0, 0.7]):
     bgl.glEnd()
 
 
-def draw_callback_mixnodes(self, context, mode="MIX"):
+def draw_rounded_node_border(node, radius=8, colour=[1.0, 1.0, 1.0, 0.7]):
+    bgl.glEnable(bgl.GL_BLEND)
+    settings = bpy.context.user_preferences.addons[__name__].preferences
+    if settings.bgl_antialiasing:
+        bgl.glEnable(bgl.GL_LINE_SMOOTH)
+    sides = 16
+    bgl.glColor4f(colour[0], colour[1], colour[2], colour[3])
+
+    nlocx = (node.location.x+1)*dpifac()
+    nlocy = (node.location.y+1)*dpifac()
+    ndimx = node.dimensions.x
+    ndimy = node.dimensions.y
+
+    bgl.glBegin(bgl.GL_TRIANGLE_FAN)
+    mx, my = bpy.context.region.view2d.view_to_region(nlocx, nlocy)
+    bgl.glVertex2f(mx,my)
+    for i in range(sides+1):
+        if (4<=i<=8):
+            if mx != 12000 and my != 12000:  # nodes that go over the view border give 12000 as coords
+                cosine = radius * cos(i * 2 * pi / sides) + mx
+                sine = radius * sin(i * 2 * pi / sides) + my
+                bgl.glVertex2f(cosine, sine)
+    bgl.glEnd()
+
+    bgl.glBegin(bgl.GL_TRIANGLE_FAN)
+    mx, my = bpy.context.region.view2d.view_to_region(nlocx + ndimx, nlocy)
+    bgl.glVertex2f(mx,my)
+    for i in range(sides+1):
+        if (0<=i<=4):
+            if mx != 12000 and my != 12000:
+                cosine = radius * cos(i * 2 * pi / sides) + mx
+                sine = radius * sin(i * 2 * pi / sides) + my
+                bgl.glVertex2f(cosine, sine)
+
+    bgl.glEnd()
+    bgl.glBegin(bgl.GL_TRIANGLE_FAN)
+    mx, my = bpy.context.region.view2d.view_to_region(nlocx, nlocy - ndimy)
+    bgl.glVertex2f(mx,my)
+    for i in range(sides+1):
+        if (8<=i<=12):
+            if mx != 12000 and my != 12000:
+                cosine = radius * cos(i * 2 * pi / sides) + mx
+                sine = radius * sin(i * 2 * pi / sides) + my
+                bgl.glVertex2f(cosine, sine)
+    bgl.glEnd()
+
+    bgl.glBegin(bgl.GL_TRIANGLE_FAN)
+    mx, my = bpy.context.region.view2d.view_to_region(nlocx + ndimx, nlocy - ndimy)
+    bgl.glVertex2f(mx,my)
+    for i in range(sides+1):
+        if (12<=i<=16):
+            if mx != 12000 and my != 12000:
+                cosine = radius * cos(i * 2 * pi / sides) + mx
+                sine = radius * sin(i * 2 * pi / sides) + my
+                bgl.glVertex2f(cosine, sine)
+    bgl.glEnd()
+
+
+    bgl.glBegin(bgl.GL_QUADS)
+    m1x, m1y = bpy.context.region.view2d.view_to_region(nlocx, nlocy)
+    m2x, m2y = bpy.context.region.view2d.view_to_region(nlocx, nlocy - ndimy)
+    if m1x != 12000 and m1y != 12000 and m2x != 12000 and m2y != 12000:
+        bgl.glVertex2f(m2x-radius,m2y)  # draw order is important, start with bottom left and go anti-clockwise
+        bgl.glVertex2f(m2x,m2y)
+        bgl.glVertex2f(m1x,m1y)
+        bgl.glVertex2f(m1x-radius,m1y)
+    bgl.glEnd()
+
+    bgl.glBegin(bgl.GL_QUADS)
+    m1x, m1y = bpy.context.region.view2d.view_to_region(nlocx, nlocy)
+    m2x, m2y = bpy.context.region.view2d.view_to_region(nlocx + ndimx, nlocy)
+    if m1x != 12000 and m1y != 12000 and m2x != 12000 and m2y != 12000:
+        bgl.glVertex2f(m1x,m2y)  # draw order is important, start with bottom left and go anti-clockwise
+        bgl.glVertex2f(m2x,m2y)
+        bgl.glVertex2f(m2x,m1y+radius)
+        bgl.glVertex2f(m1x,m1y+radius)
+    bgl.glEnd()
+
+    bgl.glBegin(bgl.GL_QUADS)
+    m1x, m1y = bpy.context.region.view2d.view_to_region(nlocx + ndimx, nlocy)
+    m2x, m2y = bpy.context.region.view2d.view_to_region(nlocx + ndimx, nlocy - ndimy)
+    if m1x != 12000 and m1y != 12000 and m2x != 12000 and m2y != 12000:
+        bgl.glVertex2f(m2x,m2y)  # draw order is important, start with bottom left and go anti-clockwise
+        bgl.glVertex2f(m2x+radius,m2y)
+        bgl.glVertex2f(m1x+radius,m1y)
+        bgl.glVertex2f(m1x,m1y)
+    bgl.glEnd()
+
+    bgl.glBegin(bgl.GL_QUADS)
+    m1x, m1y = bpy.context.region.view2d.view_to_region(nlocx, nlocy-ndimy)
+    m2x, m2y = bpy.context.region.view2d.view_to_region(nlocx + ndimx, nlocy-ndimy)
+    if m1x != 12000 and m1y != 12000 and m2x != 12000 and m2y != 12000:
+        bgl.glVertex2f(m1x,m2y)  # draw order is important, start with bottom left and go anti-clockwise
+        bgl.glVertex2f(m2x,m2y)
+        bgl.glVertex2f(m2x,m1y-radius)
+        bgl.glVertex2f(m1x,m1y-radius)
+    bgl.glEnd()
+
+    bgl.glDisable(bgl.GL_BLEND)
+    if settings.bgl_antialiasing:
+        bgl.glDisable(bgl.GL_LINE_SMOOTH)
+
+
+def draw_callback_mixnodes(self, context, mode):
     if self.mouse_path:
+        nodes = context.space_data.node_tree.nodes
         settings = context.user_preferences.addons[__name__].preferences
         if settings.bgl_antialiasing:
             bgl.glEnable(bgl.GL_LINE_SMOOTH)
 
-        colors = []
-        if mode == 'MIX':
-            colors = draw_color_sets['red_white']
-        elif mode == 'RGBA':
-            colors = draw_color_sets['yellow']
-        elif mode == 'VECTOR':
-            colors = draw_color_sets['purple']
-        elif mode == 'VALUE':
-            color

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list