Blender V5.3
node_geo_mesh_topology_offset_corner_in_face.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_input<decl::Int>("Offset"_ustr)
18 .structure_type(StructureType::Field)
20 "The number of corners to move around the face before finding the result, "
21 "circling around the start of the face if necessary");
22 b.add_output<decl::Int>("Corner Index"_ustr)
23 .structure_type(StructureType::Field)
24 .propagate_references()
25 .description("The index of the offset corner");
26}
27
29 const Field<int> corner_index_;
30 const Field<int> offset_;
31
32 public:
34 : bke::MeshFieldInput(CPPType::get<int>(), "Offset Corner in Face"),
35 corner_index_(std::move(corner_index)),
36 offset_(std::move(offset))
37 {
38 }
39
41 const AttrDomain domain,
42 const IndexMask &mask) const final
43 {
44 const IndexRange corner_range(mesh.corners_num);
45 const OffsetIndices faces = mesh.faces();
46
47 const bke::MeshFieldContext context{mesh, domain};
48 fn::FieldEvaluator evaluator{context, &mask};
49 evaluator.add(corner_index_);
50 evaluator.add(offset_);
51 evaluator.evaluate();
52 const VArray<int> corner_indices = evaluator.get_evaluated<int>(0);
53 const VArray<int> offsets = evaluator.get_evaluated<int>(1);
54
55 const Span<int> corner_to_face = mesh.corner_to_face_map();
56
57 Array<int> offset_corners(mask.min_array_size());
58 mask.foreach_index_optimized<int>(
59 [&](const int selection_i) {
60 const int corner = corner_indices[selection_i];
61 const int offset = offsets[selection_i];
62 if (!corner_to_face.index_range().contains(corner)) {
63 offset_corners[selection_i] = 0;
64 return;
65 }
66 const IndexRange face = faces[corner_to_face[corner]];
67 const int corner_index_in_face = corner - face.start();
68 offset_corners[selection_i] = face.start() +
69 math::mod_periodic<int>(corner_index_in_face + offset,
70 face.size());
71 },
73
74 return VArray<int>::from_container(std::move(offset_corners));
75 }
76
77 void foreach_recursive_field(FunctionRef<void(const GField &)> fn) const override
78 {
79 fn(corner_index_);
80 fn(offset_);
81 }
82
83 void hash_unique(UniqueHashBytes &hash, fn::FieldHashDeep &deep_hash_cache) const final
84 {
85 static constexpr int8_t id = 0;
86 hash.add(&id);
87 hash.add(deep_hash_cache.ensure(corner_index_));
88 hash.add(deep_hash_cache.ensure(offset_));
89 }
90
91 std::optional<AttrDomain> preferred_domain(const Mesh & /*mesh*/) const final
92 {
93 return AttrDomain::Corner;
94 }
95};
96
98{
99 params.set_output("Corner Index"_ustr,
101 params.extract_input<Field<int>>("Corner Index"_ustr),
102 params.extract_input<Field<int>>("Offset"_ustr)));
103}
104
105static void node_register()
106{
107 static bke::bNodeType ntype;
109 &ntype, "GeometryNodeOffsetCornerInFace"_ustr, GEO_NODE_MESH_TOPOLOGY_OFFSET_CORNER_IN_FACE);
110 ntype.ui_name = "Offset Corner in Face";
111 ntype.ui_description = "Retrieve corners in the same face as another";
112 ntype.enum_name_legacy = "OFFSET_CORNER_IN_FACE";
113 ntype.nclass = NODE_CLASS_INPUT;
115 ntype.declare = node_declare;
118}
120
121} // namespace blender::nodes::node_geo_mesh_topology_offset_corner_in_face_cc
#define NODE_CLASS_INPUT
Definition BKE_node.hh:478
#define GEO_NODE_MESH_TOPOLOGY_OFFSET_CORNER_IN_FACE
#define final(a, b, c)
Definition BLI_hash_c.hh:21
#define NOD_REGISTER_NODE(REGISTER_FUNC)
constexpr int64_t size() const
constexpr int64_t start() const
static VArray from_container(ContainerT container)
int add(GField field, GVArray *varray_ptr)
const GVArray & get_evaluated(const int field_index) const
uint64_t hash() const
Definition field.cc:185
static Field from_input(Args &&...args)
T extract_input(const UString identifier)
void set_output(const UString identifier, T &&value)
GVArray get_varray_for_context(const Mesh &mesh, const AttrDomain domain, const IndexMask &mask) const final
void node_register_type(bNodeType &ntype)
Definition node.cc:2920
constexpr ParallelGrainSize grain_size(int grain_size)
T mod_periodic(const T &a, const T &b)
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
static constexpr int _160
Definition BKE_node.hh:246
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