From 9a36b51cc7701a0979ce06ad75dc411ff8bfe020 Mon Sep 17 00:00:00 2001 From: Lukas Toenne Date: Thu, 9 Aug 2012 11:45:54 +0000 Subject: Fix for the default internal connect function for nodes (used in muting, detaching, etc.). This is supposed to look for the first input/output of every socket type, but was actually taking the first matching link from the link list, regardless of the linked socket's position. --- source/blender/nodes/intern/node_util.c | 61 +++++++++++++++++++++------------ 1 file changed, 39 insertions(+), 22 deletions(-) (limited to 'source/blender/nodes/intern') diff --git a/source/blender/nodes/intern/node_util.c b/source/blender/nodes/intern/node_util.c index 548a21ee35b..8f9214fa1b2 100644 --- a/source/blender/nodes/intern/node_util.c +++ b/source/blender/nodes/intern/node_util.c @@ -29,6 +29,7 @@ * \ingroup nodes */ +#include #include "DNA_action_types.h" #include "DNA_node_types.h" @@ -116,42 +117,58 @@ ListBase node_internal_connect_default(bNodeTree *ntree, bNode *node) return ret; for (datatype=0; datatype < NUM_SOCKET_TYPES; ++datatype) { - bNodeSocket *fromsock=NULL, *tosock=NULL; + bNodeSocket *fromsock, *tosock; + int fromindex, toindex; bNodeLink *link; /* Connect the first input of each type with outputs of the same type. */ + fromindex = INT_MAX; + fromsock = NULL; for (link=ntree->links.first; link; link=link->next) { if (link->tonode == node && link->tosock->type == datatype) { - fromsock = link->tosock; - ++num_links_in; - if (!fromsock_first) - fromsock_first = fromsock; - break; + int index = BLI_findindex(&node->inputs, link->tosock); + if (index < fromindex) { + fromindex = index; + fromsock = link->tosock; + } } } + if (fromsock) { + ++num_links_in; + if (!fromsock_first) + fromsock_first = fromsock; + } + toindex = INT_MAX; + tosock = NULL; for (link=ntree->links.first; link; link=link->next) { if (link->fromnode == node && link->fromsock->type == datatype) { - tosock = link->fromsock; - ++num_links_out; - if (!tosock_first) - tosock_first = tosock; - - if (fromsock) { - bNodeLink *ilink = MEM_callocN(sizeof(bNodeLink), "internal node link"); - ilink->fromnode = node; - ilink->fromsock = fromsock; - ilink->tonode = node; - ilink->tosock = tosock; - /* internal link is always valid */ - ilink->flag |= NODE_LINK_VALID; - BLI_addtail(&ret, ilink); - - ++num_reconnect; + int index = BLI_findindex(&node->outputs, link->fromsock); + if (index < toindex) { + toindex = index; + tosock = link->fromsock; } } } + if (tosock) { + ++num_links_out; + if (!tosock_first) + tosock_first = tosock; + + if (fromsock) { + bNodeLink *ilink = MEM_callocN(sizeof(bNodeLink), "internal node link"); + ilink->fromnode = node; + ilink->fromsock = fromsock; + ilink->tonode = node; + ilink->tosock = tosock; + /* internal link is always valid */ + ilink->flag |= NODE_LINK_VALID; + BLI_addtail(&ret, ilink); + + ++num_reconnect; + } + } } /* if there is one input and one output link, but no reconnections by type, -- cgit v1.2.3