[Bf-blender-cvs] [ea7570989d2] master: Cleanup: add utility method to get group input nodes

Jacques Lucke noreply at git.blender.org
Tue Dec 13 17:26:05 CET 2022


Commit: ea7570989d2abef4208dc41ba118859244b1db03
Author: Jacques Lucke
Date:   Tue Dec 13 17:25:37 2022 +0100
Branches: master
https://developer.blender.org/rBea7570989d2abef4208dc41ba118859244b1db03

Cleanup: add utility method to get group input nodes

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

M	source/blender/blenkernel/BKE_node_runtime.hh
M	source/blender/blenkernel/intern/node_tree_field_inferencing.cc
M	source/blender/makesdna/DNA_node_types.h
M	source/blender/modifiers/intern/MOD_nodes.cc
M	source/blender/nodes/intern/derived_node_tree.cc

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

diff --git a/source/blender/blenkernel/BKE_node_runtime.hh b/source/blender/blenkernel/BKE_node_runtime.hh
index 979c7630865..6a00e70cb5b 100644
--- a/source/blender/blenkernel/BKE_node_runtime.hh
+++ b/source/blender/blenkernel/BKE_node_runtime.hh
@@ -421,6 +421,11 @@ inline const bNode *bNodeTree::group_output_node() const
   return this->runtime->group_output_node;
 }
 
+inline blender::Span<const bNode *> bNodeTree::group_input_nodes() const
+{
+  return this->nodes_by_type("NodeGroupInput");
+}
+
 inline blender::Span<const bNodeSocket *> bNodeTree::all_input_sockets() const
 {
   BLI_assert(blender::bke::node_tree_runtime::topology_cache_is_available(*this));
diff --git a/source/blender/blenkernel/intern/node_tree_field_inferencing.cc b/source/blender/blenkernel/intern/node_tree_field_inferencing.cc
index 82e425dfbb9..88fd3636633 100644
--- a/source/blender/blenkernel/intern/node_tree_field_inferencing.cc
+++ b/source/blender/blenkernel/intern/node_tree_field_inferencing.cc
@@ -340,7 +340,7 @@ static void determine_group_input_states(
   }
   /* Check if group inputs are required to be single values, because they are (indirectly)
    * connected to some socket that does not support fields. */
-  for (const bNode *node : tree.nodes_by_type("NodeGroupInput")) {
+  for (const bNode *node : tree.group_input_nodes()) {
     for (const bNodeSocket *output_socket : node->output_sockets().drop_back(1)) {
       SocketFieldState &state = field_state_by_socket_id[output_socket->index_in_tree()];
       if (state.requires_single) {
@@ -349,7 +349,7 @@ static void determine_group_input_states(
     }
   }
   /* If an input does not support fields, this should be reflected in all Group Input nodes. */
-  for (const bNode *node : tree.nodes_by_type("NodeGroupInput")) {
+  for (const bNode *node : tree.group_input_nodes()) {
     for (const bNodeSocket *output_socket : node->output_sockets().drop_back(1)) {
       SocketFieldState &state = field_state_by_socket_id[output_socket->index_in_tree()];
       const bool supports_field = new_inferencing_interface.inputs[output_socket->index()] !=
diff --git a/source/blender/makesdna/DNA_node_types.h b/source/blender/makesdna/DNA_node_types.h
index 424a4c17e82..6313791bd3c 100644
--- a/source/blender/makesdna/DNA_node_types.h
+++ b/source/blender/makesdna/DNA_node_types.h
@@ -634,6 +634,8 @@ typedef struct bNodeTree {
   bool has_undefined_nodes_or_sockets() const;
   /** Get the active group output node. */
   const bNode *group_output_node() const;
+  /** Get all input nodes of the node group. */
+  blender::Span<const bNode *> group_input_nodes() const;
 #endif
 } bNodeTree;
 
diff --git a/source/blender/modifiers/intern/MOD_nodes.cc b/source/blender/modifiers/intern/MOD_nodes.cc
index a8e5e2ab0a2..f5ede42b0ad 100644
--- a/source/blender/modifiers/intern/MOD_nodes.cc
+++ b/source/blender/modifiers/intern/MOD_nodes.cc
@@ -1401,7 +1401,7 @@ static void attribute_search_update_fn(
     }
   }
   else {
-    for (const bNode *node : nmd->node_group->nodes_by_type("NodeGroupInput")) {
+    for (const bNode *node : nmd->node_group->group_input_nodes()) {
       for (const bNodeSocket *socket : node->output_sockets()) {
         if (socket->type == SOCK_GEOMETRY) {
           sockets_to_check.append(socket);
diff --git a/source/blender/nodes/intern/derived_node_tree.cc b/source/blender/nodes/intern/derived_node_tree.cc
index 50fbf791536..ece60ffe4ab 100644
--- a/source/blender/nodes/intern/derived_node_tree.cc
+++ b/source/blender/nodes/intern/derived_node_tree.cc
@@ -115,7 +115,7 @@ Vector<DOutputSocket> DInputSocket::get_corresponding_group_input_sockets() cons
   BLI_assert(child_context != nullptr);
 
   const bNodeTree &child_tree = child_context->btree();
-  Span<const bNode *> group_input_nodes = child_tree.nodes_by_type("NodeGroupInput");
+  Span<const bNode *> group_input_nodes = child_tree.group_input_nodes();
   const int socket_index = bsocket_->index();
   Vector<DOutputSocket> sockets;
   for (const bNode *group_input_node : group_input_nodes) {



More information about the Bf-blender-cvs mailing list