I’m creating a react component where I should be able to define a skybox and clean up once the component is removed (componentWillUnmount).
So basically I try to add a skybox and later remove it. However once I use createDefaultSkybox on the scene, some textures are being added I suppose and I’m not sure how to do proper “clean up”:
// create
public createSkybox(pathToEnvTexture: string) {
this.removeSkybox();
const { worldRadius } = utils.getWorldMeasurements(this.scene);
const envTexture = new CubeTexture(pathToEnvTexture, this.scene);
this.skybox = this.scene.createDefaultSkybox(
envTexture,
true,
worldRadius * 30
);
}
// clean up
public removeSkybox() {
if (this.skybox) {
this.skybox.dispose();
this.skybox = null;
}
}
Here is an image without skybox -> with skybox -> after removing skybox: