Blender V5.3
node_geo_separate_components.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
6
8
10{
11 b.add_input<decl::Geometry>("Geometry"_ustr)
12 .description("Geometry to split into separate components");
13 b.add_output<decl::Geometry>("Mesh"_ustr).propagate_all_geometry();
14 b.add_output<decl::Geometry>("Curve"_ustr).propagate_all_geometry();
15 b.add_output<decl::Geometry>("Grease Pencil"_ustr).propagate_all_geometry();
16 b.add_output<decl::Geometry>("Point Cloud"_ustr).propagate_all_geometry();
17 b.add_output<decl::Geometry>("Volume"_ustr)
18 .translation_context(BLT_I18NCONTEXT_ID_ID)
19 .propagate_all_geometry();
20 b.add_output<decl::Geometry>("Instances"_ustr).propagate_all_geometry();
21}
22
24{
25 GeometrySet geometry_set = params.extract_input<GeometrySet>("Geometry"_ustr);
26
27 GeometrySet meshes;
30 GeometrySet pointclouds;
31 GeometrySet volumes;
32 GeometrySet instances;
33
34 const StringRef name = geometry_set.name();
35 if (!name.is_empty()) {
36 meshes.set_name(name);
37 curves.set_name(name);
38 grease_pencil.set_name(name);
39 pointclouds.set_name(name);
40 volumes.set_name(name);
41 instances.set_name(name);
42 }
43
44 meshes.copy_bundle_from(geometry_set);
45 curves.copy_bundle_from(geometry_set);
46 grease_pencil.copy_bundle_from(geometry_set);
47 pointclouds.copy_bundle_from(geometry_set);
48 volumes.copy_bundle_from(geometry_set);
49 instances.copy_bundle_from(geometry_set);
50
51 if (geometry_set.has<MeshComponent>()) {
52 meshes.add(*geometry_set.get_component<MeshComponent>());
53 }
54 if (geometry_set.has<CurveComponent>()) {
55 curves.add(*geometry_set.get_component<CurveComponent>());
56 }
57 if (geometry_set.has<GreasePencilComponent>()) {
59 }
60 if (geometry_set.has<PointCloudComponent>()) {
61 pointclouds.add(*geometry_set.get_component<PointCloudComponent>());
62 }
63 if (geometry_set.has<VolumeComponent>()) {
64 volumes.add(*geometry_set.get_component<VolumeComponent>());
65 }
66 if (geometry_set.has<InstancesComponent>()) {
67 instances.add(*geometry_set.get_component<InstancesComponent>());
68 }
69
70 params.set_output("Mesh"_ustr, meshes);
71 params.set_output("Curve"_ustr, curves);
72 params.set_output("Grease Pencil"_ustr, grease_pencil);
73 params.set_output("Point Cloud"_ustr, pointclouds);
74 params.set_output("Volume"_ustr, volumes);
75 params.set_output("Instances"_ustr, instances);
76}
77
78static void node_register()
79{
80 static bke::bNodeType ntype;
81
82 geo_node_type_base(&ntype, "GeometryNodeSeparateComponents"_ustr, GEO_NODE_SEPARATE_COMPONENTS);
83 ntype.ui_name = "Separate Components";
84 ntype.ui_description =
85 "Split a geometry into a separate output for each type of data in the geometry";
86 ntype.enum_name_legacy = "SEPARATE_COMPONENTS";
88 ntype.declare = node_declare;
92}
94
95} // namespace blender::nodes::node_geo_separate_components_cc
#define NODE_CLASS_GEOMETRY
Definition BKE_node.hh:492
#define GEO_NODE_SEPARATE_COMPONENTS
#define BLT_I18NCONTEXT_ID_ID
#define NOD_REGISTER_NODE(REGISTER_FUNC)
constexpr bool is_empty() 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
void geo_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
StringRefNull name() const
void set_name(std::string name)
bool has(const GeometryComponent::Type component_type) const
const GeometryComponent * get_component(GeometryComponent::Type component_type) const
void copy_bundle_from(const GeometrySet &other)
void add(const GeometryComponent &component)
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
const char * enum_name_legacy
Definition BKE_node.hh:274
NodeDeclareFunction declare
Definition BKE_node.hh:393