David Catuhe 8 роки тому
батько
коміт
da57426474

Різницю між файлами не показано, бо вона завелика
+ 25 - 25
dist/preview release/babylon.core.js


Різницю між файлами не показано, бо вона завелика
+ 3646 - 3624
dist/preview release/babylon.d.ts


Різницю між файлами не показано, бо вона завелика
+ 31 - 31
dist/preview release/babylon.js


Різницю між файлами не показано, бо вона завелика
+ 27 - 22
dist/preview release/babylon.max.js


Різницю між файлами не показано, бо вона завелика
+ 3646 - 3624
dist/preview release/babylon.module.d.ts


Різницю між файлами не показано, бо вона завелика
+ 30 - 30
dist/preview release/babylon.noworker.js


+ 71 - 18
src/Math/babylon.math.ts

@@ -1603,10 +1603,10 @@
          * The cross product is then orthogonal to both "left" and "right". 
          */
         public static CrossToRef(left: Vector3, right: Vector3, result: Vector3): void {
-            Tmp.Vector3[0].x = left.y * right.z - left.z * right.y;
-            Tmp.Vector3[0].y = left.z * right.x - left.x * right.z;
-            Tmp.Vector3[0].z = left.x * right.y - left.y * right.x;
-            result.copyFrom(Tmp.Vector3[0]);
+            MathTmp.Vector3[0].x = left.y * right.z - left.z * right.y;
+            MathTmp.Vector3[0].y = left.z * right.x - left.x * right.z;
+            MathTmp.Vector3[0].z = left.x * right.y - left.y * right.x;
+            result.copyFrom(MathTmp.Vector3[0]);
         }
 
         /**
@@ -1735,7 +1735,7 @@
          * The same than RotationFromAxis but updates the passed ref Vector3 parameter instead of returning a new Vector3.  
          */
         public static RotationFromAxisToRef(axis1: Vector3, axis2: Vector3, axis3: Vector3, ref: Vector3): void {
-            var quat = BABYLON.Tmp.Quaternion[1];
+            var quat = MathTmp.Quaternion[0];
             Quaternion.QuaternionRotationFromAxisToRef(axis1, axis2, axis3, quat);
             quat.toEulerAnglesToRef(ref);
         }
@@ -2598,6 +2598,12 @@
             }
         }
         /**
+         * Returns a new Quaternion set to (0.0, 0.0, 0.0).  
+         */
+        public static Zero(): Quaternion {
+            return new Quaternion(0.0, 0.0, 0.0, 0.0);
+        }
+        /**
          * Returns a new Quaternion as the inverted current Quaternion.  
          */
         public static Inverse(q: Quaternion): Quaternion {
@@ -2704,7 +2710,7 @@
          * Note : axis1, axis2 and axis3 are normalized during this operation.   
          */
         public static QuaternionRotationFromAxisToRef(axis1: Vector3, axis2: Vector3, axis3: Vector3, ref: Quaternion): void {
-            var rotMat = Tmp.Matrix[0];
+            var rotMat = MathTmp.Matrix[0];
             BABYLON.Matrix.FromXYZAxesToRef(axis1.normalize(), axis2.normalize(), axis3.normalize(), rotMat);
             BABYLON.Quaternion.FromRotationMatrixToRef(rotMat, ref);
         }
@@ -2915,6 +2921,16 @@
             return this;
         }
         /**
+         * Inserts the translation vector (using 3 x floats) in the current Matrix.  
+         * Returns the updated Matrix.  
+         */
+        public setTranslationFromFloats(x: number, y: number, z: number): Matrix {
+            this.m[12] = x;
+            this.m[13] = y;
+            this.m[14] = z;
+            return this;
+        }
+                /**
          * Inserts the translation vector in the current Matrix.  
          * Returns the updated Matrix.  
          */
@@ -2931,6 +2947,16 @@
             return new Vector3(this.m[12], this.m[13], this.m[14]);
         }
         /**
+         * Remove rotation and scaling part from the Matrix. 
+         * Returns the updated Matrix. 
+         */
+        public removeRotationAndScaling(): Matrix {
+            this.setRowFromFloats(0, 1, 0, 0, 0);
+            this.setRowFromFloats(1, 0, 1, 0, 0);
+            this.setRowFromFloats(2, 0, 0, 1, 0);
+            return this;
+        }        
+        /**
          * Returns a new Matrix set with the multiplication result of the current Matrix and the passed one.  
          */
         public multiply(other: Matrix): Matrix {
@@ -3092,9 +3118,9 @@
                 this.m[0] / scale.x, this.m[1] / scale.x, this.m[2] / scale.x, 0,
                 this.m[4] / scale.y, this.m[5] / scale.y, this.m[6] / scale.y, 0,
                 this.m[8] / scale.z, this.m[9] / scale.z, this.m[10] / scale.z, 0,
-                0, 0, 0, 1, Tmp.Matrix[0]);
+                0, 0, 0, 1, MathTmp.Matrix[0]);
 
-            Quaternion.FromRotationMatrixToRef(Tmp.Matrix[0], rotation);
+            Quaternion.FromRotationMatrixToRef(MathTmp.Matrix[0], rotation);
 
             return true;
         }
@@ -3208,6 +3234,22 @@
             this.m[i + 3] = row.w;
             return this;
         }
+        
+        /**
+         * Sets the index-th row of the current matrix with the passed 4 x float values.
+         * Returns the updated Matrix.    
+         */
+        public setRowFromFloats(index: number, x: number, y: number, z: number, w: number): Matrix {
+            if (index < 0 || index > 3) {
+                return this;
+            }
+            var i = index * 4;
+            this.m[i + 0] = x;
+            this.m[i + 1] = y;
+            this.m[i + 2] = z;
+            this.m[i + 3] = w;
+            return this;
+        }
         /**
          * Returns a new Matrix set from the 16 passed floats.  
          */
@@ -3242,19 +3284,25 @@
          * Returns a new Matrix composed by the passed scale (vector3), rotation (quaternion) and translation (vector3).  
          */
         public static Compose(scale: Vector3, rotation: Quaternion, translation: Vector3): Matrix {
-            var result = Matrix.FromValues(scale.x, 0, 0, 0,
+            var result = Matrix.Identity();
+            Matrix.ComposeToRef(scale, rotation, translation, result);
+            return result;
+        }
+
+          /**
+         * Update a Matrix with values composed by the passed scale (vector3), rotation (quaternion) and translation (vector3).  
+         */
+        public static ComposeToRef(scale: Vector3, rotation: Quaternion, translation: Vector3, result: Matrix): void {
+            Matrix.FromValuesToRef(scale.x, 0, 0, 0,
                 0, scale.y, 0, 0,
                 0, 0, scale.z, 0,
-                0, 0, 0, 1);
+                0, 0, 0, 1, MathTmp.Matrix[1]);
 
-            var rotationMatrix = Matrix.Identity();
-            rotation.toRotationMatrix(rotationMatrix);
-            result = result.multiply(rotationMatrix);
+            rotation.toRotationMatrix(MathTmp.Matrix[0]);
+            MathTmp.Matrix[1].multiplyToRef(MathTmp.Matrix[0], result);
 
             result.setTranslation(translation);
-
-            return result;
-        }
+        }      
         /**
          * Returns a new indentity Matrix.  
          */
@@ -4909,11 +4957,16 @@
         public static Vector3: Vector3[] = [Vector3.Zero(), Vector3.Zero(), Vector3.Zero(),
             Vector3.Zero(), Vector3.Zero(), Vector3.Zero(), Vector3.Zero(), Vector3.Zero(), Vector3.Zero()];    // 9 temp Vector3 at once should be enough
         public static Vector4: Vector4[] = [Vector4.Zero(), Vector4.Zero(), Vector4.Zero()];  // 3 temp Vector4 at once should be enough
