Quellcode durchsuchen

Ref cyclic tools instantiate + engine.last...

sebavan vor 6 Jahren
Ursprung
Commit
b7fb8fe11e
46 geänderte Dateien mit 245 neuen und 187 gelöschten Zeilen
  1. 2 11
      Tools/Config/tempCircularValidation/core.json
  2. 2 1
      Tools/Config/tempCircularValidation/loaders.json
  3. 1 0
      Tools/Gulp/tasks/gulpTasks-dependencies.js
  4. 2 2
      gui/src/3D/gui3DManager.ts
  5. 3 3
      inspector/src/components/sceneExplorer/sceneExplorerComponent.tsx
  6. 3 3
      inspector/src/inspector.ts
  7. 11 8
      src/Actions/actionManager.ts
  8. 2 2
      src/Animations/animationGroup.ts
  9. 5 4
      src/Bones/skeleton.ts
  10. 2 2
      src/Debug/physicsViewer.ts
  11. 6 16
      src/Engines/engine.ts
  12. 40 0
      src/Engines/engineStore.ts
  13. 4 3
      src/Gamepads/Controllers/poseEnabledController.ts
  14. 2 1
      src/Layers/effectLayer.ts
  15. 2 2
      src/Layers/layer.ts
  16. 2 2
      src/LensFlares/lensFlareSystem.ts
  17. 9 8
      src/Loading/sceneLoader.ts
  18. 2 2
      src/Materials/Textures/Procedurals/noiseProceduralTexture.ts
  19. 2 2
      src/Materials/Textures/baseTexture.ts
  20. 2 2
      src/Materials/fresnelParameters.ts
  21. 2 2
      src/Materials/material.ts
  22. 3 2
      src/Materials/materialHelper.ts
  23. 2 2
      src/Meshes/instancedMesh.ts
  24. 2 1
      src/Meshes/mesh.ts
  25. 77 0
      src/Misc/deepCopier.ts
  26. 2 2
      src/Misc/sceneOptimizer.ts
  27. 3 64
      src/Misc/tools.ts
  28. 3 2
      src/Morph/morphTarget.ts
  29. 2 2
      src/Morph/morphTargetManager.ts
  30. 2 2
      src/Particles/EmitterTypes/boxParticleEmitter.ts
  31. 2 2
      src/Particles/EmitterTypes/coneParticleEmitter.ts
  32. 3 3
      src/Particles/EmitterTypes/cylinderParticleEmitter.ts
  33. 2 2
      src/Particles/EmitterTypes/hemisphericParticleEmitter.ts
  34. 2 2
      src/Particles/EmitterTypes/pointParticleEmitter.ts
  35. 3 3
      src/Particles/EmitterTypes/sphereParticleEmitter.ts
  36. 6 4
      src/Particles/gpuParticleSystem.ts
  37. 2 2
      src/Particles/particleHelper.ts
  38. 4 3
      src/Particles/particleSystem.ts
  39. 3 2
      src/Particles/particleSystemSet.ts
  40. 3 2
      src/Particles/solidParticleSystem.ts
  41. 2 1
      src/PostProcesses/RenderPipeline/Pipelines/defaultRenderingPipeline.ts
  42. 2 2
      src/PostProcesses/RenderPipeline/Pipelines/ssao2RenderingPipeline.ts
  43. 2 1
      src/PostProcesses/imageProcessingPostProcess.ts
  44. 3 3
      src/Rendering/utilityLayerRenderer.ts
  45. 2 1
      src/node.ts
  46. 2 1
      src/scene.ts

+ 2 - 11
Tools/Config/tempCircularValidation/core.json

@@ -1,8 +1,4 @@
 {
-    "../../src/Actions/actionManager.ts": [
-        "../../src/Engines/engine.ts",
-        "../../src/Misc/tools.ts"
-    ],
     "../../src/Animations/animatable.ts": [
         "../../src/Animations/runtimeAnimation.ts"
     ],
@@ -87,7 +83,6 @@
         "../../src/scene.ts"
     ],
     "../../src/Materials/Textures/baseTexture.ts": [
-        "../../src/Engines/engine.ts",
         "../../src/Misc/decorators.ts",
         "../../src/Misc/tools.ts"
     ],
@@ -113,13 +108,11 @@
         "../../src/Misc/tools.ts"
     ],
     "../../src/Materials/material.ts": [
-        "../../src/Engines/engine.ts",
         "../../src/Meshes/subMesh.ts",
         "../../src/Misc/decorators.ts",
         "../../src/Misc/tools.ts"
     ],
     "../../src/Materials/materialHelper.ts": [
-        "../../src/Engines/engine.ts",
         "../../src/Lights/light.ts",
         "../../src/scene.ts"
     ],
@@ -233,16 +226,13 @@
         "../../src/Rendering/geometryBufferRenderer.ts"
     ],
     "../../src/node.ts": [
-        "../../src/Engines/engine.ts",
         "../../src/Misc/decorators.ts"
     ],
     "../../src/scene.ts": [
-        "../../src/Actions/actionManager.ts",
         "../../src/Animations/animatable.ts",
         "../../src/Animations/animation.ts",
         "../../src/Cameras/camera.ts",
         "../../src/Collisions/collisionCoordinator.ts",
-        "../../src/Engines/engine.ts",
         "../../src/Lights/light.ts",
         "../../src/Materials/imageProcessingConfiguration.ts",
         "../../src/Materials/standardMaterial.ts",
@@ -250,5 +240,6 @@
         "../../src/Misc/tags.ts",
         "../../src/Misc/tools.ts",
         "../../src/PostProcesses/postProcessManager.ts"
-    ]
+    ],
+    "errorCount": 120
 }

+ 2 - 1
Tools/Config/tempCircularValidation/loaders.json

@@ -4,5 +4,6 @@
     ],
     "../../loaders/src/glTF/1.0/glTFLoaderExtension.ts": [
         "../../loaders/src/glTF/1.0/glTFLoader.ts"
-    ]
+    ],
+    "errorCount": 2
 }

+ 1 - 0
Tools/Gulp/tasks/gulpTasks-dependencies.js

