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