Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacques Lucke <jacques@blender.org>2021-11-04 16:44:21 +0300
committerJacques Lucke <jacques@blender.org>2021-11-04 16:44:21 +0300
commitbe4478d1f8b6c75b50c951f02cf0116f78e68d6d (patch)
tree605122f23a1c7fb2c08d33c0d83aa42f2c550c90 /source/blender/editors/space_node/node_relationships.cc
parentff4959eeaa5368d79f15d482da6576a1ccba5dca (diff)
Fix T92814: improve automatic linking when inserting Float Curve node
This solves the issue in a more general that can also be used to solve similar issues for other nodes in the future. Nodes can specify their "main" socket in their declaration so that we don't have to rely on heuristics. Differential Revision: https://developer.blender.org/D13108
Diffstat (limited to 'source/blender/editors/space_node/node_relationships.cc')
-rw-r--r--source/blender/editors/space_node/node_relationships.cc32
1 files changed, 28 insertions, 4 deletions
diff --git a/source/blender/editors/space_node/node_relationships.cc b/source/blender/editors/space_node/node_relationships.cc
index 76aad684b4c..55b547d3195 100644
--- a/source/blender/editors/space_node/node_relationships.cc
+++ b/source/blender/editors/space_node/node_relationships.cc
@@ -57,6 +57,7 @@
#include "BLT_translation.h"
+#include "NOD_node_declaration.hh"
#include "NOD_node_tree_ref.hh"
#include "node_intern.h" /* own include */
@@ -2182,9 +2183,32 @@ static int get_main_socket_priority(const bNodeSocket *socket)
return -1;
}
-/** Get the "main" socket of a socket list using a heuristic based on socket types. */
-static bNodeSocket *get_main_socket(ListBase *sockets)
+/** Get the "main" socket based on the node declaration or an heuristic. */
+static bNodeSocket *get_main_socket(bNodeTree &ntree, bNode &node, eNodeSocketInOut in_out)
{
+ using namespace blender;
+ using namespace blender::nodes;
+
+ ListBase *sockets = (in_out == SOCK_IN) ? &node.inputs : &node.outputs;
+
+ /* Try to get the main socket based on the socket declaration. */
+ nodeDeclarationEnsure(&ntree, &node);
+ const NodeDeclaration *node_decl = node.declaration;
+ if (node_decl != nullptr) {
+ Span<SocketDeclarationPtr> socket_decls = (in_out == SOCK_IN) ? node_decl->inputs() :
+ node_decl->outputs();
+ int index;
+ LISTBASE_FOREACH_INDEX (bNodeSocket *, socket, sockets, index) {
+ const SocketDeclaration &socket_decl = *socket_decls[index];
+ if (nodeSocketIsHidden(socket)) {
+ continue;
+ }
+ if (socket_decl.is_default_link_socket()) {
+ return socket;
+ }
+ }
+ }
+
/* find priority range */
int maxpriority = -1;
LISTBASE_FOREACH (bNodeSocket *, sock, sockets) {
@@ -2561,8 +2585,8 @@ void ED_node_link_insert(Main *bmain, ScrArea *area)
}
if (link) {
- bNodeSocket *best_input = get_main_socket(&select->inputs);
- bNodeSocket *best_output = get_main_socket(&select->outputs);
+ bNodeSocket *best_input = get_main_socket(*snode->edittree, *select, SOCK_IN);
+ bNodeSocket *best_output = get_main_socket(*snode->edittree, *select, SOCK_OUT);
if (best_input && best_output) {
bNode *node = link->tonode;