-        public static Quaternion: Quaternion[] = [new Quaternion(0.0, 0.0, 0.0, 0.0), 
-            new Quaternion(0.0, 0.0, 0.0, 0.0)];                // 2 temp Quaternion at once should be enough
+        public static Quaternion: Quaternion[] = [Quaternion.Zero(), Quaternion.Zero()];                // 2 temp Quaternion at once should be enough
         public static Matrix: Matrix[] = [Matrix.Zero(), Matrix.Zero(),
             Matrix.Zero(), Matrix.Zero(),
             Matrix.Zero(), Matrix.Zero(),
             Matrix.Zero(), Matrix.Zero()];                      // 6 temp Matrices at once should be enough
     }
+    // Same as Tmp but not exported to keep it onyl for math functions to avoid conflicts
+    class MathTmp {
+        public static Vector3: Vector3[] = [Vector3.Zero()];
+        public static Matrix: Matrix[] = [Matrix.Zero(), Matrix.Zero()];
+        public static Quaternion: Quaternion[] = [Quaternion.Zero()];
+    }
 }

+ 44 - 43
src/Mesh/babylon.abstractMesh.ts

@@ -203,7 +203,6 @@
         // Cache
         private _localWorld = Matrix.Zero();
         public _worldMatrix = Matrix.Zero();
-        private _rotateYByPI = Matrix.RotationY(Math.PI);
         private _absolutePosition = Vector3.Zero();
         private _collisionsTransformMatrix = Matrix.Zero();
         private _collisionsScalingMatrix = Matrix.Zero();
