Commit: 25bd01f2f7793f8af4e14c8385a653cc424f75e5
Author: Lukas Stockner
Date:   Wed Jul 27 15:53:32 2016 +0200
Branches: master
https://developer.blender.org/rB25bd01f2f7793f8af4e14c8385a653cc424f75e5

Avoid creating multiple outputs connected to the same socket when creating a 
node group

This patch fixes the annoyance that when creating a node group where one of its 
nodes is connected
to several other nodes, a separate output will be created for each link, even 
though they're all
connected to the same socket in the group.
Now, before adding an output for an outgoing link, the existing outputs are 
checked to find whether
any output is already connected to the same socket. If such an output is found, 
it is reused instead of
creating a new one.

Reviewers: Severin

Subscribers: Blendify

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

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

M       source/blender/editors/space_node/node_group.c

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

diff --git a/source/blender/editors/space_node/node_group.c 
b/source/blender/editors/space_node/node_group.c
index cf6e2ac..26eeaa9 100644
--- a/source/blender/editors/space_node/node_group.c
+++ b/source/blender/editors/space_node/node_group.c
@@ -794,22 +794,37 @@ static void node_group_make_insert_selected(const 
bContext *C, bNodeTree *ntree,
                        link->tosock = node_group_find_input_socket(gnode, 
iosock->identifier);
                }
                else if (fromselect) {
-                       bNodeSocket *iosock = 
ntreeAddSocketInterfaceFromSocket(ngroup, link->fromnode, link->fromsock);
-                       bNodeSocket *output_sock;
-                       
-                       /* update the group node and interface node sockets,
-                        * so the new interface socket can be linked.
-                        */
-                       node_group_verify(ntree, gnode, (ID *)ngroup);
-                       node_group_output_verify(ngroup, output_node, (ID 
*)ngroup);
+                       /* First check whether the source of this link is 
already connected to an output.
+                        * If yes, reuse that output instead of duplicating it. 
*/
+                       bool connected = false;
+                       bNodeLink *olink;
+                       for (olink = ngroup->links.first; olink; olink = 
olink->next) {
+                               if (olink->fromsock == link->fromsock && 
olink->tonode == output_node) {
+                                       bNodeSocket *output_sock = 
node_group_find_output_socket(gnode, olink->tosock->identifier);
+                                       link->fromnode = gnode;
+                                       link->fromsock = output_sock;
+                                       connected = true;
+                               }
+                       }
 
-                       /* create new internal link */
-                       output_sock = 
node_group_output_find_socket(output_node, iosock->identifier);
-                       nodeAddLink(ngroup, link->fromnode, link->fromsock, 
output_node, output_sock);
-                       
-                       /* redirect external link */
-                       link->fromnode = gnode;
-                       link->fromsock = node_group_find_output_socket(gnode, 
iosock->identifier);
+                       if (!connected) {
+                               bNodeSocket *iosock = 
ntreeAddSocketInterfaceFromSocket(ngroup, link->fromnode, link->fromsock);
+                               bNodeSocket *output_sock;
+
+                               /* update the group node and interface node 
sockets,
+                                * so the new interface socket can be linked.
+                                */
+                               node_group_verify(ntree, gnode, (ID *)ngroup);
+                               node_group_output_verify(ngroup, output_node, 
(ID *)ngroup);
+
+                               /* create new internal link */
+                               output_sock = 
node_group_output_find_socket(output_node, iosock->identifier);
+                               nodeAddLink(ngroup, link->fromnode, 
link->fromsock, output_node, output_sock);
+
+                               /* redirect external link */
+                               link->fromnode = gnode;
+                               link->fromsock = 
node_group_find_output_socket(gnode, iosock->identifier);
+                       }
                }
        }

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to