Blender V5.3
node_geo_get_attribute_names.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
5#include "BKE_attribute.hh"
6
7#include "BLI_sort.hh"
8
9#include "RNA_enum_types.hh"
10
12
13#include "node_geometry_util.hh"
14
16
18{
19 b.use_custom_socket_order();
20 b.allow_any_socket_order();
21
22 b.add_output<decl::String>("Names"_ustr).structure_type(StructureType::List);
23
24 b.add_input<decl::Geometry>("Geometry"_ustr);
25
26 {
27 auto &p = b.add_panel("Filter Data Type"_ustr);
28 p.add_input<decl::Bool>("Filter Data Type"_ustr).panel_toggle();
29 p.add_input<decl::Menu>("Data Type"_ustr)
30 .static_items(rna_enum_attrtype_items)
32 .optional_label()
33 .usage_by_panel_toggle();
34 }
35 {
36 auto &p = b.add_panel("Filter Domain"_ustr);
37 p.add_input<decl::Bool>("Filter Domain"_ustr).panel_toggle();
38 p.add_input<decl::Menu>("Domain"_ustr)
40 .default_value(AttrDomain::Point)
41 .optional_label()
42 .usage_by_panel_toggle();
43 }
44}
45
47{
48 const GeometrySet geometry_set = params.extract_input<GeometrySet>("Geometry"_ustr);
49 const bool filter_data_type = params.extract_input<bool>("Filter Data Type"_ustr);
50 const bool filter_domain = params.extract_input<bool>("Filter Domain"_ustr);
51
52 const bke::AttrType data_type = params.extract_input<bke::AttrType>("Data Type"_ustr);
53 const AttrDomain domain = params.extract_input<AttrDomain>("Domain"_ustr);
54
55 VectorSet<std::string> names_set;
56
57 for (const GeometryComponent *component : geometry_set.get_components()) {
58 const std::optional<AttributeAccessor> attributes = component->attributes();
59 if (!attributes) {
60 continue;
61 }
62 attributes->foreach_attribute([&](const AttributeIter &iter) {
63 if (filter_data_type) {
64 if (iter.data_type != data_type) {
65 return;
66 }
67 }
68 if (filter_domain) {
69 if (iter.domain != domain) {
70 return;
71 }
72 }
73 if (iter.name.startswith(".")) {
74 return;
75 }
76 names_set.add(iter.name);
77 });
78 }
79
80 Vector<std::string> names = names_set.extract_vector();
82 names.begin(), names.end(), [](const StringRef a, const StringRef b) { return a < b; });
83 params.set_output("Names"_ustr, GList::from_container(names));
84}
85
86static void node_register()
87{
88 static blender::bke::bNodeType ntype;
89
90 geo_node_type_base(&ntype, "GeometryNodeGetAttributeNames"_ustr);
91 ntype.ui_name = "Get Attribute Names";
92 ntype.ui_description = "Retrieves attribute names as a list of strings";
95 ntype.declare = node_declare;
98}
100
101} // namespace blender::nodes::node_geo_get_attribute_names_cc
#define NODE_CLASS_ATTRIBUTE
Definition BKE_node.hh:493
#define NOD_REGISTER_NODE(REGISTER_FUNC)
constexpr bool startswith(StringRef prefix) const
static GListPtr from_container(ContainerT &&container)
T extract_input(const UString identifier)
void set_output(const UString identifier, T &&value)
void node_register_type(bNodeType &ntype)
Definition node.cc:2920
void parallel_sort(RandomAccessIterator begin, RandomAccessIterator end)
Definition BLI_sort.hh:37
const EnumPropertyItem rna_enum_attrtype_items[]
void geo_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
const EnumPropertyItem rna_enum_attribute_domain_items[]
Vector< const GeometryComponent * > get_components() const
static constexpr int _160
Definition BKE_node.hh:246
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