@@ -85,6 +85,7 @@ const dependencies = function(settings, moduleName, cb) {
             boolean: ["saveCircular"]
         });
         if (commandLineOptions.saveCircular) {
+            comparaisonData.errorCount = cruiseResult.summary.error;
             fs.writeJSONSync(path.resolve(__dirname, baseValidationFile), comparaisonData, {
                 spaces: 4,
                 EOL: '\n'

+ 2 - 2
gui/src/3D/gui3DManager.ts

@@ -6,7 +6,7 @@ import { Material } from "babylonjs/Materials/material";
 import { HemisphericLight } from "babylonjs/Lights/hemisphericLight";
 import { AbstractMesh } from "babylonjs/Meshes/abstractMesh";
 import { UtilityLayerRenderer } from "babylonjs/Rendering/utilityLayerRenderer";
-import { Engine } from "babylonjs/Engines/engine";
+import { EngineStore } from "babylonjs/Engines/engineStore";
 import { IDisposable, Scene } from "babylonjs/scene";
 
 import { Container3D } from "./controls/container3D";
@@ -54,7 +54,7 @@ export class GUI3DManager implements IDisposable {
      * @param scene
      */
     public constructor(scene?: Scene) {
-        this._scene = scene || Engine.LastCreatedScene!;
+        this._scene = scene || EngineStore.LastCreatedScene!;
         this._sceneDisposeObserver = this._scene.onDisposeObservable.add(() => {
             this._sceneDisposeObserver = null;
             this._utilityLayer = null;

+ 3 - 3
inspector/src/components/sceneExplorer/sceneExplorerComponent.tsx

@@ -3,8 +3,8 @@ import * as React from "react";
 import { Nullable } from "babylonjs/types";
 import { Observer } from "babylonjs/Misc/observable";
 import { IExplorerExtensibilityGroup } from "babylonjs/Debug/debugLayer";
-import { Engine } from "babylonjs/Engines/engine";
 import { Scene } from "babylonjs/scene";
+import { EngineStore } from "babylonjs/Engines/engineStore";
 
 import { TreeItemComponent } from "./treeItemComponent";
 import Resizable from "re-resizable";
@@ -85,7 +85,7 @@ export class SceneExplorerComponent extends React.Component<ISceneExplorerCompon
         }
 
         if (this._onNewSceneAddedObserver) {
-            Engine.LastCreatedEngine!.onNewSceneAddedObservable.remove(this._onNewSceneAddedObserver);
+            EngineStore.LastCreatedEngine!.onNewSceneAddedObservable.remove(this._onNewSceneAddedObserver);
         }
 
         const scene = this.state.scene;
@@ -197,7 +197,7 @@ export class SceneExplorerComponent extends React.Component<ISceneExplorerCompon
         const scene = this.state.scene;
 
         if (!scene) {
-            this._onNewSceneAddedObserver = Engine.LastCreatedEngine!.onNewSceneAddedObservable.addOnce((scene) => this.setState({ scene: scene }));
+            this._onNewSceneAddedObserver = EngineStore.LastCreatedEngine!.onNewSceneAddedObservable.addOnce((scene) => this.setState({ scene: scene }));
             return null;
         }
 

+ 3 - 3
inspector/src/inspector.ts

@@ -4,7 +4,7 @@ import * as ReactDOM from "react-dom";
 import { IInspectorOptions } from "babylonjs/Debug/debugLayer";
 import { Nullable } from "babylonjs/types";
 import { Observable, Observer } from "babylonjs/Misc/observable";
-import { Engine } from "babylonjs/Engines/engine";
+import { EngineStore } from "babylonjs/Engines/engineStore";
 import { Scene } from "babylonjs/scene";
 import { SceneLoader } from "babylonjs/Loading/sceneLoader";
 
@@ -331,12 +331,12 @@ export class Inspector {
         }
 
         if (!scene) {
-            scene = Engine.LastCreatedScene!;
+            scene = EngineStore.LastCreatedScene!;
         }
 
         this._Scene = scene;
 
-        var canvas = scene ? scene.getEngine().getRenderingCanvas() : Engine.LastCreatedEngine!.getRenderingCanvas();
+        var canvas = scene ? scene.getEngine().getRenderingCanvas() : EngineStore.LastCreatedEngine!.getRenderingCanvas();
 
         if (options.embedMode && options.showExplorer && options.showInspector) {
             if (options.popup) {

+ 11 - 8
src/Actions/actionManager.ts

@@ -7,11 +7,12 @@ import { Condition, ValueCondition } from "./condition";
 import { Action } from "./action";
 import { DoNothingAction } from "./directActions";
 
-import { Engine } from "../Engines/engine";
 import { Constants } from "../Engines/constants";
-import { Tools } from "../Misc/tools";
+import { EngineStore } from "../Engines/engineStore";
 import { ActionEvent } from "../Actions/actionEvent";
 import { Logger } from "../Misc/logger";
+import { DeepCopier } from "../Misc/deepCopier";
+import { _TypeStore } from "../Misc/typeStore";
 
     /**
      * Action Manager manages all events to be triggered on a given mesh or the global scene.
@@ -137,7 +138,7 @@ import { Logger } from "../Misc/logger";
          * @param scene defines the hosting scene
          */
         constructor(scene: Scene) {
-            this._scene = scene || Engine.LastCreatedScene;
+            this._scene = scene || EngineStore.LastCreatedScene;
 
             scene.actionManagers.push(this);
         }
@@ -436,7 +437,7 @@ import { Logger } from "../Misc/logger";
                     }
                     else {
                         var parameter = <any>{};
-                        Tools.DeepCopy(triggerOptions.parameter, parameter, ["mesh"]);
+                        DeepCopier.DeepCopy(triggerOptions.parameter, parameter, ["mesh"]);
 
                         if (triggerOptions.parameter && triggerOptions.parameter.mesh) {
                             parameter._meshId = triggerOptions.parameter.mesh.id;
@@ -473,10 +474,12 @@ import { Logger } from "../Misc/logger";
 
             // instanciate a new object
             var instanciate = (name: string, params: Array<any>): any => {
-                // TODO: We will need to find a solution for the next line when using commonjs / es6 .
-                var newInstance: Object = Object.create(Tools.Instantiate("BABYLON." + name).prototype);
-                newInstance.constructor.apply(newInstance, params);
-                return newInstance;
+                const internalClassType = _TypeStore.GetClass("BABYLON." + name);
+                if (internalClassType) {
+                    var newInstance: Object = Object.create(internalClassType.prototype);
+                    newInstance.constructor.apply(newInstance, params);
+                    return newInstance;
+                }
             };
 
             var parseParameter = (name: string, value: string, target: any, propertyPath: Nullable<string>): any => {

+ 2 - 2
src/Animations/animationGroup.ts

@@ -4,7 +4,7 @@ import { IAnimationKey, Animation } from "./animation";
 import { Scene, IDisposable } from "../scene";
 import { Observable } from "../Misc/observable";
 import { Nullable } from "../types";
-import { Engine } from "../Engines/engine";
+import { EngineStore } from "../Engines/engineStore";
     /**
      * This class defines the direct association between an animation and a target
      */
@@ -139,7 +139,7 @@ import { Engine } from "../Engines/engine";
             /** The name of the animation group */
             public name: string,
             scene: Nullable<Scene> = null) {
-            this._scene = scene || Engine.LastCreatedScene!;
+            this._scene = scene || EngineStore.LastCreatedScene!;
             this.uniqueId = this._scene.getUniqueId();
 
             this._scene.animationGroups.push(this);

+ 5 - 4
src/Bones/skeleton.ts

@@ -1,6 +1,6 @@
 import { Bone } from "./bone";
 
-import { IAnimatable, Tools } from "../Misc/tools";
+import { IAnimatable } from "../Misc/tools";
 import { Observable } from "../Misc/observable";
 import { Vector3, Matrix, Tmp } from "../Maths/math";
 import { Scene } from "../scene";
@@ -10,9 +10,10 @@ import { RawTexture } from "../Materials/Textures/rawTexture";
 import { Animatable } from "../Animations/animatable";
 import { AnimationPropertiesOverride } from "../Animations/animationPropertiesOverride";
 import { AnimationRange, Animation } from "../Animations/animation";
-import { Engine } from "../Engines/engine";
+import { EngineStore } from "../Engines/engineStore";
 import { Constants } from "../Engines/constants";
 import { Logger } from "../Misc/logger";
+import { DeepCopier } from "../Misc/deepCopier";
 
     /**
      * Class used to handle skinning animations
@@ -113,7 +114,7 @@ import { Logger } from "../Misc/logger";
             public id: string, scene: Scene) {
             this.bones = [];
 
-            this._scene = scene || Engine.LastCreatedScene;
+            this._scene = scene || EngineStore.LastCreatedScene;
 
             this._scene.skeletons.push(this);
 
@@ -498,7 +499,7 @@ import { Logger } from "../Misc/logger";
                 }
 
                 var bone = new Bone(source.name, result, parentBone, source.getBaseMatrix().clone(), source.getRestPose().clone());
-                Tools.DeepCopy(source.animations, bone.animations);
+                DeepCopier.DeepCopy(source.animations, bone.animations);
             }
 
             if (this._ranges) {

+ 2 - 2
src/Debug/physicsViewer.ts

@@ -5,7 +5,7 @@ import { Mesh } from "../Meshes/mesh";
 import { MeshBuilder } from "../Meshes/meshBuilder";
 import { Quaternion, Color3 } from "../Maths/math";
 import { Material } from "../Materials/material";
-import { Engine } from "../Engines/engine";
+import { EngineStore } from "../Engines/engineStore";
 import { StandardMaterial } from "../Materials/standardMaterial";
 import { IPhysicsEnginePlugin } from "../Physics/IPhysicsEngine";
 import { PhysicsImpostor } from "../Physics/physicsImpostor";
@@ -38,7 +38,7 @@ import { UtilityLayerRenderer } from "../Rendering/utilityLayerRenderer";
          * @param scene defines the hosting scene
          */
         constructor(scene: Scene) {
-            this._scene = scene || Engine.LastCreatedScene;
+            this._scene = scene || EngineStore.LastCreatedScene;
             let physicEngine = this._scene.getPhysicsEngine();
 
             if (physicEngine) {

+ 6 - 16
src/Engines/engine.ts

@@ -30,6 +30,7 @@ import { _DepthCullingState, _StencilState, _AlphaState } from "../States/index"
 import { Constants } from "./constants";
 import { DomManagement } from "../Misc/domManagement";
 import { Logger } from "../Misc/logger";
+import { EngineStore } from "./engineStore";
 
 declare type Texture = import("../Materials/Textures/texture").Texture;
 declare type VideoTexture = import("../Materials/Textures/videoTexture").VideoTexture;
@@ -267,33 +268,22 @@ declare type RenderTargetTexture = import("../Materials/Textures/renderTargetTex
         ];
 
         /** Gets the list of created engines */
-        public static Instances = new Array<Engine>();
+        public static get Instances(): Engine[] {
+            return EngineStore.Instances;
+        }
 
         /**
          * Gets the latest created engine
          */
         public static get LastCreatedEngine(): Nullable<Engine> {
-            if (Engine.Instances.length === 0) {
-                return null;
-            }
-
-            return Engine.Instances[Engine.Instances.length - 1];
+            return EngineStore.LastCreatedEngine;
         }
 
         /**
          * Gets the latest created scene
          */
         public static get LastCreatedScene(): Nullable<Scene> {
-            var lastCreatedEngine = Engine.LastCreatedEngine;
-            if (!lastCreatedEngine) {
-                return null;
-            }
-
-            if (lastCreatedEngine.scenes.length === 0) {
-                return null;
-            }
-
-            return lastCreatedEngine.scenes[lastCreatedEngine.scenes.length - 1];
+            return EngineStore.LastCreatedScene;
         }
 
         /**

+ 40 - 0
src/Engines/engineStore.ts

@@ -0,0 +1,40 @@
+import { Nullable } from "../types";
+
+declare type Engine = import("./engine").Engine;
+declare type Scene = import("../scene").Scene;
+
+/**
+ * The engine store class is responsible to hold all the instances of Engine and Scene created
+ * during the life time of the application.
+ */
+export class EngineStore {
+    /** Gets the list of created engines */
+    public static Instances = new Array<Engine>();
+
+    /**
+     * Gets the latest created engine
+     */
+    public static get LastCreatedEngine(): Nullable<Engine> {
+        if (this.Instances.length === 0) {
+            return null;
+        }
+
+        return this.Instances[this.Instances.length - 1];
+    }
+
+    /**
+     * Gets the latest created scene
+     */
+    public static get LastCreatedScene(): Nullable<Scene> {
+        var lastCreatedEngine = this.LastCreatedEngine;
+        if (!lastCreatedEngine) {
+            return null;
+        }
+
+        if (lastCreatedEngine.scenes.length === 0) {
+            return null;
+        }
+
+        return lastCreatedEngine.scenes[lastCreatedEngine.scenes.length - 1];
+    }
+}

+ 4 - 3
src/Gamepads/Controllers/poseEnabledController.ts

@@ -7,12 +7,13 @@ import { AbstractMesh } from "../../Meshes/abstractMesh";
 import { Ray } from "../../Culling/ray";
 import { _TimeToken } from "../../Instrumentation/timeToken";
 import { _DepthCullingState, _StencilState, _AlphaState } from "../../States/index";
-import { Engine } from "../../Engines/engine";
+import { EngineStore } from "../../Engines/engineStore";
 
 import { Gamepad } from "../../Gamepads/gamepad";
 import { ExtendedGamepadButton } from "./poseEnabledController";
 import { WebVRFreeCamera, PoseControlled, DevicePose } from "../../Cameras/VR/webVRCamera";
 import { TargetCamera } from "../../Cameras/targetCamera";
+
     /**
     * Defines the types of pose enabled controllers that are supported
     */
@@ -239,8 +240,8 @@ import { TargetCamera } from "../../Cameras/targetCamera";
             var pose: GamepadPose = this.browserGamepad.pose;
             this.updateFromDevice(pose);
 
-            if (!this._trackPosition && Engine.LastCreatedScene && Engine.LastCreatedScene.activeCamera && (<WebVRFreeCamera>Engine.LastCreatedScene.activeCamera).devicePosition) {
-                var camera = <WebVRFreeCamera>Engine.LastCreatedScene.activeCamera;
+            if (!this._trackPosition && EngineStore.LastCreatedScene && EngineStore.LastCreatedScene.activeCamera && (<WebVRFreeCamera>EngineStore.LastCreatedScene.activeCamera).devicePosition) {
+                var camera = <WebVRFreeCamera>EngineStore.LastCreatedScene.activeCamera;
                 camera._computeDevicePosition();
 
                 this._deviceToWorld.setTranslation(camera.devicePosition);

+ 2 - 1
src/Layers/effectLayer.ts

@@ -7,6 +7,7 @@ import { Camera } from "../Cameras/camera";
 import { Scene } from "../scene";
 import { Color4, ISize } from "../Maths/math";
 import { Engine } from "../Engines/engine";
+import { EngineStore } from "../Engines/engineStore";
 import { VertexBuffer } from "../Meshes/buffer";
 import { SubMesh } from "../Meshes/subMesh";
 import { AbstractMesh } from "../Meshes/abstractMesh";
@@ -156,7 +157,7 @@ import "../Shaders/glowMapGeneration.vertex";
             scene: Scene) {
             this.name = name;
 
-            this._scene = scene || Engine.LastCreatedScene;
+            this._scene = scene || EngineStore.LastCreatedScene;
             let component = this._scene._getComponent(SceneComponentConstants.NAME_EFFECTLAYER) as EffectLayerSceneComponent;
             if (!component) {
                 component = new EffectLayerSceneComponent(this._scene);

+ 2 - 2
src/Layers/layer.ts

@@ -2,7 +2,7 @@ import { Observer, Observable } from "../Misc/observable";
 import { Nullable } from "../types";
 import { Scene } from "../scene";
 import { Vector2, Color4 } from "../Maths/math";
-import { Engine } from "../Engines/engine";
+import { EngineStore } from "../Engines/engineStore";
 import { VertexBuffer } from "../Meshes/buffer";
 import { Effect } from "../Materials/effect";
 import { Material } from "../Materials/material";
@@ -157,7 +157,7 @@ import "../Shaders/layer.vertex";
             this.isBackground = isBackground === undefined ? true : isBackground;
             this.color = color === undefined ? new Color4(1, 1, 1, 1) : color;
 
-            this._scene = <Scene>(scene || Engine.LastCreatedScene);
+            this._scene = <Scene>(scene || EngineStore.LastCreatedScene);
             let layerComponent = this._scene._getComponent(SceneComponentConstants.NAME_LAYER) as LayerSceneComponent;
             if (!layerComponent) {
                 layerComponent = new LayerSceneComponent(this._scene);

+ 2 - 2
src/LensFlares/lensFlareSystem.ts

@@ -3,7 +3,7 @@ import { Nullable } from "../types";
 import { Scene } from "../scene";
 import { Matrix, Vector3, Color3, Viewport } from "../Maths/math";
 import { Scalar } from "../Maths/math.scalar";
-import { Engine } from "../Engines/engine";
+import { EngineStore } from "../Engines/engineStore";
 import { AbstractMesh } from "../Meshes/abstractMesh";
 import { VertexBuffer } from "../Meshes/buffer";
 import { Ray } from "../Culling/ray";
@@ -82,7 +82,7 @@ import "../Shaders/lensFlare.vertex";
             emitter: any,
             scene: Scene) {
 
-            this._scene = scene || Engine.LastCreatedScene;
+            this._scene = scene || EngineStore.LastCreatedScene;
             let component = this._scene._getComponent(SceneComponentConstants.NAME_LENSFLARESYSTEM) as LensFlareSystemSceneComponent;
             if (!component) {
                 component = new LensFlareSystemSceneComponent(this._scene);

Datei-Diff unterdrückt, da er zu groß ist
+ 9 - 8
src/Loading/sceneLoader.ts


+ 2 - 2
src/Materials/Textures/Procedurals/noiseProceduralTexture.ts

@@ -1,6 +1,6 @@
 import { Nullable } from "../../../types";
 import { Scene } from "../../../scene";
-import { Engine } from "../../../Engines/engine";
+import { EngineStore } from "../../../Engines/engineStore";
 import { _TimeToken } from "../../../Instrumentation/timeToken";
 import { _DepthCullingState, _StencilState, _AlphaState } from "../../../States/index";
 import { Texture } from "../../../Materials/Textures/texture";
@@ -35,7 +35,7 @@ import "../../../Shaders/noise.fragment";
          * @param fallbackTexture defines the texture to use if the NoiseProceduralTexture can't be created
          * @param generateMipMaps defines if mipmaps must be generated (true by default)
          */
-        constructor(name: string, size: number = 256, scene: Nullable<Scene> = Engine.LastCreatedScene, fallbackTexture?: Texture, generateMipMaps?: boolean) {
+        constructor(name: string, size: number = 256, scene: Nullable<Scene> = EngineStore.LastCreatedScene, fallbackTexture?: Texture, generateMipMaps?: boolean) {
             super(name, size, "noise", scene, fallbackTexture, generateMipMaps);
             this.autoClear = false;
             this._updateShaderUniforms();

+ 2 - 2
src/Materials/Textures/baseTexture.ts

@@ -6,7 +6,7 @@ import { Nullable } from "../../types";
 import { Scene } from "../../scene";
 import { Matrix, Size, ISize } from "../../Maths/math";
 import { SphericalPolynomial } from "../../Maths/sphericalPolynomial";
-import { Engine } from "../../Engines/engine";
+import { EngineStore } from "../../Engines/engineStore";
 import { InternalTexture } from "../../Materials/Textures/internalTexture";
 import { _TimeToken } from "../../Instrumentation/timeToken";
 import { _DepthCullingState, _StencilState, _AlphaState } from "../../States/index";
@@ -339,7 +339,7 @@ declare type Animation = import("../../Animations/animation").Animation;
          * @param scene Define the scene the texture blongs to
          */
         constructor(scene: Nullable<Scene>) {
-            this._scene = scene || Engine.LastCreatedScene;
+            this._scene = scene || EngineStore.LastCreatedScene;
             if (this._scene) {
                 this.uniqueId = this._scene.getUniqueId();
                 this._scene.addTexture(this);

+ 2 - 2
src/Materials/fresnelParameters.ts

@@ -1,4 +1,4 @@
-import { Tools } from "../Misc/tools";
+import { DeepCopier } from "../Misc/deepCopier";
 import { Color3 } from "../Maths/math";
 import { Engine } from "../Engines/engine";
 import { SerializationHelper } from "../Misc/decorators";
@@ -52,7 +52,7 @@ import { Constants } from "../Engines/constants";
         public clone(): FresnelParameters {
             var newFresnelParameters = new FresnelParameters();
 
-            Tools.DeepCopy(this, newFresnelParameters);
+            DeepCopier.DeepCopy(this, newFresnelParameters);
 
             return newFresnelParameters;
         }

+ 2 - 2
src/Materials/material.ts

@@ -5,7 +5,7 @@ import { Observer, Observable } from "../Misc/observable";
 import { Nullable } from "../types";
 import { Scene } from "../scene";
 import { Plane, Matrix } from "../Maths/math";
-import { Engine } from "../Engines/engine";
+import { EngineStore } from "../Engines/engineStore";
 import { BaseSubMesh, SubMesh } from "../Meshes/subMesh";
 import { Geometry } from "../Meshes/geometry";
 import { AbstractMesh } from "../Meshes/abstractMesh";
@@ -587,7 +587,7 @@ declare var BABYLON: any;
             this.name = name;
             this.id = name || Tools.RandomId();
 
-            this._scene = scene || Engine.LastCreatedScene;
+            this._scene = scene || EngineStore.LastCreatedScene;
             this.uniqueId = this._scene.getUniqueId();
 
             if (this._scene.useRightHandedSystem) {

+ 3 - 2
src/Materials/materialHelper.ts

@@ -4,6 +4,7 @@ import { Camera } from "../Cameras/camera";
 import { Scene } from "../scene";
 import { Tmp, Color3 } from "../Maths/math";
 import { Engine } from "../Engines/engine";
+import { EngineStore } from "../Engines/engineStore";
 import { AbstractMesh } from "../Meshes/abstractMesh";
 import { Mesh } from "../Meshes/mesh";
 import { VertexBuffer } from "../Meshes/buffer";
@@ -471,8 +472,8 @@ import { BaseTexture } from "../Materials/Textures/baseTexture";
         public static PrepareAttributesForMorphTargets(attribs: string[], mesh: AbstractMesh, defines: any): void {
             var influencers = defines["NUM_MORPH_INFLUENCERS"];
 
-            if (influencers > 0 && Engine.LastCreatedEngine) {
-                var maxAttributesCount = Engine.LastCreatedEngine.getCaps().maxVertexAttribs;
+            if (influencers > 0 && EngineStore.LastCreatedEngine) {
+                var maxAttributesCount = EngineStore.LastCreatedEngine.getCaps().maxVertexAttribs;
                 var manager = (<Mesh>mesh).morphTargetManager;
                 var normal = manager && manager.supportsNormals && defines["NORMAL"];
                 var tangent = manager && manager.supportsTangents && defines["TANGENT"];

+ 2 - 2
src/Meshes/instancedMesh.ts

@@ -1,6 +1,5 @@
 import { Nullable, FloatArray, IndicesArray } from "../types";
 import { Vector3 } from "../Maths/math";
-import { Tools } from "../Misc/tools";
 import { Logger } from "../Misc/logger";
 import { Camera } from "../Cameras/camera";
 import { Node } from "../node";
@@ -8,6 +7,7 @@ import { AbstractMesh } from "../Meshes/abstractMesh";
 import { Mesh } from "../Meshes/mesh";
 import { Material } from "../Materials/material";
 import { Skeleton } from "../Bones/skeleton";
+import { DeepCopier } from "../Misc/deepCopier";
 
 Mesh._instancedMeshFactory = (name: string, mesh: Mesh): InstancedMesh => {
     return new InstancedMesh(name, mesh);
@@ -313,7 +313,7 @@ Mesh._instancedMeshFactory = (name: string, mesh: Mesh): InstancedMesh => {
             var result = this._sourceMesh.createInstance(name);
 
             // Deep copy
-            Tools.DeepCopy(this, result, ["name", "subMeshes", "uniqueId"], []);
+            DeepCopier.DeepCopy(this, result, ["name", "subMeshes", "uniqueId"], []);
 
             // Bounding info
             this.refreshBoundingInfo();

+ 2 - 1
src/Meshes/mesh.ts

@@ -1,5 +1,6 @@
 import { Observer, Observable } from "../Misc/observable";
 import { Tools, IAnimatable, AsyncLoop } from "../Misc/tools";
+import { DeepCopier } from "../Misc/deepCopier";
 import { Tags } from "../Misc/tags";
 import { Nullable, FloatArray, IndicesArray } from "../types";
 import { Camera } from "../Cameras/camera";
@@ -310,7 +311,7 @@ declare type GroundMesh = import("./groundMesh").GroundMesh;
                 }
 
                 // Deep copy
-                Tools.DeepCopy(source, this, ["name", "material", "skeleton", "instances", "parent", "uniqueId",
+                DeepCopier.DeepCopy(source, this, ["name", "material", "skeleton", "instances", "parent", "uniqueId",
                     "source", "metadata", "hasLODLevels", "geometry", "isBlocked", "areNormalsFrozen",
                     "onBeforeDrawObservable", "onBeforeRenderObservable", "onAfterRenderObservable", "onBeforeDraw",
                     "onAfterWorldMatrixUpdateObservable", "onCollideObservable", "onCollisionPositionChangeObservable", "onRebuildObservable",

+ 77 - 0
src/Misc/deepCopier.ts

@@ -0,0 +1,77 @@
+var cloneValue = (source: any, destinationObject: any) => {
+    if (!source) {
+        return null;
+    }
+
+    if (source.getClassName && source.getClassName() === "Mesh") {
+        return null;
+    }
+
+    if (source.getClassName && source.getClassName() === "SubMesh") {
+        return source.clone(destinationObject);
+    } else if (source.clone) {
+        return source.clone();
+    }
+    return null;
+};
+
+/**
+ * Class containing a set of static utilities functions for deep copy.
+ */
+export class DeepCopier {
+    /**
+     * Tries to copy an object by duplicating every property
+     * @param source defines the source object
+     * @param destination defines the target object
+     * @param doNotCopyList defines a list of properties to avoid
+     * @param mustCopyList defines a list of properties to copy (even if they start with _)
+     */
+    public static DeepCopy(source: any, destination: any, doNotCopyList?: string[], mustCopyList?: string[]): void {
+        for (var prop in source) {
+
+            if (prop[0] === "_" && (!mustCopyList || mustCopyList.indexOf(prop) === -1)) {
+                continue;
+            }
+
+            if (doNotCopyList && doNotCopyList.indexOf(prop) !== -1) {
+                continue;
+            }
+
+            var sourceValue = source[prop];
+            var typeOfSourceValue = typeof sourceValue;
+
+            if (typeOfSourceValue === "function") {
+                continue;
+            }
+
+            try {
+                if (typeOfSourceValue === "object") {
+                    if (sourceValue instanceof Array) {
+                        destination[prop] = [];
+
+                        if (sourceValue.length > 0) {
+                            if (typeof sourceValue[0] == "object") {
+                                for (var index = 0; index < sourceValue.length; index++) {
+                                    var clonedValue = cloneValue(sourceValue[index], destination);
+
+                                    if (destination[prop].indexOf(clonedValue) === -1) { // Test if auto inject was not done
+                                        destination[prop].push(clonedValue);
+                                    }
+                                }
+                            } else {
+                                destination[prop] = sourceValue.slice(0);
+                            }
+                        }
+                    } else {
+                        destination[prop] = cloneValue(sourceValue, destination);
+                    }
+                } else {
+                    destination[prop] = sourceValue;
+                }
+            }
+            catch (e) {
+                // Just ignore error (it could be because of a read-only property)
+            }
+        }
+    }
+}

+ 2 - 2
src/Misc/sceneOptimizer.ts

@@ -1,5 +1,5 @@
 import { Scene, IDisposable } from "../scene";
-import { Engine } from "../Engines/engine";
+import { EngineStore } from "../Engines/engineStore";
 import { AbstractMesh } from "../Meshes/abstractMesh";
 import { Mesh } from "../Meshes/mesh";
 import { Nullable } from "../types";
@@ -716,7 +716,7 @@ import { Observer, Observable } from "./observable";
             }
 
             this._improvementMode = improvementMode;
-            this._scene = scene || Engine.LastCreatedScene;
+            this._scene = scene || EngineStore.LastCreatedScene;
             this._sceneDisposeObserver = this._scene.onDisposeObservable.add(() => {
                 this._sceneDisposeObserver = null;
                 this.dispose();

+ 3 - 64
src/Misc/tools.ts

@@ -13,7 +13,8 @@ import { TGATools } from "./tga";
 import { Constants } from "../Engines/constants";
 import { DomManagement } from "./domManagement";
 import { Logger } from "./logger";
-import { _TypeStore } from './typeStore';
+import { _TypeStore } from "./typeStore";
+import { DeepCopier } from "./deepCopier";
 
 declare type Engine = import("../Engines/engine").Engine;
 
@@ -194,23 +195,6 @@ declare type Engine = import("../Engines/engine").Engine;
     // Screenshots
     var screenshotCanvas: HTMLCanvasElement;
 
-    var cloneValue = (source: any, destinationObject: any) => {
-        if (!source) {
-            return null;
-        }
-
-        if (source.getClassName && source.getClassName() === "Mesh") {
-            return null;
-        }
-
-        if (source.getClassName && source.getClassName() === "SubMesh") {
-            return source.clone(destinationObject);
-        } else if (source.clone) {
-            return source.clone();
-        }
-        return null;
-    };
-
     /**
      * Class containing a set of static utilities functions
      */
@@ -1150,52 +1134,7 @@ declare type Engine = import("../Engines/engine").Engine;
          * @param mustCopyList defines a list of properties to copy (even if they start with _)
          */
         public static DeepCopy(source: any, destination: any, doNotCopyList?: string[], mustCopyList?: string[]): void {
-            for (var prop in source) {
-
-                if (prop[0] === "_" && (!mustCopyList || mustCopyList.indexOf(prop) === -1)) {
-                    continue;
-                }
-
-                if (doNotCopyList && doNotCopyList.indexOf(prop) !== -1) {
-                    continue;
-                }
-
-                var sourceValue = source[prop];
-                var typeOfSourceValue = typeof sourceValue;
-
-                if (typeOfSourceValue === "function") {
-                    continue;
-                }
-
-                try {
-                    if (typeOfSourceValue === "object") {
-                        if (sourceValue instanceof Array) {
-                            destination[prop] = [];
-
-                            if (sourceValue.length > 0) {
-                                if (typeof sourceValue[0] == "object") {
-                                    for (var index = 0; index < sourceValue.length; index++) {
-                                        var clonedValue = cloneValue(sourceValue[index], destination);
-
-                                        if (destination[prop].indexOf(clonedValue) === -1) { // Test if auto inject was not done
-                                            destination[prop].push(clonedValue);
-                                        }
-                                    }
-                                } else {
-                                    destination[prop] = sourceValue.slice(0);
-                                }
-                            }
-                        } else {
-                            destination[prop] = cloneValue(sourceValue, destination);
-                        }
-                    } else {
-                        destination[prop] = sourceValue;
-                    }
-                }
-                catch (e) {
-                    // Just ignore error (it could be because of a read-only property)
-                }
-            }
+            DeepCopier.DeepCopy(source, destination, doNotCopyList, mustCopyList);
         }
 
         /**

+ 3 - 2
src/Morph/morphTarget.ts

@@ -2,12 +2,13 @@ import { IAnimatable } from "../Misc/tools";
 import { Observable } from "../Misc/observable";
 import { Nullable, FloatArray } from "../types";
 import { Scene } from "../scene";
-import { Engine } from "../Engines/engine";
+import { EngineStore } from "../Engines/engineStore";
 import { AbstractMesh } from "../Meshes/abstractMesh";
 import { VertexBuffer } from "../Meshes/buffer";
 import { Animation } from "../Animations/animation";
 import { AnimationPropertiesOverride } from "../Animations/animationPropertiesOverride";
 import { serialize, SerializationHelper } from "../Misc/decorators";
+
     /**
      * Defines a target to use with MorphTargetManager
      * @see http://doc.babylonjs.com/how_to/how_to_use_morphtargets
@@ -82,7 +83,7 @@ import { serialize, SerializationHelper } from "../Misc/decorators";
         public constructor(
             /** defines the name of the target */
             public name: string, influence = 0, scene: Nullable<Scene> = null) {
-                this._scene = scene || Engine.LastCreatedScene;
+                this._scene = scene || EngineStore.LastCreatedScene;
                 this.influence = influence;
         }
 

+ 2 - 2
src/Morph/morphTargetManager.ts

@@ -3,7 +3,7 @@ import { SmartArray } from "../Misc/smartArray";
 import { Logger } from "../Misc/logger";
 import { Nullable } from "../types";
 import { Scene } from "../scene";
-import { Engine } from "../Engines/engine";
+import { EngineStore } from "../Engines/engineStore";
 import { Mesh } from "../Meshes/mesh";
 import { MorphTarget } from "./morphTarget";
     /**
@@ -29,7 +29,7 @@ import { MorphTarget } from "./morphTarget";
          */
         public constructor(scene: Nullable<Scene> = null) {
             if (!scene) {
-                scene = Engine.LastCreatedScene;
+                scene = EngineStore.LastCreatedScene;
             }
 
             this._scene = scene;

+ 2 - 2
src/Particles/EmitterTypes/boxParticleEmitter.ts

@@ -1,4 +1,4 @@
-import { Tools } from "../../Misc/tools";
+import { DeepCopier } from "../../Misc/deepCopier";
 import { Vector3, Matrix } from "../../Maths/math";
 import { Scalar } from "../../Maths/math.scalar";
 import { Effect } from "../../Materials/effect";
@@ -71,7 +71,7 @@ import { IParticleEmitterType } from "./IParticleEmitterType";
         {
             let newOne = new BoxParticleEmitter();
 
-            Tools.DeepCopy(this, newOne);
+            DeepCopier.DeepCopy(this, newOne);
 
             return newOne;
         }

+ 2 - 2
src/Particles/EmitterTypes/coneParticleEmitter.ts

@@ -1,4 +1,4 @@
-import { Tools } from "../../Misc/tools";
+import { DeepCopier } from "../../Misc/deepCopier";
 import { Vector3, Matrix } from "../../Maths/math";
 import { Scalar } from "../../Maths/math.scalar";
 import { Effect } from "../../Materials/effect";
@@ -134,7 +134,7 @@ import { IParticleEmitterType } from "./IParticleEmitterType";
         public clone(): ConeParticleEmitter {
             let newOne = new ConeParticleEmitter(this._radius, this._angle, this.directionRandomizer);
 
-            Tools.DeepCopy(this, newOne);
+            DeepCopier.DeepCopy(this, newOne);
 
             return newOne;
         }

+ 3 - 3
src/Particles/EmitterTypes/cylinderParticleEmitter.ts

@@ -1,9 +1,9 @@
-import { Tools } from "../../Misc/tools";
 import { Vector3, Matrix } from "../../Maths/math";
 import { Scalar } from "../../Maths/math.scalar";
 import { Effect } from "../../Materials/effect";
 import { Particle } from "../../Particles/particle";
 import { IParticleEmitterType } from "./IParticleEmitterType";
+import { DeepCopier } from "../../Misc/deepCopier";
     /**
      * Particle emitter emitting particles from the inside of a cylinder.
      * It emits the particles alongside the cylinder radius. The emission direction might be randomized.
@@ -82,7 +82,7 @@ import { IParticleEmitterType } from "./IParticleEmitterType";
         public clone(): CylinderParticleEmitter {
             let newOne = new CylinderParticleEmitter(this.radius, this.directionRandomizer);
 
-            Tools.DeepCopy(this, newOne);
+            DeepCopier.DeepCopy(this, newOne);
 
             return newOne;
         }
@@ -190,7 +190,7 @@ import { IParticleEmitterType } from "./IParticleEmitterType";
         public clone(): CylinderDirectedParticleEmitter {
             let newOne = new CylinderDirectedParticleEmitter(this.radius, this.height, this.radiusRange, this.direction1, this.direction2);
 
-            Tools.DeepCopy(this, newOne);
+            DeepCopier.DeepCopy(this, newOne);
 
             return newOne;
         }

+ 2 - 2
src/Particles/EmitterTypes/hemisphericParticleEmitter.ts

@@ -1,4 +1,4 @@
-import { Tools } from "../../Misc/tools";
+import { DeepCopier } from "../../Misc/deepCopier";
 import { Vector3, Matrix } from "../../Maths/math";
 import { Scalar } from "../../Maths/math.scalar";
 import { Effect } from "../../Materials/effect";
@@ -73,7 +73,7 @@ import { IParticleEmitterType } from "./IParticleEmitterType";
         public clone(): HemisphericParticleEmitter {
             let newOne = new HemisphericParticleEmitter(this.radius, this.directionRandomizer);
 
-            Tools.DeepCopy(this, newOne);
+            DeepCopier.DeepCopy(this, newOne);
 
             return newOne;
         }

+ 2 - 2
src/Particles/EmitterTypes/pointParticleEmitter.ts

@@ -1,4 +1,4 @@
-import { Tools } from "../../Misc/tools";
+import { DeepCopier } from "../../Misc/deepCopier";
 import { Vector3, Matrix } from "../../Maths/math";
 import { Scalar } from "../../Maths/math.scalar";
 import { Effect } from "../../Materials/effect";
@@ -58,7 +58,7 @@ import { IParticleEmitterType } from "./IParticleEmitterType";
         {
             let newOne = new PointParticleEmitter();
 
-            Tools.DeepCopy(this, newOne);
+            DeepCopier.DeepCopy(this, newOne);
 
             return newOne;
         }

+ 3 - 3
src/Particles/EmitterTypes/sphereParticleEmitter.ts

@@ -1,9 +1,9 @@
-import { Tools } from "../../Misc/tools";
 import { Vector3, Matrix } from "../../Maths/math";
 import { Scalar } from "../../Maths/math.scalar";
 import { Effect } from "../../Materials/effect";
 import { Particle } from "../../Particles/particle";
 import { IParticleEmitterType } from "./IParticleEmitterType";
+import { DeepCopier } from "../../Misc/deepCopier";
     /**
      * Particle emitter emitting particles from the inside of a sphere.
      * It emits the particles alongside the sphere radius. The emission direction might be randomized.
@@ -73,7 +73,7 @@ import { IParticleEmitterType } from "./IParticleEmitterType";
         public clone(): SphereParticleEmitter {
             let newOne = new SphereParticleEmitter(this.radius, this.directionRandomizer);
 
-            Tools.DeepCopy(this, newOne);
+            DeepCopier.DeepCopy(this, newOne);
 
             return newOne;
         }
@@ -173,7 +173,7 @@ import { IParticleEmitterType } from "./IParticleEmitterType";
         public clone(): SphereDirectedParticleEmitter {
             let newOne = new SphereDirectedParticleEmitter(this.radius, this.direction1, this.direction2);
 
-            Tools.DeepCopy(this, newOne);
+            DeepCopier.DeepCopy(this, newOne);
 
             return newOne;
         }

+ 6 - 4
src/Particles/gpuParticleSystem.ts

@@ -19,6 +19,8 @@ import { ImageProcessingConfiguration } from "../Materials/imageProcessingConfig
 import { Texture } from "../Materials/Textures/texture";
 import { RawTexture } from "../Materials/Textures/rawTexture";
 import { Constants } from "../Engines/constants";
+import { EngineStore } from "../Engines/engineStore";
+import { DeepCopier } from "../Misc/deepCopier";
 
 import "../Shaders/gpuUpdateParticles.fragment";
 import "../Shaders/gpuUpdateParticles.vertex";
@@ -76,10 +78,10 @@ import "../Shaders/gpuRenderParticles.vertex";
          * Gets a boolean indicating if the GPU particles can be rendered on current browser
          */
         public static get IsSupported(): boolean {
-            if (!Engine.LastCreatedEngine) {
+            if (!EngineStore.LastCreatedEngine) {
                 return false;
             }
-            return Engine.LastCreatedEngine.webGLVersion > 1;
+            return EngineStore.LastCreatedEngine.webGLVersion > 1;
         }
 
         /**
@@ -621,7 +623,7 @@ import "../Shaders/gpuRenderParticles.vertex";
             randomTextureSize: number
         }>, scene: Scene, isAnimationSheetEnabled: boolean = false) {
             super(name);
-            this._scene = scene || Engine.LastCreatedScene;
+            this._scene = scene || EngineStore.LastCreatedScene;
             // Setup the default processing configuration to the scene.
             this._attachImageProcessingConfiguration(null);
 
@@ -1477,7 +1479,7 @@ import "../Shaders/gpuRenderParticles.vertex";
         public clone(name: string, newEmitter: any): GPUParticleSystem {
             var result = new GPUParticleSystem(name, { capacity: this._capacity, randomTextureSize: this._randomTextureSize }, this._scene);
 
-            Tools.DeepCopy(this, result);
+            DeepCopier.DeepCopy(this, result);
 
             if (newEmitter === undefined) {
                 newEmitter = this.emitter;

+ 2 - 2
src/Particles/particleHelper.ts

@@ -4,7 +4,7 @@ import { Tools } from "../Misc/tools";
 import { Vector3, Color4 } from "../Maths/math";
 import { AbstractMesh } from "../Meshes/abstractMesh";
 import { Texture } from "../Materials/Textures/texture";
-import { Engine } from "../Engines/engine";
+import { EngineStore } from "../Engines/engineStore";
 import { IParticleSystem } from "./IParticleSystem";
 import { GPUParticleSystem } from "./gpuParticleSystem";
 import { ParticleSystemSet } from "./particleSystemSet";
@@ -70,7 +70,7 @@ import { ParticleSystem } from "./particleSystem";
         public static CreateAsync(type: string, scene: Nullable<Scene>, gpu: boolean = false): Promise<ParticleSystemSet> {
 
             if (!scene) {
-                scene = Engine.LastCreatedScene;
+                scene = EngineStore.LastCreatedScene;
             }
 
             let token = {};

+ 4 - 3
src/Particles/particleSystem.ts

@@ -13,7 +13,7 @@ import { ImageProcessingConfiguration } from "../Materials/imageProcessingConfig
 import { Texture } from "../Materials/Textures/texture";
 import { RawTexture } from "../Materials/Textures/rawTexture";
 import { ProceduralTexture } from "../Materials/Textures/Procedurals/proceduralTexture";
-import { Engine } from "../Engines/engine";
+import { EngineStore } from "../Engines/engineStore";
 import { Scene, IDisposable } from "../scene";
 import { Animation } from "../Animations/animation";
 import { BoxParticleEmitter, IParticleEmitterType, HemisphericParticleEmitter, SphereParticleEmitter, SphereDirectedParticleEmitter, CylinderParticleEmitter, ConeParticleEmitter } from "../Particles/EmitterTypes/index";
@@ -23,6 +23,7 @@ import { Particle } from "./particle";
 import { SubEmitter, SubEmitterType } from "./subEmitter";
 import { Constants } from "../Engines/constants";
 import { SerializationHelper } from "../Misc/decorators";
+import { DeepCopier } from "../Misc/deepCopier";
 
 import "../Shaders/particles.fragment";
 import "../Shaders/particles.vertex";
@@ -204,7 +205,7 @@ import "../Shaders/particles.vertex";
             this._epsilon = epsilon;
             this._isAnimationSheetEnabled = isAnimationSheetEnabled;
 
-            this._scene = scene || Engine.LastCreatedScene;
+            this._scene = scene || EngineStore.LastCreatedScene;
 
             // Setup the default processing configuration to the scene.
             this._attachImageProcessingConfiguration(null);
@@ -1909,7 +1910,7 @@ import "../Shaders/particles.vertex";
             var result = new ParticleSystem(name, this._capacity, this._scene, custom);
             result.customShader = program;
 
-            Tools.DeepCopy(this, result, ["particles", "customShader", "noiseTexture"]);
+            DeepCopier.DeepCopy(this, result, ["particles", "customShader", "noiseTexture"]);
 
             if (newEmitter === undefined) {
                 newEmitter = this.emitter;

+ 3 - 2
src/Particles/particleSystemSet.ts

@@ -6,10 +6,11 @@ import { MeshBuilder } from "../Meshes/meshBuilder";
 import { IParticleSystem } from "./IParticleSystem";
 import { ParticleHelper } from "./particleHelper";
 import { GPUParticleSystem } from "./gpuParticleSystem";
-import { Engine } from "../Engines/engine";
+import { EngineStore } from "../Engines/engineStore";
 import { ParticleSystem } from "../Particles/particleSystem";
 import { Scene, IDisposable } from "../scene";
 import { StandardMaterial } from "../Materials/standardMaterial";
+
     /** Internal class used to store shapes for emitters */
     class ParticleSystemSetEmitterCreationOptions {
         public kind: string;
@@ -126,7 +127,7 @@ import { StandardMaterial } from "../Materials/standardMaterial";
             var result = new ParticleSystemSet();
             var rootUrl = ParticleHelper.BaseAssetsUrl + "/textures/";
 
-            scene = scene || Engine.LastCreatedScene;
+            scene = scene || EngineStore.LastCreatedScene;
 
             for (var system of data.systems) {
                 result.systems.push(gpu ? GPUParticleSystem.Parse(system, scene, rootUrl, true) : ParticleSystem.Parse(system, scene, rootUrl, true));

+ 3 - 2
src/Particles/solidParticleSystem.ts

@@ -4,11 +4,12 @@ import { VertexBuffer } from "../Meshes/buffer";
 import { VertexData } from "../Meshes/mesh.vertexData";
 import { Mesh } from "../Meshes/mesh";
 import { MeshBuilder } from "../Meshes/meshBuilder";
-import { Engine } from "../Engines/engine";
+import { EngineStore } from "../Engines/engineStore";
 import { Scene, IDisposable } from "../scene";
 import { DepthSortedParticle, SolidParticle, ModelShape } from "./solidParticle";
 import { TargetCamera } from "../Cameras/targetCamera";
 import { BoundingInfo } from "../Culling/boundingInfo";
+
     const depthSortFunction = (p1: DepthSortedParticle, p2: DepthSortedParticle) => p2.sqDistance - p1.sqDistance;
 
     /**
@@ -127,7 +128,7 @@ import { BoundingInfo } from "../Culling/boundingInfo";
          */
         constructor(name: string, scene: Scene, options?: { updatable?: boolean; isPickable?: boolean; enableDepthSort?: boolean; particleIntersection?: boolean; boundingSphereOnly?: boolean; bSphereRadiusFactor?: number }) {
             this.name = name;
-            this._scene = scene || Engine.LastCreatedScene;
+            this._scene = scene || EngineStore.LastCreatedScene;
             this._camera = <TargetCamera>scene.activeCamera;
             this._pickable = options ? <boolean>options.isPickable : false;
             this._depthSort = options ? <boolean>options.enableDepthSort : false;

+ 2 - 1
src/PostProcesses/RenderPipeline/Pipelines/defaultRenderingPipeline.ts

@@ -23,6 +23,7 @@ import { PostProcessRenderEffect } from "../../../PostProcesses/RenderPipeline/p
 import { DepthOfFieldEffect, DepthOfFieldEffectBlurLevel } from "../../../PostProcesses/depthOfFieldEffect";
 import { BloomEffect } from "../../../PostProcesses/bloomEffect";
 import { _TypeStore } from '../../../Misc/typeStore';
+import { EngineStore } from "../../../Engines/engineStore";
 
     /**
 	 * The default rendering pipeline can be added to a scene to apply common post processing effects such as anti-aliasing or depth of field.
@@ -391,7 +392,7 @@ import { _TypeStore } from '../../../Misc/typeStore';
          * @param cameras - The array of cameras that the rendering pipeline will be attached to (default: scene.cameras)
          * @param automaticBuild - if false, you will have to manually call prepare() to update the pipeline (default: true)
          */
-        constructor(name: string = "", hdr: boolean = true, scene: Scene = Engine.LastCreatedScene!, cameras?: Camera[], automaticBuild = true) {
+        constructor(name: string = "", hdr: boolean = true, scene: Scene = EngineStore.LastCreatedScene!, cameras?: Camera[], automaticBuild = true) {
             super(scene.getEngine(), name);
             this._cameras = cameras ||  scene.cameras;
             this._cameras = this._cameras.slice();

+ 2 - 2
src/PostProcesses/RenderPipeline/Pipelines/ssao2RenderingPipeline.ts

@@ -9,10 +9,10 @@ import { PostProcess } from "../../../PostProcesses/postProcess";
 import { PostProcessRenderPipeline } from "../../../PostProcesses/RenderPipeline/postProcessRenderPipeline";
 import { PostProcessRenderEffect } from "../../../PostProcesses/RenderPipeline/postProcessRenderEffect";
 import { PassPostProcess } from "../../../PostProcesses/passPostProcess";
-import { Engine } from "../../../Engines/engine";
 import { GeometryBufferRenderer } from "../../../Rendering/geometryBufferRenderer";
 import { Scene } from "../../../scene";
 import { _TypeStore } from '../../../Misc/typeStore';
+import { EngineStore } from '../../../Engines/engineStore';
 
 import "../../../Shaders/ssao2.fragment";
 import "../../../Shaders/ssaoCombine.fragment";
@@ -152,7 +152,7 @@ import "../../../Shaders/ssaoCombine.fragment";
         *  Support test.
         */
         public static get IsSupported(): boolean {
-            var engine = Engine.LastCreatedEngine;
+            var engine = EngineStore.LastCreatedEngine;
             if (!engine) {
                 return false;
             }

+ 2 - 1
src/PostProcesses/imageProcessingPostProcess.ts

@@ -9,6 +9,7 @@ import { ColorCurves } from "../Materials/colorCurves";
 import { ImageProcessingConfiguration, IImageProcessingConfigurationDefines } from "../Materials/imageProcessingConfiguration";
 import { PostProcess, PostProcessOptions } from "./postProcess";
 import { Engine } from "../Engines/engine";
+import { EngineStore } from "../Engines/engineStore";
 import { Scene } from "../scene";
 import { Constants } from "../Engines/constants";
 
@@ -75,7 +76,7 @@ import "../Shaders/postprocess.vertex";
                     scene = scenes[scenes.length - 1];
                 }
                 else {
-                    scene = Engine.LastCreatedScene;
+                    scene = EngineStore.LastCreatedScene;
                 }
 
                 this._imageProcessingConfiguration = (<Scene>scene).imageProcessingConfiguration;

+ 3 - 3
src/Rendering/utilityLayerRenderer.ts

@@ -3,8 +3,8 @@ import { Nullable } from "../types";
 import { Observable, Observer } from "../Misc/observable";
 import { PointerInfoPre, PointerInfo, PointerEventTypes } from "../Events/pointerEvents";
 import { PickingInfo } from "../Collisions/pickingInfo";
-import { Engine } from "../Engines/engine";
 import { AbstractMesh } from "../Meshes/abstractMesh";
+import { EngineStore } from "../Engines/engineStore";
 
     /**
      * Renders a layer on top of an existing scene
@@ -24,7 +24,7 @@ import { AbstractMesh } from "../Meshes/abstractMesh";
          */
         public static get DefaultUtilityLayer(): UtilityLayerRenderer {
             if (UtilityLayerRenderer._DefaultUtilityLayer == null) {
-                UtilityLayerRenderer._DefaultUtilityLayer = new UtilityLayerRenderer(Engine.LastCreatedScene!);
+                UtilityLayerRenderer._DefaultUtilityLayer = new UtilityLayerRenderer(EngineStore.LastCreatedScene!);
                 UtilityLayerRenderer._DefaultUtilityLayer.originalScene.onDisposeObservable.addOnce(() => {
                     UtilityLayerRenderer._DefaultUtilityLayer = null;
                 });
@@ -36,7 +36,7 @@ import { AbstractMesh } from "../Meshes/abstractMesh";
          */
         public static get DefaultKeepDepthUtilityLayer(): UtilityLayerRenderer {
             if (UtilityLayerRenderer._DefaultKeepDepthUtilityLayer == null) {
-                UtilityLayerRenderer._DefaultKeepDepthUtilityLayer = new UtilityLayerRenderer(Engine.LastCreatedScene!);
+                UtilityLayerRenderer._DefaultKeepDepthUtilityLayer = new UtilityLayerRenderer(EngineStore.LastCreatedScene!);
                 UtilityLayerRenderer._DefaultKeepDepthUtilityLayer.utilityLayerScene.autoClearDepthAndStencil = false;
                 UtilityLayerRenderer._DefaultKeepDepthUtilityLayer.originalScene.onDisposeObservable.addOnce(() => {
                     UtilityLayerRenderer._DefaultKeepDepthUtilityLayer = null;

+ 2 - 1
src/node.ts

@@ -5,6 +5,7 @@ import { Engine } from "./Engines/engine";
 import { IBehaviorAware, Behavior } from "./Behaviors/behavior";
 import { serialize } from "./Misc/decorators";
 import { Observable, Observer } from "./Misc/observable";
+import { EngineStore } from "./Engines/engineStore";
 
 declare type Animatable = import("./Animations/animatable").Animatable;
 declare type AnimationPropertiesOverride = import("./Animations/animationPropertiesOverride").AnimationPropertiesOverride;
@@ -259,7 +260,7 @@ declare type AbstractMesh = import("./Meshes/abstractMesh").AbstractMesh;
         constructor(name: string, scene: Nullable<Scene> = null, addToRootNodes = true) {
             this.name = name;
             this.id = name;
-            this._scene = <Scene>(scene || Engine.LastCreatedScene);
+            this._scene = <Scene>(scene || EngineStore.LastCreatedScene);
             this.uniqueId = this._scene.getUniqueId();
             this._initCache();
 

+ 2 - 1
src/scene.ts

@@ -50,6 +50,7 @@ import { MorphTarget } from "./Morph/morphTarget";
 import { Constants } from "./Engines/constants";
 import { DomManagement } from "./Misc/domManagement";
 import { Logger } from "./Misc/logger";
+import { EngineStore } from "./Engines/engineStore";
 
     /**
      * Define an interface for all classes that will hold resources
@@ -1278,7 +1279,7 @@ import { Logger } from "./Misc/logger";
          */
         constructor(engine: Engine, options?: SceneOptions) {
             super();
-            this._engine = engine || Engine.LastCreatedEngine;
+            this._engine = engine || EngineStore.LastCreatedEngine;
 
             this._engine.scenes.push(this);
             this._uid = null;