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>2022-03-25 17:03:35 +0300
committerHans Goudey <h.goudey@me.com>2022-03-25 17:03:35 +0300
commitcea51c1bb500eb2cfca425e1cae5dcc419dda2ce (patch)
treea7074ea2c67c0c8a40d27faac5ebfa1793390656 /source/blender/blenkernel/intern/curve_bezier.cc
parentc0016d85b2a62858229d31bd97399fbe2608f99d (diff)
Curves: Bezier and general interpolate to evaluated utility
This commit implements generic evaluation for Bezier curves (which is really just linear interpolation, since attributes are not stored on Bezier handles). For complete parity with the old curve type, we would have to add options for this (RNA: `Spline.radius_interpolation`), but it's not clear that we want to do that. This also adds a generic `interpolate_to_evaluate` utility on curves that hides the implementation details. Though there is theoretically a performance cost to that, without some abstraction calling code would usually be too complex. Differential Revision: https://developer.blender.org/D14447
Diffstat (limited to 'source/blender/blenkernel/intern/curve_bezier.cc')
-rw-r--r--source/blender/blenkernel/intern/curve_bezier.cc40
1 files changed, 40 insertions, 0 deletions
diff --git a/source/blender/blenkernel/intern/curve_bezier.cc b/source/blender/blenkernel/intern/curve_bezier.cc
index c02555dcf6a..8efe7a17a35 100644
--- a/source/blender/blenkernel/intern/curve_bezier.cc
+++ b/source/blender/blenkernel/intern/curve_bezier.cc
@@ -134,6 +134,46 @@ void calculate_evaluated_positions(const Span<float3> positions,
}
}
+template<typename T>
+static inline void linear_interpolation(const T &a, const T &b, MutableSpan<T> dst)
+{
+ dst.first() = a;
+ const float step = 1.0f / dst.size();
+ for (const int i : dst.index_range().drop_front(1)) {
+ dst[i] = attribute_math::mix2(i * step, a, b);
+ }
+}
+
+template<typename T>
+static void interpolate_to_evaluated(const Span<T> src,
+ const Span<int> evaluated_offsets,
+ MutableSpan<T> dst)
+{
+ linear_interpolation(src.first(), src[1], dst.take_front(evaluated_offsets.first()));
+
+ threading::parallel_for(
+ src.index_range().drop_back(1).drop_front(1), 512, [&](IndexRange range) {
+ for (const int i : range) {
+ const IndexRange segment_points = offsets_to_range(evaluated_offsets, i - 1);
+ linear_interpolation(src[i], src[i + 1], dst.slice(segment_points));
+ }
+ });
+
+ const IndexRange last_segment_points(evaluated_offsets.last(1),
+ evaluated_offsets.last() - evaluated_offsets.last(1));
+ linear_interpolation(src.last(), src.first(), dst.slice(last_segment_points));
+}
+
+void interpolate_to_evaluated(const GSpan src, const Span<int> evaluated_offsets, GMutableSpan dst)
+{
+ attribute_math::convert_to_static_type(src.type(), [&](auto dummy) {
+ using T = decltype(dummy);
+ if constexpr (!std::is_void_v<attribute_math::DefaultMixer<T>>) {
+ interpolate_to_evaluated(src.typed<T>(), evaluated_offsets, dst.typed<T>());
+ }
+ });
+}
+
/** \} */
} // namespace blender::bke::curves::bezier