Blender V5.0
node_geo_join_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
5#include <fmt/format.h>
6
8
10
12
14{
15 b.use_custom_socket_order();
16 b.allow_any_socket_order();
17 b.add_input<decl::Bundle>("Bundle").multi_input().description(
18 "Bundles to join together on the top level for each bundle. When there are duplicates, only "
19 "the first occurrence is used");
20 b.add_output<decl::Bundle>("Bundle").align_with_previous().propagate_all().reference_pass_all();
21}
22
24{
26 "Bundle");
27
28 if (bundles.values.is_empty()) {
29 params.set_default_remaining_outputs();
30 return;
31 }
32
33 BundlePtr output_bundle;
34 int bundle_i = 0;
35 for (; bundle_i < bundles.values.size(); bundle_i++) {
36 BundlePtr &bundle = bundles.values[bundle_i];
37 if (bundle) {
38 output_bundle = std::move(bundle);
39 bundle_i++;
40 break;
41 }
42 }
43 if (!output_bundle) {
44 output_bundle = Bundle::create();
45 }
46 else if (!output_bundle->is_mutable()) {
47 output_bundle = output_bundle->copy();
48 }
49 else {
50 output_bundle->tag_ensured_mutable();
51 }
52 Bundle &mutable_output_bundle = const_cast<Bundle &>(*output_bundle);
53
54 VectorSet<StringRef> overridden_keys;
55 for (; bundle_i < bundles.values.size(); bundle_i++) {
56 BundlePtr &bundle = bundles.values[bundle_i];
57 if (!bundle) {
58 continue;
59 }
60 for (const Bundle::StoredItem &item : bundle->items()) {
61 if (!mutable_output_bundle.add(item.key, item.value)) {
62 overridden_keys.add(item.key);
63 }
64 }
65 }
66
67 if (!overridden_keys.is_empty()) {
68 std::string message = fmt::format(
69 "{}: {}", TIP_("Duplicate keys"), fmt::join(overridden_keys, ", "));
70 params.error_message_add(NodeWarningType::Info, std::move(message));
71 }
72
73 params.set_output("Bundle", output_bundle);
74}
75
76static void node_register()
77{
78 static blender::bke::bNodeType ntype;
79 geo_node_type_base(&ntype, "NodeJoinBundle");
80 ntype.ui_name = "Join Bundle";
81 ntype.ui_description = "Join multiple bundles together";
84 ntype.declare = node_declare;
86}
88
89} // namespace blender::nodes::node_geo_join_bundle
#define NODE_CLASS_CONVERTER
Definition BKE_node.hh:453
#define TIP_(msgid)
#define NOD_REGISTER_NODE(REGISTER_FUNC)
bool add(const Key &key)
bool add(StringRef key, const BundleItemValue &value)
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
void node_register_type(bNodeType &ntype)
Definition node.cc:2416
static void node_geo_exec(GeoNodeExecParams params)
static void node_declare(NodeDeclarationBuilder &b)
ImplicitSharingPtr< Bundle > BundlePtr
void geo_node_type_base(blender::bke::bNodeType *ntype, std::string idname, const std::optional< int16_t > legacy_type)
Defines a node type.
Definition BKE_node.hh:238
std::string ui_description
Definition BKE_node.hh:244
NodeGeometryExecFunction geometry_node_execute
Definition BKE_node.hh:354
NodeDeclareFunction declare
Definition BKE_node.hh:362