Blender V5.3
node_geo_curve_topology_curve_of_point.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_curves.hh"
6
8
10
12{
13 b.add_input<decl::Int>("Point Index"_ustr)
14 .default_input_type(NODE_DEFAULT_INPUT_INDEX_FIELD)
15 .description("The control point to retrieve data from")
16 .structure_type(StructureType::Field);
17 b.add_output<decl::Int>("Curve Index"_ustr)
18 .structure_type(StructureType::Field)
19 .propagate_references()
20 .description("The curve the control point is part of");
21 b.add_output<decl::Int>("Index in Curve"_ustr)
22 .structure_type(StructureType::Field)
23 .propagate_references()
24 .description("How far along the control point is along its curve");
25}
26
28 public:
29 CurveOfPointInput() : bke::CurvesFieldInput(CPPType::get<int>(), "Point Curve Index") {}
30
32 const AttrDomain domain,
33 const IndexMask & /*mask*/) const final
34 {
35 if (domain != AttrDomain::Point) {
36 return {};
37 }
38 return VArray<int>::from_container(curves.point_to_curve_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 std::optional<AttrDomain> preferred_domain(const bke::CurvesGeometry & /*curves*/) const final
48 {
49 return AttrDomain::Point;
50 }
51};
52
54 public:
55 PointIndexInCurveInput() : bke::CurvesFieldInput(CPPType::get<int>(), "Point Index in Curve") {}
56
58 const AttrDomain domain,
59 const IndexMask & /*mask*/) const final
60 {
61 if (domain != AttrDomain::Point) {
62 return {};
63 }
64 const Span<int> offsets = curves.offsets();
65 Array<int> point_to_curve_map = curves.point_to_curve_map();
67 curves.points_num(),
68 [offsets, point_to_curve_map = std::move(point_to_curve_map)](const int point_i) {
69 const int curve_i = point_to_curve_map[point_i];
70 return point_i - offsets[curve_i];
71 });
72 }
73
74 void hash_unique(UniqueHashBytes &hash, fn::FieldHashDeep & /*deep_hash_cache*/) const override
75 {
76 static constexpr int8_t id = 0;
77 hash.add(&id);
78 }
79
80 std::optional<AttrDomain> preferred_domain(const bke::CurvesGeometry & /*curves*/) const override
81 {
82 return AttrDomain::Point;
83 }
84};
85
87{
88 const Field<int> point_index = params.extract_input<Field<int>>("Point Index"_ustr);
89 if (params.output_is_required("Curve Index"_ustr)) {
90 params.set_output(
91 "Curve Index"_ustr,
93 point_index, Field<int>::from_input<CurveOfPointInput>(), AttrDomain::Point));
94 }
95 if (params.output_is_required("Index in Curve"_ustr)) {
96 params.set_output(
97 "Index in Curve"_ustr,
99 point_index, Field<int>::from_input<PointIndexInCurveInput>(), AttrDomain::Point));
100 }
101}
102
103static void node_register()
104{
105 static bke::bNodeType ntype;
107 &ntype, "GeometryNodeCurveOfPoint"_ustr, GEO_NODE_CURVE_TOPOLOGY_CURVE_OF_POINT);
108 ntype.ui_name = "Curve of Point";
109 ntype.ui_description = "Retrieve the curve a control point is part of";
110 ntype.enum_name_legacy = "CURVE_OF_POINT";
111 ntype.nclass = NODE_CLASS_INPUT;
113 ntype.declare = node_declare;
115}
117
118} // namespace blender::nodes::node_geo_curve_topology_curve_of_point_cc
Low-level operations for curves.
#define NODE_CLASS_INPUT
Definition BKE_node.hh:478
#define GEO_NODE_CURVE_TOPOLOGY_CURVE_OF_POINT
#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_container(ContainerT container)
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 bke::CurvesGeometry &curves, const AttrDomain domain, const IndexMask &) const final
std::optional< AttrDomain > preferred_domain(const bke::CurvesGeometry &) const final
std::optional< AttrDomain > preferred_domain(const bke::CurvesGeometry &) const override
GVArray get_varray_for_context(const bke::CurvesGeometry &curves, 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