Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans Goudey <h.goudey@me.com>2021-05-16 01:44:33 +0300
committerHans Goudey <h.goudey@me.com>2021-05-16 01:44:33 +0300
commit038c6e229c4fb1518f726d7f6a828be026bae857 (patch)
tree1b46ee9a0e24ce5bce72584499960daee9df3c37 /source/blender/blenkernel/intern/curve_eval.cc
parentcb12fb78cad4be5fa18edf0de1f8891cd97a9bed (diff)
Splines: Convenience methods for point offsets of multiple splines
Since spline data is stored separately for each spline, the data often needs to be flattened into a separate array. It's helpful to have the necessarily-sequential part of that split off into a separate method. I've found myself using functions like these in quite a few places.
Diffstat (limited to 'source/blender/blenkernel/intern/curve_eval.cc')
-rw-r--r--source/blender/blenkernel/intern/curve_eval.cc35
1 files changed, 35 insertions, 0 deletions
diff --git a/source/blender/blenkernel/intern/curve_eval.cc b/source/blender/blenkernel/intern/curve_eval.cc
index 882fdbc0ec6..86ae70399db 100644
--- a/source/blender/blenkernel/intern/curve_eval.cc
+++ b/source/blender/blenkernel/intern/curve_eval.cc
@@ -23,6 +23,7 @@
#include "BKE_curve.h"
#include "BKE_spline.hh"
+using blender::Array;
using blender::float3;
using blender::float4x4;
using blender::Span;
@@ -82,6 +83,40 @@ void CurveEval::bounds_min_max(float3 &min, float3 &max, const bool use_evaluate
}
}
+/**
+ * Return the start indices for each of the curve spline's evaluated points, as if they were part
+ * of a flattened array. This can be used to facilitate parallelism by avoiding the need to
+ * accumulate an offset while doing more complex calculations.
+ *
+ * \note The result array is one longer than the spline count; the last element is the total size.
+ */
+blender::Array<int> CurveEval::control_point_offsets() const
+{
+ Array<int> offsets(splines_.size() + 1);
+ int offset = 0;
+ for (const int i : splines_.index_range()) {
+ offsets[i] = offset;
+ offset += splines_[i]->size();
+ }
+ offsets.last() = offset;
+ return offsets;
+}
+
+/**
+ * Exactly like #control_point_offsets, but uses the number of evaluated points instead.
+ */
+blender::Array<int> CurveEval::evaluated_point_offsets() const
+{
+ Array<int> offsets(splines_.size() + 1);
+ int offset = 0;
+ for (const int i : splines_.index_range()) {
+ offsets[i] = offset;
+ offset += splines_[i]->evaluated_points_size();
+ }
+ offsets.last() = offset;
+ return offsets;
+}
+
static BezierSpline::HandleType handle_type_from_dna_bezt(const eBezTriple_Handle dna_handle_type)
{
switch (dna_handle_type) {