-
-
Notifications
You must be signed in to change notification settings - Fork 36.2k
Quaternion - Rewrite .slerp() and .slerpFlat()
#31875
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
Conversation
📦 Bundle sizeFull ESM build, minified and gzipped.
🌳 Bundle size after tree-shakingMinimal build including a renderer, camera, empty scene, and dependencies.
|
|
Does that mean the new approach enables performance improvements (probably depending on the input data)? |
Correct. |
|
@mrdoob @Mugen87 @WestLangley I just stumbled upon this change and unfortunately this breaks the usage of SLERP for extrapolation (t outside 0 < t < 1). We were using this before and it worked very nice but in the current way this doesn't work anymore. Do you see a chance to adjust this allow extrapolation again as well? |
|
@maxuai Yes. I'll file a PR. |
|
@WestLangley Just to give some more background what we are using this for: We are rendering 3D bounding boxes in the context ground truth labeling. Simplified example: To achieve this the degree value is converted to a radians/Euler (degree * (PI /180)) which is used to create the quaternions. The factor t in this example is computed by taking the timestamp of the target point in time minus the timestamp of the previous point in time timestamp, divided by the reference point in time timestamp minus the the previous point in time timestamp: (1500-500) / (0-500) = -2 When applying the SLERP to a clone of the box at timestamp 500ms with the factor and -2 and qb = the box at timestamp 0ms you get the 50° (after converting everything back to degree). |
This PR modifies
Quaternion.slerp()andQuaternion.slerpFlat()to use the same algorithm -- the one used by Unity and Filament.//
True spherical linear interpolation is unnecessary for small angles. Instead, linear interpolation followed by a re-normalization is used for small angles.
I noticed in the FBX and Collada skinning examples, the small-angle case occurs less than 2% of the time.
When switching to the algorithm used by Unity, the same skinning examples execute the small-angle case about 75% of the time.
The lesson here is to avoid using
Number.EPSILONindiscriminately.