Changeset View
Changeset View
Standalone View
Standalone View
source/blender/nodes/geometry/nodes/node_geo_input_spline_length.cc
| Show All 19 Lines | static VArray<float> construct_spline_length_gvarray(const CurveComponent &component, | ||||
| const AttributeDomain domain) | const AttributeDomain domain) | ||||
| { | { | ||||
| if (!component.has_curves()) { | if (!component.has_curves()) { | ||||
| return {}; | return {}; | ||||
| } | } | ||||
| const std::unique_ptr<CurveEval> curve = curves_to_curve_eval(*component.get_for_read()); | const std::unique_ptr<CurveEval> curve = curves_to_curve_eval(*component.get_for_read()); | ||||
| Span<SplinePtr> splines = curve->splines(); | Span<SplinePtr> splines = curve->splines(); | ||||
| auto length_fn = [splines](int i) { return splines[i]->length(); }; | Array<float> spline_lenghts(splines.size()); | ||||
| for (const int i : splines.index_range()) { | |||||
| spline_lenghts[i] = splines[i]->length(); | |||||
| } | |||||
| if (domain == ATTR_DOMAIN_CURVE) { | if (domain == ATTR_DOMAIN_CURVE) { | ||||
| return VArray<float>::ForFunc(splines.size(), length_fn); | return VArray<float>::ForContainer(std::move(spline_lenghts)); | ||||
| } | } | ||||
| if (domain == ATTR_DOMAIN_POINT) { | if (domain == ATTR_DOMAIN_POINT) { | ||||
| VArray<float> length = VArray<float>::ForFunc(splines.size(), length_fn); | VArray<float> length = VArray<float>::ForContainer(std::move(spline_lenghts)); | ||||
| return component.attribute_try_adapt_domain<float>( | return component.attribute_try_adapt_domain<float>( | ||||
| std::move(length), ATTR_DOMAIN_CURVE, ATTR_DOMAIN_POINT); | std::move(length), ATTR_DOMAIN_CURVE, ATTR_DOMAIN_POINT); | ||||
| } | } | ||||
| return {}; | return {}; | ||||
| } | } | ||||
| class SplineLengthFieldInput final : public GeometryFieldInput { | class SplineLengthFieldInput final : public GeometryFieldInput { | ||||
| ▲ Show 20 Lines • Show All 107 Lines • Show Last 20 Lines | |||||