[Bf-blender-cvs] [7ab7ae80c5a] master: Fix: Incorrect cyclic interpolation for nodes bezier spline

Hans Goudey noreply at git.blender.org
Tue May 4 23:28:28 CEST 2021


Commit: 7ab7ae80c5a32be2cf4003f818e09fa3f1759fc4
Author: Hans Goudey
Date:   Tue May 4 16:28:22 2021 -0500
Branches: master
https://developer.blender.org/rB7ab7ae80c5a32be2cf4003f818e09fa3f1759fc4

Fix: Incorrect cyclic interpolation for nodes bezier spline

The special case for the interpolation to the last point was being used
for every point in the last segment, because of the rounding. Instead,
make the function slightly more complicated to properly handle the
correct interolation in the cyclic and non-cyclic cases.

===================================================================

M	source/blender/blenkernel/intern/spline_bezier.cc

===================================================================

diff --git a/source/blender/blenkernel/intern/spline_bezier.cc b/source/blender/blenkernel/intern/spline_bezier.cc
index 4981f441190..c52f71002d7 100644
--- a/source/blender/blenkernel/intern/spline_bezier.cc
+++ b/source/blender/blenkernel/intern/spline_bezier.cc
@@ -423,15 +423,22 @@ BezierSpline::InterpolationData BezierSpline::interpolation_data_from_index_fact
     const float index_factor) const
 {
   const int points_len = this->size();
-  const int index = std::floor(index_factor);
-  if (index == points_len) {
-    BLI_assert(is_cyclic_);
+
+  if (is_cyclic_) {
+    if (index_factor < points_len) {
+      const int index = std::floor(index_factor);
+      const int next_index = (index < points_len - 1) ? index + 1 : 0;
+      return InterpolationData{index, next_index, index_factor - index};
+    }
     return InterpolationData{points_len - 1, 0, 1.0f};
   }
-  if (index == points_len - 1) {
-    return InterpolationData{points_len - 2, points_len - 1, 1.0f};
+
+  if (index_factor < points_len - 1) {
+    const int index = std::floor(index_factor);
+    const int next_index = index + 1;
+    return InterpolationData{index, next_index, index_factor - index};
   }
-  return InterpolationData{index, index + 1, index_factor - index};
+  return InterpolationData{points_len - 2, points_len - 1, 1.0f};
 }
 
 /* Use a spline argument to avoid adding this to the header. */



More information about the Bf-blender-cvs mailing list