mirror of
https://github.com/storytold/storyteller-bevy.git
synced 2026-10-13 23:52:55 +00:00
e1235d6a8f
The initial BVH retargeting solution produced very jittery results. Much of that jitter was eliminated by using linear interpolation between frames instead of immediate stepped transitions, but some jittering still remained, particularly noticeable in the finger motions. This PR largely fixes remaining jitter issues by making a few changes: #### Frame-time quantization Previously, we had been using the `BvhAnim::timer` field incorrectly, by manually resetting it after `Timer::just_finished` returned `true`, and returning `0.0` as the interpolation parameter for that frame. This resulted in a herky-jerky animation due to misalignment between the BVH animation's frame time and the actual application refresh rate, meaning we would lose fractions of a frame every time the timer elapsed and the frame was incremented. This PR addresses that by never calling `Timer::reset` and always using `Timer::percent` for the interpolation parameter. #### Matrix instability This PR refactors the retargeting system to operate on `Affine3A` matrices instead of `Mat4`s. `Affine3A` represents a SIMD-optimized 3x3 matrix + a translation vector, so using it provides a small performance boost in addition to being slightly more numerically stable. Additionally, we now periodically re-orthonormalize the 3x3 matrices in-between operations to mitigate drifting due to the accumulation of floating-point errors.