Blender V5.0
node_geo_separate_geometry.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
5#include "NOD_rna_define.hh"
6
8#include "UI_resources.hh"
9
10#include "RNA_enum_types.hh"
11
14
15#include "node_geometry_util.hh"
16
18
20
22{
23 b.add_input<decl::Geometry>("Geometry").description("Geometry to split into two parts");
24 b.add_input<decl::Bool>("Selection")
25 .default_value(true)
26 .hide_value()
27 .field_on_all()
28 .description("The parts of the geometry that go into the first output");
29 b.add_output<decl::Geometry>("Selection")
30 .propagate_all()
31 .description("The parts of the geometry in the selection");
32 b.add_output<decl::Geometry>("Inverted")
33 .propagate_all()
34 .description("The parts of the geometry not in the selection");
35}
36
37static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
38{
39 layout->prop(ptr, "domain", UI_ITEM_NONE, "", ICON_NONE);
40}
41
42static void node_init(bNodeTree * /*tree*/, bNode *node)
43{
45 data->domain = int8_t(AttrDomain::Point);
46 node->storage = data;
47}
48
50{
51 GeometrySet geometry_set = params.extract_input<GeometrySet>("Geometry");
52
53 const Field<bool> selection_field = params.extract_input<Field<bool>>("Selection");
54
55 const NodeGeometrySeparateGeometry &storage = node_storage(params.node());
56 const AttrDomain domain = AttrDomain(storage.domain);
57
58 auto separate_geometry_maybe_recursively = [&](GeometrySet &geometry_set,
59 const Field<bool> &selection,
60 const AttributeFilter &attribute_filter) {
61 bool is_error;
62 if (domain == AttrDomain::Instance) {
63 /* Only delete top level instances. */
64 geometry::separate_geometry(geometry_set,
65 domain,
67 selection,
68 attribute_filter,
69 is_error);
70 }
71 else {
72 geometry::foreach_real_geometry(geometry_set, [&](GeometrySet &geometry_set) {
73 geometry::separate_geometry(geometry_set,
74 domain,
76 selection,
77 attribute_filter,
78 is_error);
79 });
80 }
81 };
82
83 GeometrySet second_set(geometry_set);
84 if (params.output_is_required("Selection")) {
85 separate_geometry_maybe_recursively(
86 geometry_set, selection_field, params.get_attribute_filter("Selection"));
87 params.set_output("Selection", std::move(geometry_set));
88 }
89 if (params.output_is_required("Inverted")) {
90 separate_geometry_maybe_recursively(second_set,
91 fn::invert_boolean_field(selection_field),
92 params.get_attribute_filter("Inverted"));
93 params.set_output("Inverted", std::move(second_set));
94 }
95}
96
97static void node_rna(StructRNA *srna)
98{
100 "domain",
101 "Domain",
102 "Which domain to separate on",
105 int(AttrDomain::Point));
106}
107
108static void node_register()
109{
110 static blender::bke::bNodeType ntype;
111
112 geo_node_type_base(&ntype, "GeometryNodeSeparateGeometry", GEO_NODE_SEPARATE_GEOMETRY);
113 ntype.ui_name = "Separate Geometry";
114 ntype.ui_description = "Split a geometry into two geometry outputs based on a selection";
115 ntype.enum_name_legacy = "SEPARATE_GEOMETRY";
118 "NodeGeometrySeparateGeometry",
121
122 ntype.initfunc = node_init;
123
124 ntype.declare = node_declare;
128
129 node_rna(ntype.rna_ext.srna);
130}
132
133} // namespace blender::nodes::node_geo_separate_geometry_cc
#define NODE_STORAGE_FUNCS(StorageT)
Definition BKE_node.hh:1240
#define NODE_CLASS_GEOMETRY
Definition BKE_node.hh:461
#define GEO_NODE_SEPARATE_GEOMETRY
@ GEO_NODE_DELETE_GEOMETRY_MODE_ALL
#define NOD_REGISTER_NODE(REGISTER_FUNC)
#define NOD_storage_enum_accessors(member)
#define UI_ITEM_NONE
BMesh const char void * data
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
void * MEM_callocN(size_t len, const char *str)
Definition mallocn.cc:118
void node_register_type(bNodeType &ntype)
Definition node.cc:2416
void node_type_storage(bNodeType &ntype, std::optional< StringRefNull > storagename, void(*freefunc)(bNode *node), void(*copyfunc)(bNodeTree *dest_ntree, bNode *dest_node, const bNode *src_node))
Definition node.cc:5414
Field< bool > invert_boolean_field(const Field< bool > &field)
Definition field.cc:520
void foreach_real_geometry(bke::GeometrySet &geometry, FunctionRef< void(bke::GeometrySet &geometry_set)> fn)
void separate_geometry(bke::GeometrySet &geometry_set, bke::AttrDomain domain, GeometryNodeDeleteGeometryMode mode, const fn::Field< bool > &selection_field, const bke::AttributeFilter &attribute_filter, bool &r_is_error)
static void node_layout(uiLayout *layout, bContext *, PointerRNA *ptr)
static void node_declare(NodeDeclarationBuilder &b)
static void node_geo_exec(GeoNodeExecParams params)
PropertyRNA * RNA_def_node_enum(StructRNA *srna, const char *identifier, const char *ui_name, const char *ui_description, const EnumPropertyItem *static_items, const EnumRNAAccessors accessors, std::optional< int > default_value, const EnumPropertyItemFunc item_func, const bool allow_animation)
void geo_node_type_base(blender::bke::bNodeType *ntype, std::string idname, const std::optional< int16_t > legacy_type)
void node_free_standard_storage(bNode *node)
Definition node_util.cc:42
void node_copy_standard_storage(bNodeTree *, bNode *dest_node, const bNode *src_node)
Definition node_util.cc:54
const EnumPropertyItem rna_enum_attribute_domain_without_corner_items[]
StructRNA * srna
void * storage
Defines a node type.
Definition BKE_node.hh:238
std::string ui_description
Definition BKE_node.hh:244
void(* initfunc)(bNodeTree *ntree, bNode *node)
Definition BKE_node.hh:289
NodeGeometryExecFunction geometry_node_execute
Definition BKE_node.hh:354
const char * enum_name_legacy
Definition BKE_node.hh:247
void(* draw_buttons)(uiLayout *, bContext *C, PointerRNA *ptr)
Definition BKE_node.hh:259
NodeDeclareFunction declare
Definition BKE_node.hh:362
void prop(PointerRNA *ptr, PropertyRNA *prop, int index, int value, eUI_Item_Flag flag, std::optional< blender::StringRef > name_opt, int icon, std::optional< blender::StringRef > placeholder=std::nullopt)
PointerRNA * ptr
Definition wm_files.cc:4238