Skip to content

Commit

Permalink
Merge pull request #6295 from TrevorDev/virtualScene
Browse files Browse the repository at this point in the history
add virtual option when creating a scene to avoid impacting engine
  • Loading branch information
deltakosh committed May 1, 2019
2 parents 5935296 + 3179c54 commit 73aca00
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
3 changes: 1 addition & 2 deletions src/Behaviors/Meshes/pointerDragBehavior.ts
Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions src/Rendering/utilityLayerRenderer.ts
Expand Up @@ -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();
Expand Down
13 changes: 10 additions & 3 deletions src/scene.ts
Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
}

/**
Expand Down

0 comments on commit 73aca00

Please sign in to comment.