Bläddra i källkod

Change the BuildArray prorotype + some cleaning

Julien Barrois 6 år sedan
förälder
incheckning
4cd8925a1e

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

@@ -5,9 +5,9 @@ module BABYLON {
      */
     export class Bone extends Node {
 
-        private static _tmpVecs: Vector3[] = Tools.BuildArray(2, Vector3);
+        private static _tmpVecs: Vector3[] = Tools.BuildArray(2, Vector3.Zero);
         private static _tmpQuat = Quaternion.Identity();
-        private static _tmpMats: Matrix[] = Tools.BuildArray(5, Matrix);
+        private static _tmpMats: Matrix[] = Tools.BuildArray(5, Matrix.Identity);
 
         /**
          * Gets the list of child bones

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

@@ -5,9 +5,9 @@ module BABYLON {
      */
     export class BoneLookController {
 
-        private static _tmpVecs: Vector3[] = Tools.BuildArray(10, Vector3);
+        private static _tmpVecs: Vector3[] = Tools.BuildArray(10, Vector3.Zero);
         private static _tmpQuat = Quaternion.Identity();
-        private static _tmpMats: Matrix[] = Tools.BuildArray(5, Matrix);
+        private static _tmpMats: Matrix[] = Tools.BuildArray(5, Matrix.Identity);
 
         /**
          * The target Vector3 that the bone will look at

+ 3 - 3
src/Culling/babylon.boundingBox.ts

@@ -6,7 +6,7 @@ module BABYLON {
         /**
          * Gets the 8 vectors representing the bounding box in local space
          */
-        public vectors: Vector3[] = Tools.BuildArray(8, Vector3);
+        public vectors: Vector3[] = Tools.BuildArray(8, Vector3.Zero);
         /**
          * Gets the center of the bounding box in local space
          */
@@ -26,11 +26,11 @@ module BABYLON {
         /**
          * Gets the OBB (object bounding box) directions
          */
-        public directions: Vector3[] = Tools.BuildArray(3, Vector3);
+        public directions: Vector3[] = Tools.BuildArray(3, Vector3.Zero);
         /**
          * Gets the 8 vectors representing the bounding box in world space
          */
-        public vectorsWorld: Vector3[] = Tools.BuildArray(8, Vector3);
+        public vectorsWorld: Vector3[] = Tools.BuildArray(8, Vector3.Zero);
         /**
          * Gets the minimum vector in world space
          */

+ 14 - 28
src/Math/babylon.math.ts

@@ -1632,20 +1632,6 @@ module BABYLON {
         }
 
         /**
-         * Adds the given coordinates to the current Vector3
-         * @param x defines the x coordinate of the operand
-         * @param y defines the y coordinate of the operand
-         * @param z defines the z coordinate of the operand
-         * @returns the current updated Vector3
-         */
-        public addInPlaceFromFloats(x: number, y: number, z: number): Vector3 {
-            this.x += x;
-            this.y += y;
-            this.z += z;
-            return this;
-        }
-
-        /**
          * Gets a new Vector3, result of the addition the current Vector3 and the given vector
          * @param otherVector defines the second operand
          * @returns the resulting Vector3
@@ -2708,13 +2694,13 @@ module BABYLON {
          */
         constructor(
             /** x value of the vector */
-            public x: number = 0,
+            public x: number,
             /** y value of the vector */
-            public y: number = 0,
+            public y: number,
             /** z value of the vector */
-            public z: number = 0,
+            public z: number,
             /** w value of the vector */
-            public w: number = 0
+            public w: number
         ) { }
 
         /**
@@ -7193,21 +7179,21 @@ module BABYLON {
      * @hidden
      */
     export class Tmp {
-        public static Color3: Color3[] = Tools.BuildArray(3, Color3);
-        public static Color4: Color4[] = Tools.BuildArray(3, Color4);
-        public static Vector2: Vector2[] = Tools.BuildArray(3, Vector2); // 3 temp Vector2 at once should be enough
-        public static Vector3: Vector3[] = Tools.BuildArray(9, Vector3); // 9 temp Vector3 at once should be enough
-        public static Vector4: Vector4[] = Tools.BuildArray(3, Vector4); // 3 temp Vector4 at once should be enough
-        public static Quaternion: Quaternion[] = Tools.BuildArray(2, Quaternion); // 2 temp Quaternion at once should be enough
-        public static Matrix: Matrix[] = Tools.BuildArray(6, Matrix); // 6 temp Matrices at once should be enough
+        public static Color3: Color3[] = Tools.BuildArray(3, Color3.Black);
+        public static Color4: Color4[] = Tools.BuildArray(3, () => new Color4(0, 0, 0, 0));
+        public static Vector2: Vector2[] = Tools.BuildArray(3, Vector2.Zero); // 3 temp Vector2 at once should be enough
+        public static Vector3: Vector3[] = Tools.BuildArray(9, Vector3.Zero); // 9 temp Vector3 at once should be enough
+        public static Vector4: Vector4[] = Tools.BuildArray(3, Vector4.Zero); // 3 temp Vector4 at once should be enough
+        public static Quaternion: Quaternion[] = Tools.BuildArray(2, Quaternion.Zero); // 2 temp Quaternion at once should be enough
+        public static Matrix: Matrix[] = Tools.BuildArray(6, Matrix.Identity); // 6 temp Matrices at once should be enough
     }
     /**
      * @hidden
      * Same as Tmp but not exported to keep it only for math functions to avoid conflicts
      */
     class MathTmp {
-        public static Vector3: Vector3[] = Tools.BuildArray(6, Vector3);
-        public static Matrix: Matrix[] = Tools.BuildArray(2, Matrix);
-        public static Quaternion: Quaternion[] = Tools.BuildArray(3, Quaternion);
+        public static Vector3: Vector3[] = Tools.BuildArray(6, Vector3.Zero);
+        public static Matrix: Matrix[] = Tools.BuildArray(2, Matrix.Identity);
+        public static Quaternion: Quaternion[] = Tools.BuildArray(3, Quaternion.Zero);
     }
 }

+ 1 - 1
src/Physics/babylon.physicsImpostor.ts

@@ -167,7 +167,7 @@ module BABYLON {
 
         private _isDisposed = false;
 
-        private static _tmpVecs: Vector3[] = Tools.BuildArray(3, Vector3);
+        private static _tmpVecs: Vector3[] = Tools.BuildArray(3, Vector3.Zero);
         private static _tmpQuat: Quaternion = Quaternion.Identity();
 
         /**

+ 3 - 4
src/Tools/babylon.tools.ts

@@ -589,14 +589,13 @@ module BABYLON {
         /**
          * Returns an array of the given size filled with element built from the given constructor and the paramters
          * @param size the number of element to construct and put in the array
-         * @param konstructor the class name (or constructor function)
-         * @param kparams the arguments to pass to each call to the constructor
+         * @param itemBuilder a callback responsable for creating new instance of item. Called once per array entry.
          * @returns a new array filled with new objects
          */
-        public static BuildArray<T, P extends any[]>(size: number, konstructor: new (...p: P) => T, ...kparams: P): Array<T> {
+        public static BuildArray<T>(size: number, itemBuilder: () => T): Array<T> {
             const a: T[] = [];
             for (let i = 0; i < size; ++i) {
-                a.push(new konstructor(...kparams));
+                a.push(itemBuilder());
             }
             return a;
         }