Blender V4.5
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
7#include "UI_interface.hh"
8#include "UI_resources.hh"
9
10#include "RNA_enum_types.hh"
11
13
14#include "node_geometry_util.hh"
15
17
19
21{
22 b.add_input<decl::Geometry>("Geometry");
23 b.add_input<decl::Bool>("Selection")
24 .default_value(true)
25 .hide_value()
26 .field_on_all()
27 .description("The parts of the geometry that go into the first output");
28 b.add_output<decl::Geometry>("Selection")
29 .propagate_all()
30 .description("The parts of the geometry in the selection");
31 b.add_output<decl::Geometry>("Inverted")
32 .propagate_all()
33 .description("The parts of the geometry not in the selection");
34}
35
36static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
37{
38 layout->prop(ptr, "domain", UI_ITEM_NONE, "", ICON_NONE);
39}
40
41static void node_init(bNodeTree * /*tree*/, bNode *node)
42{
44 data->domain = int8_t(AttrDomain::Point);
45 node->storage = data;
46}
47
49{
50 GeometrySet geometry_set = params.extract_input<GeometrySet>("Geometry");
51
52 const Field<bool> selection_field = params.extract_input<Field<bool>>("Selection");
53
54 const NodeGeometrySeparateGeometry &storage = node_storage(params.node());
55 const AttrDomain domain = AttrDomain(storage.domain);
56
57 auto separate_geometry_maybe_recursively = [&](GeometrySet &geometry_set,
58 const Field<bool> &selection,
59 const AttributeFilter &attribute_filter) {
60 bool is_error;
61 if (domain == AttrDomain::Instance) {
62 /* Only delete top level instances. */
63 geometry::separate_geometry(geometry_set,
64 domain,
66 selection,
67 attribute_filter,
68 is_error);
69 }
70 else {
71 geometry_set.modify_geometry_sets([&](GeometrySet &geometry_set) {
72 geometry::separate_geometry(geometry_set,
73 domain,
75 selection,
76 attribute_filter,
77 is_error);
78 });
79 }
80 };
81
82 GeometrySet second_set(geometry_set);
83 if (params.output_is_required("Selection")) {
84 separate_geometry_maybe_recursively(
85 geometry_set, selection_field, params.get_attribute_filter("Selection"));
86 params.set_output("Selection", std::move(geometry_set));
87 }
88 if (params.output_is_required("Inverted")) {
89 separate_geometry_maybe_recursively(second_set,
90 fn::invert_boolean_field(selection_field),
91 params.get_attribute_filter("Inverted"));
92 params.set_output("Inverted", std::move(second_set));
93 }
94}
95
96static void node_rna(StructRNA *srna)
97{
99 "domain",
100 "Domain",
101 "Which domain to separate on",
104 int(AttrDomain::Point));
105}
106
107static void node_register()
108{
109 static blender::bke::bNodeType ntype;
110
111 geo_node_type_base(&ntype, "GeometryNodeSeparateGeometry", GEO_NODE_SEPARATE_GEOMETRY);
112 ntype.ui_name = "Separate Geometry";
113 ntype.ui_description = "Split a geometry into two geometry outputs based on a selection";
114 ntype.enum_name_legacy = "SEPARATE_GEOMETRY";
117 "NodeGeometrySeparateGeometry",
120
121 ntype.initfunc = node_init;
122
123 ntype.declare = node_declare;
127
128 node_rna(ntype.rna_ext.srna);
129}
131
132} // namespace blender::nodes::node_geo_separate_geometry_cc
#define NODE_STORAGE_FUNCS(StorageT)
Definition BKE_node.hh:1215
#define NODE_CLASS_GEOMETRY
Definition BKE_node.hh:447
#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:2748
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:5603
Field< bool > invert_boolean_field(const Field< bool > &field)
Definition field.cc:520
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
Definition RNA_types.hh:909
void * storage
void modify_geometry_sets(ForeachSubGeometryCallback callback)
Defines a node type.
Definition BKE_node.hh:226
std::string ui_description
Definition BKE_node.hh:232
void(* initfunc)(bNodeTree *ntree, bNode *node)
Definition BKE_node.hh:277
NodeGeometryExecFunction geometry_node_execute
Definition BKE_node.hh:347
const char * enum_name_legacy
Definition BKE_node.hh:235
void(* draw_buttons)(uiLayout *, bContext *C, PointerRNA *ptr)
Definition BKE_node.hh:247
NodeDeclareFunction declare
Definition BKE_node.hh:355
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:4226