Blender V5.0
node_geo_mesh_topology_face_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 "DNA_mesh_types.h"
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>("Face Index")
18 .field_source_reference_all()
19 .description("The index of the face the corner is a part of");
20 b.add_output<decl::Int>("Index in Face")
21 .field_source_reference_all()
22 .description("The index of the corner starting from the first corner in the face");
23}
24
26 public:
27 CornerFaceIndexInput() : bke::MeshFieldInput(CPPType::get<int>(), "Corner Face Index")
28 {
30 }
31
33 const AttrDomain domain,
34 const IndexMask & /*mask*/) const final
35 {
36 if (domain != AttrDomain::Corner) {
37 return {};
38 }
39 return VArray<int>::from_span(mesh.corner_to_face_map());
40 }
41
43 {
44 return 2348712958475728;
45 }
46
47 bool is_equal_to(const fn::FieldNode &other) const final
48 {
49 return dynamic_cast<const CornerFaceIndexInput *>(&other) != nullptr;
50 }
51};
52
54 public:
55 CornerIndexInFaceInput() : bke::MeshFieldInput(CPPType::get<int>(), "Corner Index In Face")
56 {
58 }
59
61 const AttrDomain domain,
62 const IndexMask & /*mask*/) const final
63 {
64 if (domain != AttrDomain::Corner) {
65 return {};
66 }
67 const OffsetIndices faces = mesh.faces();
68 const Span<int> corner_to_face = mesh.corner_to_face_map();
69 return VArray<int>::from_func(mesh.corners_num, [faces, corner_to_face](const int corner) {
70 const int face_i = corner_to_face[corner];
71 return corner - faces[face_i].start();
72 });
73 }
74
76 {
77 return 97837176448;
78 }
79
80 bool is_equal_to(const fn::FieldNode &other) const final
81 {
82 return dynamic_cast<const CornerIndexInFaceInput *>(&other) != nullptr;
83 }
84
85 std::optional<AttrDomain> preferred_domain(const Mesh & /*mesh*/) const final
86 {
87 return AttrDomain::Corner;
88 }
89};
90
92{
93 const Field<int> corner_index = params.extract_input<Field<int>>("Corner Index");
94 if (params.output_is_required("Face Index")) {
95 params.set_output("Face Index",
96 Field<int>(std::make_shared<bke::EvaluateAtIndexInput>(
97 corner_index,
98 Field<int>(std::make_shared<CornerFaceIndexInput>()),
99 AttrDomain::Corner)));
100 }
101 if (params.output_is_required("Index in Face")) {
102 params.set_output("Index in Face",
103 Field<int>(std::make_shared<bke::EvaluateAtIndexInput>(
104 corner_index,
105 Field<int>(std::make_shared<CornerIndexInFaceInput>()),
106 AttrDomain::Corner)));
107 }
108}
109
110static void node_register()
111{
112 static blender::bke::bNodeType ntype;
113 geo_node_type_base(&ntype, "GeometryNodeFaceOfCorner", GEO_NODE_MESH_TOPOLOGY_FACE_OF_CORNER);
114 ntype.ui_name = "Face of Corner";
115 ntype.ui_description = "Retrieve the face each face corner is part of";
116 ntype.enum_name_legacy = "FACE_OF_CORNER";
117 ntype.nclass = NODE_CLASS_INPUT;
119 ntype.declare = node_declare;
121}
123
124} // namespace blender::nodes::node_geo_mesh_topology_face_of_corner_cc
#define NODE_CLASS_INPUT
Definition BKE_node.hh:447
#define GEO_NODE_MESH_TOPOLOGY_FACE_OF_CORNER
#define final(a, b, c)
Definition BLI_hash.h:19
#define NOD_REGISTER_NODE(REGISTER_FUNC)
unsigned long long int uint64_t
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