Blender V4.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 "BKE_mesh.hh"
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>::ForContainer(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>::ForContainer(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, GEO_NODE_INPUT_MESH_VERTEX_NEIGHBORS, "Vertex Neighbors", NODE_CLASS_INPUT);
111 ntype.declare = node_declare;
114}
116
117} // namespace blender::nodes::node_geo_input_mesh_vertex_neighbors_cc
#define NODE_CLASS_INPUT
Definition BKE_node.hh:404
#define NOD_REGISTER_NODE(REGISTER_FUNC)
static VArray ForContainer(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
local_group_size(16, 16) .push_constant(Type b
draw_view push_constant(Type::INT, "radiance_src") .push_constant(Type capture_info_buf storage_buf(1, Qualifier::READ, "ObjectBounds", "bounds_buf[]") .push_constant(Type draw_view int
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
void count_indices(Span< int > indices, MutableSpan< int > counts)
void node_register_type(bNodeType *ntype)
Definition node.cc:1708
void geo_node_type_base(blender::bke::bNodeType *ntype, int type, const char *name, short nclass)
unsigned __int64 uint64_t
Definition stdint.h:90
Defines a node type.
Definition BKE_node.hh:218
NodeGeometryExecFunction geometry_node_execute
Definition BKE_node.hh:339
NodeDeclareFunction declare
Definition BKE_node.hh:347