Blender V5.3
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"_ustr)
16 .structure_type(StructureType::Field)
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"_ustr)
21 .structure_type(StructureType::Field)
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 const AttrDomain domain,
31 const IndexMask & /*mask*/) const final
32 {
33 if (domain != AttrDomain::Point) {
34 return {};
35 }
36 Array<int> counts(mesh.verts_num, 0);
37 array_utils::count_indices(mesh.edges().cast<int>(), counts);
38 return VArray<int>::from_container(std::move(counts));
39 }
40
41 void hash_unique(UniqueHashBytes &hash, fn::FieldHashDeep & /*deep_hash_cache*/) const override
42 {
43 static constexpr int8_t id = 0;
44 hash.add(&id);
45 }
46
47 std::optional<AttrDomain> preferred_domain(const Mesh & /*mesh*/) const override
48 {
49 return AttrDomain::Point;
50 }
51};
52
54 public:
55 VertexFaceCountFieldInput() : bke::MeshFieldInput(CPPType::get<int>(), "Vertex Face Count Field")
56 {
57 }
58
60 const AttrDomain domain,
61 const IndexMask & /*mask*/) const final
62 {
63 if (domain != AttrDomain::Point) {
64 return {};
65 }
66 Array<int> counts(mesh.verts_num, 0);
67 array_utils::count_indices(mesh.corner_verts(), counts);
68 return VArray<int>::from_container(std::move(counts));
69 }
70
71 void hash_unique(UniqueHashBytes &hash, fn::FieldHashDeep & /*deep_hash_cache*/) const override
72 {
73 static constexpr int8_t id = 0;
74 hash.add(&id);
75 }
76
77 std::optional<AttrDomain> preferred_domain(const Mesh & /*mesh*/) const override
78 {
79 return AttrDomain::Point;
80 }
81};
82
84{
85 params.set_output("Vertex Count"_ustr, Field<int>::from_input<VertexCountFieldInput>());
87}
88
89static void node_register()
90{
91 static bke::bNodeType ntype;
93 &ntype, "GeometryNodeInputMeshVertexNeighbors"_ustr, GEO_NODE_INPUT_MESH_VERTEX_NEIGHBORS);
94 ntype.ui_name = "Vertex Neighbors";
95 ntype.ui_description = "Retrieve topology information relating to each vertex of a mesh";
96 ntype.enum_name_legacy = "MESH_VERTEX_NEIGHBORS";
98 ntype.declare = node_declare;
101}
103
104} // namespace blender::nodes::node_geo_input_mesh_vertex_neighbors_cc
#define NODE_CLASS_INPUT
Definition BKE_node.hh:478
#define GEO_NODE_INPUT_MESH_VERTEX_NEIGHBORS
#define final(a, b, c)
Definition BLI_hash_c.hh:21
#define NOD_REGISTER_NODE(REGISTER_FUNC)
static VArray from_container(ContainerT container)
uint64_t hash() const
Definition field.cc:185
static Field from_input(Args &&...args)
void set_output(const UString identifier, T &&value)
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
void count_indices(Span< int > indices, MutableSpan< int > counts)
void node_register_type(bNodeType &ntype)
Definition node.cc:2920
void geo_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
signed char int8_t
Definition BKE_text.h:76
Defines a node type.
Definition BKE_node.hh:265
std::string ui_description
Definition BKE_node.hh:271
NodeGeometryExecFunction geometry_node_execute
Definition BKE_node.hh:385
const char * enum_name_legacy
Definition BKE_node.hh:274
NodeDeclareFunction declare
Definition BKE_node.hh:393