Blender V4.5
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 b.add_output<decl::Int>("Next Edge Index")
17 .field_source_reference_all()
19 "The edge after the corner in the face, in the direction of increasing indices");
20 b.add_output<decl::Int>("Previous Edge Index")
21 .field_source_reference_all()
23 "The edge before the corner in the face, in the direction of decreasing indices");
24}
25
27 public:
28 CornerNextEdgeFieldInput() : bke::MeshFieldInput(CPPType::get<int>(), "Corner Next Edge")
29 {
31 }
32
34 const AttrDomain domain,
35 const IndexMask & /*mask*/) const final
36 {
37 if (domain != AttrDomain::Corner) {
38 return {};
39 }
40 return VArray<int>::ForSpan(mesh.corner_edges());
41 }
42
44 {
45 return 1892753404495;
46 }
47
48 bool is_equal_to(const fn::FieldNode &other) const final
49 {
50 return dynamic_cast<const CornerNextEdgeFieldInput *>(&other) != nullptr;
51 }
52
53 std::optional<AttrDomain> preferred_domain(const Mesh & /*mesh*/) const final
54 {
55 return AttrDomain::Corner;
56 }
57};
58
60 public:
61 CornerPreviousEdgeFieldInput() : bke::MeshFieldInput(CPPType::get<int>(), "Corner Previous Edge")
62 {
64 }
65
67 const AttrDomain domain,
68 const IndexMask & /*mask*/) const final
69 {
70 if (domain != AttrDomain::Corner) {
71 return {};
72 }
73 const OffsetIndices faces = mesh.faces();
74 const Span<int> corner_edges = mesh.corner_edges();
75 const Span<int> corner_to_face = mesh.corner_to_face_map();
77 corner_edges.size(), [faces, corner_edges, corner_to_face](const int corner) {
78 return corner_edges[bke::mesh::face_corner_prev(faces[corner_to_face[corner]], corner)];
79 });
80 }
81
83 {
84 return 987298345762465;
85 }
86
87 bool is_equal_to(const fn::FieldNode &other) const final
88 {
89 return dynamic_cast<const CornerPreviousEdgeFieldInput *>(&other) != nullptr;
90 }
91
92 std::optional<AttrDomain> preferred_domain(const Mesh & /*mesh*/) const final
93 {
94 return AttrDomain::Corner;
95 }
96};
97
99{
100 const Field<int> corner_index = params.extract_input<Field<int>>("Corner Index");
101 if (params.output_is_required("Next Edge Index")) {
102 params.set_output("Next Edge Index",
103 Field<int>(std::make_shared<bke::EvaluateAtIndexInput>(
104 corner_index,
105 Field<int>(std::make_shared<CornerNextEdgeFieldInput>()),
106 AttrDomain::Corner)));
107 }
108 if (params.output_is_required("Previous Edge Index")) {
109 params.set_output("Previous Edge Index",
110 Field<int>(std::make_shared<bke::EvaluateAtIndexInput>(
111 corner_index,
112 Field<int>(std::make_shared<CornerPreviousEdgeFieldInput>()),
113 AttrDomain::Corner)));
114 }
115}
116
117static void node_register()
118{
119 static blender::bke::bNodeType ntype;
120 geo_node_type_base(&ntype, "GeometryNodeEdgesOfCorner", GEO_NODE_MESH_TOPOLOGY_EDGES_OF_CORNER);
121 ntype.ui_name = "Edges of Corner";
122 ntype.ui_description = "Retrieve the edges on both sides of a face corner";
123 ntype.enum_name_legacy = "EDGES_OF_CORNER";
124 ntype.nclass = NODE_CLASS_INPUT;
126 ntype.declare = node_declare;
128}
130
131} // namespace blender::nodes::node_geo_mesh_topology_edges_of_corner_cc
#define NODE_CLASS_INPUT
Definition BKE_node.hh:433
#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 ForSpan(Span< T > values)
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
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:2748
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:226
std::string ui_description
Definition BKE_node.hh:232
NodeGeometryExecFunction geometry_node_execute
Definition BKE_node.hh:347
const char * enum_name_legacy
Definition BKE_node.hh:235
NodeDeclareFunction declare
Definition BKE_node.hh:355