Skip to content

Conversation

@WestLangley
Copy link
Collaborator

This PR modifies Quaternion.slerp() and Quaternion.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.EPSILON indiscriminately.

@WestLangley WestLangley added this to the r181 milestone Sep 10, 2025
@github-actions
Copy link

📦 Bundle size

Full ESM build, minified and gzipped.

Before After Diff
WebGL 338.24
79.14
338.24
79.14
+0 B
+0 B
WebGPU 580.27
160.28
580.27
160.28
+0 B
+0 B
WebGPU Nodes 578.88
160.04
578.88
160.04
+0 B
+0 B

🌳 Bundle size after tree-shaking

Minimal build including a renderer, camera, empty scene, and dependencies.

Before After Diff
WebGL 469.88
113.85
469.7
113.74
-177 B
-104 B
WebGPU 649.98
175.93
649.8
175.85
-177 B
-85 B
WebGPU Nodes 604.09
165.11
603.91
165.01
-177 B
-97 B

@Mugen87
Copy link
Collaborator

Mugen87 commented Sep 10, 2025

Does that mean the new approach enables performance improvements (probably depending on the input data)?

@WestLangley
Copy link
Collaborator Author

Does that mean the new approach enables performance improvements (probably depending on the input data)?

Correct.

@mrdoob mrdoob merged commit 7085e35 into mrdoob:dev Sep 11, 2025
9 checks passed
@WestLangley WestLangley deleted the dev-quaternion branch September 11, 2025 05:27
@maxuai
Copy link

maxuai commented Dec 12, 2025

@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?

@WestLangley
Copy link
Collaborator Author

@maxuai Yes. I'll file a PR.

@maxuai
Copy link

maxuai commented Dec 15, 2025

@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.
The SLERP implementation is used to extrapolate the rotation of a box (e.g. wrapping a car) for a future point in time.

Simplified example:
When such a box has a roll of 20° degree at a timestamp 0 and 30° at a timestamp 500ms the extrapolated value for a timestamp 1500ms would be 50°.

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).

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.

4 participants