David Catuhe 7 年之前
父節點
當前提交
606a86f47e

文件差異過大導致無法顯示
+ 8284 - 8282
dist/preview release/babylon.d.ts


文件差異過大導致無法顯示
+ 21 - 21
dist/preview release/babylon.js


+ 38 - 29
dist/preview release/babylon.max.js

@@ -25955,36 +25955,41 @@ var BABYLON;
                 return BABYLON.Quaternion.Slerp(originalValue, originalAnimation.currentValue, Math.min(1.0, holder.totalWeight));
             }
             var normalizer = 1.0;
-            var cumulativeQuaternion = null;
+            var quaternions;
+            var weights;
             if (holder.totalWeight < 1.0) {
-                // We need to mix the original value in                     
-                //originalValue.decompose(finalScaling, finalQuaternion, finalPosition);
                 var scale = 1.0 - holder.totalWeight;
-                cumulativeQuaternion = originalValue.scaleInPlace(scale);
-                cumulativeQuaternion.normalize();
+                quaternions = [];
+                weights = [];
+                quaternions.push(originalValue);
+                weights.push(scale);
             }
             else {
                 if (holder.animations.length === 2) { // Slerp as soon as we can
                     return BABYLON.Quaternion.Slerp(holder.animations[0].currentValue, holder.animations[1].currentValue, holder.animations[1].weight / holder.totalWeight);
                 }
+                quaternions = [];
+                weights = [];
                 normalizer = holder.totalWeight;
             }
-            // There is no simple way to cumulate and weight quaternions so doing approximations here
             for (var animIndex = 0; animIndex < holder.animations.length; animIndex++) {
                 var runtimeAnimation = holder.animations[animIndex];
-                var scale = runtimeAnimation.weight / normalizer;
-                var current = runtimeAnimation.currentValue;
-                current.scaleInPlace(scale);
-                current.normalize();
+                quaternions.push(runtimeAnimation.currentValue);
+                weights.push(runtimeAnimation.weight / normalizer);
+            }
+            // https://gamedev.stackexchange.com/questions/62354/method-for-interpolation-between-3-quaternions
+            var cumulativeAmount = 0;
+            var cumulativeQuaternion = null;
+            for (var index = 0; index < quaternions.length;) {
                 if (!cumulativeQuaternion) {
-                    cumulativeQuaternion = current;
+                    cumulativeQuaternion = BABYLON.Quaternion.Slerp(quaternions[index], quaternions[index + 1], weights[index + 1] / (weights[index] + weights[index + 1]));
+                    cumulativeAmount = weights[index] + weights[index + 1];
+                    index += 2;
                     continue;
                 }
-                if (!BABYLON.Quaternion.AreClose(current, cumulativeQuaternion)) {
-                    current.conjugateInPlace();
-                }
-                cumulativeQuaternion.addInPlace(current);
-                cumulativeQuaternion.normalize();
+                cumulativeAmount += weights[index];
+                cumulativeQuaternion = BABYLON.Quaternion.Slerp(cumulativeQuaternion, quaternions[index], weights[index] / cumulativeAmount);
+                index++;
             }
             return cumulativeQuaternion;
         };
