diff options
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/blenkernel/BKE_curves.hh | 4 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/curves_geometry.cc | 20 |
2 files changed, 21 insertions, 3 deletions
diff --git a/source/blender/blenkernel/BKE_curves.hh b/source/blender/blenkernel/BKE_curves.hh index 6a95bc7d2d2..0f2ae8a02a6 100644 --- a/source/blender/blenkernel/BKE_curves.hh +++ b/source/blender/blenkernel/BKE_curves.hh @@ -250,6 +250,7 @@ class CurvesGeometry : public ::CurvesGeometry { * Call #evaluated_offsets() first to ensure that the evaluated offsets cache is current. */ IndexRange evaluated_points_for_curve(int index) const; + IndexRange evaluated_points_for_curves(IndexRange curves) const; /** * The index of the first evaluated point for every curve. The size of this span is one larger @@ -258,6 +259,9 @@ class CurvesGeometry : public ::CurvesGeometry { */ Span<int> evaluated_offsets() const; + /** Makes sure the data described by #evaluated_offsets if necessary. */ + void ensure_evaluated_offsets() const; + Span<float3> evaluated_positions() const; private: diff --git a/source/blender/blenkernel/intern/curves_geometry.cc b/source/blender/blenkernel/intern/curves_geometry.cc index a069176c6f3..e31a983e0bb 100644 --- a/source/blender/blenkernel/intern/curves_geometry.cc +++ b/source/blender/blenkernel/intern/curves_geometry.cc @@ -469,16 +469,25 @@ IndexRange CurvesGeometry::evaluated_points_for_curve(int index) const return offsets_to_range(this->runtime->evaluated_offsets_cache.as_span(), index); } -Span<int> CurvesGeometry::evaluated_offsets() const +IndexRange CurvesGeometry::evaluated_points_for_curves(const IndexRange curves) const +{ + BLI_assert(!this->runtime->offsets_cache_dirty); + BLI_assert(this->curve_size > 0); + const int offset = this->runtime->evaluated_offsets_cache[curves.start()]; + const int offset_next = this->runtime->evaluated_offsets_cache[curves.one_after_last()]; + return {offset, offset_next - offset}; +} + +void CurvesGeometry::ensure_evaluated_offsets() const { if (!this->runtime->offsets_cache_dirty) { - return this->runtime->evaluated_offsets_cache; + return; } /* A double checked lock. */ std::scoped_lock lock{this->runtime->offsets_cache_mutex}; if (!this->runtime->offsets_cache_dirty) { - return this->runtime->evaluated_offsets_cache; + return; } threading::isolate_task([&]() { @@ -496,6 +505,11 @@ Span<int> CurvesGeometry::evaluated_offsets() const }); this->runtime->offsets_cache_dirty = false; +} + +Span<int> CurvesGeometry::evaluated_offsets() const +{ + this->ensure_evaluated_offsets(); return this->runtime->evaluated_offsets_cache; } |