Blender V5.0
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")
14 .implicit_field(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")
18 .field_source_reference_all()
20 "The edge after the corner in the face, in the direction of increasing indices");
21 b.add_output<decl::Int>("Previous Edge Index")
22 .field_source_reference_all()
24 "The edge before the corner in the face, in the direction of decreasing indices");
25}
26
28 public:
29 CornerNextEdgeFieldInput() : bke::MeshFieldInput(CPPType::get<int>(), "Corner Next Edge")
30 {
32 }
33
35 const AttrDomain domain,
36 const IndexMask & /*mask*/) const final
37 {
38 if (domain != AttrDomain::Corner) {
39 return {};
40 }
41 return VArray<int>::from_span(mesh.corner_edges());
42 }
43
45 {
46 return 1892753404495;
47 }
48
49 bool is_equal_to(const fn::FieldNode &other) const final
50 {
51 return dynamic_cast<const CornerNextEdgeFieldInput *>(&other) != nullptr;
52 }
53
54 std::optional<AttrDomain> preferred_domain(const Mesh & /*mesh*/) const final
55 {
56 return AttrDomain::Corner;
57 }
58};
59
61 public:
62 CornerPreviousEdgeFieldInput() : bke::MeshFieldInput(CPPType::get<int>(), "Corner Previous Edge")
63 {
65 }
66
68 const AttrDomain domain,
69 const IndexMask & /*mask*/) const final
70 {
71 if (domain != AttrDomain::Corner) {
72 return {};
73 }
74 const OffsetIndices faces = mesh.faces();
75 const Span<int> corner_edges = mesh.corner_edges();
76 const Span<int> corner_to_face = mesh.corner_to_face_map();
78 corner_edges.size(), [faces, corner_edges, corner_to_face](const int corner) {
79 return corner_edges[bke::mesh::face_corner_prev(faces[corner_to_face[corner]], corner)];
80 });
81 }
82
84 {
85 return 987298345762465;
86 }
87
88 bool is_equal_to(const fn::FieldNode &other) const final
89 {
90 return dynamic_cast<const CornerPreviousEdgeFieldInput *>(&other) != nullptr;
91 }
92
93 std::optional<AttrDomain> preferred_domain(const Mesh & /*mesh*/) const final
94 {
95 return AttrDomain::Corner;
96 }
97};
98
100{
101 const Field<int> corner_index = params.extract_input<Field<int>>("Corner Index");
102 if (params.output_is_required("Next Edge Index")) {
103 params.set_output("Next Edge Index",
104 Field<int>(std::make_shared<bke::EvaluateAtIndexInput>(
105 corner_index,
106 Field<int>(std::make_shared<CornerNextEdgeFieldInput>()),
107 AttrDomain::Corner)));
108 }
109 if (params.output_is_required("Previous Edge Index")) {
110 params.set_output("Previous Edge Index",
111 Field<int>(std::make_shared<bke::EvaluateAtIndexInput>(
112 corner_index,
113 Field<int>(std::make_shared<CornerPreviousEdgeFieldInput>()),
114 AttrDomain::Corner)));
115 }
116}
117
118static void node_register()
119{
120 static blender::bke::bNodeType ntype;
121 geo_node_type_base(&ntype, "GeometryNodeEdgesOfCorner", GEO_NODE_MESH_TOPOLOGY_EDGES_OF_CORNER);
122 ntype.ui_name = "Edges of Corner";
123 ntype.ui_description = "Retrieve the edges on both sides of a face corner";
124 ntype.enum_name_legacy = "EDGES_OF_CORNER";
125 ntype.nclass = NODE_CLASS_INPUT;
127 ntype.declare = node_declare;
129}
131
132} // namespace blender::nodes::node_geo_mesh_topology_edges_of_corner_cc
#define NODE_CLASS_INPUT
Definition BKE_node.hh:447
#define GEO_NODE_MESH_TOPOLOGY_EDGES_OF_CORNER
#define final(a, b, c)
Definition BLI_hash.h:19
#define NOD_REGISTER_NODE(REGISTER_FUNC)
unsigned long long int uint64_t
constexpr int64_t size() const
Definition BLI_span.hh:252
static VArray from_func(const int64_t size, GetFunc get_func)
static VArray from_span(Span< T > values)
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
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
static char faces[256]
void node_register_type(bNodeType &ntype)
Definition node.cc:2416
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