Blender V4.3
node_geo_delete_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
11
12#include "RNA_enum_types.hh"
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 to be deleted");
28 b.add_output<decl::Geometry>("Geometry").propagate_all();
29}
30
31static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
32{
33 const bNode *node = static_cast<bNode *>(ptr->data);
34 const NodeGeometryDeleteGeometry &storage = node_storage(*node);
35 const AttrDomain domain = AttrDomain(storage.domain);
36
37 uiItemR(layout, ptr, "domain", UI_ITEM_NONE, "", ICON_NONE);
38 /* Only show the mode when it is relevant. */
39 if (ELEM(domain, AttrDomain::Point, AttrDomain::Edge, AttrDomain::Face)) {
40 uiItemR(layout, ptr, "mode", UI_ITEM_NONE, "", ICON_NONE);
41 }
42}
43
44static void node_init(bNodeTree * /*tree*/, bNode *node)
45{
46 NodeGeometryDeleteGeometry *data = MEM_cnew<NodeGeometryDeleteGeometry>(__func__);
47 data->domain = int(AttrDomain::Point);
49
50 node->storage = data;
51}
52
54{
55 GeometrySet geometry_set = params.extract_input<GeometrySet>("Geometry");
56
57 /* The node's input is a selection of elements that should be deleted, but the code is
58 * implemented as a separation operation that copies the selected elements to a new geometry.
59 * Invert the selection to avoid the need to keep track of both cases in the code. */
60 const Field<bool> selection = fn::invert_boolean_field(
61 params.extract_input<Field<bool>>("Selection"));
62
63 const NodeGeometryDeleteGeometry &storage = node_storage(params.node());
64 const AttrDomain domain = AttrDomain(storage.domain);
66
67 const NodeAttributeFilter &attribute_filter = params.get_attribute_filter("Geometry");
68
69 if (domain == AttrDomain::Instance) {
70 bool is_error;
71 geometry::separate_geometry(geometry_set, domain, mode, selection, attribute_filter, is_error);
72 }
73 else {
74 geometry_set.modify_geometry_sets([&](GeometrySet &geometry_set) {
75 bool is_error;
76 /* Invert here because we want to keep the things not in the selection. */
78 geometry_set, domain, mode, selection, attribute_filter, is_error);
79 });
80 }
81
82 params.set_output("Geometry", std::move(geometry_set));
83}
84
85static void node_rna(StructRNA *srna)
86{
87 static const EnumPropertyItem mode_items[] = {
88 {GEO_NODE_DELETE_GEOMETRY_MODE_ALL, "ALL", 0, "All", ""},
89 {GEO_NODE_DELETE_GEOMETRY_MODE_EDGE_FACE, "EDGE_FACE", 0, "Only Edges & Faces", ""},
90 {GEO_NODE_DELETE_GEOMETRY_MODE_ONLY_FACE, "ONLY_FACE", 0, "Only Faces", ""},
91 {0, nullptr, 0, nullptr, nullptr},
92 };
93
95 "mode",
96 "Mode",
97 "Which parts of the mesh component to delete",
98 mode_items,
101
103 "domain",
104 "Domain",
105 "Which domain to delete in",
108 int(AttrDomain::Point));
109}
110
111static void node_register()
112{
113 static blender::bke::bNodeType ntype;
114
115 geo_node_type_base(&ntype, GEO_NODE_DELETE_GEOMETRY, "Delete Geometry", NODE_CLASS_GEOMETRY);
116
118 "NodeGeometryDeleteGeometry",
121
122 ntype.initfunc = node_init;
123 ntype.declare = node_declare;
127
128 node_rna(ntype.rna_ext.srna);
129}
131
132} // namespace blender::nodes::node_geo_delete_geometry_cc
#define NODE_STORAGE_FUNCS(StorageT)
Definition BKE_node.hh:1799
#define NODE_CLASS_GEOMETRY
Definition BKE_node.hh:418
#define ELEM(...)
GeometryNodeDeleteGeometryMode
@ GEO_NODE_DELETE_GEOMETRY_MODE_EDGE_FACE
@ GEO_NODE_DELETE_GEOMETRY_MODE_ONLY_FACE
@ 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
draw_view push_constant(Type::INT, "radiance_src") .push_constant(Type capture_info_buf storage_buf(1, Qualifier::READ, "ObjectBounds", "bounds_buf[]") .push_constant(Type draw_view int
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_declare(NodeDeclarationBuilder &b)
static void node_init(bNodeTree *, bNode *node)
static void node_geo_exec(GeoNodeExecParams params)
static void node_layout(uiLayout *layout, bContext *, PointerRNA *ptr)
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
const EnumPropertyItem rna_enum_attribute_domain_without_corner_items[]
StructRNA * srna
Definition RNA_types.hh:780
void * data
Definition RNA_types.hh:42
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