Browse Source

Restore original naming

David Catuhe 7 years ago
parent
commit
1729168e5a

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

@@ -145,4 +145,3 @@
 - 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))
-- Removed `setScale`, `getScale`, `getScaleToRef` of the `Bone` class ([bghgary](https://github.com/bghgary)]

+ 47 - 8
src/Bones/babylon.bone.ts

@@ -228,11 +228,11 @@
 
         /** Gets or sets current scaling (in local space) */
         public get scaling(): Vector3 {
-            return this.getScaling();
+            return this.getScale();
         }
 
         public set scaling(newScaling: Vector3) {
-            this.setScaling(newScaling);
+            this.setScale(newScaling, true);
         }
 
         /**
@@ -505,32 +505,71 @@
          * @param x The amount to scale the bone on the x axis
          * @param y The amount to scale the bone on the y axis
          * @param z The amount to scale the bone on the z axis
+         * @param scaleChildren sets this to true if children of the bone should be scaled as well (false by default)
          */
-        public scale(x: number, y: number, z: number): void {
+        public scale(x: number, y: number, z: number, scaleChildren = false): void {
+            if (!scaleChildren) {
+                this._scaleOnlyLocally(x, y, z);
+                return;
+            }            
+
             this._decompose();
             this._localScaling.x *= x;
             this._localScaling.y *= y;
             this._localScaling.z *= z;
-
+            
             this._markAsDirtyAndCompose();
         }
 
         /**
          * Set the bone scaling in local space
          * @param scale defines the scaling vector
+         * @param scaleChildren sets this to true if children of the bone should be scaled as well (false by default)
          */
-        public setScaling(scale: Vector3): void {
+        public setScale(scale: Vector3, scaleChildren = false): void {
+            if (!scaleChildren) {
+                this._scaleOnlyLocally(scale.x, scale.y, scale.z);
+                return;
+            }
+            
             this._decompose();
             this._localScaling.copyFrom(scale);
-            
             this._markAsDirtyAndCompose();
         }    
+
+        private _scaleOnlyLocally(x: number, y: number, z: number): void {
+            var locMat = this.getLocalMatrix();
+
+            // Apply new scaling on top of current local matrix
+            var scaleMat = Bone._tmpMats[0];
+            Matrix.ScalingToRef(x, y, z, scaleMat);
+            scaleMat.multiplyToRef(locMat, locMat);
+
+            // Update the absolute transform
+            var parent = this.getParent();
+
+            if (parent) {
+                locMat.multiplyToRef(parent.getAbsoluteTransform(), this.getAbsoluteTransform());
+            } else {
+                this.getAbsoluteTransform().copyFrom(locMat);
+            }
+
+            // Invert scaling matrix and apply the inverse to all children
+            scaleMat.invert();
+
+            for (var child of this.children) {
+                var cm = child.getLocalMatrix();
+                cm.multiplyToRef(scaleMat, cm);
+            }
+
+            this.markAsDirty();
+        }
         
         /**
          * Gets the current scaling in local space
          * @returns the current scaling vector
          */
-        public getScaling(): Vector3 {
+        public getScale(): Vector3 {
             this._decompose();
             return this._localScaling;
         }
@@ -539,7 +578,7 @@
          * Gets the current scaling in local space and stores it in a target vector
          * @param result defines the target vector
          */
-        public getScalingToRef(result: Vector3) {
+        public getScaleToRef(result: Vector3) {
             this._decompose();
             result.copyFrom(this._localScaling);
         }        

+ 2 - 2
src/Bones/babylon.boneIKController.ts

@@ -84,8 +84,8 @@ module BABYLON {
             
             if (this._bone1.length) {
 
-                var boneScale1 = this._bone1.getScaling();
-                var boneScale2 = this._bone2.getScaling();
+                var boneScale1 = this._bone1.getScale();
+                var boneScale2 = this._bone2.getScale();
                 
                 this._bone1Length = this._bone1.length * boneScale1.y * this.mesh.scaling.y;
                 this._bone2Length = this._bone2.length * boneScale2.y * this.mesh.scaling.y;