[Bf-blender-cvs] [3734ae5d548] master: Fix T70331 Node group passthrough is broken

Clément Foucault noreply at git.blender.org
Wed Oct 2 16:32:43 CEST 2019


Commit: 3734ae5d5484a1d52fefd8d6d82ace4211df8011
Author: Clément Foucault
Date:   Wed Oct 2 15:47:36 2019 +0200
Branches: master
https://developer.blender.org/rB3734ae5d5484a1d52fefd8d6d82ace4211df8011

Fix T70331 Node group passthrough is broken

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

M	source/blender/editors/space_node/node_group.c
M	source/blender/nodes/shader/node_shader_tree.c

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

diff --git a/source/blender/editors/space_node/node_group.c b/source/blender/editors/space_node/node_group.c
index 08ac84cbb2f..681d1e46f71 100644
--- a/source/blender/editors/space_node/node_group.c
+++ b/source/blender/editors/space_node/node_group.c
@@ -241,6 +241,8 @@ static int node_group_ungroup(Main *bmain, bNodeTree *ntree, bNode *gnode)
     node->flag |= NODE_SELECT;
   }
 
+  bNodeLink *glinks_first = ntree->links.last;
+
   /* Add internal links to the ntree */
   for (link = wgroup->links.first; link; link = linkn) {
     linkn = link->next;
@@ -248,6 +250,8 @@ static int node_group_ungroup(Main *bmain, bNodeTree *ntree, bNode *gnode)
     BLI_addtail(&ntree->links, link);
   }
 
+  bNodeLink *glinks_last = ntree->links.last;
+
   /* and copy across the animation,
    * note that the animation data's action can be NULL here */
   if (wgroup->adt) {
@@ -280,70 +284,64 @@ static int node_group_ungroup(Main *bmain, bNodeTree *ntree, bNode *gnode)
   BKE_id_free(bmain, wgroup);
 
   /* restore external links to and from the gnode */
-  /* note: the nodes have been copied to intermediate wgroup first (so need to use new_node),
-   *       then transferred to ntree (new_node pointers remain valid).
-   */
 
   /* input links */
-  for (link = ngroup->links.first; link; link = link->next) {
-    if (link->fromnode->type == NODE_GROUP_INPUT) {
-      const char *identifier = link->fromsock->identifier;
-      int num_external_links = 0;
-
-      /* find external links to this input */
-      for (tlink = ntree->links.first; tlink; tlink = tlink->next) {
-        if (tlink->tonode == gnode && STREQ(tlink->tosock->identifier, identifier)) {
-          nodeAddLink(ntree,
-                      tlink->fromnode,
-                      tlink->fromsock,
-                      link->tonode->new_node,
-                      link->tosock->new_sock);
-          num_external_links++;
+  if (glinks_first != NULL) {
+    for (link = glinks_first->next; link != glinks_last->next; link = link->next) {
+      if (link->fromnode->type == NODE_GROUP_INPUT) {
+        const char *identifier = link->fromsock->identifier;
+        int num_external_links = 0;
+
+        /* find external links to this input */
+        for (tlink = ntree->links.first; tlink != glinks_first->next; tlink = tlink->next) {
+          if (tlink->tonode == gnode && STREQ(tlink->tosock->identifier, identifier)) {
+            nodeAddLink(ntree, tlink->fromnode, tlink->fromsock, link->tonode, link->tosock);
+            num_external_links++;
+          }
         }
-      }
 
-      /* if group output is not externally linked,
-       * convert the constant input value to ensure somewhat consistent behavior */
-      if (num_external_links == 0) {
-        /* XXX TODO bNodeSocket *sock = node_group_find_input_socket(gnode, identifier);
-        BLI_assert(sock);*/
+        /* if group output is not externally linked,
+         * convert the constant input value to ensure somewhat consistent behavior */
+        if (num_external_links == 0) {
+          /* XXX TODO bNodeSocket *sock = node_group_find_input_socket(gnode, identifier);
+          BLI_assert(sock);*/
 
-        /* XXX TODO
-         * nodeSocketCopy(ntree, link->tosock->new_sock, link->tonode->new_node,
-         *                ntree, sock, gnode);*/
+          /* XXX TODO
+           * nodeSocketCopy(ntree, link->tosock->new_sock, link->tonode->new_node,
+           *                ntree, sock, gnode);*/
+        }
       }
     }
-  }
 
-  /* output links */
-  for (link = ntree->links.first; link; link = link->next) {
-    if (link->fromnode == gnode) {
-      const char *identifier = link->fromsock->identifier;
-      int num_internal_links = 0;
-
-      /* find internal links to this output */
-      for (tlink = ngroup->links.first; tlink; tlink = tlink->next) {
-        /* only use active output node */
-        if (tlink->tonode->type == NODE_GROUP_OUTPUT && (tlink->tonode->flag & NODE_DO_OUTPUT)) {
-          if (STREQ(tlink->tosock->identifier, identifier)) {
-            nodeAddLink(ntree,
-                        tlink->fromnode->new_node,
-                        tlink->fromsock->new_sock,
-                        link->tonode,
-                        link->tosock);
-            num_internal_links++;
+    /* Also iterate over new links to cover passthrough links. */
+    glinks_last = ntree->links.last;
+
+    /* output links */
+    for (link = ntree->links.first; link != glinks_first->next; link = link->next) {
+      if (link->fromnode == gnode) {
+        const char *identifier = link->fromsock->identifier;
+        int num_internal_links = 0;
+
+        /* find internal links to this output */
+        for (tlink = glinks_first->next; tlink != glinks_last->next; tlink = tlink->next) {
+          /* only use active output node */
+          if (tlink->tonode->type == NODE_GROUP_OUTPUT && (tlink->tonode->flag & NODE_DO_OUTPUT)) {
+            if (STREQ(tlink->tosock->identifier, identifier)) {
+              nodeAddLink(ntree, tlink->fromnode, tlink->fromsock, link->tonode, link->tosock);
+              num_internal_links++;
+            }
           }
         }
-      }
 
-      /* if group output is not internally linked,
-       * convert the constant output value to ensure somewhat consistent behavior */
-      if (num_internal_links == 0) {
-        /* XXX TODO bNodeSocket *sock = node_group_find_output_socket(gnode, identifier);
-        BLI_assert(sock);*/
+        /* if group output is not internally linked,
+         * convert the constant output value to ensure somewhat consistent behavior */
+        if (num_internal_links == 0) {
+          /* XXX TODO bNodeSocket *sock = node_group_find_output_socket(gnode, identifier);
+          BLI_assert(sock);*/
 
-        /* XXX TODO
-         * nodeSocketCopy(ntree, link->tosock, link->tonode, ntree, sock, gnode); */
+          /* XXX TODO
+           * nodeSocketCopy(ntree, link->tosock, link->tonode, ntree, sock, gnode); */
+        }
       }
     }
   }
diff --git a/source/blender/nodes/shader/node_shader_tree.c b/source/blender/nodes/shader/node_shader_tree.c
index 92266600612..cb73931a381 100644
--- a/source/blender/nodes/shader/node_shader_tree.c
+++ b/source/blender/nodes/shader/node_shader_tree.c
@@ -441,6 +441,8 @@ static void flatten_group_do(bNodeTree *ntree, bNode *gnode)
         }
       }
     }
+    /* Also iterate over the new links to cover passthrough links. */
+    glinks_last = ntree->links.last;
     /* output links */
     for (tlink = ntree->links.first; tlink != glinks_first->next; tlink = tlink->next) {
       if (tlink->fromnode == gnode) {



More information about the Bf-blender-cvs mailing list