[Bf-blender-cvs] [ba4b7b43195] master: Fix T94162: incorrect handling when there are multiple group outputs

Jacques Lucke noreply at git.blender.org
Fri Dec 24 12:34:25 CET 2021


Commit: ba4b7b43195c17436beaba95956087be4fb746a9
Author: Jacques Lucke
Date:   Fri Dec 24 12:34:04 2021 +0100
Branches: master
https://developer.blender.org/rBba4b7b43195c17436beaba95956087be4fb746a9

Fix T94162: incorrect handling when there are multiple group outputs

Typically a node group should only have a single Group Output node.
However, currently Blender already supports having multiple group outputs,
one of which is active. This wasn't handled correctly by geometry nodes.

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

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

M	source/blender/nodes/NOD_node_tree_ref.hh
M	source/blender/nodes/intern/derived_node_tree.cc
M	source/blender/nodes/intern/node_tree_ref.cc

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

diff --git a/source/blender/nodes/NOD_node_tree_ref.hh b/source/blender/nodes/NOD_node_tree_ref.hh
index 65789069231..ebbec20a139 100644
--- a/source/blender/nodes/NOD_node_tree_ref.hh
+++ b/source/blender/nodes/NOD_node_tree_ref.hh
@@ -262,6 +262,7 @@ class NodeTreeRef : NonCopyable, NonMovable {
   Vector<LinkRef *> links_;
   MultiValueMap<const bNodeType *, NodeRef *> nodes_by_type_;
   Vector<std::unique_ptr<SocketIndexByIdentifierMap>> owned_identifier_maps_;
+  const NodeRef *group_output_node_ = nullptr;
 
  public:
   NodeTreeRef(bNodeTree *btree);
@@ -279,6 +280,11 @@ class NodeTreeRef : NonCopyable, NonMovable {
 
   const NodeRef *find_node(const bNode &bnode) const;
 
+  /**
+   * This is the active group output node if there are multiple.
+   */
+  const NodeRef *group_output_node() const;
+
   /**
    * \return True when there is a link cycle. Unavailable sockets are ignored.
    */
@@ -759,6 +765,11 @@ inline Span<const LinkRef *> NodeTreeRef::links() const
   return links_;
 }
 
+inline const NodeRef *NodeTreeRef::group_output_node() const
+{
+  return group_output_node_;
+}
+
 inline bNodeTree *NodeTreeRef::btree() const
 {
   return btree_;
diff --git a/source/blender/nodes/intern/derived_node_tree.cc b/source/blender/nodes/intern/derived_node_tree.cc
index dc223f07a26..449c6598307 100644
--- a/source/blender/nodes/intern/derived_node_tree.cc
+++ b/source/blender/nodes/intern/derived_node_tree.cc
@@ -270,6 +270,9 @@ void DOutputSocket::foreach_target_socket(ForeachTargetSocketFn target_fn,
       }
     }
     else if (linked_node->is_group_output_node()) {
+      if (linked_node.node_ref() != context_->tree().group_output_node()) {
+        continue;
+      }
       if (context_->is_root()) {
         /* This is a group output in the root node group. */
         path_info.sockets.append(linked_socket);
diff --git a/source/blender/nodes/intern/node_tree_ref.cc b/source/blender/nodes/intern/node_tree_ref.cc
index ffe0edb9762..bc78533d45c 100644
--- a/source/blender/nodes/intern/node_tree_ref.cc
+++ b/source/blender/nodes/intern/node_tree_ref.cc
@@ -117,6 +117,22 @@ NodeTreeRef::NodeTreeRef(bNodeTree *btree) : btree_(btree)
     const bNodeType *nodetype = node->bnode_->typeinfo;
     nodes_by_type_.add(nodetype, node);
   }
+
+  const Span<const NodeRef *> group_output_nodes = this->nodes_by_type("NodeGroupOutput");
+  if (group_output_nodes.is_empty()) {
+    group_output_node_ = nullptr;
+  }
+  else if (group_output_nodes.size() == 1) {
+    group_output_node_ = group_output_nodes.first();
+  }
+  else {
+    for (const NodeRef *group_output : group_output_nodes) {
+      if (group_output->bnode_->flag & NODE_DO_OUTPUT) {
+        group_output_node_ = group_output;
+        break;
+      }
+    }
+  }
 }
 
 NodeTreeRef::~NodeTreeRef()



More information about the Bf-blender-cvs mailing list