Blender V4.3
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 uiItemR(layout, ptr, "domain", UI_ITEM_NONE, "", ICON_NONE);
39}
40
41static void node_init(bNodeTree * /*tree*/, bNode *node)
42{
43 NodeGeometrySeparateGeometry *data = MEM_cnew<NodeGeometrySeparateGeometry>(__func__);
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,
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, GEO_NODE_SEPARATE_GEOMETRY, "Separate Geometry", NODE_CLASS_GEOMETRY);
112
114 "NodeGeometrySeparateGeometry",
117
118 ntype.initfunc = node_init;
119
120 ntype.declare = node_declare;
124
125 node_rna(ntype.rna_ext.srna);
126}
128
129} // namespace blender::nodes::node_geo_separate_geometry_cc
#define NODE_STORAGE_FUNCS(StorageT)
Definition BKE_node.hh:1799
#define NODE_CLASS_GEOMETRY
Definition BKE_node.hh:418
@ GEO_NODE_DELETE_GEOMETRY_MODE_ALL
#define NOD_REGISTER_NODE(REGISTER_FUNC)
#define NOD_storage_enum_accessors(member)
#define UI_ITEM_NONE
void uiItemR(uiLayout *layout, PointerRNA *ptr, const char *propname, eUI_Item_Flag flag, const char *name, int icon)
local_group_size(16, 16) .push_constant(Type b
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
void node_type_storage(bNodeType *ntype, const char *storagename, void(*freefunc)(bNode *node), void(*copyfunc)(bNodeTree *dest_ntree, bNode *dest_node, const bNode *src_node))
Definition node.cc:4632
void node_register_type(bNodeType *ntype)
Definition node.cc:1708
Field< bool > invert_boolean_field(const Field< bool > &field)
Definition field.cc:525
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, int type, const char *name, short nclass)
void node_free_standard_storage(bNode *node)
Definition node_util.cc:46
void node_copy_standard_storage(bNodeTree *, bNode *dest_node, const bNode *src_node)
Definition node_util.cc:58
GPU_SHADER_INTERFACE_INFO(overlay_edit_curve_handle_iface, "vert").flat(Type pos vertex_in(1, Type::UINT, "data") .vertex_out(overlay_edit_curve_handle_iface) .geometry_layout(PrimitiveIn Frequency::GEOMETRY storage_buf(1, Qualifier::READ, "uint", "data[]", Frequency::GEOMETRY) .push_constant(Type Frequency::GEOMETRY selection[]
const EnumPropertyItem rna_enum_attribute_domain_without_corner_items[]
signed char int8_t
Definition stdint.h:75
StructRNA * srna
Definition RNA_types.hh:780
void modify_geometry_sets(ForeachSubGeometryCallback callback)
Defines a node type.
Definition BKE_node.hh:218
void(* initfunc)(bNodeTree *ntree, bNode *node)
Definition BKE_node.hh:267
NodeGeometryExecFunction geometry_node_execute
Definition BKE_node.hh:339
void(* draw_buttons)(uiLayout *, bContext *C, PointerRNA *ptr)
Definition BKE_node.hh:238
NodeDeclareFunction declare
Definition BKE_node.hh:347
PointerRNA * ptr
Definition wm_files.cc:4126