Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replaced SQUAD interpolation with Cubic Hermite to align with GLTF 2.0 spec #3920

Merged
merged 1 commit into from
Apr 17, 2024

Conversation

benjitrosch
Copy link
Contributor

@benjitrosch benjitrosch commented Apr 17, 2024

This is a follow up PR on #3919.

During that PR, I went researching for a quaternion cubic spline algorithm that could be used, and landed on SQUAD. Turns out, the GLTF 2.0 very specifically provides an algorithm that is says to use (which looks to me like Cubic Hermite Spline):

Let ak, vk, and bk be the in-tangent, the property value, and the out-tangent of the k-th frame respectively.

The interpolated sampler value vt at the timestamp tc is computed as follows.

vt=(2t3−3t2+1)∗vk+td(t3−2t2+t)∗bk+(−2t3+3t2)∗vk+1+td(t3−t2)∗ak+1

However, Cubic Hermite Spline showed flipping/spinning when I was doing tests due to quaternion double-cover. To alleviate this, I added some logic to check the dot product and negate them (and also normalized them).

After this change I'm happy to say it looks pretty good and should be technically more "correct" and compliant with what GLTF 2.0 expects!

@raysan5 raysan5 merged commit 4491ff0 into raysan5:master Apr 17, 2024
14 checks passed
@raysan5
Copy link
Owner

raysan5 commented Apr 17, 2024

@benjitrosch Nice! thanks for the review!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants