Browse Source

Making sure the env helper is recreating the meshes
But yet not disposed completly

Please note that Core's env helper was also changed

Raanan Weber 7 years ago
parent
commit
bb952884e8

+ 13 - 4
Viewer/src/managers/sceneManager.ts

@@ -857,7 +857,7 @@ export class SceneManager {
         if (!skyboxConifguration && !groundConfiguration) {
             if (this.environmentHelper) {
                 this.environmentHelper.dispose();
-                delete this.environmentHelper;
+                this.environmentHelper = undefined;
             };
         } else {
 
@@ -963,10 +963,19 @@ export class SceneManager {
                     this.environmentHelper.dispose();
                     this.environmentHelper = this.scene.createDefaultEnvironment(options)!;
                 } else {
-                    //this.environmentHelper.updateOptions(options)!;
+                    // recreate the ground
+                    if (this.environmentHelper.ground) {
+                        this.environmentHelper.ground.dispose();
+                    }
+                    // recreate the skybox
+                    if (this.environmentHelper.skybox) {
+                        this.environmentHelper.skybox.dispose();
+                    }
+
+                    this.environmentHelper.updateOptions(options)!;
                     // update doesn't change the size of the skybox and ground, so we have to recreate!
-                    this.environmentHelper.dispose();
-                    this.environmentHelper = this.scene.createDefaultEnvironment(options)!;
+                    //this.environmentHelper.dispose();
+                    //this.environmentHelper = this.scene.createDefaultEnvironment(options)!;
                 }
             }
 

+ 1 - 1
dist/preview release/what's new.md

@@ -38,7 +38,7 @@
 - Added a new `mesh.ignoreNonUniformScaling` to turn off non uniform scaling compensation ([Deltakosh](https://github.com/deltakosh))
 - AssetsManager tasks will only run when their state is INIT. It is now possible to remove a task from the assets manager ([RaananW](https://github.com/RaananW))
 - Added sprite isVisible field ([TrevorDev](https://github.com/TrevorDev))
-
+- EnvironmentHelper will recreate ground and skybox meshes if force-disposed ([RaananW](https://github.com/RaananW))
 
 ### glTF Loader
 

+ 2 - 2
src/Helpers/babylon.environmentHelper.ts

@@ -515,7 +515,7 @@ module BABYLON {
          * Setup the ground according to the specified options.
          */
         private _setupGround(sceneSize: ISceneSize): void {
-            if (!this._ground) {
+            if (!this._ground || this._ground.isDisposed()) {
                 this._ground = Mesh.CreatePlane("BackgroundPlane", sceneSize.groundSize, this._scene);
                 this._ground.rotation.x = Math.PI / 2; // Face up by default.
                 this._ground.parent = this._rootMesh;
@@ -623,7 +623,7 @@ module BABYLON {
          * Setup the skybox according to the specified options.
          */
         private _setupSkybox(sceneSize: ISceneSize): void {
-            if (!this._skybox) {
+            if (!this._skybox || this._skybox.isDisposed()) {
                 this._skybox = Mesh.CreateBox("BackgroundSkybox", sceneSize.skyboxSize, this._scene, undefined, Mesh.BACKSIDE);
                 this._skybox.onDisposeObservable.add(() => { this._skybox = null; })
             }