[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [45089] trunk/blender/source/blender/nodes /intern/node_util.c: Fix for #30627.

Lukas Toenne lukas.toenne at googlemail.com
Thu Mar 22 17:07:46 CET 2012


Revision: 45089
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=45089
Author:   lukastoenne
Date:     2012-03-22 16:07:41 +0000 (Thu, 22 Mar 2012)
Log Message:
-----------
Fix for #30627. This improves the behaviour of the internal_reconnect function for dissolving, detaching and muting nodes a bit. Instead of only linking a single, perfectly matching socket pair it now connects all outputs of a type to the first input of the same. Also if no such connections can be made it simply links the first connected input to the first connected output. This is the previous behaviour of the delete_reconnect operator (ctrl+x).

Modified Paths:
--------------
    trunk/blender/source/blender/nodes/intern/node_util.c

Modified: trunk/blender/source/blender/nodes/intern/node_util.c
===================================================================
--- trunk/blender/source/blender/nodes/intern/node_util.c	2012-03-22 14:53:42 UTC (rev 45088)
+++ trunk/blender/source/blender/nodes/intern/node_util.c	2012-03-22 16:07:41 UTC (rev 45089)
@@ -102,11 +102,10 @@
 
 ListBase node_internal_connect_default(bNodeTree *ntree, bNode *node)
 {
-	static int types[] = { SOCK_FLOAT, SOCK_VECTOR, SOCK_RGBA };
-	bNodeLink *link;
-	bNodeSocket *fromsock, *tosock;
 	ListBase ret;
-	int in, out, i;
+	bNodeSocket *fromsock_first=NULL, *tosock_first=NULL;	/* used for fallback link if no other reconnections are found */
+	int datatype;
+	int num_links_in = 0, num_links_out = 0, num_reconnect = 0;
 
 	ret.first = ret.last = NULL;
 
@@ -114,31 +113,58 @@
 	if(!ntree)
 		return ret;
 
-	/* Connect the first input of each type with first output of the same type. */
-
-	for (i=0; i < 3; ++i) {
-		/* find input socket */
-		for (in=0, fromsock=node->inputs.first; fromsock; in++, fromsock=fromsock->next) {
-			if (fromsock->type==types[i] && nodeCountSocketLinks(ntree, fromsock) > 0)
+	for (datatype=0; datatype < NUM_SOCKET_TYPES; ++datatype) {
+		bNodeSocket *fromsock=NULL, *tosock=NULL;
+		bNodeLink *link;
+		
+		/* Connect the first input of each type with outputs of the same type. */
+		
+		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;
+			}
 		}
-		if (fromsock) {
-			for (out=0, tosock=node->outputs.first; tosock; out++, tosock=tosock->next) {
-				if (tosock->type==types[i] && (nodeCountSocketLinks(ntree, tosock) > 0))
-					break;
+		
+		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;
+				}
 			}
-			if (tosock) {
-				link = MEM_callocN(sizeof(bNodeLink), "internal node link");
-				link->fromnode = node;
-				link->fromsock = fromsock;
-				link->tonode = node;
-				link->tosock = tosock;
-				/* internal link is always valid */
-				link->flag |= NODE_LINK_VALID;
-				BLI_addtail(&ret, link);
-			}
 		}
 	}
-
+	
+	/* if there is one input and one output link, but no reconnections by type,
+	 * simply connect those two sockets.
+	 */
+	if (num_reconnect==0 && num_links_in==1 && num_links_out==1) {
+		bNodeLink *ilink = MEM_callocN(sizeof(bNodeLink), "internal node link");
+		ilink->fromnode = node;
+		ilink->fromsock = fromsock_first;
+		ilink->tonode = node;
+		ilink->tosock = tosock_first;
+		/* internal link is always valid */
+		ilink->flag |= NODE_LINK_VALID;
+		BLI_addtail(&ret, ilink);
+	}
+	
 	return ret;
 }




More information about the Bf-blender-cvs mailing list