Blender V4.5
node_geo_combine_bundle.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
6
7#include "NOD_geo_bundle.hh"
11
12#include "BLO_read_write.hh"
13
15
16#include "UI_interface.hh"
17
19
21
23{
24 const bNodeTree *tree = b.tree_or_null();
25 const bNode *node = b.node_or_null();
26 if (tree && node) {
27 const NodeGeometryCombineBundle &storage = node_storage(*node);
28 for (const int i : IndexRange(storage.items_num)) {
29 const NodeGeometryCombineBundleItem &item = storage.items[i];
30 const eNodeSocketDatatype socket_type = eNodeSocketDatatype(item.socket_type);
31 const StringRef name = item.name ? item.name : "";
32 const std::string identifier = CombineBundleItemsAccessor::socket_identifier_for_item(item);
33 b.add_input(socket_type, name, identifier)
34 .socket_name_ptr(&tree->id, CombineBundleItemsAccessor::item_srna, &item, "name");
35 }
36 }
37 b.add_input<decl::Extend>("", "__extend__");
38 b.add_output<decl::Bundle>("Bundle").propagate_all().reference_pass_all();
39}
40
41static void node_init(bNodeTree * /*tree*/, bNode *node)
42{
43 auto *storage = MEM_callocN<NodeGeometryCombineBundle>(__func__);
44 node->storage = storage;
45}
46
47static void node_copy_storage(bNodeTree * /*dst_tree*/, bNode *dst_node, const bNode *src_node)
48{
49 const NodeGeometryCombineBundle &src_storage = node_storage(*src_node);
50 auto *dst_storage = MEM_dupallocN<NodeGeometryCombineBundle>(__func__, src_storage);
51 dst_node->storage = dst_storage;
52
54}
55
61
67
68static void node_layout_ex(uiLayout *layout, bContext *C, PointerRNA *node_ptr)
69{
70 bNodeTree &ntree = *reinterpret_cast<bNodeTree *>(node_ptr->owner_id);
71 bNode &node = *static_cast<bNode *>(node_ptr->data);
72
73 if (uiLayout *panel = layout->panel(C, "bundle_items", false, TIP_("Bundle Items"))) {
75 C, panel, ntree, node);
77 ntree, node, [&](PointerRNA *item_ptr) {
78 panel->prop(item_ptr, "socket_type", UI_ITEM_NONE, "Type", ICON_NONE);
79 });
80 }
81}
82
87
89{
90 if (!U.experimental.use_bundle_and_closure_nodes) {
91 params.set_default_remaining_outputs();
92 return;
93 }
94
95 const bNode &node = params.node();
96 const NodeGeometryCombineBundle &storage = node_storage(node);
97
98 BundlePtr bundle_ptr = Bundle::create();
99 BLI_assert(bundle_ptr->is_mutable());
100 Bundle &bundle = const_cast<Bundle &>(*bundle_ptr);
101
102 for (const int i : IndexRange(storage.items_num)) {
103 const NodeGeometryCombineBundleItem &item = storage.items[i];
105 if (!stype || !stype->geometry_nodes_cpp_type) {
106 continue;
107 }
108 const StringRef name = item.name;
109 if (name.is_empty()) {
110 continue;
111 }
112 void *input_ptr = params.low_level_lazy_function_params().try_get_input_data_ptr(i);
113 BLI_assert(input_ptr);
114 bundle.add(SocketInterfaceKey(name), *stype, input_ptr);
115 }
116
117 params.set_output("Bundle", std::move(bundle_ptr));
118}
119
120static void node_blend_write(const bNodeTree & /*tree*/, const bNode &node, BlendWriter &writer)
121{
123}
124
125static void node_blend_read(bNodeTree & /*tree*/, bNode &node, BlendDataReader &reader)
126{
128}
129
130static void node_register()
131{
132 static blender::bke::bNodeType ntype;
133
134 geo_node_type_base(&ntype, "GeometryNodeCombineBundle", GEO_NODE_COMBINE_BUNDLE);
135 ntype.ui_name = "Combine Bundle";
136 ntype.ui_description = "Combine multiple socket values into one.";
138 ntype.declare = node_declare;
139 ntype.initfunc = node_init;
146 bke::node_type_storage(ntype, "NodeGeometryCombineBundle", node_free_storage, node_copy_storage);
148}
150
151} // namespace blender::nodes::node_geo_combine_bundle_cc
152
153namespace blender::nodes {
154
155StructRNA *CombineBundleItemsAccessor::item_srna = &RNA_NodeGeometryCombineBundleItem;
156
158{
159 BLO_write_string(writer, item.name);
160}
161
166
167} // 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_COMBINE_BUNDLE
#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 TIP_(msgid)
eNodeSocketDatatype
#define NOD_REGISTER_NODE(REGISTER_FUNC)
#define C
Definition RandGen.cpp:29
#define UI_ITEM_NONE
#define U
constexpr bool is_empty() const
bool add(const SocketInterfaceKey &key, const bke::bNodeSocketType &type, const void *value)
KDTree_3d * tree
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
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
bNodeSocketType * node_socket_type_find_static(int type, int subtype=0)
Definition node.cc:2803
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_blend_write(const bNodeTree &, const bNode &node, BlendWriter &writer)
static void node_init(bNodeTree *, bNode *node)
static void node_geo_exec(GeoNodeExecParams params)
static void node_copy_storage(bNodeTree *, bNode *dst_node, const bNode *src_node)
static void node_blend_read(bNodeTree &, bNode &node, BlendDataReader &reader)
static void node_declare(NodeDeclarationBuilder &b)
static bool node_insert_link(bNodeTree *tree, bNode *node, bNodeLink *link)
static void node_layout_ex(uiLayout *layout, bContext *C, PointerRNA *node_ptr)
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)
ImplicitSharingPtr< Bundle > BundlePtr
void geo_node_type_base(blender::bke::bNodeType *ntype, std::string idname, const std::optional< int16_t > legacy_type)
NodeGeometryCombineBundleItem * items
ID * owner_id
Definition RNA_types.hh:51
void * data
Definition RNA_types.hh:53
void * storage
Defines a socket type.
Definition BKE_node.hh:152
const blender::CPPType * geometry_nodes_cpp_type
Definition BKE_node.hh:203
Defines a node type.
Definition BKE_node.hh:226
NodeBlendWriteFunction blend_write_storage_content
Definition BKE_node.hh:383
std::string ui_description
Definition BKE_node.hh:232
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
NodeGeometryExecFunction geometry_node_execute
Definition BKE_node.hh:347
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
static void blend_write_item(BlendWriter *writer, const ItemT &item)
NodeGeometryCombineBundleItem ItemT
static void blend_read_data_item(BlendDataReader *reader, 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