Blender V5.0
NOD_geo_closure.hh
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#pragma once
6
7#include "DNA_node_types.h"
8
9#include "NOD_socket_items.hh"
10
11namespace blender::nodes {
12
14 const int ntree_type)
15{
16 switch (ntree_type) {
17 case NTREE_GEOMETRY:
18 return ELEM(socket_type,
34 case NTREE_SHADER:
35 return ELEM(socket_type,
42 SOCK_INT);
43 default:
44 return false;
45 }
46}
47
51 static int node_type;
52 static constexpr StringRefNull node_idname = "NodeClosureOutput";
53 static constexpr bool has_type = true;
54 static constexpr bool has_name = true;
56 static constexpr StringRefNull add_item = "NODE_OT_closure_input_item_add";
57 static constexpr StringRefNull remove_item = "NODE_OT_closure_input_item_remove";
58 static constexpr StringRefNull move_item = "NODE_OT_closure_input_item_move";
59 };
60 struct ui_idnames {
61 static constexpr StringRefNull list = "DATA_UL_closure_input_items";
62 };
63 struct rna_names {
64 static constexpr StringRefNull items = "input_items";
65 static constexpr StringRefNull active_index = "active_input_index";
66 };
67
69 {
70 auto *storage = static_cast<NodeClosureOutput *>(node.storage);
71 return {&storage->input_items.items,
72 &storage->input_items.items_num,
73 &storage->input_items.active_index};
74 }
75
76 static void copy_item(const ItemT &src, ItemT &dst)
77 {
78 dst = src;
79 dst.name = BLI_strdup_null(dst.name);
80 }
81
82 static void destruct_item(ItemT *item)
83 {
84 MEM_SAFE_FREE(item->name);
85 }
86
87 static void blend_write_item(BlendWriter *writer, const ItemT &item);
88 static void blend_read_data_item(BlendDataReader *reader, ItemT &item);
89
91 {
93 }
94
95 static char **get_name(ItemT &item)
96 {
97 return &item.name;
98 }
99
100 static bool supports_socket_type(const eNodeSocketDatatype socket_type, const int ntree_type)
101 {
102 return socket_type_supported_in_closure(socket_type, ntree_type);
103 }
104
106 ItemT &item,
107 const eNodeSocketDatatype socket_type,
108 const char *name)
109 {
110 auto *storage = static_cast<NodeClosureOutput *>(node.storage);
111 item.socket_type = socket_type;
112 item.identifier = storage->input_items.next_identifier++;
114 }
115
116 static std::string socket_identifier_for_item(const ItemT &item)
117 {
118 return "Item_" + std::to_string(item.identifier);
119 }
120};
121
125 static int node_type;
126 static constexpr StringRefNull node_idname = "NodeClosureOutput";
127 static constexpr bool has_type = true;
128 static constexpr bool has_name = true;
130 static constexpr StringRefNull add_item = "NODE_OT_closure_output_item_add";
131 static constexpr StringRefNull remove_item = "NODE_OT_closure_output_item_remove";
132 static constexpr StringRefNull move_item = "NODE_OT_closure_output_item_move";
133 };
134 struct ui_idnames {
135 static constexpr StringRefNull list = "DATA_UL_closure_output_items";
136 };
137 struct rna_names {
138 static constexpr StringRefNull items = "output_items";
139 static constexpr StringRefNull active_index = "active_output_index";
140 };
141
143 {
144 auto *storage = static_cast<NodeClosureOutput *>(node.storage);
145 return {&storage->output_items.items,
146 &storage->output_items.items_num,
147 &storage->output_items.active_index};
148 }
149
150 static void copy_item(const ItemT &src, ItemT &dst)
151 {
152 dst = src;
153 dst.name = BLI_strdup_null(dst.name);
154 }
155
156 static void destruct_item(ItemT *item)
157 {
158 MEM_SAFE_FREE(item->name);
159 }
160
161 static void blend_write_item(BlendWriter *writer, const ItemT &item);
162 static void blend_read_data_item(BlendDataReader *reader, ItemT &item);
163
165 {
166 return eNodeSocketDatatype(item.socket_type);
167 }
168
169 static char **get_name(ItemT &item)
170 {
171 return &item.name;
172 }
173
174 static bool supports_socket_type(const eNodeSocketDatatype socket_type, const int ntree_type)
175 {
176 return socket_type_supported_in_closure(socket_type, ntree_type);
177 }
178
180 ItemT &item,
181 const eNodeSocketDatatype socket_type,
182 const char *name)
183 {
184 auto *storage = static_cast<NodeClosureOutput *>(node.storage);
185 item.socket_type = socket_type;
186 item.identifier = storage->output_items.next_identifier++;
188 }
189
190 static std::string socket_identifier_for_item(const ItemT &item)
191 {
192 return "Item_" + std::to_string(item.identifier);
193 }
194};
195
199 static int node_type;
200 static constexpr StringRefNull node_idname = "NodeEvaluateClosure";
201 static constexpr bool has_type = true;
202 static constexpr bool has_name = true;
204 static constexpr StringRefNull add_item = "NODE_OT_evaluate_closure_input_item_add";
205 static constexpr StringRefNull remove_item = "NODE_OT_evaluate_closure_input_item_remove";
206 static constexpr StringRefNull move_item = "NODE_OT_evaluate_closure_input_item_move";
207 };
208 struct ui_idnames {
209 static constexpr StringRefNull list = "DATA_UL_evaluate_closure_input_items";
210 };
211 struct rna_names {
212 static constexpr StringRefNull items = "input_items";
213 static constexpr StringRefNull active_index = "active_input_index";
214 };
215
217 {
218 auto *storage = static_cast<NodeEvaluateClosure *>(node.storage);
219 return {&storage->input_items.items,
220 &storage->input_items.items_num,
221 &storage->input_items.active_index};
222 }
223
224 static void copy_item(const ItemT &src, ItemT &dst)
225 {
226 dst = src;
227 dst.name = BLI_strdup_null(dst.name);
228 }
229
230 static void destruct_item(ItemT *item)
231 {
232 MEM_SAFE_FREE(item->name);
233 }
234
235 static void blend_write_item(BlendWriter *writer, const ItemT &item);
236 static void blend_read_data_item(BlendDataReader *reader, ItemT &item);
237
239 {
240 return eNodeSocketDatatype(item.socket_type);
241 }
242
243 static char **get_name(ItemT &item)
244 {
245 return &item.name;
246 }
247
248 static bool supports_socket_type(const eNodeSocketDatatype socket_type, const int ntree_type)
249 {
250 return socket_type_supported_in_closure(socket_type, ntree_type);
251 }
252
254 ItemT &item,
255 const eNodeSocketDatatype socket_type,
256 const char *name)
257 {
258 auto *storage = static_cast<NodeEvaluateClosure *>(node.storage);
259 item.socket_type = socket_type;
260 item.identifier = storage->input_items.next_identifier++;
262 node, item, name);
263 }
264
265 static std::string socket_identifier_for_item(const ItemT &item)
266 {
267 return "Item_" + std::to_string(item.identifier);
268 }
269};
270
274 static int node_type;
275 static constexpr StringRefNull node_idname = "NodeEvaluateClosure";
276 static constexpr bool has_type = true;
277 static constexpr bool has_name = true;
279 static constexpr StringRefNull add_item = "NODE_OT_evaluate_closure_output_item_add";
280 static constexpr StringRefNull remove_item = "NODE_OT_evaluate_closure_output_item_remove";
281 static constexpr StringRefNull move_item = "NODE_OT_evaluate_closure_output_item_move";
282 };
283 struct ui_idnames {
284 static constexpr StringRefNull list = "DATA_UL_evaluate_closure_output_items";
285 };
286 struct rna_names {
287 static constexpr StringRefNull items = "output_items";
288 static constexpr StringRefNull active_index = "active_output_index";
289 };
290
292 {
293 auto *storage = static_cast<NodeEvaluateClosure *>(node.storage);
294 return {&storage->output_items.items,
295 &storage->output_items.items_num,
296 &storage->output_items.active_index};
297 }
298
299 static void copy_item(const ItemT &src, ItemT &dst)
300 {
301 dst = src;
302 dst.name = BLI_strdup_null(dst.name);
303 }
304
305 static void destruct_item(ItemT *item)
306 {
307 MEM_SAFE_FREE(item->name);
308 }
309
310 static void blend_write_item(BlendWriter *writer, const ItemT &item);
311 static void blend_read_data_item(BlendDataReader *reader, ItemT &item);
312
314 {
315 return eNodeSocketDatatype(item.socket_type);
316 }
317
318 static char **get_name(ItemT &item)
319 {
320 return &item.name;
321 }
322
323 static bool supports_socket_type(const eNodeSocketDatatype socket_type, const int ntree_type)
324 {
325 return socket_type_supported_in_closure(socket_type, ntree_type);
326 }
327
329 ItemT &item,
330 const eNodeSocketDatatype socket_type,
331 const char *name)
332 {
333 auto *storage = static_cast<NodeEvaluateClosure *>(node.storage);
334 item.socket_type = socket_type;
335 item.identifier = storage->output_items.next_identifier++;
337 node, item, name);
338 }
339
340 static std::string socket_identifier_for_item(const ItemT &item)
341 {
342 return "Item_" + std::to_string(item.identifier);
343 }
344};
345
351
352} // namespace blender::nodes
char * BLI_strdup_null(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_MALLOC
Definition string.cc:46
#define ELEM(...)
@ NTREE_SHADER
@ NTREE_GEOMETRY
eNodeSocketDatatype
@ SOCK_INT
@ SOCK_VECTOR
@ SOCK_CLOSURE
@ SOCK_BOOLEAN
@ SOCK_MATERIAL
@ SOCK_SHADER
@ SOCK_MATRIX
@ SOCK_FLOAT
@ SOCK_IMAGE
@ SOCK_COLLECTION
@ SOCK_BUNDLE
@ SOCK_GEOMETRY
@ SOCK_ROTATION
@ SOCK_OBJECT
@ SOCK_STRING
@ SOCK_RGBA
#define MEM_SAFE_FREE(v)
void set_item_name_and_make_unique(bNode &node, typename Accessor::ItemT &item, const char *value)
const bNodeSocket * evaluate_closure_node_internally_linked_input(const bNodeSocket &output_socket)
bool socket_type_supported_in_closure(const eNodeSocketDatatype socket_type, const int ntree_type)
const char * name
void * storage
static void blend_read_data_item(BlendDataReader *reader, ItemT &item)
static void copy_item(const ItemT &src, ItemT &dst)
static socket_items::SocketItemsRef< ItemT > get_items_from_node(bNode &node)
static eNodeSocketDatatype get_socket_type(const ItemT &item)
static std::string socket_identifier_for_item(const ItemT &item)
static void init_with_socket_type_and_name(bNode &node, ItemT &item, const eNodeSocketDatatype socket_type, const char *name)
static void blend_write_item(BlendWriter *writer, const ItemT &item)
static bool supports_socket_type(const eNodeSocketDatatype socket_type, const int ntree_type)
static constexpr StringRefNull node_idname
static socket_items::SocketItemsRef< ItemT > get_items_from_node(bNode &node)
static void init_with_socket_type_and_name(bNode &node, ItemT &item, const eNodeSocketDatatype socket_type, const char *name)
static void copy_item(const ItemT &src, ItemT &dst)
static void blend_write_item(BlendWriter *writer, const ItemT &item)
static std::string socket_identifier_for_item(const ItemT &item)
static eNodeSocketDatatype get_socket_type(const ItemT &item)
static void blend_read_data_item(BlendDataReader *reader, ItemT &item)
static constexpr StringRefNull node_idname
static bool supports_socket_type(const eNodeSocketDatatype socket_type, const int ntree_type)
static eNodeSocketDatatype get_socket_type(const ItemT &item)
static void copy_item(const ItemT &src, ItemT &dst)
static socket_items::SocketItemsRef< ItemT > get_items_from_node(bNode &node)
static void init_with_socket_type_and_name(bNode &node, ItemT &item, const eNodeSocketDatatype socket_type, const char *name)
static void blend_read_data_item(BlendDataReader *reader, ItemT &item)
static bool supports_socket_type(const eNodeSocketDatatype socket_type, const int ntree_type)
static std::string socket_identifier_for_item(const ItemT &item)
static void blend_write_item(BlendWriter *writer, const ItemT &item)
static void copy_item(const ItemT &src, ItemT &dst)
static void blend_read_data_item(BlendDataReader *reader, ItemT &item)
static void blend_write_item(BlendWriter *writer, const ItemT &item)
static socket_items::SocketItemsRef< ItemT > get_items_from_node(bNode &node)
static std::string socket_identifier_for_item(const ItemT &item)
static void init_with_socket_type_and_name(bNode &node, ItemT &item, const eNodeSocketDatatype socket_type, const char *name)
static bool supports_socket_type(const eNodeSocketDatatype socket_type, const int ntree_type)
static eNodeSocketDatatype get_socket_type(const ItemT &item)