Blender V5.3
node_geo_mesh_topology_edges_of_corner.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_input<decl::Int>("Corner Index"_ustr)
14 .default_input_type(NODE_DEFAULT_INPUT_INDEX_FIELD)
15 .description("The corner to retrieve data from. Defaults to the corner from the context")
16 .structure_type(StructureType::Field);
17 b.add_output<decl::Int>("Next Edge Index"_ustr)
18 .structure_type(StructureType::Field)
19 .propagate_references()
21 "The edge after the corner in the face, in the direction of increasing indices");
22 b.add_output<decl::Int>("Previous Edge Index"_ustr)
23 .structure_type(StructureType::Field)
24 .propagate_references()
26 "The edge before the corner in the face, in the direction of decreasing indices");
27}
28
30 public:
31 CornerNextEdgeFieldInput() : bke::MeshFieldInput(CPPType::get<int>(), "Corner Next Edge") {}
32
34 const AttrDomain domain,
35 const IndexMask & /*mask*/) const final
36 {
37 if (domain != AttrDomain::Corner) {
38 return {};
39 }
40 return VArray<int>::from_span(mesh.corner_edges());
41 }
42
43 void hash_unique(UniqueHashBytes &hash, fn::FieldHashDeep & /*deep_hash_cache*/) const override
44 {
45 static constexpr int8_t id = 0;
46 hash.add(&id);
47 }
48
49 std::optional<AttrDomain> preferred_domain(const Mesh & /*mesh*/) const final
50 {
51 return AttrDomain::Corner;
52 }
53};
54
56 public:
57 CornerPreviousEdgeFieldInput() : bke::MeshFieldInput(CPPType::get<int>(), "Corner Previous Edge")
58 {
59 }
60
62 const AttrDomain domain,
63 const IndexMask & /*mask*/) const final
64 {
65 if (domain != AttrDomain::Corner) {
66 return {};
67 }
68 const OffsetIndices faces = mesh.faces();
69 const Span<int> corner_edges = mesh.corner_edges();
70 const Span<int> corner_to_face = mesh.corner_to_face_map();
72 corner_edges.size(), [faces, corner_edges, corner_to_face](const int corner) {
73 return corner_edges[bke::mesh::face_corner_prev(faces[corner_to_face[corner]], corner)];
74 });
75 }
76
77 void hash_unique(UniqueHashBytes &hash, fn::FieldHashDeep & /*deep_hash_cache*/) const override
78 {
79 static constexpr int8_t id = 0;
80 hash.add(&id);
81 }
82
83 std::optional<AttrDomain> preferred_domain(const Mesh & /*mesh*/) const final
84 {
85 return AttrDomain::Corner;
86 }
87};
88
90{
91 const Field<int> corner_index = params.extract_input<Field<int>>("Corner Index"_ustr);
92 if (params.output_is_required("Next Edge Index"_ustr)) {
93 params.set_output(
94 "Next Edge Index"_ustr,
96 corner_index, Field<int>::from_input<CornerNextEdgeFieldInput>(), AttrDomain::Corner));
97 }
98 if (params.output_is_required("Previous Edge Index"_ustr)) {
99 params.set_output("Previous Edge Index"_ustr,
101 corner_index,
103 AttrDomain::Corner));
104 }
105}
106
107static void node_register()
108{
109 static bke::bNodeType ntype;
111 &ntype, "GeometryNodeEdgesOfCorner"_ustr, GEO_NODE_MESH_TOPOLOGY_EDGES_OF_CORNER);
112 ntype.ui_name = "Edges of Corner";
113 ntype.ui_description = "Retrieve the edges on both sides of a face corner";
114 ntype.enum_name_legacy = "EDGES_OF_CORNER";
115 ntype.nclass = NODE_CLASS_INPUT;
117 ntype.declare = node_declare;
119}
121
122} // namespace blender::nodes::node_geo_mesh_topology_edges_of_corner_cc
#define NODE_CLASS_INPUT
Definition BKE_node.hh:478
#define GEO_NODE_MESH_TOPOLOGY_EDGES_OF_CORNER
#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)
static VArray from_span(Span< T > values)
uint64_t hash() const
Definition field.cc:185
static Field from_input(Args &&...args)
T extract_input(const UString identifier)
bool output_is_required(const UString identifier) const
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 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