Blender V5.0
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")
14 .field_source()
15 .description("The index of the first vertex in the edge");
16 b.add_output<decl::Int>("Vertex Index 2")
17 .field_source()
18 .description("The index of the second vertex in the edge");
19 b.add_output<decl::Vector>("Position 1")
20 .field_source()
21 .description("The position of the first vertex in the edge");
22 b.add_output<decl::Vector>("Position 2")
23 .field_source()
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 {
52 }
53
55 const AttrDomain domain,
56 const IndexMask & /*mask*/) const final
57 {
58 return construct_edge_verts_gvarray(mesh, vertex_, domain);
59 }
60
61 uint64_t hash() const override
62 {
63 return vertex_ == VertNumber::V1 ? 23847562893465 : 92384598734567;
64 }
65
66 bool is_equal_to(const fn::FieldNode &other) const override
67 {
68 if (const EdgeVertsInput *other_field = dynamic_cast<const EdgeVertsInput *>(&other)) {
69 return vertex_ == other_field->vertex_;
70 }
71 return false;
72 }
73
74 std::optional<AttrDomain> preferred_domain(const Mesh & /*mesh*/) const override
75 {
76 return AttrDomain::Edge;
77 }
78};
79
81 const VertNumber vertex,
82 const AttrDomain domain)
83{
84 const Span<float3> positions = mesh.vert_positions();
85 const Span<int2> edges = mesh.edges();
86
87 if (vertex == VertNumber::V1) {
88 return mesh.attributes().adapt_domain<float3>(
90 edges.size(), [positions, edges](const int i) { return positions[edges[i][0]]; }),
91 AttrDomain::Edge,
92 domain);
93 }
94 return mesh.attributes().adapt_domain<float3>(
96 edges.size(), [positions, edges](const int i) { return positions[edges[i][1]]; }),
97 AttrDomain::Edge,
98 domain);
99}
100
102 private:
103 VertNumber vertex_;
104
105 public:
107 : bke::MeshFieldInput(CPPType::get<float3>(), "Edge Position Field"), vertex_(vertex)
108 {
110 }
111
113 const AttrDomain domain,
114 const IndexMask & /*mask*/) const final
115 {
116 return construct_edge_positions_gvarray(mesh, vertex_, domain);
117 }
118
119 uint64_t hash() const override
120 {
121 return vertex_ == VertNumber::V1 ? 987456978362 : 374587679866;
122 }
123
124 bool is_equal_to(const fn::FieldNode &other) const override
125 {
126 if (const EdgePositionFieldInput *other_field = dynamic_cast<const EdgePositionFieldInput *>(
127 &other))
128 {
129 return vertex_ == other_field->vertex_;
130 }
131 return false;
132 }
133
134 std::optional<AttrDomain> preferred_domain(const Mesh & /*mesh*/) const override
135 {
136 return AttrDomain::Edge;
137 }
138};
139
141{
142 Field<int> vertex_field_1{std::make_shared<EdgeVertsInput>(VertNumber::V1)};
143 Field<int> vertex_field_2{std::make_shared<EdgeVertsInput>(VertNumber::V2)};
144 Field<float3> position_field_1{std::make_shared<EdgePositionFieldInput>(VertNumber::V1)};
145 Field<float3> position_field_2{std::make_shared<EdgePositionFieldInput>(VertNumber::V2)};
146
147 params.set_output("Vertex Index 1", std::move(vertex_field_1));
148 params.set_output("Vertex Index 2", std::move(vertex_field_2));
149 params.set_output("Position 1", std::move(position_field_1));
150 params.set_output("Position 2", std::move(position_field_2));
151}
152
153static void node_register()
154{
155 static blender::bke::bNodeType ntype;
157 &ntype, "GeometryNodeInputMeshEdgeVertices", GEO_NODE_INPUT_MESH_EDGE_VERTICES);
158 ntype.ui_name = "Edge Vertices";
159 ntype.ui_description = "Retrieve topology information relating to each edge of a mesh";
160 ntype.enum_name_legacy = "MESH_EDGE_VERTICES";
161 ntype.nclass = NODE_CLASS_INPUT;
162 ntype.declare = node_declare;
165}
167
168} // namespace blender::nodes::node_geo_input_mesh_edge_vertices_cc
#define NODE_CLASS_INPUT
Definition BKE_node.hh:447
#define GEO_NODE_INPUT_MESH_EDGE_VERTICES
#define final(a, b, c)
Definition BLI_hash.h:19
#define NOD_REGISTER_NODE(REGISTER_FUNC)
unsigned long long int uint64_t
AttributeSet attributes
constexpr int64_t size() const
Definition BLI_span.hh:252
static VArray from_func(const int64_t size, GetFunc get_func)
GVArray get_varray_for_context(const Mesh &mesh, const AttrDomain domain, const IndexMask &) const final
std::optional< AttrDomain > preferred_domain(const Mesh &) const override
GVArray get_varray_for_context(const Mesh &mesh, const AttrDomain domain, const IndexMask &) const final
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
void node_register_type(bNodeType &ntype)
Definition node.cc:2416
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(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
i
Definition text_draw.cc:230