Explorar o código

Merge pull request #911 from jbousquie/feature.ClassTMP

Added class "Tmp" to hold temporary pre-allocated objects
David Catuhe %!s(int64=9) %!d(string=hai) anos
pai
achega
fdd2a8e13b
Modificáronse 1 ficheiros con 14 adicións e 1 borrados
  1. 14 1
      src/Math/babylon.math.ts

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

@@ -3612,5 +3612,18 @@
             return new PositionNormalTextureVertex(this.position.clone(), this.normal.clone(), this.uv.clone());
         }
     }
-}
 
+    // Temporary pre-allocated objects for engine internal use
+    // usage in any internal function :
+    // var tmp = Tmp.Vector3[0];   <= gets access to the first pre-created Vector3
+    // There's a Tmp array per object type : int, float, Vector2, Vector3, Vector4, Quaternion, Matrix
+    export class Tmp {
+        public static Int: number[] = [ 0, 0, 0, 0, 0, 0 ];                                     // 6 temp integers at once should be enough
+        public static Float: number[] = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ];                       // 6 temp floats at once should be enough
+        public static Vector2: Vector2[] = [ Vector2.Zero(), Vector2.Zero(), Vector2.Zero() ];  // 3 temp Vector2 at once should be enough
+        public static Vector3: Vector3[] = [ Vector3.Zero(), Vector3.Zero(), Vector3.Zero() ];  // 3 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) ];                // 1 temp Quaternion at once should be enough
+        public static Matrix: Matrix[] = [ Matrix.Zero() ];                                     // 1 temp Matrix at once should be enough
+    }
+}