Blender  V3.3
node_geo_attribute_domain_size.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 #include "UI_interface.h"
4 #include "UI_resources.h"
5 
6 #include "node_geometry_util.hh"
7 
9 
11 {
12  b.add_input<decl::Geometry>("Geometry");
13  b.add_output<decl::Int>("Point Count").make_available([](bNode &node) {
14  node.custom1 = GEO_COMPONENT_TYPE_MESH;
15  });
16  b.add_output<decl::Int>("Edge Count").make_available([](bNode &node) {
17  node.custom1 = GEO_COMPONENT_TYPE_MESH;
18  });
19  b.add_output<decl::Int>("Face Count").make_available([](bNode &node) {
20  node.custom1 = GEO_COMPONENT_TYPE_MESH;
21  });
22  b.add_output<decl::Int>("Face Corner Count").make_available([](bNode &node) {
23  node.custom1 = GEO_COMPONENT_TYPE_MESH;
24  });
25  b.add_output<decl::Int>("Spline Count").make_available([](bNode &node) {
27  });
28  b.add_output<decl::Int>("Instance Count").make_available([](bNode &node) {
30  });
31 }
32 
33 static void node_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
34 {
35  uiItemR(layout, ptr, "component", 0, "", ICON_NONE);
36 }
37 
39 {
40  node->custom1 = GEO_COMPONENT_TYPE_MESH;
41 }
42 
44 {
45  bNodeSocket *point_socket = (bNodeSocket *)node->outputs.first;
46  bNodeSocket *edge_socket = point_socket->next;
47  bNodeSocket *face_socket = edge_socket->next;
48  bNodeSocket *face_corner_socket = face_socket->next;
49  bNodeSocket *spline_socket = face_corner_socket->next;
50  bNodeSocket *instances_socket = spline_socket->next;
51 
53  point_socket,
54  ELEM(node->custom1,
60  nodeSetSocketAvailability(ntree, face_corner_socket, node->custom1 == GEO_COMPONENT_TYPE_MESH);
61  nodeSetSocketAvailability(ntree, spline_socket, node->custom1 == GEO_COMPONENT_TYPE_CURVE);
63  ntree, instances_socket, node->custom1 == GEO_COMPONENT_TYPE_INSTANCES);
64 }
65 
67 {
69  const GeometrySet geometry_set = params.extract_input<GeometrySet>("Geometry");
70 
71  switch (component) {
73  if (const MeshComponent *component = geometry_set.get_component_for_read<MeshComponent>()) {
74  const AttributeAccessor attributes = *component->attributes();
75  params.set_output("Point Count", attributes.domain_size(ATTR_DOMAIN_POINT));
76  params.set_output("Edge Count", attributes.domain_size(ATTR_DOMAIN_EDGE));
77  params.set_output("Face Count", attributes.domain_size(ATTR_DOMAIN_FACE));
78  params.set_output("Face Corner Count", attributes.domain_size(ATTR_DOMAIN_CORNER));
79  }
80  else {
81  params.set_default_remaining_outputs();
82  }
83  break;
84  }
86  if (const CurveComponent *component =
87  geometry_set.get_component_for_read<CurveComponent>()) {
88  const AttributeAccessor attributes = *component->attributes();
89  params.set_output("Point Count", attributes.domain_size(ATTR_DOMAIN_POINT));
90  params.set_output("Spline Count", attributes.domain_size(ATTR_DOMAIN_CURVE));
91  }
92  else {
93  params.set_default_remaining_outputs();
94  }
95  break;
96  }
98  if (const PointCloudComponent *component =
100  const AttributeAccessor attributes = *component->attributes();
101  params.set_output("Point Count", attributes.domain_size(ATTR_DOMAIN_POINT));
102  }
103  else {
104  params.set_default_remaining_outputs();
105  }
106  break;
107  }
109  if (const InstancesComponent *component =
110  geometry_set.get_component_for_read<InstancesComponent>()) {
111  const AttributeAccessor attributes = *component->attributes();
112  params.set_output("Instance Count", attributes.domain_size(ATTR_DOMAIN_INSTANCE));
113  }
114  else {
115  params.set_default_remaining_outputs();
116  }
117  break;
118  }
119  default:
121  }
122 }
123 
124 } // namespace blender::nodes::node_geo_attribute_domain_size_cc
125 
127 {
129 
130  static bNodeType ntype;
137 
138  nodeRegisterType(&ntype);
139 }
@ ATTR_DOMAIN_CURVE
Definition: BKE_attribute.h:31
@ ATTR_DOMAIN_INSTANCE
Definition: BKE_attribute.h:32
@ ATTR_DOMAIN_POINT
Definition: BKE_attribute.h:27
@ ATTR_DOMAIN_FACE
Definition: BKE_attribute.h:29
@ ATTR_DOMAIN_CORNER
Definition: BKE_attribute.h:30
@ ATTR_DOMAIN_EDGE
Definition: BKE_attribute.h:28
GeometryComponentType
@ GEO_COMPONENT_TYPE_MESH
@ GEO_COMPONENT_TYPE_POINT_CLOUD
@ GEO_COMPONENT_TYPE_INSTANCES
@ GEO_COMPONENT_TYPE_CURVE
void nodeSetSocketAvailability(struct bNodeTree *ntree, struct bNodeSocket *sock, bool is_available)
Definition: node.cc:3664
void node_type_init(struct bNodeType *ntype, void(*initfunc)(struct bNodeTree *ntree, struct bNode *node))
Definition: node.cc:4390
#define GEO_NODE_ATTRIBUTE_DOMAIN_SIZE
Definition: BKE_node.h:1477
#define NODE_CLASS_ATTRIBUTE
Definition: BKE_node.h:360
void nodeRegisterType(struct bNodeType *ntype)
Definition: node.cc:1357
#define BLI_assert_unreachable()
Definition: BLI_assert.h:93
#define UNUSED(x)
#define ELEM(...)
static uint8 component(Color32 c, uint i)
Definition: ColorBlock.cpp:108
void uiItemR(uiLayout *layout, struct PointerRNA *ptr, const char *propname, int flag, const char *name, int icon)
int domain_size(const eAttrDomain domain) const
OperationNode * node
void * tree
bNodeTree * ntree
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
static void node_update(bNodeTree *ntree, bNode *node)
static void node_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
static void node_init(bNodeTree *UNUSED(tree), bNode *node)
static const pxr::TfToken b("b", pxr::TfToken::Immortal)
static void node_init(const struct bContext *C, bNodeTree *ntree, bNode *node)
Definition: node.cc:1082
void register_node_type_geo_attribute_domain_size()
void geo_node_type_base(bNodeType *ntype, int type, const char *name, short nclass)
const GeometryComponent * get_component_for_read(GeometryComponentType component_type) const
struct bNodeSocket * next
Defines a node type.
Definition: BKE_node.h:226
NodeGeometryExecFunction geometry_node_execute
Definition: BKE_node.h:316
void(* updatefunc)(struct bNodeTree *ntree, struct bNode *node)
Definition: BKE_node.h:265
void(* draw_buttons)(struct uiLayout *, struct bContext *C, struct PointerRNA *ptr)
Definition: BKE_node.h:244
NodeDeclareFunction declare
Definition: BKE_node.h:324
PointerRNA * ptr
Definition: wm_files.c:3480