Blender V5.0
geometry_nodes_closure.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2025 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#include "BKE_node_runtime.hh"
6
9
10namespace blender::nodes {
11
12std::optional<int> ClosureSignature::find_input_index(const StringRef key) const
13{
14 for (const int i : this->inputs.index_range()) {
15 const Item &item = this->inputs[i];
16 if (item.key == key) {
17 return i;
18 }
19 }
20 return std::nullopt;
21}
22
23std::optional<int> ClosureSignature::find_output_index(const StringRef key) const
24{
25 for (const int i : this->outputs.index_range()) {
26 const Item &item = this->outputs[i];
27 if (item.key == key) {
28 return i;
29 }
30 }
31 return std::nullopt;
32}
33
35{
36 for (const Item &item : this->inputs) {
37 const_cast<Item &>(item).structure_type = NODE_INTERFACE_SOCKET_STRUCTURE_TYPE_AUTO;
38 }
39 for (const Item &item : this->outputs) {
40 const_cast<Item &>(item).structure_type = NODE_INTERFACE_SOCKET_STRUCTURE_TYPE_AUTO;
41 }
42}
43
45{
46 return a.inputs.as_span() == b.inputs.as_span() && a.outputs.as_span() == b.outputs.as_span();
47}
48
50{
51 return !(a == b);
52}
53
55 const bool allow_auto_structure_type)
56{
57 BLI_assert(node.is_type("NodeClosureOutput"));
58 const bNodeTree &tree = node.owner_tree();
59 const bNode *input_node =
61 const auto &storage = *static_cast<const NodeClosureOutput *>(node.storage);
63 if (input_node) {
64 for (const int i : IndexRange(storage.input_items.items_num)) {
65 const NodeClosureInputItem &item = storage.input_items.items[i];
66 const bNodeSocket &socket = input_node->output_socket(i);
68 {
69 const NodeSocketInterfaceStructureType structure_type =
71 socket,
73 allow_auto_structure_type);
74 signature.inputs.add({item.name, stype, structure_type});
75 }
76 }
77 }
78 for (const int i : IndexRange(storage.output_items.items_num)) {
79 const NodeClosureOutputItem &item = storage.output_items.items[i];
80 const bNodeSocket &socket = node.input_socket(i);
82 const NodeSocketInterfaceStructureType structure_type =
84 socket,
86 allow_auto_structure_type);
87 signature.outputs.add({item.name, stype, structure_type});
88 }
89 }
90 return signature;
91}
92
94 const bool allow_auto_structure_type)
95{
96 BLI_assert(node.is_type("NodeEvaluateClosure"));
97 const auto &storage = *static_cast<const NodeEvaluateClosure *>(node.storage);
99 for (const int i : IndexRange(storage.input_items.items_num)) {
100 const NodeEvaluateClosureInputItem &item = storage.input_items.items[i];
101 const bNodeSocket &socket = node.input_socket(i + 1);
103 const NodeSocketInterfaceStructureType structure_type =
105 socket,
107 allow_auto_structure_type);
108 signature.inputs.add({item.name, stype, structure_type});
109 }
110 }
111 for (const int i : IndexRange(storage.output_items.items_num)) {
112 const NodeEvaluateClosureOutputItem &item = storage.output_items.items[i];
113 const bNodeSocket &socket = node.output_socket(i);
115 const NodeSocketInterfaceStructureType structure_type =
117 socket,
119 allow_auto_structure_type);
120 signature.outputs.add({item.name, stype, structure_type});
121 }
122 }
123 return signature;
124}
125
127{
128 for (const Item &item : this->items) {
129 if (item.define_signature) {
130 return true;
131 }
132 }
133 return false;
134}
135
136std::optional<ClosureSignature> LinkedClosureSignatures::get_merged_signature() const
137{
138 ClosureSignature signature;
139 for (const Item &src_signature : this->items) {
140 for (const ClosureSignature::Item &item : src_signature.signature.inputs) {
141 if (!signature.inputs.add(item)) {
142 const ClosureSignature::Item &existing_item = *signature.inputs.lookup_key_ptr_as(
143 item.key);
144 if (existing_item.type->type != item.type->type) {
145 return std::nullopt;
146 }
147 if (existing_item.structure_type != item.structure_type) {
148 const_cast<ClosureSignature::Item &>(existing_item).structure_type =
150 }
151 }
152 }
153 for (const ClosureSignature::Item &item : src_signature.signature.outputs) {
154 if (!signature.outputs.add(item)) {
155 const ClosureSignature::Item &existing_item = *signature.outputs.lookup_key_ptr_as(
156 item.key);
157 if (existing_item.type->type != item.type->type) {
158 return std::nullopt;
159 }
160 if (existing_item.structure_type != item.structure_type) {
161 const_cast<ClosureSignature::Item &>(existing_item).structure_type =
163 }
164 }
165 }
166 }
167 return signature;
168}
169
170} // namespace blender::nodes
#define BLI_assert(a)
Definition BLI_assert.h:46
@ NODE_INTERFACE_SOCKET_STRUCTURE_TYPE_DYNAMIC
@ NODE_INTERFACE_SOCKET_STRUCTURE_TYPE_AUTO
const bNode * get_corresponding_input(const bNodeTree &tree, const bNode &output_bnode) const
std::optional< int > find_output_index(StringRef key) const
CustomIDVectorSet< Item, ItemKeyGetter > inputs
std::optional< int > find_input_index(StringRef key) const
CustomIDVectorSet< Item, ItemKeyGetter > outputs
static ClosureSignature from_evaluate_closure_node(const bNode &node, bool allow_auto_structure_type)
static ClosureSignature from_closure_output_node(const bNode &node, bool allow_auto_structure_type)
KDTree_3d * tree
const bNodeZoneType * zone_type_by_node_type(const int node_type)
bNodeSocketType * node_socket_type_find_static(int type, int subtype=0)
Definition node.cc:2471
bool operator==(const BokehKernelKey &a, const BokehKernelKey &b)
bool operator!=(const Domain &a, const Domain &b)
Definition domain.cc:51
NodeSocketInterfaceStructureType get_structure_type_for_bundle_signature(const bNodeSocket &socket, const NodeSocketInterfaceStructureType stored_structure_type, const bool allow_auto_structure_type)
int16_t type_legacy
void * storage
Defines a socket type.
Definition BKE_node.hh:158
eNodeSocketDatatype type
Definition BKE_node.hh:193
std::optional< ClosureSignature > get_merged_signature() const
i
Definition text_draw.cc:230