[Bf-blender-cvs] [62334c6ee4c] master: Curves: Port length node to the new data-block
Hans Goudey
noreply at git.blender.org
Wed Mar 30 03:18:04 CEST 2022
Commit: 62334c6ee4c9672067edb8e8aa6cd3a685e3fd17
Author: Hans Goudey
Date: Tue Mar 29 20:17:35 2022 -0500
Branches: master
https://developer.blender.org/rB62334c6ee4c9672067edb8e8aa6cd3a685e3fd17
Curves: Port length node to the new data-block
Ref T95443
===================================================================
M 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<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 {};
More information about the Bf-blender-cvs
mailing list