diff options
author | Lukas Toenne <lukas.toenne@googlemail.com> | 2012-08-09 15:45:54 +0400 |
---|---|---|
committer | Lukas Toenne <lukas.toenne@googlemail.com> | 2012-08-09 15:45:54 +0400 |
commit | 9a36b51cc7701a0979ce06ad75dc411ff8bfe020 (patch) | |
tree | 1d5c94f9e3a5226e1aad41602f1079a3f208657e | |
parent | f05257f969dccb5362c76ee8583148775a372541 (diff) |
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.
-rw-r--r-- | source/blender/nodes/intern/node_util.c | 61 |
1 files changed, 39 insertions, 22 deletions
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 <limits.h> #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, |