Blender V5.0
node_geo_input_mesh_vertex_neighbors.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 "BLI_array_utils.hh"
6
7#include "DNA_mesh_types.h"
8
10
12
14{
15 b.add_output<decl::Int>("Vertex Count")
16 .field_source()
18 "The number of vertices connected to this vertex with an edge, "
19 "equal to the number of connected edges");
20 b.add_output<decl::Int>("Face Count")
21 .field_source()
22 .description("Number of faces that contain the vertex");
23}
24
26 public:
27 VertexCountFieldInput() : bke::MeshFieldInput(CPPType::get<int>(), "Vertex Count Field")
28 {
30 }
31
33 const AttrDomain domain,
34 const IndexMask & /*mask*/) const final
35 {
36 if (domain != AttrDomain::Point) {
37 return {};
38 }
39 Array<int> counts(mesh.verts_num, 0);
40 array_utils::count_indices(mesh.edges().cast<int>(), counts);
41 return VArray<int>::from_container(std::move(counts));
42 }
43
44 uint64_t hash() const override
45 {
46 /* Some random constant hash. */
47 return 23574528465;
48 }
49
50 bool is_equal_to(const fn::FieldNode &other) const override
51 {
52 return dynamic_cast<const VertexCountFieldInput *>(&other) != nullptr;
53 }
54
55 std::optional<AttrDomain> preferred_domain(const Mesh & /*mesh*/) const override
56 {
57 return AttrDomain::Point;
58 }
59};
60
62 public:
63 VertexFaceCountFieldInput() : bke::MeshFieldInput(CPPType::get<int>(), "Vertex Face Count Field")
64 {
66 }
67
69 const AttrDomain domain,
70 const IndexMask & /*mask*/) const final
71 {
72 if (domain != AttrDomain::Point) {
73 return {};
74 }
75 Array<int> counts(mesh.verts_num, 0);
76 array_utils::count_indices(mesh.corner_verts(), counts);
77 return VArray<int>::from_container(std::move(counts));
78 }
79
80 uint64_t hash() const override
81 {
82 /* Some random constant hash. */
83 return 3462374322;
84 }
85
86 bool is_equal_to(const fn::FieldNode &other) const override
87 {
88 return dynamic_cast<const VertexFaceCountFieldInput *>(&other) != nullptr;
89 }
90
91 std::optional<AttrDomain> preferred_domain(const Mesh & /*mesh*/) const override
92 {
93 return AttrDomain::Point;
94 }
95};
96
98{
99 Field<int> vertex_field{std::make_shared<VertexCountFieldInput>()};
100 Field<int> face_field{std::make_shared<VertexFaceCountFieldInput>()};
101
102 params.set_output("Vertex Count", std::move(vertex_field));
103 params.set_output("Face Count", std::move(face_field));
104}
105
106static void node_register()
107{
108 static blender::bke::bNodeType ntype;
110 &ntype, "GeometryNodeInputMeshVertexNeighbors", GEO_NODE_INPUT_MESH_VERTEX_NEIGHBORS);
111 ntype.ui_name = "Vertex Neighbors";
112 ntype.ui_description = "Retrieve topology information relating to each vertex of a mesh";
113 ntype.enum_name_legacy = "MESH_VERTEX_NEIGHBORS";
114 ntype.nclass = NODE_CLASS_INPUT;
115 ntype.declare = node_declare;
118}
120
121} // namespace blender::nodes::node_geo_input_mesh_vertex_neighbors_cc
#define NODE_CLASS_INPUT
Definition BKE_node.hh:447
#define GEO_NODE_INPUT_MESH_VERTEX_NEIGHBORS
#define final(a, b, c)
Definition BLI_hash.h:19
#define NOD_REGISTER_NODE(REGISTER_FUNC)
unsigned long long int uint64_t
static VArray from_container(ContainerT container)
GVArray get_varray_for_context(const Mesh &mesh, const AttrDomain domain, const IndexMask &) const final
GVArray get_varray_for_context(const Mesh &mesh, const AttrDomain domain, const IndexMask &) const final
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
void count_indices(Span< int > indices, MutableSpan< int > counts)
void node_register_type(bNodeType &ntype)
Definition node.cc:2416
void geo_node_type_base(blender::bke::bNodeType *ntype, std::string idname, const std::optional< int16_t > legacy_type)
Defines a node type.
Definition BKE_node.hh:238
std::string ui_description
Definition BKE_node.hh:244
NodeGeometryExecFunction geometry_node_execute
Definition BKE_node.hh:354
const char * enum_name_legacy
Definition BKE_node.hh:247
NodeDeclareFunction declare
Definition BKE_node.hh:362