Blender V5.3
node_geo_attribute_domain_size.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 "BKE_curves.hh"
9#include "BKE_instances.hh"
10
11#include "DNA_mesh_types.h"
13
15#include "UI_resources.hh"
16
17#include "RNA_enum_types.hh"
18
19#include "node_geometry_util.hh"
20
22
24{
25 b.add_input<decl::Geometry>("Geometry"_ustr)
26 .description(
27 "Geometry to get the domain sizes of. Only the root geometry is considered, not nested "
28 "instances");
29 auto &total_points = b.add_output<decl::Int>("Point Count"_ustr)
30 .make_available([](bNode &node) {
32 })
33 .available(false);
34 auto &total_edges = b.add_output<decl::Int>("Edge Count"_ustr)
35 .make_available([](bNode &node) {
37 })
38 .available(false);
39 auto &total_faces = b.add_output<decl::Int>("Face Count"_ustr)
40 .make_available([](bNode &node) {
42 })
43 .available(false);
44 auto &total_corners = b.add_output<decl::Int>("Face Corner Count"_ustr)
45 .make_available([](bNode &node) {
47 })
48 .available(false);
49 auto &total_curves = b.add_output<decl::Int>("Spline Count"_ustr)
50 .make_available([](bNode &node) {
52 })
53 .available(false);
54 auto &total_instances = b.add_output<decl::Int>("Instance Count"_ustr)
55 .make_available([](bNode &node) {
57 })
58 .available(false);
59 auto &total_layers = b.add_output<decl::Int>("Layer Count"_ustr)
60 .make_available([](bNode &node) {
62 })
63 .available(false);
64
65 const bNode *node = b.node_or_null();
66 if (node != nullptr) {
67 switch (GeometryComponent::Type(node->custom1)) {
69 total_points.available(true);
70 total_edges.available(true);
71 total_faces.available(true);
72 total_corners.available(true);
73 break;
75 total_points.available(true);
76 total_curves.available(true);
77 break;
79 total_points.available(true);
80 break;
82 total_instances.available(true);
83 break;
85 total_layers.available(true);
86 break;
87 default:
88 break;
89 }
90 }
91}
92
93static void node_layout(ui::Layout &layout, bContext * /*C*/, PointerRNA *ptr)
94{
95 layout.prop(ptr, "component", UI_ITEM_NONE, "", ICON_NONE);
96}
97
98static void node_init(bNodeTree * /*tree*/, bNode *node)
99{
101}
102
104{
106 const GeometrySet geometry_set = params.extract_input<GeometrySet>("Geometry"_ustr);
107
108 switch (component) {
110 if (const Mesh *mesh = geometry_set.get_mesh()) {
111 const AttributeAccessor attributes = mesh->attributes();
112 params.set_output("Point Count"_ustr, attributes.domain_size(AttrDomain::Point));
113 params.set_output("Edge Count"_ustr, attributes.domain_size(AttrDomain::Edge));
114 params.set_output("Face Count"_ustr, attributes.domain_size(AttrDomain::Face));
115 params.set_output("Face Corner Count"_ustr, attributes.domain_size(AttrDomain::Corner));
116 }
117 else {
119 }
120 break;
121 }
123 if (const Curves *curves_id = geometry_set.get_curves()) {
124 const AttributeAccessor attributes = curves_id->geometry.wrap().attributes();
125 params.set_output("Point Count"_ustr, attributes.domain_size(AttrDomain::Point));
126 params.set_output("Spline Count"_ustr, attributes.domain_size(AttrDomain::Curve));
127 }
128 else {
130 }
131 break;
132 }
134 if (const PointCloud *pointcloud = geometry_set.get_pointcloud()) {
135 const AttributeAccessor attributes = pointcloud->attributes();
136 params.set_output("Point Count"_ustr, attributes.domain_size(AttrDomain::Point));
137 }
138 else {
140 }
141 break;
142 }
144 if (const bke::Instances *instances = geometry_set.get_instances()) {
145 const AttributeAccessor attributes = instances->attributes();
146 params.set_output("Instance Count"_ustr, attributes.domain_size(AttrDomain::Instance));
147 }
148 else {
150 }
151 break;
152 }
154 if (const GreasePencil *grease_pencil = geometry_set.get_grease_pencil()) {
155 const AttributeAccessor attributes = grease_pencil->attributes();
156 params.set_output("Layer Count"_ustr, attributes.domain_size(AttrDomain::Layer));
157 }
158 else {
160 }
161 break;
162 }
163 default:
165 break;
166 }
167}
168
169static void node_rna(StructRNA *srna)
170{
172 srna,
173 "component",
174 "Component",
175 "",
179 [](bContext * /*C*/, PointerRNA * /*ptr*/, PropertyRNA * /*prop*/, bool *r_free) {
180 *r_free = true;
182 [](const EnumPropertyItem &item) -> bool {
183 return ELEM(item.value,
189 });
190 });
191}
192
193static void node_register()
194{
195 static bke::bNodeType ntype;
197 &ntype, "GeometryNodeAttributeDomainSize"_ustr, GEO_NODE_ATTRIBUTE_DOMAIN_SIZE);
198 ntype.ui_name = "Domain Size";
199 ntype.ui_description = "Retrieve the number of elements in a geometry for each attribute domain";
200 ntype.enum_name_legacy = "ATTRIBUTE_DOMAIN_SIZE";
203 ntype.declare = node_declare;
205 ntype.initfunc = node_init;
206
208
209 node_rna(ntype.rna_ext.srna);
210}
212
213} // namespace blender::nodes::node_geo_attribute_domain_size_cc
Low-level operations for curves.
Low-level operations for grease pencil.
#define NODE_CLASS_ATTRIBUTE
Definition BKE_node.hh:493
#define GEO_NODE_ATTRIBUTE_DOMAIN_SIZE
#define NOD_REGISTER_NODE(REGISTER_FUNC)
#define NOD_inline_enum_accessors(member)
#define UI_ITEM_NONE
#define ELEM(...)
int domain_size(const AttrDomain domain) const
T extract_input(const UString identifier)
void set_output(const UString identifier, T &&value)
void node_register_type(bNodeType &ntype)
Definition node.cc:2920
static void node_layout(ui::Layout &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)
const EnumPropertyItem * enum_items_filter(const EnumPropertyItem *original_item_array, FunctionRef< bool(const EnumPropertyItem &item)> fn)
const EnumPropertyItem rna_enum_geometry_component_type_items[]
Definition rna_space.cc:51
void geo_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
signed short int16_t
Definition BKE_text.h:77
const GreasePencil * get_grease_pencil() const
const Curves * get_curves() const
const Instances * get_instances() const
const PointCloud * get_pointcloud() const
const Mesh * get_mesh() const
Defines a node type.
Definition BKE_node.hh:265
void(*) draw_buttons(ui::Layout &, bContext *C, PointerRNA *ptr)
Definition BKE_node.hh:290
std::string ui_description
Definition BKE_node.hh:271
NodeGeometryExecFunction geometry_node_execute
Definition BKE_node.hh:385
void(*) initfunc(bNodeTree *ntree, bNode *node)
Definition BKE_node.hh:320
const char * enum_name_legacy
Definition BKE_node.hh:274
NodeDeclareFunction declare
Definition BKE_node.hh:393
void prop(PointerRNA *ptr, PropertyRNA *prop, int index, int value, eUI_Item_Flag flag, std::optional< StringRef > name_opt, int icon, std::optional< StringRef > placeholder=std::nullopt)