Blender V5.0
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 .structure_type(StructureType::Field);
17 b.add_output<decl::Int>("Curve Index")
18 .field_source_reference_all()
19 .description("The curve the control point is part of");
20 b.add_output<decl::Int>("Index in Curve")
21 .field_source_reference_all()
22 .description("How far along the control point is along its curve");
23}
24
26 public:
27 CurveOfPointInput() : bke::CurvesFieldInput(CPPType::get<int>(), "Point Curve Index")
28 {
30 }
31
33 const AttrDomain domain,
34 const IndexMask & /*mask*/) const final
35 {
36 if (domain != AttrDomain::Point) {
37 return {};
38 }
39 return VArray<int>::from_container(curves.point_to_curve_map());
40 }
41
42 uint64_t hash() const override
43 {
44 return 413209687345908697;
45 }
46
47 bool is_equal_to(const fn::FieldNode &other) const override
48 {
49 return dynamic_cast<const CurveOfPointInput *>(&other) != nullptr;
50 }
51
52 std::optional<AttrDomain> preferred_domain(const bke::CurvesGeometry & /*curves*/) const final
53 {
54 return AttrDomain::Point;
55 }
56};
57
59 public:
60 PointIndexInCurveInput() : bke::CurvesFieldInput(CPPType::get<int>(), "Point Index in Curve")
61 {
63 }
64
66 const AttrDomain domain,
67 const IndexMask & /*mask*/) const final
68 {
69 if (domain != AttrDomain::Point) {
70 return {};
71 }
72 const Span<int> offsets = curves.offsets();
73 Array<int> point_to_curve_map = curves.point_to_curve_map();
75 curves.points_num(),
76 [offsets, point_to_curve_map = std::move(point_to_curve_map)](const int point_i) {
77 const int curve_i = point_to_curve_map[point_i];
78 return point_i - offsets[curve_i];
79 });
80 }
81
83 {
84 return 9834765987345677;
85 }
86
87 bool is_equal_to(const fn::FieldNode &other) const final
88 {
89 return dynamic_cast<const PointIndexInCurveInput *>(&other) != nullptr;
90 }
91
92 std::optional<AttrDomain> preferred_domain(const bke::CurvesGeometry & /*curves*/) const override
93 {
94 return AttrDomain::Point;
95 }
96};
97
99{
100 const Field<int> point_index = params.extract_input<Field<int>>("Point Index");
101 if (params.output_is_required("Curve Index")) {
102 params.set_output(
103 "Curve Index",
104 Field<int>(std::make_shared<bke::EvaluateAtIndexInput>(
105 point_index, Field<int>(std::make_shared<CurveOfPointInput>()), AttrDomain::Point)));
106 }
107 if (params.output_is_required("Index in Curve")) {
108 params.set_output("Index in Curve",
109 Field<int>(std::make_shared<bke::EvaluateAtIndexInput>(
110 point_index,
111 Field<int>(std::make_shared<PointIndexInCurveInput>()),
112 AttrDomain::Point)));
113 }
114}
115
116static void node_register()
117{
118 static blender::bke::bNodeType ntype;
119 geo_node_type_base(&ntype, "GeometryNodeCurveOfPoint", GEO_NODE_CURVE_TOPOLOGY_CURVE_OF_POINT);
120 ntype.ui_name = "Curve of Point";
121 ntype.ui_description = "Retrieve the curve a control point is part of";
122 ntype.enum_name_legacy = "CURVE_OF_POINT";
123 ntype.nclass = NODE_CLASS_INPUT;
125 ntype.declare = node_declare;
127}
129
130} // namespace blender::nodes::node_geo_curve_topology_curve_of_point_cc
Low-level operations for curves.
#define NODE_CLASS_INPUT
Definition BKE_node.hh:447
#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 from_func(const int64_t size, GetFunc get_func)
static VArray from_container(ContainerT container)
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:2416
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:238
std::string ui_description
Definition BKE_node.hh:244
NodeGeometryExecFunction geometry_node_execute
Definition BKE_node.hh:354
const char * enum_name_legacy
Definition BKE_node.hh:247
NodeDeclareFunction declare
Definition BKE_node.hh:362