Blender V5.3
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"_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>("Face Index"_ustr)
18 .structure_type(StructureType::Field)
19 .propagate_references()
20 .description("The index of the face the corner is a part of");
21 b.add_output<decl::Int>("Index in Face"_ustr)
22 .structure_type(StructureType::Field)
23 .propagate_references()
24 .description("The index of the corner starting from the first corner in the face");
25}
26
28 public:
29 CornerFaceIndexInput() : bke::MeshFieldInput(CPPType::get<int>(), "Corner Face Index") {}
30
32 const AttrDomain domain,
33 const IndexMask & /*mask*/) const final
34 {
35 if (domain != AttrDomain::Corner) {
36 return {};
37 }
38 return VArray<int>::from_span(mesh.corner_to_face_map());
39 }
40
41 void hash_unique(UniqueHashBytes &hash, fn::FieldHashDeep & /*deep_hash_cache*/) const override
42 {
43 static constexpr int8_t id = 0;
44 hash.add(&id);
45 }
46};
47
49 public:
50 CornerIndexInFaceInput() : bke::MeshFieldInput(CPPType::get<int>(), "Corner Index In Face") {}
51
53 const AttrDomain domain,
54 const IndexMask & /*mask*/) const final
55 {
56 if (domain != AttrDomain::Corner) {
57 return {};
58 }
59 const OffsetIndices faces = mesh.faces();
60 const Span<int> corner_to_face = mesh.corner_to_face_map();
61 return VArray<int>::from_func(mesh.corners_num, [faces, corner_to_face](const int corner) {
62 const int face_i = corner_to_face[corner];
63 return corner - faces[face_i].start();
64 });
65 }
66
67 void hash_unique(UniqueHashBytes &hash, fn::FieldHashDeep & /*deep_hash_cache*/) const override
68 {
69 static constexpr int8_t id = 0;
70 hash.add(&id);
71 }
72
73 std::optional<AttrDomain> preferred_domain(const Mesh & /*mesh*/) const final
74 {
75 return AttrDomain::Corner;
76 }
77};
78
80{
81 const Field<int> corner_index = params.extract_input<Field<int>>("Corner Index"_ustr);
82 if (params.output_is_required("Face Index"_ustr)) {
83 params.set_output(
84 "Face Index"_ustr,
86 corner_index, Field<int>::from_input<CornerFaceIndexInput>(), AttrDomain::Corner));
87 }
88 if (params.output_is_required("Index in Face"_ustr)) {
89 params.set_output(
90 "Index in Face"_ustr,
92 corner_index, Field<int>::from_input<CornerIndexInFaceInput>(), AttrDomain::Corner));
93 }
94}
95
96static void node_register()
97{
98 static bke::bNodeType ntype;
100 &ntype, "GeometryNodeFaceOfCorner"_ustr, GEO_NODE_MESH_TOPOLOGY_FACE_OF_CORNER);
101 ntype.ui_name = "Face of Corner";
102 ntype.ui_description = "Retrieve the face each face corner is part of";
103 ntype.enum_name_legacy = "FACE_OF_CORNER";
104 ntype.nclass = NODE_CLASS_INPUT;
106 ntype.declare = node_declare;
108}
110
111} // namespace blender::nodes::node_geo_mesh_topology_face_of_corner_cc
#define NODE_CLASS_INPUT
Definition BKE_node.hh:478
#define GEO_NODE_MESH_TOPOLOGY_FACE_OF_CORNER
#define final(a, b, c)
Definition BLI_hash_c.hh:21
#define NOD_REGISTER_NODE(REGISTER_FUNC)
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