@@ -871,61 +870,63 @@
 
             // Billboarding
             if (this.billboardMode !== AbstractMesh.BILLBOARDMODE_NONE && this.getScene().activeCamera) {
-                Tmp.Vector3[0].copyFrom(this.position);
-                var localPosition = Tmp.Vector3[0];
+                Tmp.Matrix[1].copyFrom(this.getScene().activeCamera.getViewMatrix());
 
-                if (this.parent && this.parent.getWorldMatrix) {
-                    this._markSyncedWithParent();
+                Tmp.Matrix[1].setTranslationFromFloats(0, 0, 0);
+                Tmp.Matrix[1].invertToRef(Tmp.Matrix[5]);
 
-                    var parentMatrix: Matrix;
-                    if (this._meshToBoneReferal) {
-                        this.parent.getWorldMatrix().multiplyToRef(this._meshToBoneReferal.getWorldMatrix(), Tmp.Matrix[6]);
-                        parentMatrix = Tmp.Matrix[6];
-                    } else {
-                        parentMatrix = this.parent.getWorldMatrix();
+                if ((this.billboardMode & AbstractMesh.BILLBOARDMODE_ALL) !== AbstractMesh.BILLBOARDMODE_ALL)
+                {
+                    // Need to extract rotation vectors
+                    var scale = Tmp.Vector3[2];
+                    var rotation = Tmp.Quaternion[0];
+                    var translation = Tmp.Vector3[3];
+                    Tmp.Matrix[5].decompose(scale, rotation, translation);
+
+                    var finalQuaternion = Tmp.Quaternion[1];
+                    finalQuaternion.w = rotation.w;
+                    if ((this.billboardMode & AbstractMesh.BILLBOARDMODE_X) === AbstractMesh.BILLBOARDMODE_X)
+                    {
+                        finalQuaternion.x = rotation.x;
                     }
-
-                    Vector3.TransformNormalToRef(localPosition, parentMatrix, Tmp.Vector3[1]);
-                    localPosition = Tmp.Vector3[1];
-                }
-
-                var zero = this.getScene().activeCamera.globalPosition.clone();
-
-                if (this.parent && (<any>this.parent).position) {
-                    localPosition.addInPlace((<any>this.parent).position);
-                    Matrix.TranslationToRef(localPosition.x, localPosition.y, localPosition.z, Tmp.Matrix[2]);
-                }
-
-                if ((this.billboardMode & AbstractMesh.BILLBOARDMODE_ALL) !== AbstractMesh.BILLBOARDMODE_ALL) {
-                    if (this.billboardMode & AbstractMesh.BILLBOARDMODE_X)
-                        zero.x = localPosition.x + Epsilon;
-                    if (this.billboardMode & AbstractMesh.BILLBOARDMODE_Y)
-                        zero.y = localPosition.y + Epsilon;
-                    if (this.billboardMode & AbstractMesh.BILLBOARDMODE_Z)
-                        zero.z = localPosition.z + Epsilon;
+                    
+                    if ((this.billboardMode & AbstractMesh.BILLBOARDMODE_Y) === AbstractMesh.BILLBOARDMODE_Y)
+                    {
+                        finalQuaternion.y = rotation.y;
+                    }
+                    
+                    if ((this.billboardMode & AbstractMesh.BILLBOARDMODE_Z) === AbstractMesh.BILLBOARDMODE_Z)
+                    {
+                        finalQuaternion.z = rotation.z;
+                    }
+ 
+                    Matrix.ComposeToRef(scale, finalQuaternion, translation, Tmp.Matrix[5]);
                 }
-
-                Matrix.LookAtLHToRef(localPosition, zero, Vector3.Up(), Tmp.Matrix[3]);
-                Tmp.Matrix[3].m[12] = Tmp.Matrix[3].m[13] = Tmp.Matrix[3].m[14] = 0;
-
-                Tmp.Matrix[3].invert();
-
-                Tmp.Matrix[5].multiplyToRef(Tmp.Matrix[3], this._localWorld);
-                this._rotateYByPI.multiplyToRef(this._localWorld, Tmp.Matrix[5]);
             }
 
             // Local world
             Tmp.Matrix[5].multiplyToRef(Tmp.Matrix[2], this._localWorld);
 
             // Parent
-            if (this.parent && this.parent.getWorldMatrix && this.billboardMode === AbstractMesh.BILLBOARDMODE_NONE) {
+            if (this.parent && this.parent.getWorldMatrix) {
                 this._markSyncedWithParent();
 
-                if (this._meshToBoneReferal) {
-                    this._localWorld.multiplyToRef(this.parent.getWorldMatrix(), Tmp.Matrix[6]);
-                    Tmp.Matrix[6].multiplyToRef(this._meshToBoneReferal.getWorldMatrix(), this._worldMatrix);
+                if (this.billboardMode !== AbstractMesh.BILLBOARDMODE_NONE) {
+                    if (this._meshToBoneReferal) {
+                        this.parent.getWorldMatrix().multiplyToRef(this._meshToBoneReferal.getWorldMatrix(), Tmp.Matrix[5]);
+                    } else {
+                        Tmp.Matrix[5].copyFrom(this.parent.getWorldMatrix());
+                    }
+                    Tmp.Matrix[5].removeRotationAndScaling();
+
+                    this._localWorld.multiplyToRef(Tmp.Matrix[5], this._worldMatrix);
                 } else {
-                    this._localWorld.multiplyToRef(this.parent.getWorldMatrix(), this._worldMatrix);
+                    if (this._meshToBoneReferal) {
+                        this._localWorld.multiplyToRef(this.parent.getWorldMatrix(), Tmp.Matrix[6]);
+                        Tmp.Matrix[6].multiplyToRef(this._meshToBoneReferal.getWorldMatrix(), this._worldMatrix);
+                    } else {
+                        this._localWorld.multiplyToRef(this.parent.getWorldMatrix(), this._worldMatrix);
+                    }
                 }
             } else {
                 this._worldMatrix.copyFrom(this._localWorld);