Explorar o código

Merge pull request #6295 from TrevorDev/virtualScene

add virtual option when creating a scene to avoid impacting engine
David Catuhe %!s(int64=6) %!d(string=hai) anos
pai
achega
73aca00241

+ 1 - 2
src/Behaviors/Meshes/pointerDragBehavior.ts

@@ -144,9 +144,8 @@ export class PointerDragBehavior implements Behavior<AbstractMesh> {
             if (this._debugMode) {
                 PointerDragBehavior._planeScene = this._scene;
             } else {
-                PointerDragBehavior._planeScene = new Scene(this._scene.getEngine());
+                PointerDragBehavior._planeScene = new Scene(this._scene.getEngine(), {virtual: true});
                 PointerDragBehavior._planeScene.detachControl();
-                this._scene.getEngine().scenes.pop();
                 this._scene.onDisposeObservable.addOnce(() => {
                     PointerDragBehavior._planeScene.dispose();
                     (<any>PointerDragBehavior._planeScene) = null;

+ 1 - 2
src/Rendering/utilityLayerRenderer.ts

@@ -100,10 +100,9 @@ export class UtilityLayerRenderer implements IDisposable {
         public originalScene: Scene,
         handleEvents: boolean = true) {
         // Create scene which will be rendered in the foreground and remove it from being referenced by engine to avoid interfering with existing app
-        this.utilityLayerScene = new Scene(originalScene.getEngine());
+        this.utilityLayerScene = new Scene(originalScene.getEngine(), {virtual: true});
         this.utilityLayerScene.useRightHandedSystem = originalScene.useRightHandedSystem;
         this.utilityLayerScene._allowPostProcessClearColor = false;
-        originalScene.getEngine().scenes.pop();
 
         // Detach controls on utility scene, events will be fired by logic below to handle picking priority
         this.utilityLayerScene.detachControl();

+ 10 - 3
src/scene.ts

@@ -85,6 +85,9 @@ export interface SceneOptions {
      * It will improve performance when the number of mesh becomes important, but might consume a bit more memory
      */
     useClonedMeshhMap?: boolean;
+
+    /** Defines if the creation of the scene should impact the engine (Eg. UtilityLayer's scene) */
+    virtual?: boolean;
 }
 
 /**
@@ -1300,9 +1303,11 @@ export class Scene extends AbstractScene implements IAnimatable {
     constructor(engine: Engine, options?: SceneOptions) {
         super();
         this._engine = engine || EngineStore.LastCreatedEngine;
-        EngineStore._LastCreatedScene = this;
+        if (!options || !options.virtual) {
+            EngineStore._LastCreatedScene = this;
+            this._engine.scenes.push(this);
+        }
 
-        this._engine.scenes.push(this);
         this._uid = null;
 
         this._renderingManager = new RenderingManager(this);
@@ -1332,7 +1337,9 @@ export class Scene extends AbstractScene implements IAnimatable {
         this.useMaterialMeshMap = options && options.useGeometryUniqueIdsMap || false;
         this.useClonedMeshhMap = options && options.useClonedMeshhMap || false;
 
-        this._engine.onNewSceneAddedObservable.notifyObservers(this);
+        if (!options || !options.virtual) {
+            this._engine.onNewSceneAddedObservable.notifyObservers(this);
+        }
     }
 
     /**