Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 18 additions & 10 deletions utils/curve/algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down