Pārlūkot izejas kodu

Remove BoneScalingMode, rename setScale to setAdditionalScale, etc.

Gary Hsu 7 gadi atpakaļ
vecāks
revīzija
d80ce98447

+ 3 - 0
dist/preview release/what's new.md

@@ -136,6 +136,7 @@
 - Reflection and refraction no longer apply a toLinear conversion twice when applying image processing as a post process - [#4060](https://github.com/BabylonJS/Babylon.js/issues/4060) ([trevordev](https://github.com/trevordev))
 - Fix ember.js compatibility in ```PostProcessRenderEffect``` ([sebavan](https://github.com/sebavan))
 - Fix ember.js compatibility in ```BloomEffect``` and ```Camera``` ([kaysabelle](https://github.com/kaysabelle))
+- Fix bug with glTF animation when animating bone scale. ([bghgary](https://github.com/bghgary)]
 
 ## Breaking changes
 
@@ -144,3 +145,5 @@
 - glTF 2.0 loader now creates a mesh for each primitive instead of merging the primitives together into one mesh. If a mesh only has one primitive, the behavior is the same as before. This change only affects meshes that have multiple primitives. ([bghgary](https://github.com/bghgary)]
 - Engine's onCanvasPointerOutObservable will now return a PointerEvent instead of the Engine. ([trevordev](https://github.com/trevordev))
 - Removed public references to default rendering pipeline's internal post process ([trevordev](https://github.com/trevordev))
+- Rename `setScale`, `getScale`, `getScaleToRef` of the `Bone` class to `setAdditionalScale`, `getAdditionalScale`, `getAdditionalScaleToRef`. ([bghgary](https://github.com/bghgary)]
+- Bone `scaling` now replaces the scale of the local matrix instead of adding scale. ([bghgary](https://github.com/bghgary)]

+ 0 - 1
loaders/src/glTF/2.0/babylon.glTFLoader.ts

@@ -712,7 +712,6 @@ module BABYLON.GLTF2 {
 
         private _createBone(node: ILoaderNode, skin: ILoaderSkin, parent: Nullable<Bone>, localMatrix: Matrix, baseMatrix: Matrix, index: number): Bone {
             const babylonBone = new Bone(node.name || `joint${node._index}`, skin._babylonSkeleton!, parent, localMatrix, null, baseMatrix, index);
-            babylonBone.setScalingMode(BoneScalingMode.REPLACE);
 
             node._babylonAnimationTargets = node._babylonAnimationTargets || [];
             node._babylonAnimationTargets.push(babylonBone);

+ 17 - 56
src/Bones/babylon.bone.ts

@@ -1,19 +1,4 @@
 module BABYLON {
-    /**
-     * The bone scaling mode.
-     */
-    export enum BoneScalingMode {
-        /**
-         * Setting the `scaling` property on a bone adds an new scale factor on top of the existing local bone scale.
-         */
-        ADD,
-
-        /**
-         * Setting the `scaling` property on a bone replaces the existing local bone scale.
-         */
-        REPLACE
-    }
-
     export class Bone extends Node {
 
         private static _tmpVecs: Vector3[] = [Vector3.Zero(), Vector3.Zero()];
@@ -42,8 +27,6 @@
         private _negateScaleChildren = Vector3.One();
         private _scalingDeterminant = 1;
 
-        private _setScaling: (value: Vector3) => void;
-
         get _matrix(): Matrix {
             return this._localMatrix;
         }
@@ -66,8 +49,6 @@
             this.setParent(parentBone, false);
 
             this._updateDifferenceMatrix();
-
-            this.setScalingMode(BoneScalingMode.ADD);
         }
 
         // Members
@@ -158,35 +139,15 @@
         }
 
         public get scaling(): Vector3 {
-            return this.getScale();
+            let value = Vector3.One();
+            this._localMatrix.decompose(value, undefined, undefined);
+            return value;
         }
 
         public set scaling(newScaling: Vector3) {
-            this._setScaling(newScaling);
-        }
-
-        /**
-         * Sets the scaling mode for the scaling property.
-         * @param scalingMode the mode to use
-         */
-        public setScalingMode(scalingMode: BoneScalingMode): void {
-            switch (scalingMode) {
-                case BoneScalingMode.ADD: {
-                    this._setScaling = value => this.setScale(value.x, value.y, value.z);
-                    break;
-                }
-                case BoneScalingMode.REPLACE: {
-                    this._setScaling = value => {
-                        this._localMatrix.decompose(undefined, Bone._tmpQuat, Bone._tmpVecs[0]);
-                        Matrix.ComposeToRef(value, Bone._tmpQuat, Bone._tmpVecs[0], this._localMatrix);
-                        this.markAsDirty();
-                    };
-                    break;
-                }
-                default: {
-                    throw new Error(`Invalid scaling mode (${scalingMode})`);
-                }
-            }
+            this._localMatrix.decompose(undefined, Bone._tmpQuat, Bone._tmpVecs[0]);
+            Matrix.ComposeToRef(newScaling, Bone._tmpQuat, Bone._tmpVecs[0], this._localMatrix);
+            this.markAsDirty();
         }
 
         /**
@@ -408,13 +369,13 @@
         }
 
         /**
-         * Set the scale of the bone on the x, y and z axes.
-         * @param x The scale of the bone on the x axis.
-         * @param y The scale of the bone on the y axis.
-         * @param z The scale of the bone on the z axis.
+         * Adds an additional scale to the bone on the x, y and z axes.
+         * @param x The additional scale of the bone on the x axis.
+         * @param y The additional scale of the bone on the y axis.
+         * @param z The additional scale of the bone on the z axis.
          * @param scaleChildren Set this to true if children of the bone should be scaled.
          */
-        public setScale(x: number, y: number, z: number, scaleChildren = false): void {
+        public setAdditionalScale(x: number, y: number, z: number, scaleChildren = false): void {
 
             if (this.animations[0] && !this.animations[0].hasRunningRuntimeAnimations) {
                 if (!scaleChildren) {
@@ -713,20 +674,20 @@
         }
 
         /**
-         * Get the scale of the bone
-         * @returns the scale of the bone
+         * Get the additional scale of the bone
+         * @returns the additional scale of the bone
          */
-        public getScale(): Vector3 {
+        public getAdditionalScale(): Vector3 {
 
             return this._scaleVector.clone();
 
         }
 
         /**
-         * Copy the scale of the bone to a vector3.
-         * @param result The vector3 to copy the scale to
+         * Copy the additional scale of the bone to a vector3.
+         * @param result The vector3 to copy the additional scale to
          */
-        public getScaleToRef(result: Vector3): void {
+        public getAdditionalScaleToRef(result: Vector3): void {
 
             result.copyFrom(this._scaleVector);
 

+ 3 - 3
src/Math/babylon.math.ts

@@ -4199,9 +4199,9 @@
 
         /**
          * Decomposes the current Matrix into a translation, rotation and scaling components
-         * @param scale defines the scale vector3 given as a reference to update (optional)
-         * @param rotation defines the rotation quaternion given as a reference to update (optional)
-         * @param translation defines the translation vector3 given as a reference to update (optional)
+         * @param scale defines the scale vector3 given as a reference to update
+         * @param rotation defines the rotation quaternion given as a reference to update
+         * @param translation defines the translation vector3 given as a reference to update
          * @returns true if operation was successful
          */
         public decompose(scale?: Vector3, rotation?: Quaternion, translation?: Vector3): boolean {