From 2455fd52178de971da86410be7b4fd4eabac8d37 Mon Sep 17 00:00:00 2001 From: "Ilya V. Portnov" Date: Sun, 26 Oct 2025 15:14:56 +0500 Subject: [PATCH] Fix "index out of range" error when using "Track normal" algorithm. --- utils/curve/algorithms.py | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/utils/curve/algorithms.py b/utils/curve/algorithms.py index d1c88341a0..08241e0f87 100644 --- a/utils/curve/algorithms.py +++ b/utils/curve/algorithms.py @@ -172,23 +172,31 @@ def evaluate_array(self, ts): ts = np.array(ts) tknots, quats = self.tknots, self.quats base_indexes = tknots.searchsorted(ts, side='left')-1 - t1s, t2s = tknots[base_indexes], tknots[base_indexes+1] - dts = (ts - t1s) / (t2s - t1s) + shifted_indexes = base_indexes + 1 + good = shifted_indexes < len(tknots) + shifted_indexes[np.logical_not(good)] = len(tknots) - 1 + t1s, t2s = tknots[base_indexes], tknots[shifted_indexes] + dts = np.empty_like(ts) + dts[good] = (ts[good] - t1s[good]) / (t2s[good] - t1s[good]) + dts[np.logical_not(good)] = 0 #dts = np.clip(dts, 0.0, 1.0) # Just in case... matrix_out = [] # TODO: ideally this should be vectorized with numpy; # but that would require implementation of quaternion # interpolation in numpy. for dt, base_index in zip(dts, base_indexes): - q1, q2 = quats[base_index], quats[base_index+1] - # spherical linear interpolation. - # TODO: implement `squad`. - if dt < 0: - q = q1 - elif dt > 1.0: - q = q2 + if base_index+1 < len(quats): + q1, q2 = quats[base_index], quats[base_index+1] + # spherical linear interpolation. + # TODO: implement `squad`. + if dt < 0: + q = q1 + elif dt > 1.0: + q = q2 + else: + q = q1.slerp(q2, dt) else: - q = q1.slerp(q2, dt) + q = quats[base_index] matrix = np.array(q.to_matrix()) matrix_out.append(matrix) return np.array(matrix_out)