Blender V5.3
node_geo_store_bundle_item.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2026 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
6
7#include "NOD_geo_bundle.hh"
9#include "NOD_rna_define.hh"
10
11#include "RNA_enum_types.hh"
12
14#include "UI_resources.hh"
15
16#include "COM_bundle_item.hh"
17#include "COM_node_operation.hh"
18
20
22
24{
25 b.use_custom_socket_order();
26 b.allow_any_socket_order();
27 b.add_default_layout();
28 const bNode *node = b.node_or_null();
29
30 b.add_input<decl::Bundle>("Bundle"_ustr);
31 b.add_output<decl::Bundle>("Bundle"_ustr).align_with_previous().propagate_all();
32 b.add_input<decl::String>("Path"_ustr).optional_label();
33
34 if (node != nullptr) {
35 const NodeStoreBundleItem &storage = node_storage(*node);
36 const eNodeSocketDatatype socket_type = storage.socket_type;
37 auto &decl = b.add_input(socket_type, "Item"_ustr);
38 if (storage.structure_type == NodeSocketInterfaceStructureType::Auto) {
39 decl.structure_type(StructureType::Dynamic);
40 }
41 else {
42 decl.structure_type(StructureType(storage.structure_type));
43 }
44
45 decl.compositor_realization_mode(CompositorInputRealizationMode::None);
46 }
47}
48
49static void node_layout(ui::Layout &layout, bContext * /*C*/, PointerRNA *ptr)
50{
51 layout.use_property_split_set(true);
52 layout.use_property_decorate_set(false);
53 layout.prop(ptr, "socket_type", UI_ITEM_NONE, "", ICON_NONE);
54}
55
56static void node_layout_ex(ui::Layout &layout, bContext * /*C*/, PointerRNA *ptr)
57{
58 layout.prop(ptr, "socket_type", UI_ITEM_NONE, "", ICON_NONE);
59 layout.use_property_split_set(true);
60 layout.use_property_decorate_set(false);
61 layout.prop(ptr, "structure_type", UI_ITEM_NONE, IFACE_("Shape"), ICON_NONE);
62}
63
64static void node_init(bNodeTree * /*tree*/, bNode *node)
65{
66 auto *storage = MEM_new<NodeStoreBundleItem>(__func__);
67 storage->socket_type = SOCK_FLOAT;
68 node->storage = storage;
69}
70
72{
73 const bNode &bnode = params.node();
74 const NodeStoreBundleItem &storage = node_storage(bnode);
75
76 BundlePtr bundle_ptr = params.extract_input<nodes::BundlePtr>("Bundle"_ustr);
77 if (!bundle_ptr) {
78 bundle_ptr = Bundle::create();
79 }
80 Bundle &bundle = bundle_ptr.ensure_mutable_inplace();
81
82 const std::string path = params.extract_input<std::string>("Path"_ustr);
83 const std::optional<Vector<BundleKey>> split_path = Bundle::split_path(path);
84 if (!split_path) {
85 if (!path.empty()) {
86 params.error_message_add(NodeWarningType::Warning, "Invalid bundle path");
87 }
88 params.set_output("Bundle"_ustr, std::move(bundle_ptr));
89 return;
90 }
91
93 const bNodeSocket *item_sock = bnode.input_by_identifier("Item"_ustr);
94 if (!item_sock) {
95 params.set_output("Bundle"_ustr, std::move(bundle_ptr));
96 return;
97 }
98
100 if (!stype || !stype->geometry_nodes_default_value) {
101 params.set_output("Bundle"_ustr, std::move(bundle_ptr));
102 return;
103 }
104
105 bundle.add_path_override(*split_path, BundleItemSocketValue{stype, std::move(value)});
106
107 params.set_output("Bundle"_ustr, std::move(bundle_ptr));
108}
109
110using namespace blender::compositor;
111
113 public:
115
116 void execute() override
117 {
118 const Result &input_bundle = this->get_input("Bundle");
119 BundlePtr bundle_ptr = input_bundle.get_single_value<nodes::BundlePtr>();
120 Bundle &bundle = bundle_ptr.ensure_mutable_inplace();
121
122 Result &output_bundle = this->get_result("Bundle");
123
124 const std::string path = this->get_input("Path").get_single_value<std::string>();
125 const std::optional<Vector<BundleKey>> split_path = Bundle::split_path(path);
126 if (!split_path.has_value()) {
127 if (!path.empty()) {
128 this->add_warning(NodeWarningType::Warning, "Invalid bundle path");
129 }
130 output_bundle.share_data(input_bundle);
131 return;
132 }
133
134 Result &input_item = this->get_input("Item");
135 bundle.add_path_override(*split_path,
136 BundleItem::new_bundle_item_value(this->context(), input_item));
137 output_bundle.allocate_single_value();
138 output_bundle.set_single_value(bundle_ptr);
139 }
140};
141
143{
144 return new StoreBundleItemOperation(context, node);
145}
146
147static void node_rna(StructRNA *srna)
148{
150 "socket_type",
151 "Socket Type",
152 "",
154 NOD_storage_enum_accessors(socket_type),
156 [](bContext * /*C*/, PointerRNA *ptr, PropertyRNA * /*prop*/, bool *r_free) {
157 *r_free = true;
158 const bNodeTree &ntree = *id_cast<const bNodeTree *>(ptr->owner_id);
160 [&](const EnumPropertyItem &item) -> bool {
162 eNodeSocketDatatype(item.value), ntree.type);
163 });
164 });
166 "structure_type",
167 "Structure Type",
168 "What kind of higher order types are expected to flow through this socket",
170 NOD_storage_enum_accessors(structure_type));
171}
172
173static void node_register()
174{
175 static bke::bNodeType ntype;
176
177 geo_cmp_node_type_base(&ntype, "NodeStoreBundleItem"_ustr);
178 ntype.ui_name = "Store Bundle Item";
179 ntype.ui_description = "Store a bundle item by path and data type.";
181 ntype.initfunc = node_init;
182 ntype.declare = node_declare;
188 ntype, "NodeStoreBundleItem", node_free_standard_storage, node_copy_standard_storage);
190
191 node_rna(ntype.rna_ext.srna);
192}
194
195} // namespace blender::nodes::node_geo_store_bundle_item_cc
#define NODE_CLASS_CONVERTER
Definition BKE_node.hh:484
#define NODE_STORAGE_FUNCS(StorageT)
Definition BKE_node.hh:1353
#define IFACE_(msgid)
#define NOD_REGISTER_NODE(REGISTER_FUNC)
#define NOD_storage_enum_accessors(member)
#define UI_ITEM_NONE
static nodes::BundleItemValue new_bundle_item_value(Context &context, Result &result)
NodeOperation(Context &context, const bNode &node)
void add_warning(nodes::NodeWarningType type, std::string message)
Result & get_result(StringRef identifier)
Definition operation.cc:40
Context & context() const
Definition operation.cc:57
Result & get_input(StringRef identifier) const
Definition operation.cc:35
void share_data(const Result &source)
Definition result.cc:996
void set_single_value(const T &value)
const T & get_single_value() const
void add_path_override(StringRef path, const BundleItemValue &value)
static std::optional< Vector< BundleKey > > split_path(StringRef path)
void error_message_add(const NodeWarningType type, StringRef message) const
T extract_input(const UString identifier)
void set_output(const UString identifier, T &&value)
#define storage(slot, qualifiers)
void node_register_type(bNodeType &ntype)
Definition node.cc:2920
bNodeSocketType * node_socket_type_find_static(int type, int subtype=0)
Definition node.cc:2975
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:6166
static void node_geo_exec(GeoNodeExecParams params)
static void node_layout_ex(ui::Layout &layout, bContext *, PointerRNA *ptr)
static void node_declare(NodeDeclarationBuilder &b)
static void node_layout(ui::Layout &layout, bContext *, PointerRNA *ptr)
static NodeOperation * get_compositor_operation(Context &context, const bNode &node)
PropertyRNA * RNA_def_node_enum(StructRNA *srna, const char *identifier, const char *ui_name, const char *ui_description, const EnumPropertyItem *static_items, const EnumRNAAccessors accessors, std::optional< int > default_value, const EnumPropertyItemFunc item_func, const bool allow_animation)
bool socket_type_supported_in_bundle(const eNodeSocketDatatype socket_type, const int ntree_type)
const EnumPropertyItem * enum_items_filter(const EnumPropertyItem *original_item_array, FunctionRef< bool(const EnumPropertyItem &item)> fn)
ImplicitSharingPtr< Bundle > BundlePtr
const EnumPropertyItem rna_enum_node_socket_structure_type_items[]
void node_copy_standard_storage(bNodeTree *, bNode *dest_node, const bNode *src_node)
Definition node_util.cc:57
const EnumPropertyItem rna_enum_node_socket_data_type_items[]
void node_free_standard_storage(bNode *node)
Definition node_util.cc:45
void geo_cmp_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
eNodeTree_Type type
Defines a socket type.
Definition BKE_node.hh:163
const SocketValueVariant * geometry_nodes_default_value
Definition BKE_node.hh:216
Defines a node type.
Definition BKE_node.hh:265
void(*) draw_buttons(ui::Layout &, bContext *C, PointerRNA *ptr)
Definition BKE_node.hh:290
std::string ui_description
Definition BKE_node.hh:271
NodeGetCompositorOperationFunction get_compositor_operation
Definition BKE_node.hh:379
NodeGeometryExecFunction geometry_node_execute
Definition BKE_node.hh:385
void(*) draw_buttons_ex(ui::Layout &, bContext *C, PointerRNA *ptr)
Definition BKE_node.hh:292
void(*) initfunc(bNodeTree *ntree, bNode *node)
Definition BKE_node.hh:320
NodeDeclareFunction declare
Definition BKE_node.hh:393
void use_property_decorate_set(bool is_decorate)
void use_property_split_set(bool is_sep)
void prop(PointerRNA *ptr, PropertyRNA *prop, int index, int value, eUI_Item_Flag flag, std::optional< StringRef > name_opt, int icon, std::optional< StringRef > placeholder=std::nullopt)