Blender V5.3
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#include <fmt/ranges.h>
7
9
10#include "node_geometry_util.hh"
12
14
16{
17 b.use_custom_socket_order();
18 b.allow_any_socket_order();
19 b.add_input<decl::Bundle>("Bundle"_ustr)
20 .multi_input()
22 "Bundles to join together on the top level for each bundle. When there are duplicates, "
23 "only "
24 "the first occurrence is used");
25 b.add_output<decl::Bundle>("Bundle"_ustr).align_with_previous().propagate_all();
26}
27
29{
31 "Bundle"_ustr);
32
33 if (bundles.values.is_empty()) {
35 return;
36 }
37
38 BundlePtr output_bundle;
39 int bundle_i = 0;
40 for (; bundle_i < bundles.values.size(); bundle_i++) {
41 BundlePtr &bundle = bundles.values[bundle_i];
42 if (bundle) {
43 output_bundle = std::move(bundle);
44 bundle_i++;
45 break;
46 }
47 }
48 if (!output_bundle) {
49 output_bundle = Bundle::create();
50 }
51 Bundle &mutable_output_bundle = output_bundle.ensure_mutable_inplace();
52
53 VectorSet<BundleKey> overridden_keys;
54 for (; bundle_i < bundles.values.size(); bundle_i++) {
55 BundlePtr &bundle = bundles.values[bundle_i];
56 if (!bundle) {
57 continue;
58 }
59 for (const auto &item : bundle->items()) {
60 if (!mutable_output_bundle.add(item.key, item.value)) {
61 overridden_keys.add(item.key);
62 }
63 }
64 }
65
66 if (!overridden_keys.is_empty()) {
67 std::string message = fmt::format(
68 "{}: {}", TIP_("Duplicate keys"), fmt::join(overridden_keys, ", "));
69 params.error_message_add(NodeWarningType::Info, std::move(message));
70 }
71
72 params.set_output("Bundle"_ustr, output_bundle);
73}
74
75static void node_register()
76{
77 static bke::bNodeType ntype;
78 sh_geo_node_type_base(&ntype, "NodeJoinBundle"_ustr);
79 ntype.ui_name = "Join Bundle";
80 ntype.ui_description = "Join multiple bundles together";
83 ntype.declare = node_declare;
85}
87
88} // namespace blender::nodes::node_geo_join_bundle
#define NODE_CLASS_CONVERTER
Definition BKE_node.hh:484
#define TIP_(msgid)
#define NOD_REGISTER_NODE(REGISTER_FUNC)
bool add(const Key &key)
bool add(BundleKey key, const BundleItemValue &value)
BundleItemMap::ItemIterator items() const
void error_message_add(const NodeWarningType type, StringRef message) const
T extract_input(const UString identifier)
void set_output(const UString identifier, T &&value)
void node_register_type(bNodeType &ntype)
Definition node.cc:2920
static void node_geo_exec(GeoNodeExecParams params)
static void node_declare(NodeDeclarationBuilder &b)
ImplicitSharingPtr< Bundle > BundlePtr
void sh_geo_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
Defines a node type.
Definition BKE_node.hh:265
std::string ui_description
Definition BKE_node.hh:271
NodeGeometryExecFunction geometry_node_execute
Definition BKE_node.hh:385
NodeDeclareFunction declare
Definition BKE_node.hh:393