@@ -51333,6 +51338,22 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+        /** @ignore */
+        Animation._UniversalLerp = function (left, right, amount) {
+            var constructor = left.constructor;
+            if (constructor.Lerp) { // Lerp supported
+                return constructor.Lerp(left, right, amount);
+            }
+            else if (constructor.Slerp) { // Slerp supported
+                return constructor.Slerp(left, right, amount);
+            }
+            else if (left.toFixed) { // Number
+                return left * (1.0 - amount) + amount * right;
+            }
+            else { // Blending not supported
+                return right;
+            }
+        };
         /**
          * Parses an animation object and creates an animation
          * @param parsedAnimation Parsed animation object
@@ -52076,19 +52097,7 @@ var BABYLON;
                     }
                 }
                 else {
-                    var constructor = this._originalBlendValue.constructor;
-                    if (constructor.Lerp) { // Lerp supported
-                        this._currentValue = constructor.Lerp(this._originalBlendValue, currentValue, this._blendingFactor);
-                    }
-                    else if (constructor.Slerp) { // Slerp supported
-                        this._currentValue = constructor.Slerp(this._originalBlendValue, currentValue, this._blendingFactor);
-                    }
-                    else if (this._originalBlendValue.toFixed) { // Number
-                        this._currentValue = this._originalBlendValue * (1.0 - this._blendingFactor) + this._blendingFactor * currentValue;
-                    }
-                    else { // Blending not supported
-                        this._currentValue = currentValue;
-                    }
+                    this._currentValue = BABYLON.Animation._UniversalLerp(this._originalBlendValue, currentValue, this._blendingFactor);
                 }
                 var blendingSpeed = target && target.animationPropertiesOverride ? target.animationPropertiesOverride.blendingSpeed : this._animation.blendingSpeed;
                 this._blendingFactor += blendingSpeed;

+ 38 - 29
dist/preview release/babylon.no-module.max.js

@@ -25922,36 +25922,41 @@ var BABYLON;
                 return BABYLON.Quaternion.Slerp(originalValue, originalAnimation.currentValue, Math.min(1.0, holder.totalWeight));
             }
             var normalizer = 1.0;
-            var cumulativeQuaternion = null;
+            var quaternions;
+            var weights;
             if (holder.totalWeight < 1.0) {
-                // We need to mix the original value in                     
-                //originalValue.decompose(finalScaling, finalQuaternion, finalPosition);
                 var scale = 1.0 - holder.totalWeight;
-                cumulativeQuaternion = originalValue.scaleInPlace(scale);
-                cumulativeQuaternion.normalize();
+                quaternions = [];
+                weights = [];
+                quaternions.push(originalValue);
+                weights.push(scale);
             }
             else {
                 if (holder.animations.length === 2) { // Slerp as soon as we can
                     return BABYLON.Quaternion.Slerp(holder.animations[0].currentValue, holder.animations[1].currentValue, holder.animations[1].weight / holder.totalWeight);
                 }
+                quaternions = [];
+                weights = [];
                 normalizer = holder.totalWeight;
             }
-            // There is no simple way to cumulate and weight quaternions so doing approximations here
             for (var animIndex = 0; animIndex < holder.animations.length; animIndex++) {
                 var runtimeAnimation = holder.animations[animIndex];
-                var scale = runtimeAnimation.weight / normalizer;
-                var current = runtimeAnimation.currentValue;
-                current.scaleInPlace(scale);
-                current.normalize();
+                quaternions.push(runtimeAnimation.currentValue);
+                weights.push(runtimeAnimation.weight / normalizer);
+            }
+            // https://gamedev.stackexchange.com/questions/62354/method-for-interpolation-between-3-quaternions
+            var cumulativeAmount = 0;
+            var cumulativeQuaternion = null;
+            for (var index = 0; index < quaternions.length;) {
                 if (!cumulativeQuaternion) {
-                    cumulativeQuaternion = current;
+                    cumulativeQuaternion = BABYLON.Quaternion.Slerp(quaternions[index], quaternions[index + 1], weights[index + 1] / (weights[index] + weights[index + 1]));
+                    cumulativeAmount = weights[index] + weights[index + 1];
+                    index += 2;
                     continue;
                 }
-                if (!BABYLON.Quaternion.AreClose(current, cumulativeQuaternion)) {
-                    current.conjugateInPlace();
-                }
-                cumulativeQuaternion.addInPlace(current);
-                cumulativeQuaternion.normalize();
+                cumulativeAmount += weights[index];
+                cumulativeQuaternion = BABYLON.Quaternion.Slerp(cumulativeQuaternion, quaternions[index], weights[index] / cumulativeAmount);
+                index++;
             }
             return cumulativeQuaternion;
         };
@@ -51300,6 +51305,22 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+        /** @ignore */
+        Animation._UniversalLerp = function (left, right, amount) {
+            var constructor = left.constructor;
+            if (constructor.Lerp) { // Lerp supported
+                return constructor.Lerp(left, right, amount);
+            }
+            else if (constructor.Slerp) { // Slerp supported
+                return constructor.Slerp(left, right, amount);
+            }
+            else if (left.toFixed) { // Number
+                return left * (1.0 - amount) + amount * right;
+            }
+            else { // Blending not supported
+                return right;
+            }
+        };
         /**
          * Parses an animation object and creates an animation
          * @param parsedAnimation Parsed animation object
@@ -52043,19 +52064,7 @@ var BABYLON;
                     }
                 }
                 else {
-                    var constructor = this._originalBlendValue.constructor;
-                    if (constructor.Lerp) { // Lerp supported
-                        this._currentValue = constructor.Lerp(this._originalBlendValue, currentValue, this._blendingFactor);
-                    }
-                    else if (constructor.Slerp) { // Slerp supported
-                        this._currentValue = constructor.Slerp(this._originalBlendValue, currentValue, this._blendingFactor);
-                    }
-                    else if (this._originalBlendValue.toFixed) { // Number
-                        this._currentValue = this._originalBlendValue * (1.0 - this._blendingFactor) + this._blendingFactor * currentValue;
-                    }
-                    else { // Blending not supported
-                        this._currentValue = currentValue;
-                    }
+                    this._currentValue = BABYLON.Animation._UniversalLerp(this._originalBlendValue, currentValue, this._blendingFactor);
                 }
                 var blendingSpeed = target && target.animationPropertiesOverride ? target.animationPropertiesOverride.blendingSpeed : this._animation.blendingSpeed;
                 this._blendingFactor += blendingSpeed;

文件差異過大導致無法顯示
+ 21 - 21
dist/preview release/babylon.worker.js


+ 38 - 29
dist/preview release/es6.js

@@ -25922,36 +25922,41 @@ var BABYLON;
                 return BABYLON.Quaternion.Slerp(originalValue, originalAnimation.currentValue, Math.min(1.0, holder.totalWeight));
             }
             var normalizer = 1.0;
-            var cumulativeQuaternion = null;
+            var quaternions;
+            var weights;
             if (holder.totalWeight < 1.0) {
-                // We need to mix the original value in                     
-                //originalValue.decompose(finalScaling, finalQuaternion, finalPosition);
                 var scale = 1.0 - holder.totalWeight;
-                cumulativeQuaternion = originalValue.scaleInPlace(scale);
-                cumulativeQuaternion.normalize();
+                quaternions = [];
+                weights = [];
+                quaternions.push(originalValue);
+                weights.push(scale);
             }
             else {
                 if (holder.animations.length === 2) { // Slerp as soon as we can
                     return BABYLON.Quaternion.Slerp(holder.animations[0].currentValue, holder.animations[1].currentValue, holder.animations[1].weight / holder.totalWeight);
                 }
+                quaternions = [];
+                weights = [];
                 normalizer = holder.totalWeight;
             }
-            // There is no simple way to cumulate and weight quaternions so doing approximations here
             for (var animIndex = 0; animIndex < holder.animations.length; animIndex++) {
                 var runtimeAnimation = holder.animations[animIndex];
-                var scale = runtimeAnimation.weight / normalizer;
-                var current = runtimeAnimation.currentValue;
-                current.scaleInPlace(scale);
-                current.normalize();
+                quaternions.push(runtimeAnimation.currentValue);
+                weights.push(runtimeAnimation.weight / normalizer);
+            }
+            // https://gamedev.stackexchange.com/questions/62354/method-for-interpolation-between-3-quaternions
+            var cumulativeAmount = 0;
+            var cumulativeQuaternion = null;
+            for (var index = 0; index < quaternions.length;) {
                 if (!cumulativeQuaternion) {
-                    cumulativeQuaternion = current;
+                    cumulativeQuaternion = BABYLON.Quaternion.Slerp(quaternions[index], quaternions[index + 1], weights[index + 1] / (weights[index] + weights[index + 1]));
+                    cumulativeAmount = weights[index] + weights[index + 1];
+                    index += 2;
                     continue;
                 }
-                if (!BABYLON.Quaternion.AreClose(current, cumulativeQuaternion)) {
-                    current.conjugateInPlace();
-                }
-                cumulativeQuaternion.addInPlace(current);
-                cumulativeQuaternion.normalize();
+                cumulativeAmount += weights[index];
+                cumulativeQuaternion = BABYLON.Quaternion.Slerp(cumulativeQuaternion, quaternions[index], weights[index] / cumulativeAmount);
+                index++;
             }
             return cumulativeQuaternion;
         };
@@ -51300,6 +51305,22 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+        /** @ignore */
+        Animation._UniversalLerp = function (left, right, amount) {
+            var constructor = left.constructor;
+            if (constructor.Lerp) { // Lerp supported
+                return constructor.Lerp(left, right, amount);
+            }
+            else if (constructor.Slerp) { // Slerp supported
+                return constructor.Slerp(left, right, amount);
+            }
+            else if (left.toFixed) { // Number
+                return left * (1.0 - amount) + amount * right;
+            }
+            else { // Blending not supported
+                return right;
+            }
+        };
         /**
          * Parses an animation object and creates an animation
          * @param parsedAnimation Parsed animation object
@@ -52043,19 +52064,7 @@ var BABYLON;
                     }
                 }
                 else {
-                    var constructor = this._originalBlendValue.constructor;
-                    if (constructor.Lerp) { // Lerp supported
-                        this._currentValue = constructor.Lerp(this._originalBlendValue, currentValue, this._blendingFactor);
-                    }
-                    else if (constructor.Slerp) { // Slerp supported
-                        this._currentValue = constructor.Slerp(this._originalBlendValue, currentValue, this._blendingFactor);
-                    }
-                    else if (this._originalBlendValue.toFixed) { // Number
-                        this._currentValue = this._originalBlendValue * (1.0 - this._blendingFactor) + this._blendingFactor * currentValue;
-                    }
-                    else { // Blending not supported
-                        this._currentValue = currentValue;
-                    }
+                    this._currentValue = BABYLON.Animation._UniversalLerp(this._originalBlendValue, currentValue, this._blendingFactor);
                 }
                 var blendingSpeed = target && target.animationPropertiesOverride ? target.animationPropertiesOverride.blendingSpeed : this._animation.blendingSpeed;
                 this._blendingFactor += blendingSpeed;

文件差異過大導致無法顯示
+ 22 - 22
dist/preview release/viewer/babylon.viewer.js


+ 38 - 29
dist/preview release/viewer/babylon.viewer.max.js

@@ -26043,36 +26043,41 @@ var BABYLON;
                 return BABYLON.Quaternion.Slerp(originalValue, originalAnimation.currentValue, Math.min(1.0, holder.totalWeight));
             }
             var normalizer = 1.0;
-            var cumulativeQuaternion = null;
+            var quaternions;
+            var weights;
             if (holder.totalWeight < 1.0) {
-                // We need to mix the original value in                     
-                //originalValue.decompose(finalScaling, finalQuaternion, finalPosition);
                 var scale = 1.0 - holder.totalWeight;
-                cumulativeQuaternion = originalValue.scaleInPlace(scale);
-                cumulativeQuaternion.normalize();
+                quaternions = [];
+                weights = [];
+                quaternions.push(originalValue);
+                weights.push(scale);
             }
             else {
                 if (holder.animations.length === 2) { // Slerp as soon as we can
                     return BABYLON.Quaternion.Slerp(holder.animations[0].currentValue, holder.animations[1].currentValue, holder.animations[1].weight / holder.totalWeight);
                 }
+                quaternions = [];
+                weights = [];
                 normalizer = holder.totalWeight;
             }
-            // There is no simple way to cumulate and weight quaternions so doing approximations here
             for (var animIndex = 0; animIndex < holder.animations.length; animIndex++) {
                 var runtimeAnimation = holder.animations[animIndex];
-                var scale = runtimeAnimation.weight / normalizer;
-                var current = runtimeAnimation.currentValue;
-                current.scaleInPlace(scale);
-                current.normalize();
+                quaternions.push(runtimeAnimation.currentValue);
+                weights.push(runtimeAnimation.weight / normalizer);
+            }
+            // https://gamedev.stackexchange.com/questions/62354/method-for-interpolation-between-3-quaternions
+            var cumulativeAmount = 0;
+            var cumulativeQuaternion = null;
+            for (var index = 0; index < quaternions.length;) {
                 if (!cumulativeQuaternion) {
-                    cumulativeQuaternion = current;
+                    cumulativeQuaternion = BABYLON.Quaternion.Slerp(quaternions[index], quaternions[index + 1], weights[index + 1] / (weights[index] + weights[index + 1]));
+                    cumulativeAmount = weights[index] + weights[index + 1];
+                    index += 2;
                     continue;
                 }
-                if (!BABYLON.Quaternion.AreClose(current, cumulativeQuaternion)) {
-                    current.conjugateInPlace();
-                }
-                cumulativeQuaternion.addInPlace(current);
-                cumulativeQuaternion.normalize();
+                cumulativeAmount += weights[index];
+                cumulativeQuaternion = BABYLON.Quaternion.Slerp(cumulativeQuaternion, quaternions[index], weights[index] / cumulativeAmount);
+                index++;
             }
             return cumulativeQuaternion;
         };
@@ -51421,6 +51426,22 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+        /** @ignore */
+        Animation._UniversalLerp = function (left, right, amount) {
+            var constructor = left.constructor;
+            if (constructor.Lerp) { // Lerp supported
+                return constructor.Lerp(left, right, amount);
+            }
+            else if (constructor.Slerp) { // Slerp supported
+                return constructor.Slerp(left, right, amount);
+            }
+            else if (left.toFixed) { // Number
+                return left * (1.0 - amount) + amount * right;
+            }
+            else { // Blending not supported
+                return right;
+            }
+        };
         /**
          * Parses an animation object and creates an animation
          * @param parsedAnimation Parsed animation object
@@ -52164,19 +52185,7 @@ var BABYLON;
                     }
                 }
                 else {
-                    var constructor = this._originalBlendValue.constructor;
-                    if (constructor.Lerp) { // Lerp supported
-                        this._currentValue = constructor.Lerp(this._originalBlendValue, currentValue, this._blendingFactor);
-                    }
-                    else if (constructor.Slerp) { // Slerp supported
-                        this._currentValue = constructor.Slerp(this._originalBlendValue, currentValue, this._blendingFactor);
-                    }
-                    else if (this._originalBlendValue.toFixed) { // Number
-                        this._currentValue = this._originalBlendValue * (1.0 - this._blendingFactor) + this._blendingFactor * currentValue;
-                    }
-                    else { // Blending not supported
-                        this._currentValue = currentValue;
-                    }
+                    this._currentValue = BABYLON.Animation._UniversalLerp(this._originalBlendValue, currentValue, this._blendingFactor);
                 }
                 var blendingSpeed = target && target.animationPropertiesOverride ? target.animationPropertiesOverride.blendingSpeed : this._animation.blendingSpeed;
                 this._blendingFactor += blendingSpeed;

+ 14 - 0
src/Animations/babylon.animation.ts

@@ -1108,6 +1108,20 @@
             return Animation._ANIMATIONLOOPMODE_CONSTANT;
         }
 
+        /** @ignore */
+        public static _UniversalLerp(left: any, right: any, amount: number): any {
+            let constructor = left.constructor;
+            if (constructor.Lerp) { // Lerp supported
+                return constructor.Lerp(left, right, amount);
+            } else if (constructor.Slerp) { // Slerp supported
+                return constructor.Slerp(left, right, amount);
+            } else if (left.toFixed) { // Number
+                return left * (1.0 - amount) + amount* right;
+            } else { // Blending not supported
+                return right;
+            }
+        }
+
         /**
          * Parses an animation object and creates an animation
          * @param parsedAnimation Parsed animation object

+ 1 - 10
src/Animations/babylon.runtimeAnimation.ts

@@ -309,16 +309,7 @@
                         }
                     }
                 } else { 
-                    let constructor = this._originalBlendValue.constructor;
-                    if (constructor.Lerp) { // Lerp supported
-                        this._currentValue = constructor.Lerp(this._originalBlendValue, currentValue, this._blendingFactor);
-                    } else if (constructor.Slerp) { // Slerp supported
-                        this._currentValue = constructor.Slerp(this._originalBlendValue, currentValue, this._blendingFactor);
-                    } else if (this._originalBlendValue.toFixed) { // Number
-                        this._currentValue = this._originalBlendValue * (1.0 - this._blendingFactor) + this._blendingFactor * currentValue;
-                    } else { // Blending not supported
-                        this._currentValue = currentValue;
-                    }
+                    this._currentValue = Animation._UniversalLerp(this._originalBlendValue, currentValue, this._blendingFactor);
                 }
 
                 const blendingSpeed = target && target.animationPropertiesOverride ? target.animationPropertiesOverride.blendingSpeed : this._animation.blendingSpeed;

+ 26 - 18
src/babylon.scene.ts

@@ -2770,38 +2770,46 @@
             }
 
             let normalizer = 1.0;
-            let cumulativeQuaternion: Nullable<Quaternion> = null;
+            let quaternions: Array<Quaternion>;
+            let weights: Array<number>;
             
             if (holder.totalWeight < 1.0) {
-                // We need to mix the original value in                     
-                //originalValue.decompose(finalScaling, finalQuaternion, finalPosition);
                 let scale = 1.0 - holder.totalWeight;
-                cumulativeQuaternion = originalValue.scaleInPlace(scale);
-                cumulativeQuaternion.normalize();
+
+                quaternions = [];
+                weights = [];
+
+                quaternions.push(originalValue);
+                weights.push(scale);
             } else {
                 if (holder.animations.length === 2) { // Slerp as soon as we can
                     return Quaternion.Slerp(holder.animations[0].currentValue,  holder.animations[1].currentValue, holder.animations[1].weight / holder.totalWeight);
                 }
+                quaternions = [];
+                weights = [];
+                
                 normalizer = holder.totalWeight;
             }
-
-            // There is no simple way to cumulate and weight quaternions so doing approximations here
             for (var animIndex = 0; animIndex < holder.animations.length; animIndex++) {
                 let runtimeAnimation = holder.animations[animIndex];   
-                let scale = runtimeAnimation.weight / normalizer;
-                let current: Quaternion = runtimeAnimation.currentValue;
-                current.scaleInPlace(scale);
-                current.normalize();
+                quaternions.push(runtimeAnimation.currentValue);
+                weights.push(runtimeAnimation.weight / normalizer);
+            }
+
+            // https://gamedev.stackexchange.com/questions/62354/method-for-interpolation-between-3-quaternions
+
+            let cumulativeAmount = 0;
+            let cumulativeQuaternion: Nullable<Quaternion> = null;
+            for (var index = 0; index < quaternions.length; ) {
                 if (!cumulativeQuaternion) {
-                    cumulativeQuaternion = current;
+                    cumulativeQuaternion = Quaternion.Slerp(quaternions[index], quaternions[index + 1], weights[index + 1] / (weights[index] + weights[index + 1]));
+                    cumulativeAmount = weights[index] + weights[index + 1];
+                    index += 2;
                     continue;
                 }
-
-                if (!Quaternion.AreClose(current, cumulativeQuaternion)) {
-                    current.conjugateInPlace();
-                }
-                cumulativeQuaternion.addInPlace(current);
-                cumulativeQuaternion.normalize();
+                cumulativeAmount += weights[index];
+                cumulativeQuaternion = Quaternion.Slerp(cumulativeQuaternion, quaternions[index], weights[index] / cumulativeAmount);
+                index++;
             }
 
             return cumulativeQuaternion!;