Blender V4.5
node_geo_evaluate_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 "UI_interface.hh"
6#include "UI_resources.hh"
7
8#include "NOD_geo_closure.hh"
12
13#include "BLO_read_write.hh"
14
15#include "node_geometry_util.hh"
16
18
20
22{
23 b.add_input<decl::Closure>("Closure");
24
25 const bNode *node = b.node_or_null();
26 if (node) {
27 const auto &storage = node_storage(*node);
28 for (const int i : IndexRange(storage.input_items.items_num)) {
29 const NodeGeometryEvaluateClosureInputItem &item = storage.input_items.items[i];
30 const eNodeSocketDatatype socket_type = eNodeSocketDatatype(item.socket_type);
32 item);
33 b.add_input(socket_type, item.name, identifier);
34 }
35 for (const int i : IndexRange(storage.output_items.items_num)) {
36 const NodeGeometryEvaluateClosureOutputItem &item = storage.output_items.items[i];
37 const eNodeSocketDatatype socket_type = eNodeSocketDatatype(item.socket_type);
38 const std::string identifier =
40 b.add_output(socket_type, item.name, identifier).propagate_all().reference_pass_all();
41 }
42 }
43
44 b.add_input<decl::Extend>("", "__extend__");
45 b.add_output<decl::Extend>("", "__extend__");
46}
47
48static void node_init(bNodeTree * /*tree*/, bNode *node)
49{
50 auto *storage = MEM_callocN<NodeGeometryEvaluateClosure>(__func__);
51 node->storage = storage;
52}
53
54static void node_copy_storage(bNodeTree * /*tree*/, bNode *dst_node, const bNode *src_node)
55{
56 const NodeGeometryEvaluateClosure &src_storage = node_storage(*src_node);
57 auto *dst_storage = MEM_dupallocN<NodeGeometryEvaluateClosure>(__func__, src_storage);
58 dst_node->storage = dst_storage;
59
62}
63
70
71static bool node_insert_link(bNodeTree *ntree, bNode *node, bNodeLink *link)
72{
73 if (link->tonode == node) {
75 *ntree, *node, *node, *link);
76 }
78 *ntree, *node, *node, *link);
79}
80
82{
83 bNodeTree &tree = *reinterpret_cast<bNodeTree *>(ptr->owner_id);
84 bNode &node = *static_cast<bNode *>(ptr->data);
85
86 if (uiLayout *panel = layout->panel(C, "input_items", false, IFACE_("Input Items"))) {
88 C, panel, tree, node);
90 tree, node, [&](PointerRNA *item_ptr) {
91 panel->prop(item_ptr, "socket_type", UI_ITEM_NONE, std::nullopt, ICON_NONE);
92 });
93 }
94 if (uiLayout *panel = layout->panel(C, "output_items", false, IFACE_("Output Items"))) {
96 C, panel, tree, node);
98 tree, node, [&](PointerRNA *item_ptr) {
99 panel->prop(item_ptr, "socket_type", UI_ITEM_NONE, std::nullopt, ICON_NONE);
100 });
101 }
102}
103
105 const bNode & /*node*/,
106 const bNodeSocket &output_socket)
107{
109}
110
116
122
128
129static void node_register()
130{
131 static blender::bke::bNodeType ntype;
132
133 geo_node_type_base(&ntype, "GeometryNodeEvaluateClosure", GEO_NODE_EVALUATE_CLOSURE);
134 ntype.ui_name = "Evaluate Closure";
136 ntype.declare = node_declare;
137 ntype.initfunc = node_init;
145 ntype, "NodeGeometryEvaluateClosure", node_free_storage, node_copy_storage);
147}
149
150} // namespace blender::nodes::node_geo_evaluate_closure_cc
151
152namespace blender::nodes {
153
155 &RNA_NodeGeometryEvaluateClosureInputItem;
156
158{
159 BLO_write_string(writer, item.name);
160}
161
166
168 &RNA_NodeGeometryEvaluateClosureOutputItem;
169
174
179
181{
182 const bNode &node = output_socket.owner_node();
183 const bNodeTree &tree = node.owner_tree();
184 BLI_assert(node.is_type("GeometryNodeEvaluateClosure"));
185 const auto &storage = *static_cast<const NodeGeometryEvaluateClosure *>(node.storage);
186 if (output_socket.index() >= storage.output_items.items_num) {
187 return nullptr;
188 }
189 const NodeGeometryEvaluateClosureOutputItem &output_item =
190 storage.output_items.items[output_socket.index()];
191 const SocketInterfaceKey output_key{output_item.name};
192 for (const int i : IndexRange(storage.input_items.items_num)) {
193 const NodeGeometryEvaluateClosureInputItem &input_item = storage.input_items.items[i];
194 const SocketInterfaceKey input_key{input_item.name};
195 if (output_key.matches(input_key)) {
196 if (!tree.typeinfo->validate_link ||
197 tree.typeinfo->validate_link(eNodeSocketDatatype(input_item.socket_type),
198 eNodeSocketDatatype(output_item.socket_type)))
199 {
200 return &node.input_socket(i + 1);
201 }
202 }
203 }
204 return nullptr;
205}
206
207} // namespace blender::nodes
#define NODE_CLASS_CONVERTER
Definition BKE_node.hh:439
#define NODE_STORAGE_FUNCS(StorageT)
Definition BKE_node.hh:1215
#define GEO_NODE_EVALUATE_CLOSURE
#define BLI_assert(a)
Definition BLI_assert.h:46
void BLO_read_string(BlendDataReader *reader, char **ptr_p)
Definition readfile.cc:5351
void BLO_write_string(BlendWriter *writer, const char *data_ptr)
#define IFACE_(msgid)
eNodeSocketDatatype
#define NOD_REGISTER_NODE(REGISTER_FUNC)
#define C
Definition RandGen.cpp:29
#define UI_ITEM_NONE
bool matches(const SocketInterfaceKey &other) const
KDTree_3d * tree
void * MEM_callocN(size_t len, const char *str)
Definition mallocn.cc:118
void * MEM_dupallocN(const void *vmemh)
Definition mallocn.cc:143
void MEM_freeN(void *vmemh)
Definition mallocn.cc:113
void node_register_type(bNodeType &ntype)
Definition node.cc:2748
void node_type_storage(bNodeType &ntype, std::optional< StringRefNull > storagename, void(*freefunc)(bNode *node), void(*copyfunc)(bNodeTree *dest_ntree, bNode *dest_node, const bNode *src_node))
Definition node.cc:5603
static void node_declare(NodeDeclarationBuilder &b)
static void node_blend_read(bNodeTree &, bNode &node, BlendDataReader &reader)
static const bNodeSocket * node_internally_linked_input(const bNodeTree &, const bNode &, const bNodeSocket &output_socket)
static bool node_insert_link(bNodeTree *ntree, bNode *node, bNodeLink *link)
static void node_copy_storage(bNodeTree *, bNode *dst_node, const bNode *src_node)
static void node_init(bNodeTree *, bNode *node)
static void node_layout_ex(uiLayout *layout, bContext *C, PointerRNA *ptr)
static void node_blend_write(const bNodeTree &, const bNode &node, BlendWriter &writer)
static void draw_items_list_with_operators(const bContext *C, uiLayout *layout, const bNodeTree &tree, const bNode &node)
static void draw_active_item_props(const bNodeTree &tree, const bNode &node, const FunctionRef< void(PointerRNA *item_ptr)> draw_item)
void blend_write(BlendWriter *writer, const bNode &node)
void blend_read_data(BlendDataReader *reader, bNode &node)
void copy_array(const bNode &src_node, bNode &dst_node)
bool try_add_item_via_any_extend_socket(bNodeTree &ntree, bNode &extend_node, bNode &storage_node, bNodeLink &link, const std::optional< StringRef > socket_identifier=std::nullopt)
const bNodeSocket * evaluate_closure_node_internally_linked_input(const bNodeSocket &output_socket)
void geo_node_type_base(blender::bke::bNodeType *ntype, std::string idname, const std::optional< int16_t > legacy_type)
void * storage
Defines a node type.
Definition BKE_node.hh:226
NodeInternallyLinkedInputFunction internally_linked_input
Definition BKE_node.hh:377
NodeBlendWriteFunction blend_write_storage_content
Definition BKE_node.hh:383
NodeBlendDataReadFunction blend_data_read_storage_content
Definition BKE_node.hh:384
void(* initfunc)(bNodeTree *ntree, bNode *node)
Definition BKE_node.hh:277
void(* draw_buttons_ex)(uiLayout *, bContext *C, PointerRNA *ptr)
Definition BKE_node.hh:249
bool(* insert_link)(bNodeTree *ntree, bNode *node, bNodeLink *link)
Definition BKE_node.hh:321
NodeDeclareFunction declare
Definition BKE_node.hh:355
void(* register_operators)()
Definition BKE_node.hh:410
NodeGeometryEvaluateClosureInputItem ItemT
static void blend_read_data_item(BlendDataReader *reader, ItemT &item)
static std::string socket_identifier_for_item(const ItemT &item)
static void blend_write_item(BlendWriter *writer, const ItemT &item)
static void blend_read_data_item(BlendDataReader *reader, ItemT &item)
NodeGeometryEvaluateClosureOutputItem ItemT
static void blend_write_item(BlendWriter *writer, const ItemT &item)
static std::string socket_identifier_for_item(const ItemT &item)
PanelLayout panel(const bContext *C, blender::StringRef idname, bool default_closed)
i
Definition text_draw.cc:230
PointerRNA * ptr
Definition wm_files.cc:4227