فهرست منبع

use static readonly + restore comment

Julien Barrois 6 سال پیش
والد
کامیت
83af2c3893

+ 5 - 6
src/Culling/babylon.boundingBox.ts

@@ -1,7 +1,4 @@
 module BABYLON {
-
-    const _identityMatrix = Matrix.Identity();
-
     /**
      * Class used to store bounding box information
      */
@@ -52,7 +49,8 @@ module BABYLON {
         public maximum: Vector3 = Vector3.Zero();
 
         private _worldMatrix: Matrix;
-        private static TmpVector3 = Tools.BuildArray(3, Vector3.Zero);
+        private static readonly TmpVector3 = Tools.BuildArray(3, Vector3.Zero);
+        private static readonly _identityMatrix = Matrix.Identity();
 
         /**
          * @hidden
@@ -96,7 +94,7 @@ module BABYLON {
             max.addToRef(min, this.center).scaleInPlace(0.5);
             max.subtractToRef(min, this.extendSize).scaleInPlace(0.5);
 
-            this._update(worldMatrix || _identityMatrix);
+            this._update(worldMatrix || BoundingBox._identityMatrix);
         }
 
         /**
@@ -147,7 +145,7 @@ module BABYLON {
             const vectorsWorld = this.vectorsWorld;
             const vectors = this.vectors;
 
-            if (world !== _identityMatrix) {
+            if (world !== BoundingBox._identityMatrix) {
                 minWorld.setAll(Number.MAX_VALUE);
                 maxWorld.setAll(-Number.MAX_VALUE);
 
@@ -166,6 +164,7 @@ module BABYLON {
                 }
             }
 
+            // Extend
             maxWorld.subtractToRef(minWorld, this.extendSizeWorld).scaleInPlace(0.5);
             maxWorld.addToRef(minWorld, this.centerWorld).scaleInPlace(0.5);
 

+ 5 - 3
src/Culling/babylon.boundingInfo.ts

@@ -57,6 +57,8 @@ module BABYLON {
 
         private _isLocked = false;
 
+        private static readonly TmpVector3 = Tools.BuildArray(2, Vector3.Zero);
+
         /**
          * Constructs bounding info
          * @param minimum min vector of the bounding box/sphere
@@ -125,8 +127,8 @@ module BABYLON {
          */
         public centerOn(center: Vector3, extend: Vector3): BoundingInfo {
 
-            const minimum = Tmp.Vector3[0].copyFrom(center).subtractInPlace(extend);
-            const maximum = Tmp.Vector3[1].copyFrom(center).addInPlace(extend);
+            const minimum = BoundingInfo.TmpVector3[0].copyFrom(center).subtractInPlace(extend);
+            const maximum = BoundingInfo.TmpVector3[1].copyFrom(center).addInPlace(extend);
 
             this.boundingBox.reConstruct(minimum, maximum, this.boundingBox.getWorldMatrix());
             this.boundingSphere.reConstruct(minimum, maximum, this.boundingSphere.getWorldMatrix());
@@ -168,7 +170,7 @@ module BABYLON {
 		 */
         public get diagonalLength(): number {
             const boundingBox = this.boundingBox;
-            const diag = boundingBox.maximumWorld.subtractToRef(boundingBox.minimumWorld, Tmp.Vector3[0]);
+            const diag = boundingBox.maximumWorld.subtractToRef(boundingBox.minimumWorld, BoundingInfo.TmpVector3[0]);
             return diag.length();
         }
 

+ 5 - 6
src/Culling/babylon.boundingSphere.ts

@@ -1,7 +1,4 @@
 module BABYLON {
-    // This matrix is used as a value to reset the bounding box.
-    const _identityMatrix = Matrix.Identity();
-
     /**
      * Class used to store bounding sphere information
      */
@@ -33,7 +30,9 @@ module BABYLON {
 
         private _worldMatrix: Matrix;
 
-        private static TmpVector3 = Tools.BuildArray(3, Vector3.Zero);
+        private static readonly TmpVector3 = Tools.BuildArray(3, Vector3.Zero);
+        // This matrix is used as a value to reset the bounding box.
+        private static readonly _identityMatrix = Matrix.Identity();
 
         /**
          * Creates a new bounding sphere
@@ -60,7 +59,7 @@ module BABYLON {
             max.addToRef(min, this.center).scaleInPlace(0.5);
             this.radius = distance * 0.5;
 
-            this._update(worldMatrix || _identityMatrix);
+            this._update(worldMatrix || BoundingSphere._identityMatrix);
         }
 
         /**
@@ -85,7 +84,7 @@ module BABYLON {
         public _update(worldMatrix: Matrix): void {
             this._worldMatrix = worldMatrix;
 
-            if (this._worldMatrix !== _identityMatrix) {
+            if (this._worldMatrix !== BoundingSphere._identityMatrix) {
                 Vector3.TransformCoordinatesToRef(this.center, worldMatrix, this.centerWorld);
                 const tempVector = BoundingSphere.TmpVector3[0];
                 Vector3.TransformNormalFromFloatsToRef(1.0, 1.0, 1.0, worldMatrix, tempVector);

+ 7 - 7
src/Culling/babylon.ray.ts

@@ -3,13 +3,13 @@ module BABYLON {
      * Class representing a ray with position and direction
      */
     export class Ray {
-        private static _edge1 = Vector3.Zero();
-        private static _edge2 = Vector3.Zero();
-        private static _pvec = Vector3.Zero();
-        private static _tvec = Vector3.Zero();
-        private static _qvec = Vector3.Zero();
-        private static _min = Vector3.Zero();
-        private static _max = Vector3.Zero();
+        private static readonly _edge1 = Vector3.Zero();
+        private static readonly _edge2 = Vector3.Zero();
+        private static readonly _pvec = Vector3.Zero();
+        private static readonly _tvec = Vector3.Zero();
+        private static readonly _qvec = Vector3.Zero();
+        private static readonly _min = Vector3.Zero();
+        private static readonly _max = Vector3.Zero();
 
         private _tmpRay: Ray;