Blender V5.3
node_geo_input_mesh_edge_vertices.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 "DNA_mesh_types.h"
6
8
10
12{
13 b.add_output<decl::Int>("Vertex Index 1"_ustr)
14 .structure_type(StructureType::Field)
15 .description("The index of the first vertex in the edge");
16 b.add_output<decl::Int>("Vertex Index 2"_ustr)
17 .structure_type(StructureType::Field)
18 .description("The index of the second vertex in the edge");
19 b.add_output<decl::Vector>("Position 1"_ustr)
20 .structure_type(StructureType::Field)
21 .description("The position of the first vertex in the edge");
22 b.add_output<decl::Vector>("Position 2"_ustr)
23 .structure_type(StructureType::Field)
24 .description("The position of the second vertex in the edge");
25}
26
27enum class VertNumber { V1, V2 };
28
30 const VertNumber vertex,
31 const AttrDomain domain)
32{
33 const Span<int2> edges = mesh.edges();
34 if (domain == AttrDomain::Edge) {
35 if (vertex == VertNumber::V1) {
36 return VArray<int>::from_func(edges.size(), [edges](const int i) { return edges[i][0]; });
37 }
38 return VArray<int>::from_func(edges.size(), [edges](const int i) { return edges[i][1]; });
39 }
40 return {};
41}
42
44 private:
45 VertNumber vertex_;
46
47 public:
49 : bke::MeshFieldInput(CPPType::get<int>(), "Edge Vertices Field"), vertex_(vertex)
50 {
51 }
52
54 const AttrDomain domain,
55 const IndexMask & /*mask*/) const final
56 {
57 return construct_edge_verts_gvarray(mesh, vertex_, domain);
58 }
59
60 void hash_unique(UniqueHashBytes &hash, fn::FieldHashDeep & /*deep_hash_cache*/) const override
61 {
62 static constexpr int8_t id = 0;
63 hash.add(&id);
64 hash.add(vertex_);
65 }
66
67 std::optional<AttrDomain> preferred_domain(const Mesh & /*mesh*/) const override
68 {
69 return AttrDomain::Edge;
70 }
71};
72
74 const VertNumber vertex,
75 const AttrDomain domain)
76{
77 const Span<float3> positions = mesh.vert_positions();
78 const Span<int2> edges = mesh.edges();
79
80 if (vertex == VertNumber::V1) {
81 return mesh.attributes().adapt_domain<float3>(
83 edges.size(), [positions, edges](const int i) { return positions[edges[i][0]]; }),
84 AttrDomain::Edge,
85 domain);
86 }
87 return mesh.attributes().adapt_domain<float3>(
89 edges.size(), [positions, edges](const int i) { return positions[edges[i][1]]; }),
90 AttrDomain::Edge,
91 domain);
92}
93
95 private:
96 VertNumber vertex_;
97
98 public:
100 : bke::MeshFieldInput(CPPType::get<float3>(), "Edge Position Field"), vertex_(vertex)
101 {
102 }
103
105 const AttrDomain domain,
106 const IndexMask & /*mask*/) const final
107 {
108 return construct_edge_positions_gvarray(mesh, vertex_, domain);
109 }
110
111 void hash_unique(UniqueHashBytes &hash, fn::FieldHashDeep & /*deep_hash_cache*/) const override
112 {
113 static constexpr int8_t id = 0;
114 hash.add(&id);
115 hash.add(vertex_);
116 }
117
118 std::optional<AttrDomain> preferred_domain(const Mesh & /*mesh*/) const override
119 {
120 return AttrDomain::Edge;
121 }
122};
123
133
134static void node_register()
135{
136 static bke::bNodeType ntype;
138 &ntype, "GeometryNodeInputMeshEdgeVertices"_ustr, GEO_NODE_INPUT_MESH_EDGE_VERTICES);
139 ntype.ui_name = "Edge Vertices";
140 ntype.ui_description = "Retrieve topology information relating to each edge of a mesh";
141 ntype.enum_name_legacy = "MESH_EDGE_VERTICES";
142 ntype.nclass = NODE_CLASS_INPUT;
143 ntype.declare = node_declare;
146}
148
149} // namespace blender::nodes::node_geo_input_mesh_edge_vertices_cc
#define NODE_CLASS_INPUT
Definition BKE_node.hh:478
#define GEO_NODE_INPUT_MESH_EDGE_VERTICES
#define final(a, b, c)
Definition BLI_hash_c.hh:21
#define NOD_REGISTER_NODE(REGISTER_FUNC)
constexpr int64_t size() const
Definition BLI_span.hh:256
static VArray from_func(const int64_t size, GetFunc get_func)
uint64_t hash() const
Definition field.cc:185
static Field from_input(Args &&...args)
void set_output(const UString identifier, T &&value)
void hash_unique(UniqueHashBytes &hash, fn::FieldHashDeep &) const override
GVArray get_varray_for_context(const Mesh &mesh, const AttrDomain domain, const IndexMask &) const final
std::optional< AttrDomain > preferred_domain(const Mesh &) const override
void hash_unique(UniqueHashBytes &hash, fn::FieldHashDeep &) const override
GVArray get_varray_for_context(const Mesh &mesh, const AttrDomain domain, const IndexMask &) const final
#define vertex
void node_register_type(bNodeType &ntype)
Definition node.cc:2920
static VArray< int > construct_edge_verts_gvarray(const Mesh &mesh, const VertNumber vertex, const AttrDomain domain)
static VArray< float3 > construct_edge_positions_gvarray(const Mesh &mesh, const VertNumber vertex, const AttrDomain domain)
VecBase< float, 3 > float3
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