diff options
author | Hans Goudey <h.goudey@me.com> | 2022-03-30 04:17:35 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2022-03-30 04:17:35 +0300 |
commit | 62334c6ee4c9672067edb8e8aa6cd3a685e3fd17 (patch) | |
tree | a0b08332380a795bb90c8c133d255d52d1c11c18 /source | |
parent | f4f89a76a8f4ca77bc59c9572cd2aab6da1e9023 (diff) |
Curves: Port length node to the new data-block
Ref T95443
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/nodes/geometry/nodes/node_geo_input_spline_length.cc | 22 |
1 files changed, 12 insertions, 10 deletions
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<float> construct_spline_length_gvarray(const CurveComponent &compo if (!component.has_curves()) { return {}; } - const std::unique_ptr<CurveEval> 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<SplinePtr> splines = curve->splines(); - Array<float> spline_lenghts(splines.size()); - for (const int i : splines.index_range()) { - spline_lenghts[i] = splines[i]->length(); - } + curves.ensure_evaluated_lengths(); + + VArray<bool> cyclic = curves.cyclic(); + VArray<float> lengths = VArray<float>::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<float>::ForContainer(std::move(spline_lenghts)); + return lengths; } + if (domain == ATTR_DOMAIN_POINT) { - VArray<float> length = VArray<float>::ForContainer(std::move(spline_lenghts)); return component.attribute_try_adapt_domain<float>( - std::move(length), ATTR_DOMAIN_CURVE, ATTR_DOMAIN_POINT); + std::move(lengths), ATTR_DOMAIN_CURVE, ATTR_DOMAIN_POINT); } return {}; |