[Bf-blender-cvs] [31e120ef499] master: Nodes: Support linking to existing group input from link drag search.

Jacques Lucke noreply at git.blender.org
Mon Dec 27 16:16:19 CET 2021


Commit: 31e120ef4997583332aa9b5af93521e7e666e9f3
Author: Jacques Lucke
Date:   Mon Dec 27 16:15:11 2021 +0100
Branches: master
https://developer.blender.org/rB31e120ef4997583332aa9b5af93521e7e666e9f3

Nodes: Support linking to existing group input from link drag search.

Before one could only create a new group input using the link drag search.
With this patch it becomes possible to create a Group Input node for an
existing input.

Differential Revision: https://developer.blender.org/D13674

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

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

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

diff --git a/source/blender/editors/space_node/link_drag_search.cc b/source/blender/editors/space_node/link_drag_search.cc
index a2dd32b7cc6..45126e9cee0 100644
--- a/source/blender/editors/space_node/link_drag_search.cc
+++ b/source/blender/editors/space_node/link_drag_search.cc
@@ -105,6 +105,26 @@ static void add_group_input_node_fn(nodes::LinkSearchOpParams &params)
   nodeAddLink(&params.node_tree, &group_input, socket, &params.node, &params.socket);
 }
 
+static void add_existing_group_input_fn(nodes::LinkSearchOpParams &params,
+                                        const bNodeSocket &interface_socket)
+{
+  const int group_input_index = BLI_findindex(&params.node_tree.inputs, &interface_socket);
+  bNode &group_input = params.add_node("NodeGroupInput");
+
+  LISTBASE_FOREACH (bNodeSocket *, socket, &group_input.outputs) {
+    socket->flag |= SOCK_HIDDEN;
+  }
+
+  bNodeSocket *socket = (bNodeSocket *)BLI_findlink(&group_input.outputs, group_input_index);
+  if (socket == nullptr) {
+    /* Adding sockets can fail in some cases. There's no good reason not to be safe here. */
+    return;
+  }
+
+  socket->flag &= ~SOCK_HIDDEN;
+  nodeAddLink(&params.node_tree, &group_input, socket, &params.node, &params.socket);
+}
+
 /**
  * Call the callback to gather compatible socket connections for all node types, and the operations
  * that will actually make the connections. Also add some custom operations like connecting a group
@@ -136,6 +156,22 @@ static void gather_socket_link_operations(bNodeTree &node_tree,
 
   if (is_node_group && socket.in_out == SOCK_IN) {
     search_link_ops.append({IFACE_("Group Input"), add_group_input_node_fn});
+
+    int weight = -1;
+    LISTBASE_FOREACH (const bNodeSocket *, interface_socket, &node_tree.inputs) {
+      eNodeSocketDatatype from = (eNodeSocketDatatype)interface_socket->type;
+      eNodeSocketDatatype to = (eNodeSocketDatatype)socket.type;
+      if (node_tree.typeinfo->validate_link && !node_tree.typeinfo->validate_link(from, to)) {
+        continue;
+      }
+      search_link_ops.append(
+          {std::string(IFACE_("Group Input ")) + UI_MENU_ARROW_SEP + interface_socket->name,
+           [interface_socket](nodes::LinkSearchOpParams &params) {
+             add_existing_group_input_fn(params, *interface_socket);
+           },
+           weight});
+      weight--;
+    }
   }
 }



More information about the Bf-blender-cvs mailing list