Blender V5.0
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
8#include "UI_resources.hh"
9
10#include "RNA_enum_types.hh"
11
12#include "node_geometry_util.hh"
13
15
17{
18 b.add_input<decl::Geometry>("Geometry")
19 .description(
20 "Geometry to get the domain sizes of. Only the root geometry is considered, not nested "
21 "instances");
22 auto &total_points = b.add_output<decl::Int>("Point Count")
23 .make_available([](bNode &node) {
24 node.custom1 = int16_t(GeometryComponent::Type::Mesh);
25 })
26 .available(false);
27 auto &total_edges = b.add_output<decl::Int>("Edge Count")
28 .make_available([](bNode &node) {
29 node.custom1 = int16_t(GeometryComponent::Type::Mesh);
30 })
31 .available(false);
32 auto &total_faces = b.add_output<decl::Int>("Face Count")
33 .make_available([](bNode &node) {
34 node.custom1 = int16_t(GeometryComponent::Type::Mesh);
35 })
36 .available(false);
37 auto &total_corners = b.add_output<decl::Int>("Face Corner Count")
38 .make_available([](bNode &node) {
39 node.custom1 = int16_t(GeometryComponent::Type::Mesh);
40 })
41 .available(false);
42 auto &total_curves = b.add_output<decl::Int>("Spline Count")
43 .make_available([](bNode &node) {
44 node.custom1 = int16_t(GeometryComponent::Type::Curve);
45 })
46 .available(false);
47 auto &total_instances = b.add_output<decl::Int>("Instance Count")
48 .make_available([](bNode &node) {
49 node.custom1 = int16_t(GeometryComponent::Type::Instance);
50 })
51 .available(false);
52 auto &total_layers = b.add_output<decl::Int>("Layer Count")
53 .make_available([](bNode &node) {
54 node.custom1 = int16_t(GeometryComponent::Type::GreasePencil);
55 })
56 .available(false);
57
58 const bNode *node = b.node_or_null();
59 if (node != nullptr) {
60 switch (GeometryComponent::Type(node->custom1)) {
61 case GeometryComponent::Type::Mesh:
62 total_points.available(true);
63 total_edges.available(true);
64 total_faces.available(true);
65 total_corners.available(true);
66 break;
67 case GeometryComponent::Type::Curve:
68 total_points.available(true);
69 total_curves.available(true);
70 break;
71 case GeometryComponent::Type::PointCloud:
72 total_points.available(true);
73 break;
74 case GeometryComponent::Type::Instance:
75 total_instances.available(true);
76 break;
77 case GeometryComponent::Type::GreasePencil:
78 total_layers.available(true);
79 break;
80 default:
82 }
83 }
84}
85
86static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
87{
88 layout->prop(ptr, "component", UI_ITEM_NONE, "", ICON_NONE);
89}
90
91static void node_init(bNodeTree * /*tree*/, bNode *node)
92{
93 node->custom1 = int16_t(GeometryComponent::Type::Mesh);
94}
95
97{
98 const GeometryComponent::Type component = GeometryComponent::Type(params.node().custom1);
99 const GeometrySet geometry_set = params.extract_input<GeometrySet>("Geometry");
100
101 switch (component) {
102 case GeometryComponent::Type::Mesh: {
103 if (const MeshComponent *component = geometry_set.get_component<MeshComponent>()) {
104 const AttributeAccessor attributes = *component->attributes();
105 params.set_output("Point Count", attributes.domain_size(AttrDomain::Point));
106 params.set_output("Edge Count", attributes.domain_size(AttrDomain::Edge));
107 params.set_output("Face Count", attributes.domain_size(AttrDomain::Face));
108 params.set_output("Face Corner Count", attributes.domain_size(AttrDomain::Corner));
109 }
110 else {
111 params.set_default_remaining_outputs();
112 }
113 break;
114 }
115 case GeometryComponent::Type::Curve: {
116 if (const CurveComponent *component = geometry_set.get_component<CurveComponent>()) {
117 const AttributeAccessor attributes = *component->attributes();
118 params.set_output("Point Count", attributes.domain_size(AttrDomain::Point));
119 params.set_output("Spline Count", attributes.domain_size(AttrDomain::Curve));
120 }
121 else {
122 params.set_default_remaining_outputs();
123 }
124 break;
125 }
126 case GeometryComponent::Type::PointCloud: {
127 if (const PointCloudComponent *component = geometry_set.get_component<PointCloudComponent>())
128 {
129 const AttributeAccessor attributes = *component->attributes();
130 params.set_output("Point Count", attributes.domain_size(AttrDomain::Point));
131 }
132 else {
133 params.set_default_remaining_outputs();
134 }
135 break;
136 }
137 case GeometryComponent::Type::Instance: {
138 if (const InstancesComponent *component = geometry_set.get_component<InstancesComponent>()) {
139 const AttributeAccessor attributes = *component->attributes();
140 params.set_output("Instance Count", attributes.domain_size(AttrDomain::Instance));
141 }
142 else {
143 params.set_default_remaining_outputs();
144 }
145 break;
146 }
147 case GeometryComponent::Type::GreasePencil: {
148 if (const GreasePencilComponent *component =
149 geometry_set.get_component<GreasePencilComponent>())
150 {
151 const AttributeAccessor attributes = *component->attributes();
152 params.set_output("Layer Count", attributes.domain_size(AttrDomain::Layer));
153 }
154 else {
155 params.set_default_remaining_outputs();
156 }
157 break;
158 }
159 default:
161 }
162}
163
164static void node_rna(StructRNA *srna)
165{
167 "component",
168 "Component",
169 "",
173}
174
175static void node_register()
176{
177 static blender::bke::bNodeType ntype;
178 geo_node_type_base(&ntype, "GeometryNodeAttributeDomainSize", GEO_NODE_ATTRIBUTE_DOMAIN_SIZE);
179 ntype.ui_name = "Domain Size";
180 ntype.ui_description = "Retrieve the number of elements in a geometry for each attribute domain";
181 ntype.enum_name_legacy = "ATTRIBUTE_DOMAIN_SIZE";
184 ntype.declare = node_declare;
186 ntype.initfunc = node_init;
187
189
190 node_rna(ntype.rna_ext.srna);
191}
193
194} // namespace blender::nodes::node_geo_attribute_domain_size_cc
#define NODE_CLASS_ATTRIBUTE
Definition BKE_node.hh:462
#define GEO_NODE_ATTRIBUTE_DOMAIN_SIZE
#define BLI_assert_unreachable()
Definition BLI_assert.h:93
#define NOD_REGISTER_NODE(REGISTER_FUNC)
#define NOD_inline_enum_accessors(member)
#define UI_ITEM_NONE
int domain_size(const AttrDomain domain) const
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
void node_register_type(bNodeType &ntype)
Definition node.cc:2416
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)
const EnumPropertyItem rna_enum_geometry_component_type_items[]
Definition rna_space.cc:44
StructRNA * srna
int16_t custom1
const GeometryComponent * get_component(GeometryComponent::Type component_type) const
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