Blender V4.5
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")
14 .implicit_field(NODE_DEFAULT_INPUT_INDEX_FIELD)
15 .description("The control point to retrieve data from");
16 b.add_output<decl::Int>("Curve Index")
17 .field_source_reference_all()
18 .description("The curve the control point is part of");
19 b.add_output<decl::Int>("Index in Curve")
20 .field_source_reference_all()
21 .description("How far along the control point is along its curve");
22}
23
25 public:
26 CurveOfPointInput() : bke::CurvesFieldInput(CPPType::get<int>(), "Point Curve Index")
27 {
29 }
30
32 const AttrDomain domain,
33 const IndexMask & /*mask*/) const final
34 {
35 if (domain != AttrDomain::Point) {
36 return {};
37 }
38 return VArray<int>::ForContainer(curves.point_to_curve_map());
39 }
40
41 uint64_t hash() const override
42 {
43 return 413209687345908697;
44 }
45
46 bool is_equal_to(const fn::FieldNode &other) const override
47 {
48 return dynamic_cast<const CurveOfPointInput *>(&other) != nullptr;
49 }
50
51 std::optional<AttrDomain> preferred_domain(const bke::CurvesGeometry & /*curves*/) const final
52 {
53 return AttrDomain::Point;
54 }
55};
56
58 public:
59 PointIndexInCurveInput() : bke::CurvesFieldInput(CPPType::get<int>(), "Point Index in Curve")
60 {
62 }
63
65 const AttrDomain domain,
66 const IndexMask & /*mask*/) const final
67 {
68 if (domain != AttrDomain::Point) {
69 return {};
70 }
71 const Span<int> offsets = curves.offsets();
72 Array<int> point_to_curve_map = curves.point_to_curve_map();
74 curves.points_num(),
75 [offsets, point_to_curve_map = std::move(point_to_curve_map)](const int point_i) {
76 const int curve_i = point_to_curve_map[point_i];
77 return point_i - offsets[curve_i];
78 });
79 }
80
82 {
83 return 9834765987345677;
84 }
85
86 bool is_equal_to(const fn::FieldNode &other) const final
87 {
88 return dynamic_cast<const PointIndexInCurveInput *>(&other) != nullptr;
89 }
90
91 std::optional<AttrDomain> preferred_domain(const bke::CurvesGeometry & /*curves*/) const override
92 {
93 return AttrDomain::Point;
94 }
95};
96
98{
99 const Field<int> point_index = params.extract_input<Field<int>>("Point Index");
100 if (params.output_is_required("Curve Index")) {
101 params.set_output(
102 "Curve Index",
103 Field<int>(std::make_shared<bke::EvaluateAtIndexInput>(
104 point_index, Field<int>(std::make_shared<CurveOfPointInput>()), AttrDomain::Point)));
105 }
106 if (params.output_is_required("Index in Curve")) {
107 params.set_output("Index in Curve",
108 Field<int>(std::make_shared<bke::EvaluateAtIndexInput>(
109 point_index,
110 Field<int>(std::make_shared<PointIndexInCurveInput>()),
111 AttrDomain::Point)));
112 }
113}
114
115static void node_register()
116{
117 static blender::bke::bNodeType ntype;
118 geo_node_type_base(&ntype, "GeometryNodeCurveOfPoint", GEO_NODE_CURVE_TOPOLOGY_CURVE_OF_POINT);
119 ntype.ui_name = "Curve of Point";
120 ntype.ui_description = "Retrieve the curve a control point is part of";
121 ntype.enum_name_legacy = "CURVE_OF_POINT";
122 ntype.nclass = NODE_CLASS_INPUT;
124 ntype.declare = node_declare;
126}
128
129} // namespace blender::nodes::node_geo_curve_topology_curve_of_point_cc
Low-level operations for curves.
#define NODE_CLASS_INPUT
Definition BKE_node.hh:433
#define GEO_NODE_CURVE_TOPOLOGY_CURVE_OF_POINT
#define final(a, b, c)
Definition BLI_hash.h:19
#define NOD_REGISTER_NODE(REGISTER_FUNC)
unsigned long long int uint64_t
static VArray ForContainer(ContainerT container)
static VArray ForFunc(const int64_t size, GetFunc get_func)
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
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
void node_register_type(bNodeType &ntype)
Definition node.cc:2748
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:226
std::string ui_description
Definition BKE_node.hh:232
NodeGeometryExecFunction geometry_node_execute
Definition BKE_node.hh:347
const char * enum_name_legacy
Definition BKE_node.hh:235
NodeDeclareFunction declare
Definition BKE_node.hh:355