Popov72 5 years ago
parent
commit
9860c6b325
2 changed files with 17 additions and 7 deletions
  1. 3 0
      src/Engines/thinEngine.ts
  2. 14 7
      src/Maths/math.vector.ts

+ 3 - 0
src/Engines/thinEngine.ts

@@ -28,6 +28,7 @@ import { IOfflineProvider } from '../Offline/IOfflineProvider';
 import { IEffectFallbacks } from '../Materials/iEffectFallbacks';
 import { IWebRequest } from '../Misc/interfaces/iWebRequest';
 import { CanvasGenerator } from '../Misc/canvasGenerator';
+import { Matrix } from '../Maths/math.vector';
 
 declare type WebRequest = import("../Misc/webRequest").WebRequest;
 declare type LoadFileError = import("../Misc/fileTools").LoadFileError;
@@ -476,6 +477,8 @@ export class ThinEngine {
      */
     constructor(canvasOrContext: Nullable<HTMLCanvasElement | WebGLRenderingContext | WebGL2RenderingContext>, antialias?: boolean, options?: EngineOptions, adaptToDeviceRatio: boolean = false) {
 
+        Matrix._StopTrackingInstances();
+
         let canvas: Nullable<HTMLCanvasElement> = null;
 
         if (!canvasOrContext) {

+ 14 - 7
src/Maths/math.vector.ts

@@ -3558,26 +3558,28 @@ export class Matrix {
     private static _TrackedMatrices: Array<Matrix> = [];
 
     /**
-     * Gets or sets the precision of matrix computations
-     * Note that changing the precision can only be done a single time, and should be performed early in your application
+     * Gets the precision of matrix computations
      */
     public static get Use64Bits(): boolean {
         return Matrix._Use64Bits;
     }
 
-    public static set Use64Bits(value: boolean) {
-        if (Matrix._Use64Bits === value || !Matrix._trackPrecisionChange) {
+    /**
+     * Switch the matrix computations to 64 bits mode
+     */
+    public static switchTo64Bits() {
+        if (Matrix._Use64Bits) {
             return;
         }
 
         Matrix._trackPrecisionChange = false;
-        Matrix._Use64Bits = value;
+        Matrix._Use64Bits = true;
 
         for (let m = 0; m < Matrix._TrackedMatrices.length; ++m) {
             const matrix = Matrix._TrackedMatrices[m];
             const values = matrix._m;
 
-            (matrix._m as any) = value ? new Array(16) : new Float32Array(16);
+            (matrix._m as any) = new Array(16);
 
             for (let i = 0; i < 16; ++i) {
                 matrix._m[i] = values[i];
@@ -3585,6 +3587,11 @@ export class Matrix {
         }
     }
 
+    /** @hidden */
+    public static _StopTrackingInstances() {
+        Matrix._trackPrecisionChange = false;
+    }
+
     private static _updateFlagSeed = 0;
     private static _identityReadOnly = Matrix.Identity() as DeepImmutable<Matrix>;
 
@@ -3632,7 +3639,7 @@ export class Matrix {
             Matrix._TrackedMatrices.push(this);
         }
 
-        this._m = Matrix.Use64Bits ? new Array(16) : new Float32Array(16);
+        this._m = Matrix._Use64Bits ? new Array(16) : new Float32Array(16);
         this._updateIdentityStatus(false);
     }