Blender V4.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 "BKE_mesh.hh"
6
7#include "BLI_task.hh"
8
10
12
14{
15 b.add_input<decl::Int>("Corner Index")
16 .implicit_field(implicit_field_inputs::index)
17 .description("The corner to retrieve data from. Defaults to the corner from the context");
18 b.add_input<decl::Int>("Offset").supports_field().description(
19 "The number of corners to move around the face before finding the result, "
20 "circling around the start of the face if necessary");
21 b.add_output<decl::Int>("Corner Index")
22 .field_source_reference_all()
23 .description("The index of the offset corner");
24}
25
27 const Field<int> corner_index_;
28 const Field<int> offset_;
29
30 public:
32 : bke::MeshFieldInput(CPPType::get<int>(), "Offset Corner in Face"),
33 corner_index_(std::move(corner_index)),
34 offset_(std::move(offset))
35 {
37 }
38
40 const AttrDomain domain,
41 const IndexMask &mask) const final
42 {
43 const IndexRange corner_range(mesh.corners_num);
44 const OffsetIndices faces = mesh.faces();
45
46 const bke::MeshFieldContext context{mesh, domain};
47 fn::FieldEvaluator evaluator{context, &mask};
48 evaluator.add(corner_index_);
49 evaluator.add(offset_);
50 evaluator.evaluate();
51 const VArray<int> corner_indices = evaluator.get_evaluated<int>(0);
52 const VArray<int> offsets = evaluator.get_evaluated<int>(1);
53
54 const Span<int> corner_to_face = mesh.corner_to_face_map();
55
56 Array<int> offset_corners(mask.min_array_size());
57 mask.foreach_index_optimized<int>(GrainSize(2048), [&](const int selection_i) {
58 const int corner_i = corner_indices[selection_i];
59 const int offset = offsets[selection_i];
60 if (!corner_range.contains(corner_i)) {
61 offset_corners[selection_i] = 0;
62 return;
63 }
64
65 const IndexRange face = faces[corner_to_face[corner_i]];
66 offset_corners[selection_i] = apply_offset_in_cyclic_range(face, corner_i, offset);
67 });
68
69 return VArray<int>::ForContainer(std::move(offset_corners));
70 }
71
72 void for_each_field_input_recursive(FunctionRef<void(const FieldInput &)> fn) const override
73 {
74 corner_index_.node().for_each_field_input_recursive(fn);
76 }
77
78 uint64_t hash() const final
79 {
80 return get_default_hash(offset_);
81 }
82
83 bool is_equal_to(const fn::FieldNode &other) const final
84 {
85 if (const OffsetCornerInFaceFieldInput *other_field =
86 dynamic_cast<const OffsetCornerInFaceFieldInput *>(&other))
87 {
88 return other_field->corner_index_ == corner_index_ && other_field->offset_ == offset_;
89 }
90 return false;
91 }
92
93 std::optional<AttrDomain> preferred_domain(const Mesh & /*mesh*/) const final
94 {
95 return AttrDomain::Corner;
96 }
97};
98
100{
101 params.set_output("Corner Index",
102 Field<int>(std::make_shared<OffsetCornerInFaceFieldInput>(
103 params.extract_input<Field<int>>("Corner Index"),
104 params.extract_input<Field<int>>("Offset"))));
105}
106
107static void node_register()
108{
109 static blender::bke::bNodeType ntype;
110 geo_node_type_base(&ntype,
111 GEO_NODE_MESH_TOPOLOGY_OFFSET_CORNER_IN_FACE,
112 "Offset Corner in Face",
115 ntype.declare = node_declare;
117}
119
120} // namespace blender::nodes::node_geo_mesh_topology_offset_corner_in_face_cc
#define NODE_CLASS_INPUT
Definition BKE_node.hh:404
#define NOD_REGISTER_NODE(REGISTER_FUNC)
constexpr bool contains(int64_t value) const
static VArray ForContainer(ContainerT container)
int add(GField field, GVArray *varray_ptr)
Definition field.cc:756
virtual void for_each_field_input_recursive(FunctionRef< void(const FieldInput &)> fn) const
Definition field.cc:587
const FieldNode & node() const
Definition FN_field.hh:137
GVArray get_varray_for_context(const Mesh &mesh, const AttrDomain domain, const IndexMask &mask) const final
local_group_size(16, 16) .push_constant(Type b
draw_view push_constant(Type::INT, "radiance_src") .push_constant(Type capture_info_buf storage_buf(1, Qualifier::READ, "ObjectBounds", "bounds_buf[]") .push_constant(Type draw_view int
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
void node_register_type(bNodeType *ntype)
Definition node.cc:1708
void index(const bNode &, void *r_value)
int apply_offset_in_cyclic_range(IndexRange range, int start_index, int offset)
uint64_t get_default_hash(const T &v)
Definition BLI_hash.hh:219
void geo_node_type_base(blender::bke::bNodeType *ntype, int type, const char *name, short nclass)
unsigned __int64 uint64_t
Definition stdint.h:90
Defines a node type.
Definition BKE_node.hh:218
NodeGeometryExecFunction geometry_node_execute
Definition BKE_node.hh:339
NodeDeclareFunction declare
Definition BKE_node.hh:347