Blender V5.3
node_geo_get_geometry_component.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 "RNA_enum_types.hh"
6
8
10
12{
13 b.use_custom_socket_order();
14 b.allow_any_socket_order();
15
16 b.add_input<decl::Geometry>("Geometry"_ustr);
17 b.add_output<decl::Geometry>("Geometry"_ustr)
18 .align_with_previous()
19 .description("The input geometry with optionally the selected component removed")
20 .propagate_all_geometry();
21 b.add_output<decl::Geometry>("Component"_ustr).propagate_all_geometry();
22 b.add_output<decl::Bool>("Exists"_ustr)
23 .description(
24 "Whether the geometry had a component of the type. This does not check if the component "
25 "is empty");
26 b.add_input<decl::Menu>("Type"_ustr)
29 b.add_input<decl::Bool>("Remove"_ustr).default_value(true);
30}
31
33{
34 GeometrySet geometry = params.extract_input<GeometrySet>("Geometry"_ustr);
35 const GeometryComponent::Type type = params.extract_input<GeometryComponent::Type>("Type"_ustr);
36 const bool remove = params.extract_input<bool>("Remove"_ustr);
37
38 GeometrySet component_geo;
39 bool exists = false;
40
41 switch (type) {
48 if (const GeometryComponent *component = geometry.get_component(type)) {
49 component_geo.add(*component);
50 exists = true;
51 }
52 component_geo.copy_bundle_from(geometry);
53 component_geo.set_name(geometry.name());
54 if (remove) {
55 geometry.remove(type);
56 }
57 break;
58 }
60 break;
61 }
62 }
63
64 params.set_output("Geometry"_ustr, geometry);
65 params.set_output("Component"_ustr, component_geo);
66 params.set_output("Exists"_ustr, exists);
67}
68
69static void node_register()
70{
71 static bke::bNodeType ntype;
72
73 geo_node_type_base(&ntype, "GeometryNodeGetGeometryComponent"_ustr);
74 ntype.ui_name = "Get Geometry Component";
75 ntype.ui_description = "Get a single component of a geometry";
77 ntype.declare = node_declare;
81}
83
84} // namespace blender::nodes::node_geo_get_geometry_component_cc
#define NODE_CLASS_GEOMETRY
Definition BKE_node.hh:492
#define NOD_REGISTER_NODE(REGISTER_FUNC)
T extract_input(const UString identifier)
void set_output(const UString identifier, T &&value)
void node_register_type(bNodeType &ntype)
Definition node.cc:2920
const EnumPropertyItem rna_enum_geometry_component_type_items[]
Definition rna_space.cc:51
void geo_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
static constexpr int _180
Definition BKE_node.hh:247
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