|
|
@@ -3591,7 +3591,7 @@ class Quaternion {
|
|
|
|
|
|
/**
|
|
|
* Interpolates between two quaternions via SLERP. This implementation assumes the
|
|
|
- * quaternion data are managed in flat arrays.
|
|
|
+ * quaternion data are managed in flat arrays.
|
|
|
*
|
|
|
* @param {Array<number>} dst - The destination array.
|
|
|
* @param {number} dstOffset - An offset into the destination array.
|
|
|
@@ -3604,65 +3604,78 @@ class Quaternion {
|
|
|
*/
|
|
|
static slerpFlat( dst, dstOffset, src0, srcOffset0, src1, srcOffset1, t ) {
|
|
|
|
|
|
- // fuzz-free, array-based Quaternion SLERP operation
|
|
|
-
|
|
|
let x0 = src0[ srcOffset0 + 0 ],
|
|
|
y0 = src0[ srcOffset0 + 1 ],
|
|
|
z0 = src0[ srcOffset0 + 2 ],
|
|
|
w0 = src0[ srcOffset0 + 3 ];
|
|
|
|
|
|
- const x1 = src1[ srcOffset1 + 0 ],
|
|
|
+ let x1 = src1[ srcOffset1 + 0 ],
|
|
|
y1 = src1[ srcOffset1 + 1 ],
|
|
|
z1 = src1[ srcOffset1 + 2 ],
|
|
|
w1 = src1[ srcOffset1 + 3 ];
|
|
|
|
|
|
- if ( t === 0 ) {
|
|
|
+ if ( t <= 0 ) {
|
|
|
|
|
|
dst[ dstOffset + 0 ] = x0;
|
|
|
dst[ dstOffset + 1 ] = y0;
|
|
|
dst[ dstOffset + 2 ] = z0;
|
|
|
dst[ dstOffset + 3 ] = w0;
|
|
|
+
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
- if ( t === 1 ) {
|
|
|
+ if ( t >= 1 ) {
|
|
|
|
|
|
dst[ dstOffset + 0 ] = x1;
|
|
|
dst[ dstOffset + 1 ] = y1;
|
|
|
dst[ dstOffset + 2 ] = z1;
|
|
|
dst[ dstOffset + 3 ] = w1;
|
|
|
+
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
if ( w0 !== w1 || x0 !== x1 || y0 !== y1 || z0 !== z1 ) {
|
|
|
|
|
|
- let s = 1 - t;
|
|
|
- const cos = x0 * x1 + y0 * y1 + z0 * z1 + w0 * w1,
|
|
|
- dir = ( cos >= 0 ? 1 : -1 ),
|
|
|
- sqrSin = 1 - cos * cos;
|
|
|
+ let dot = x0 * x1 + y0 * y1 + z0 * z1 + w0 * w1;
|
|
|
|
|
|
- // Skip the Slerp for tiny steps to avoid numeric problems:
|
|
|
- if ( sqrSin > Number.EPSILON ) {
|
|
|
+ if ( dot < 0 ) {
|
|
|
|
|
|
- const sin = Math.sqrt( sqrSin ),
|
|
|
- len = Math.atan2( sin, cos * dir );
|
|
|
+ x1 = - x1;
|
|
|
+ y1 = - y1;
|
|
|
+ z1 = - z1;
|
|
|
+ w1 = - w1;
|
|
|
|
|
|
- s = Math.sin( s * len ) / sin;
|
|
|
- t = Math.sin( t * len ) / sin;
|
|
|
+ dot = - dot;
|
|
|
|
|
|
}
|
|
|
|
|
|
- const tDir = t * dir;
|
|
|
+ let s = 1 - t;
|
|
|
+
|
|
|
+ if ( dot < 0.9995 ) {
|
|
|
+
|
|
|
+ // slerp
|
|
|
+
|
|
|
+ const theta = Math.acos( dot );
|
|
|
+ const sin = Math.sin( theta );
|
|
|
+
|
|
|
+ s = Math.sin( s * theta ) / sin;
|
|
|
+ t = Math.sin( t * theta ) / sin;
|
|
|
+
|
|
|
+ x0 = x0 * s + x1 * t;
|
|
|
+ y0 = y0 * s + y1 * t;
|
|
|
+ z0 = z0 * s + z1 * t;
|
|
|
+ w0 = w0 * s + w1 * t;
|
|
|
+
|
|
|
+ } else {
|
|
|
|
|
|
- x0 = x0 * s + x1 * tDir;
|
|
|
- y0 = y0 * s + y1 * tDir;
|
|
|
- z0 = z0 * s + z1 * tDir;
|
|
|
- w0 = w0 * s + w1 * tDir;
|
|
|
+ // for small angles, lerp then normalize
|
|
|
|
|
|
- // Normalize in case we just did a lerp:
|
|
|
- if ( s === 1 - t ) {
|
|
|
+ x0 = x0 * s + x1 * t;
|
|
|
+ y0 = y0 * s + y1 * t;
|
|
|
+ z0 = z0 * s + z1 * t;
|
|
|
+ w0 = w0 * s + w1 * t;
|
|
|
|
|
|
const f = 1 / Math.sqrt( x0 * x0 + y0 * y0 + z0 * z0 + w0 * w0 );
|
|
|
|
|
|
@@ -4272,68 +4285,56 @@ class Quaternion {
|
|
|
*/
|
|
|
slerp( qb, t ) {
|
|
|
|
|
|
- if ( t === 0 ) return this;
|
|
|
- if ( t === 1 ) return this.copy( qb );
|
|
|
+ if ( t <= 0 ) return this;
|
|
|
|
|
|
- const x = this._x, y = this._y, z = this._z, w = this._w;
|
|
|
+ if ( t >= 1 ) return this.copy( qb ); // copy calls _onChangeCallback()
|
|
|
|
|
|
- // http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/
|
|
|
+ let x = qb._x, y = qb._y, z = qb._z, w = qb._w;
|
|
|
|
|
|
- let cosHalfTheta = w * qb._w + x * qb._x + y * qb._y + z * qb._z;
|
|
|
+ let dot = this.dot( qb );
|
|
|
|
|
|
- if ( cosHalfTheta < 0 ) {
|
|
|
+ if ( dot < 0 ) {
|
|
|
|
|
|
- this._w = - qb._w;
|
|
|
- this._x = - qb._x;
|
|
|
- this._y = - qb._y;
|
|
|
- this._z = - qb._z;
|
|
|
+ x = - x;
|
|
|
+ y = - y;
|
|
|
+ z = - z;
|
|
|
+ w = - w;
|
|
|
|
|
|
- cosHalfTheta = - cosHalfTheta;
|
|
|
-
|
|
|
- } else {
|
|
|
-
|
|
|
- this.copy( qb );
|
|
|
+ dot = - dot;
|
|
|
|
|
|
}
|
|
|
|
|
|
- if ( cosHalfTheta >= 1.0 ) {
|
|
|
+ let s = 1 - t;
|
|
|
|
|
|
- this._w = w;
|
|
|
- this._x = x;
|
|
|
- this._y = y;
|
|
|
- this._z = z;
|
|
|
+ if ( dot < 0.9995 ) {
|
|
|
|
|
|
- return this;
|
|
|
+ // slerp
|
|
|
|
|
|
- }
|
|
|
-
|
|
|
- const sqrSinHalfTheta = 1.0 - cosHalfTheta * cosHalfTheta;
|
|
|
+ const theta = Math.acos( dot );
|
|
|
+ const sin = Math.sin( theta );
|
|
|
|
|
|
- if ( sqrSinHalfTheta <= Number.EPSILON ) {
|
|
|
+ s = Math.sin( s * theta ) / sin;
|
|
|
+ t = Math.sin( t * theta ) / sin;
|
|
|
|
|
|
- const s = 1 - t;
|
|
|
- this._w = s * w + t * this._w;
|
|
|
- this._x = s * x + t * this._x;
|
|
|
- this._y = s * y + t * this._y;
|
|
|
- this._z = s * z + t * this._z;
|
|
|
+ this._x = this._x * s + x * t;
|
|
|
+ this._y = this._y * s + y * t;
|
|
|
+ this._z = this._z * s + z * t;
|
|
|
+ this._w = this._w * s + w * t;
|
|
|
|
|
|
- this.normalize(); // normalize calls _onChangeCallback()
|
|
|
+ this._onChangeCallback();
|
|
|
|
|
|
- return this;
|
|
|
+ } else {
|
|
|
|
|
|
- }
|
|
|
+ // for small angles, lerp then normalize
|
|
|
|
|
|
- const sinHalfTheta = Math.sqrt( sqrSinHalfTheta );
|
|
|
- const halfTheta = Math.atan2( sinHalfTheta, cosHalfTheta );
|
|
|
- const ratioA = Math.sin( ( 1 - t ) * halfTheta ) / sinHalfTheta,
|
|
|
- ratioB = Math.sin( t * halfTheta ) / sinHalfTheta;
|
|
|
+ this._x = this._x * s + x * t;
|
|
|
+ this._y = this._y * s + y * t;
|
|
|
+ this._z = this._z * s + z * t;
|
|
|
+ this._w = this._w * s + w * t;
|
|
|
|
|
|
- this._w = ( w * ratioA + this._w * ratioB );
|
|
|
- this._x = ( x * ratioA + this._x * ratioB );
|
|
|
- this._y = ( y * ratioA + this._y * ratioB );
|
|
|
- this._z = ( z * ratioA + this._z * ratioB );
|
|
|
+ this.normalize(); // normalize calls _onChangeCallback()
|
|
|
|
|
|
- this._onChangeCallback();
|
|
|
+ }
|
|
|
|
|
|
return this;
|
|
|
|
|
|
@@ -54018,7 +54019,7 @@ class AnimationMixer extends EventDispatcher {
|
|
|
/**
|
|
|
* Deactivates all previously scheduled actions on this mixer.
|
|
|
*
|
|
|
- * @return {AnimationMixer} A reference to thi animation mixer.
|
|
|
+ * @return {AnimationMixer} A reference to this animation mixer.
|
|
|
*/
|
|
|
stopAllAction() {
|
|
|
|
|
|
@@ -54042,7 +54043,7 @@ class AnimationMixer extends EventDispatcher {
|
|
|
* time from {@link Clock} or {@link Timer}.
|
|
|
*
|
|
|
* @param {number} deltaTime - The delta time in seconds.
|
|
|
- * @return {AnimationMixer} A reference to thi animation mixer.
|
|
|
+ * @return {AnimationMixer} A reference to this animation mixer.
|
|
|
*/
|
|
|
update( deltaTime ) {
|
|
|
|
|
|
@@ -54088,7 +54089,7 @@ class AnimationMixer extends EventDispatcher {
|
|
|
* input parameter will be scaled by {@link AnimationMixer#timeScale}
|
|
|
*
|
|
|
* @param {number} time - The time to set in seconds.
|
|
|
- * @return {AnimationMixer} A reference to thi animation mixer.
|
|
|
+ * @return {AnimationMixer} A reference to this animation mixer.
|
|
|
*/
|
|
|
setTime( time ) {
|
|
|
|