[Bf-blender-cvs] [a0c28a80548] blender-v3.3-release: Fix T100430: Restore larger node socket snap hitbox

Leon Schittek noreply at git.blender.org
Sun Aug 21 10:19:03 CEST 2022


Commit: a0c28a805483afb9f34199789d19c51d9811ff84
Author: Leon Schittek
Date:   Sun Aug 21 10:12:50 2022 +0200
Branches: blender-v3.3-release
https://developer.blender.org/rBa0c28a805483afb9f34199789d19c51d9811ff84

Fix T100430: Restore larger node socket snap hitbox

Restore old hitbox for connecting links to sockets.

Commit rBd9d97db018d2 improved the node socket snapping when nodes
are close together by decreasing the tolerance around the cursor when
checking for nodes in front, that might occlude the socket.
In doing so it also reduced the hitbox of the node socket itself that
extended outside of the node.

This commit restores the old node socket hitbox while keeping the
improved behavior when nodes are close together with the following
changes:
1) When looking for the socket under the cursor, iterate through the
nodes front to back, which prioritizes node sockets in the foreground.
2) Instead of checking for another node underneath the cursor it checks
if the socket is actually occluded by another node.

The way the occlusion test for sockets is tweaked you can now connect to
sockets that are only partially occluded, which is a bit more forgiving
than previously.

Reviewed By: Hans Goudey

Differential Revision: http://developer.blender.org/D15731

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

M	source/blender/editors/space_node/node_edit.cc

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

diff --git a/source/blender/editors/space_node/node_edit.cc b/source/blender/editors/space_node/node_edit.cc
index 0b1f2037292..1e01373029d 100644
--- a/source/blender/editors/space_node/node_edit.cc
+++ b/source/blender/editors/space_node/node_edit.cc
@@ -913,15 +913,24 @@ static void edit_node_properties_get(
 /** \name Node Generic
  * \{ */
 
-/* is rct in visible part of node? */
-static bNode *visible_node(SpaceNode &snode, const rctf &rct)
+static bool socket_is_occluded(const bNodeSocket &sock,
+                               const bNode &node_the_socket_belongs_to,
+                               const SpaceNode &snode)
 {
   LISTBASE_FOREACH_BACKWARD (bNode *, node, &snode.edittree->nodes) {
-    if (BLI_rctf_isect(&node->totr, &rct, nullptr)) {
-      return node;
+    if (node == &node_the_socket_belongs_to) {
+      /* Nodes after this one are underneath and can't occlude the socket. */
+      return false;
+    }
+
+    rctf socket_hitbox;
+    const float socket_hitbox_radius = NODE_SOCKSIZE - 0.1f * U.widget_unit;
+    BLI_rctf_init_pt_radius(&socket_hitbox, float2(sock.locx, sock.locy), socket_hitbox_radius);
+    if (BLI_rctf_inside_rctf(&node->totr, &socket_hitbox)) {
+      return true;
     }
   }
-  return nullptr;
+  return false;
 }
 
 /** \} */
@@ -1216,10 +1225,8 @@ bool node_find_indicated_socket(SpaceNode &snode,
   *sockp = nullptr;
 
   /* check if we click in a socket */
-  LISTBASE_FOREACH (bNode *, node, &snode.edittree->nodes) {
+  LISTBASE_FOREACH_BACKWARD (bNode *, node, &snode.edittree->nodes) {
     BLI_rctf_init_pt_radius(&rect, cursor, size_sock_padded);
-    rctf node_visible;
-    BLI_rctf_init_pt_radius(&node_visible, cursor, size_sock_padded);
 
     if (!(node->flag & NODE_HIDDEN)) {
       /* extra padding inside and out - allow dragging on the text areas too */
@@ -1238,7 +1245,7 @@ bool node_find_indicated_socket(SpaceNode &snode,
         if (!nodeSocketIsHidden(sock)) {
           if (sock->flag & SOCK_MULTI_INPUT && !(node->flag & NODE_HIDDEN)) {
             if (cursor_isect_multi_input_socket(cursor, *sock)) {
-              if (node == visible_node(snode, node_visible)) {
+              if (!socket_is_occluded(*sock, *node, snode)) {
                 *nodep = node;
                 *sockp = sock;
                 return true;
@@ -1246,7 +1253,7 @@ bool node_find_indicated_socket(SpaceNode &snode,
             }
           }
           else if (BLI_rctf_isect_pt(&rect, sock->locx, sock->locy)) {
-            if (node == visible_node(snode, node_visible)) {
+            if (!socket_is_occluded(*sock, *node, snode)) {
               *nodep = node;
               *sockp = sock;
               return true;
@@ -1259,7 +1266,7 @@ bool node_find_indicated_socket(SpaceNode &snode,
       LISTBASE_FOREACH (bNodeSocket *, sock, &node->outputs) {
         if (!nodeSocketIsHidden(sock)) {
           if (BLI_rctf_isect_pt(&rect, sock->locx, sock->locy)) {
-            if (node == visible_node(snode, node_visible)) {
+            if (!socket_is_occluded(*sock, *node, snode)) {
               *nodep = node;
               *sockp = sock;
               return true;



More information about the Bf-blender-cvs mailing list