فهرست منبع

ArrayTools to prevent cyclic ref

sebastien 6 سال پیش
والد
کامیت
e68fa87f14

+ 2 - 2
src/Bones/bone.ts

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

+ 5 - 6
src/Bones/boneLookController.ts

@@ -1,9 +1,8 @@
-import { Bone } from "./bone";
-
+import { Nullable } from "types";
+import { ArrayTools } from "Tools/arrayTools";
 import { Vector3, Quaternion, Matrix, Space, Axis } from "Math/math";
 import { Vector3, Quaternion, Matrix, Space, Axis } from "Math/math";
-import { Tools } from "Tools/tools";
 import { AbstractMesh } from "Mesh/abstractMesh";
 import { AbstractMesh } from "Mesh/abstractMesh";
-import { Nullable } from "types";
+import { Bone } from "./bone";
 
 
     /**
     /**
      * Class used to make a bone look toward a point in space
      * Class used to make a bone look toward a point in space
@@ -11,9 +10,9 @@ import { Nullable } from "types";
      */
      */
     export class BoneLookController {
     export class BoneLookController {
 
 
-        private static _tmpVecs: Vector3[] = Tools.BuildArray(10, Vector3.Zero);
+        private static _tmpVecs: Vector3[] = ArrayTools.BuildArray(10, Vector3.Zero);
         private static _tmpQuat = Quaternion.Identity();
         private static _tmpQuat = Quaternion.Identity();
-        private static _tmpMats: Matrix[] = Tools.BuildArray(5, Matrix.Identity);
+        private static _tmpMats: Matrix[] = ArrayTools.BuildArray(5, Matrix.Identity);
 
 
         /**
         /**
          * The target Vector3 that the bone will look at
          * The target Vector3 that the bone will look at

+ 5 - 5
src/Culling/boundingBox.ts

@@ -1,5 +1,5 @@
 import { DeepImmutable } from "types";
 import { DeepImmutable } from "types";
-import { Tools } from "Tools/tools";
+import { ArrayTools } from "Tools/arrayTools";
 import { Matrix, Vector3, Plane, Epsilon } from "Math/math";
 import { Matrix, Vector3, Plane, Epsilon } from "Math/math";
 import { BoundingSphere } from "Culling/boundingSphere";
 import { BoundingSphere } from "Culling/boundingSphere";
 
 
@@ -12,7 +12,7 @@ import { ICullable } from "./boundingInfo";
         /**
         /**
          * Gets the 8 vectors representing the bounding box in local space
          * Gets the 8 vectors representing the bounding box in local space
          */
          */
-        public readonly vectors: Vector3[] = Tools.BuildArray(8, Vector3.Zero);
+        public readonly vectors: Vector3[] = ArrayTools.BuildArray(8, Vector3.Zero);
         /**
         /**
          * Gets the center of the bounding box in local space
          * Gets the center of the bounding box in local space
          */
          */
@@ -32,11 +32,11 @@ import { ICullable } from "./boundingInfo";
         /**
         /**
          * Gets the OBB (object bounding box) directions
          * Gets the OBB (object bounding box) directions
          */
          */
-        public readonly directions: Vector3[] = Tools.BuildArray(3, Vector3.Zero);
+        public readonly directions: Vector3[] = ArrayTools.BuildArray(3, Vector3.Zero);
         /**
         /**
          * Gets the 8 vectors representing the bounding box in world space
          * Gets the 8 vectors representing the bounding box in world space
          */
          */
-        public readonly vectorsWorld: Vector3[] = Tools.BuildArray(8, Vector3.Zero);
+        public readonly vectorsWorld: Vector3[] = ArrayTools.BuildArray(8, Vector3.Zero);
         /**
         /**
          * Gets the minimum vector in world space
          * Gets the minimum vector in world space
          */
          */
@@ -55,7 +55,7 @@ import { ICullable } from "./boundingInfo";
         public readonly maximum: Vector3 = Vector3.Zero();
         public readonly maximum: Vector3 = Vector3.Zero();
 
 
         private _worldMatrix: DeepImmutable<Matrix>;
         private _worldMatrix: DeepImmutable<Matrix>;
-        private static readonly TmpVector3 = Tools.BuildArray(3, Vector3.Zero);
+        private static readonly TmpVector3 = ArrayTools.BuildArray(3, Vector3.Zero);
 
 
         /**
         /**
          * @hidden
          * @hidden

+ 2 - 2
src/Culling/boundingInfo.ts

@@ -1,5 +1,5 @@
 import { DeepImmutable } from "types";
 import { DeepImmutable } from "types";
-import { Tools } from "Tools/tools";
+import { ArrayTools } from "Tools/arrayTools";
 import { Matrix, Vector3, Plane } from "Math/math";
 import { Matrix, Vector3, Plane } from "Math/math";
 import { AbstractMesh } from "Mesh/abstractMesh";
 import { AbstractMesh } from "Mesh/abstractMesh";
 import { Collider } from "Collisions/collider";
 import { Collider } from "Collisions/collider";
@@ -62,7 +62,7 @@ import { BoundingSphere } from "./boundingSphere";
 
 
         private _isLocked = false;
         private _isLocked = false;
 
 
-        private static readonly TmpVector3 = Tools.BuildArray(2, Vector3.Zero);
+        private static readonly TmpVector3 = ArrayTools.BuildArray(2, Vector3.Zero);
 
 
         /**
         /**
          * Constructs bounding info
          * Constructs bounding info

+ 2 - 2
src/Culling/boundingSphere.ts

@@ -1,5 +1,5 @@
 import { DeepImmutable } from "types";
 import { DeepImmutable } from "types";
-import { Tools } from "Tools/tools";
+import { ArrayTools } from "Tools/arrayTools";
 import { Matrix, Vector3, Plane } from "Math/math";
 import { Matrix, Vector3, Plane } from "Math/math";
 
 
     /**
     /**
@@ -32,7 +32,7 @@ import { Matrix, Vector3, Plane } from "Math/math";
         public readonly maximum = Vector3.Zero();
         public readonly maximum = Vector3.Zero();
 
 
         private _worldMatrix: DeepImmutable<Matrix>;
         private _worldMatrix: DeepImmutable<Matrix>;
-        private static readonly TmpVector3 = Tools.BuildArray(3, Vector3.Zero);
+        private static readonly TmpVector3 = ArrayTools.BuildArray(3, Vector3.Zero);
 
 
         /**
         /**
          * Creates a new bounding sphere
          * Creates a new bounding sphere

+ 2 - 2
src/Culling/ray.ts

@@ -1,5 +1,5 @@
 import { DeepImmutable, Nullable } from "types";
 import { DeepImmutable, Nullable } from "types";
-import { Tools } from "Tools";
+import { ArrayTools } from "Tools/arrayTools";
 import { Matrix, Vector3, Plane, Tmp } from "Math";
 import { Matrix, Vector3, Plane, Tmp } from "Math";
 import { AbstractMesh } from "Mesh";
 import { AbstractMesh } from "Mesh";
 import { PickingInfo, IntersectionInfo } from "Collisions";
 import { PickingInfo, IntersectionInfo } from "Collisions";
@@ -8,7 +8,7 @@ import { BoundingBox, BoundingSphere } from "Culling";
      * Class representing a ray with position and direction
      * Class representing a ray with position and direction
      */
      */
     export class Ray {
     export class Ray {
-        private static readonly TmpVector3 = Tools.BuildArray(6, Vector3.Zero);
+        private static readonly TmpVector3 = ArrayTools.BuildArray(6, Vector3.Zero);
         private _tmpRay: Ray;
         private _tmpRay: Ray;
 
 
         /**
         /**

+ 11 - 11
src/Math/math.ts

@@ -1,5 +1,5 @@
 import { DeepImmutable } from "types";
 import { DeepImmutable } from "types";
-import { Tools } from "Tools/tools";
+import { ArrayTools } from "Tools/arrayTools";
 import { Nullable, FloatArray, float } from "types";
 import { Nullable, FloatArray, float } from "types";
 import { Scalar } from "Math/math.scalar";
 import { Scalar } from "Math/math.scalar";
 import { Engine } from "Engine/engine";
 import { Engine } from "Engine/engine";
@@ -7342,20 +7342,20 @@ import { Ray } from "Culling/ray";
      */
      */
     export class Tmp {
     export class Tmp {
 
 
-        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(13, Vector3.Zero); // 13 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(8, Matrix.Identity); // 8 temp Matrices at once should be enough
+        public static Color3: Color3[] = ArrayTools.BuildArray(3, Color3.Black);
+        public static Color4: Color4[] = ArrayTools.BuildArray(3, () => new Color4(0, 0, 0, 0));
+        public static Vector2: Vector2[] = ArrayTools.BuildArray(3, Vector2.Zero); // 3 temp Vector2 at once should be enough
+        public static Vector3: Vector3[] = ArrayTools.BuildArray(13, Vector3.Zero); // 13 temp Vector3 at once should be enough
+        public static Vector4: Vector4[] = ArrayTools.BuildArray(3, Vector4.Zero); // 3 temp Vector4 at once should be enough
+        public static Quaternion: Quaternion[] = ArrayTools.BuildArray(2, Quaternion.Zero); // 2 temp Quaternion at once should be enough
+        public static Matrix: Matrix[] = ArrayTools.BuildArray(8, Matrix.Identity); // 8 temp Matrices at once should be enough
     }
     }
     /**
     /**
      * @hidden
      * @hidden
      * Same as Tmp but not exported to keep it only for math functions to avoid conflicts
      * Same as Tmp but not exported to keep it only for math functions to avoid conflicts
      */
      */
     class MathTmp {
     class MathTmp {
-        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);
+        public static Vector3: Vector3[] = ArrayTools.BuildArray(6, Vector3.Zero);
+        public static Matrix: Matrix[] = ArrayTools.BuildArray(2, Matrix.Identity);
+        public static Quaternion: Quaternion[] = ArrayTools.BuildArray(3, Quaternion.Zero);
     }
     }

+ 2 - 1
src/Physics/physicsImpostor.ts

@@ -1,5 +1,6 @@
 import { Nullable, IndicesArray } from "types";
 import { Nullable, IndicesArray } from "types";
 import { Tools } from "Tools/tools";
 import { Tools } from "Tools/tools";
+import { ArrayTools } from "Tools/arrayTools";
 import { Vector3, Matrix, Quaternion, Space } from "Math/math";
 import { Vector3, Matrix, Quaternion, Space } from "Math/math";
 import { TransformNode } from "Mesh/transformNode";
 import { TransformNode } from "Mesh/transformNode";
 import { AbstractMesh } from "Mesh/abstractMesh";
 import { AbstractMesh } from "Mesh/abstractMesh";
@@ -175,7 +176,7 @@ import { PhysicsJoint, PhysicsJointData } from "./physicsJoint";
 
 
         private _isDisposed = false;
         private _isDisposed = false;
 
 
-        private static _tmpVecs: Vector3[] = Tools.BuildArray(3, Vector3.Zero);
+        private static _tmpVecs: Vector3[] = ArrayTools.BuildArray(3, Vector3.Zero);
         private static _tmpQuat: Quaternion = Quaternion.Identity();
         private static _tmpQuat: Quaternion = Quaternion.Identity();
 
 
         /**
         /**

+ 18 - 0
src/Tools/arrayTools.ts

@@ -0,0 +1,18 @@
+/**
+ * Class containing a set of static utilities functions for arrays.
+ */
+export class ArrayTools {
+    /**
+     * 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 itemBuilder a callback responsible for creating new instance of item. Called once per array entry.
+     * @returns a new array filled with new objects
+     */
+    public static BuildArray<T>(size: number, itemBuilder: () => T): Array<T> {
+        const a: T[] = [];
+        for (let i = 0; i < size; ++i) {
+            a.push(itemBuilder());
+        }
+        return a;
+    }
+}

+ 0 - 14
src/Tools/tools.ts

@@ -620,20 +620,6 @@ import { TGATools } from "./tga";
         }
         }
 
 
         /**
         /**
-         * 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 itemBuilder a callback responsible for creating new instance of item. Called once per array entry.
-         * @returns a new array filled with new objects
-         */
-        public static BuildArray<T>(size: number, itemBuilder: () => T): Array<T> {
-            const a: T[] = [];
-            for (let i = 0; i < size; ++i) {
-                a.push(itemBuilder());
-            }
-            return a;
-        }
-
-        /**
          * Gets the pointer prefix to use
          * Gets the pointer prefix to use
          * @returns "pointer" if touch is enabled. Else returns "mouse"
          * @returns "pointer" if touch is enabled. Else returns "mouse"
          */
          */