ソースを参照

Added performat matrix.isIdentity() function

David Catuhe 8 年 前
コミット
4f1df92b84

ファイルの差分が大きいため隠しています
+ 4961 - 4959
dist/preview release/babylon.d.ts


ファイルの差分が大きいため隠しています
+ 40 - 40
dist/preview release/babylon.js


+ 19 - 8
dist/preview release/babylon.max.js

@@ -2730,25 +2730,36 @@ var __extends = (this && this.__extends) || (function () {
     BABYLON.Quaternion = Quaternion;
     var Matrix = (function () {
         function Matrix() {
+            this._isIdentity = false;
+            this._isIdentityDirty = true;
             this.m = new Float32Array(16);
             this._markAsUpdated();
         }
         Matrix.prototype._markAsUpdated = function () {
             this.updateFlag = Matrix._updateFlagSeed++;
+            this._isIdentityDirty = true;
         };
         // Properties
         /**
          * Boolean : True is the matrix is the identity matrix
          */
         Matrix.prototype.isIdentity = function () {
-            if (this.m[0] !== 1.0 || this.m[5] !== 1.0 || this.m[10] !== 1.0 || this.m[15] !== 1.0)
-                return false;
-            if (this.m[1] !== 0.0 || this.m[2] !== 0.0 || this.m[3] !== 0.0 ||
-                this.m[4] !== 0.0 || this.m[6] !== 0.0 || this.m[7] !== 0.0 ||
-                this.m[8] !== 0.0 || this.m[9] !== 0.0 || this.m[11] !== 0.0 ||
-                this.m[12] !== 0.0 || this.m[13] !== 0.0 || this.m[14] !== 0.0)
-                return false;
-            return true;
+            if (this._isIdentityDirty) {
+                this._isIdentityDirty = false;
+                if (this.m[0] !== 1.0 || this.m[5] !== 1.0 || this.m[10] !== 1.0 || this.m[15] !== 1.0) {
+                    this._isIdentity = false;
+                }
+                else if (this.m[1] !== 0.0 || this.m[2] !== 0.0 || this.m[3] !== 0.0 ||
+                    this.m[4] !== 0.0 || this.m[6] !== 0.0 || this.m[7] !== 0.0 ||
+                    this.m[8] !== 0.0 || this.m[9] !== 0.0 || this.m[11] !== 0.0 ||
+                    this.m[12] !== 0.0 || this.m[13] !== 0.0 || this.m[14] !== 0.0) {
+                    this._isIdentity = false;
+                }
+                else {
+                    this._isIdentity = true;
+                }
+            }
+            return this._isIdentity;
         };
         /**
          * Returns the matrix determinant (float).

ファイルの差分が大きいため隠しています
+ 4961 - 4959
dist/preview release/babylon.module.d.ts


ファイルの差分が大きいため隠しています
+ 41 - 41
dist/preview release/babylon.worker.js


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

@@ -2923,11 +2923,14 @@
         private static _zAxis: Vector3 = Vector3.Zero();
         private static _updateFlagSeed = 0;
 
-        public updateFlag: number;
+        private _isIdentity = false;
+        private _isIdentityDirty = true;
+        public updateFlag: number;        
         public m: Float32Array = new Float32Array(16);
 
         public _markAsUpdated() {
             this.updateFlag = Matrix._updateFlagSeed++;
+            this._isIdentityDirty = true;
         }
 
         public constructor() {
@@ -2939,16 +2942,21 @@
          * Boolean : True is the matrix is the identity matrix
          */
         public isIdentity(): boolean {
-            if (this.m[0] !== 1.0 || this.m[5] !== 1.0 || this.m[10] !== 1.0 || this.m[15] !== 1.0)
-                return false;
-
-            if (this.m[1] !== 0.0 || this.m[2] !== 0.0 || this.m[3] !== 0.0 ||
-                this.m[4] !== 0.0 || this.m[6] !== 0.0 || this.m[7] !== 0.0 ||
-                this.m[8] !== 0.0 || this.m[9] !== 0.0 || this.m[11] !== 0.0 ||
-                this.m[12] !== 0.0 || this.m[13] !== 0.0 || this.m[14] !== 0.0)
-                return false;
+            if (this._isIdentityDirty) {
+                this._isIdentityDirty = false;
+                if (this.m[0] !== 1.0 || this.m[5] !== 1.0 || this.m[10] !== 1.0 || this.m[15] !== 1.0) {
+                    this._isIdentity = false;
+                } else if (this.m[1] !== 0.0 || this.m[2] !== 0.0 || this.m[3] !== 0.0 ||
+                    this.m[4] !== 0.0 || this.m[6] !== 0.0 || this.m[7] !== 0.0 ||
+                    this.m[8] !== 0.0 || this.m[9] !== 0.0 || this.m[11] !== 0.0 ||
+                    this.m[12] !== 0.0 || this.m[13] !== 0.0 || this.m[14] !== 0.0) {
+                    this._isIdentity = false;
+                } else {
+                    this._isIdentity = true;
+                }
+            }
 
-            return true;
+            return this._isIdentity;
         }
         /**
          * Returns the matrix determinant (float).