From 62334c6ee4c9672067edb8e8aa6cd3a685e3fd17 Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Tue, 29 Mar 2022 20:17:35 -0500 Subject: Curves: Port length node to the new data-block Ref T95443 --- .../geometry/nodes/node_geo_input_spline_length.cc | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'source/blender/nodes/geometry/nodes/node_geo_input_spline_length.cc') diff --git a/source/blender/nodes/geometry/nodes/node_geo_input_spline_length.cc b/source/blender/nodes/geometry/nodes/node_geo_input_spline_length.cc index ab6f6b40d5e..38bd79ff1a7 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_input_spline_length.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_input_spline_length.cc @@ -3,7 +3,6 @@ #include "node_geometry_util.hh" #include "BKE_curves.hh" -#include "BKE_spline.hh" namespace blender::nodes::node_geo_input_spline_length_cc { @@ -23,21 +22,24 @@ static VArray construct_spline_length_gvarray(const CurveComponent &compo if (!component.has_curves()) { return {}; } - const std::unique_ptr curve = curves_to_curve_eval(*component.get_for_read()); + const Curves &curves_id = *component.get_for_read(); + const bke::CurvesGeometry &curves = bke::CurvesGeometry::wrap(curves_id.geometry); - Span splines = curve->splines(); - Array spline_lenghts(splines.size()); - for (const int i : splines.index_range()) { - spline_lenghts[i] = splines[i]->length(); - } + curves.ensure_evaluated_lengths(); + + VArray cyclic = curves.cyclic(); + VArray lengths = VArray::ForFunc( + curves.curves_num(), [&curves, cyclic = std::move(cyclic)](int64_t index) { + return curves.evaluated_length_total_for_curve(index, cyclic[index]); + }); if (domain == ATTR_DOMAIN_CURVE) { - return VArray::ForContainer(std::move(spline_lenghts)); + return lengths; } + if (domain == ATTR_DOMAIN_POINT) { - VArray length = VArray::ForContainer(std::move(spline_lenghts)); return component.attribute_try_adapt_domain( - std::move(length), ATTR_DOMAIN_CURVE, ATTR_DOMAIN_POINT); + std::move(lengths), ATTR_DOMAIN_CURVE, ATTR_DOMAIN_POINT); } return {}; -- cgit v1.2.3