Blender V4.5
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.use_custom_socket_order();
23 b.allow_any_socket_order();
24 b.add_default_layout();
25 b.add_input<decl::Geometry>("Geometry");
26 b.add_output<decl::Geometry>("Geometry").propagate_all().align_with_previous();
27 b.add_input<decl::Bool>("Selection")
28 .default_value(true)
29 .hide_value()
30 .field_on_all()
31 .description("The parts of the geometry to be deleted");
32}
33
34static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
35{
36 const bNode *node = static_cast<bNode *>(ptr->data);
37 const NodeGeometryDeleteGeometry &storage = node_storage(*node);
38 const AttrDomain domain = AttrDomain(storage.domain);
39
40 layout->prop(ptr, "domain", UI_ITEM_NONE, "", ICON_NONE);
41 /* Only show the mode when it is relevant. */
42 if (ELEM(domain, AttrDomain::Point, AttrDomain::Edge, AttrDomain::Face)) {
43 layout->prop(ptr, "mode", UI_ITEM_NONE, "", ICON_NONE);
44 }
45}
46
47static void node_init(bNodeTree * /*tree*/, bNode *node)
48{
50 data->domain = int(AttrDomain::Point);
52
53 node->storage = data;
54}
55
57{
58 GeometrySet geometry_set = params.extract_input<GeometrySet>("Geometry");
59
60 /* The node's input is a selection of elements that should be deleted, but the code is
61 * implemented as a separation operation that copies the selected elements to a new geometry.
62 * Invert the selection to avoid the need to keep track of both cases in the code. */
63 const Field<bool> selection = fn::invert_boolean_field(
64 params.extract_input<Field<bool>>("Selection"));
65
66 const NodeGeometryDeleteGeometry &storage = node_storage(params.node());
67 const AttrDomain domain = AttrDomain(storage.domain);
69
70 const NodeAttributeFilter &attribute_filter = params.get_attribute_filter("Geometry");
71
72 if (domain == AttrDomain::Instance) {
73 bool is_error;
74 geometry::separate_geometry(geometry_set, domain, mode, selection, attribute_filter, is_error);
75 }
76 else {
77 geometry_set.modify_geometry_sets([&](GeometrySet &geometry_set) {
78 bool is_error;
79 /* Invert here because we want to keep the things not in the selection. */
81 geometry_set, domain, mode, selection, attribute_filter, is_error);
82 });
83 }
84
85 params.set_output("Geometry", std::move(geometry_set));
86}
87
88static void node_rna(StructRNA *srna)
89{
90 static const EnumPropertyItem mode_items[] = {
91 {GEO_NODE_DELETE_GEOMETRY_MODE_ALL, "ALL", 0, "All", ""},
92 {GEO_NODE_DELETE_GEOMETRY_MODE_EDGE_FACE, "EDGE_FACE", 0, "Only Edges & Faces", ""},
93 {GEO_NODE_DELETE_GEOMETRY_MODE_ONLY_FACE, "ONLY_FACE", 0, "Only Faces", ""},
94 {0, nullptr, 0, nullptr, nullptr},
95 };
96
98 "mode",
99 "Mode",
100 "Which parts of the mesh component to delete",
101 mode_items,
104
106 "domain",
107 "Domain",
108 "Which domain to delete in",
111 int(AttrDomain::Point));
112}
113
114static void node_register()
115{
116 static blender::bke::bNodeType ntype;
117
118 geo_node_type_base(&ntype, "GeometryNodeDeleteGeometry", GEO_NODE_DELETE_GEOMETRY);
119 ntype.ui_name = "Delete Geometry";
120 ntype.ui_description = "Remove selected elements of a geometry";
121 ntype.enum_name_legacy = "DELETE_GEOMETRY";
124 ntype, "NodeGeometryDeleteGeometry", node_free_standard_storage, node_copy_standard_storage);
125
126 ntype.initfunc = node_init;
127 ntype.declare = node_declare;
131
132 node_rna(ntype.rna_ext.srna);
133}
135
136} // namespace blender::nodes::node_geo_delete_geometry_cc
#define NODE_STORAGE_FUNCS(StorageT)
Definition BKE_node.hh:1215
#define NODE_CLASS_GEOMETRY
Definition BKE_node.hh:447
#define GEO_NODE_DELETE_GEOMETRY
#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
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_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, 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:4227