51 const int last_index = curves.curves_num() - 1;
52 const float total_length = lengths.last() + curves.evaluated_length_total_for_curve(
53 last_index, cyclic[last_index]);
54 if (total_length > 0.0f) {
55 const float factor = 1.0f / total_length;
56 for (
float &value : lengths) {
64 for (
const int i : lengths.index_range()) {
65 lengths[i] = i / (lengths.size() - 1.0f);
85 curves.ensure_evaluated_lengths();
86 const OffsetIndices points_by_curve = curves.points_by_curve();
88 const VArray<int> resolutions = curves.resolution();
94 for (const int i_curve : range) {
95 const IndexRange points = points_by_curve[i_curve];
96 const bool is_cyclic = cyclic[i_curve];
97 const Span<float> evaluated_lengths = curves.evaluated_lengths_for_curve(i_curve, is_cyclic);
98 MutableSpan<float> lengths = result.as_mutable_span().slice(points);
99 lengths.first() = 0.0f;
100 const float last_evaluated_length = evaluated_lengths.is_empty() ? 0.0f :
101 evaluated_lengths.last();
104 switch (types[i_curve]) {
105 case CURVE_TYPE_CATMULL_ROM: {
106 const int resolution = resolutions[i_curve];
107 for (const int i : IndexRange(points.size()).drop_back(1)) {
108 lengths[i + 1] = evaluated_lengths[resolution * (i + 1) - 1];
110 total = last_evaluated_length;
113 case CURVE_TYPE_POLY:
114 lengths.drop_front(1).copy_from(evaluated_lengths.take_front(lengths.size() - 1));
115 total = last_evaluated_length;
117 case CURVE_TYPE_BEZIER: {
118 const Span<int> offsets = curves.bezier_evaluated_offsets_for_curve(i_curve);
119 for (const int i : IndexRange(points.size()).drop_back(1)) {
120 lengths[i + 1] = evaluated_lengths[offsets[i + 1] - 1];
122 total = last_evaluated_length;
125 case CURVE_TYPE_NURBS: {
126 const Span<float3> positions = curves.positions().slice(points);
128 for (const int i : positions.index_range().drop_back(1)) {
130 length += math::distance(positions[i], positions[i + 1]);
132 lengths.last() = length;
134 length += math::distance(positions.first(), positions.last());
140 postprocess_lengths_for_curve(lengths, total);
285 Field<float> parameter_field{std::make_shared<CurveParameterFieldInput>()};
286 Field<float> length_field{std::make_shared<CurveLengthParameterFieldInput>()};
287 Field<int> index_on_spline_field{std::make_shared<IndexOnSplineFieldInput>()};
288 params.set_output(
"Factor", std::move(parameter_field));
289 params.set_output(
"Length", std::move(length_field));
290 params.set_output(
"Index", std::move(index_on_spline_field));