Blender V4.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 "BKE_mesh.hh"
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>::ForFunc(edges.size(), [edges](const int i) { return edges[i][0]; });
37 }
38 return VArray<int>::ForFunc(edges.size(), [edges](const int i) { return edges[i][1]; });
39 }
40 return {};
41}
42
43class EdgeVertsInput final : public bke::MeshFieldInput {
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>(
95 VArray<float3>::ForFunc(edges.size(),
96 [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;
156 geo_node_type_base(&ntype, GEO_NODE_INPUT_MESH_EDGE_VERTICES, "Edge Vertices", NODE_CLASS_INPUT);
157 ntype.declare = node_declare;
160}
162
163} // namespace blender::nodes::node_geo_input_mesh_edge_vertices_cc
#define NODE_CLASS_INPUT
Definition BKE_node.hh:404
#define NOD_REGISTER_NODE(REGISTER_FUNC)
static VArray ForFunc(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
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 node_register_type(bNodeType *ntype)
Definition node.cc:1708
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)
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