From e013c2ac39269ee8e237c2d4663343739b9f20b5 Mon Sep 17 00:00:00 2001 From: Vincent Fretin Date: Thu, 15 Jun 2023 12:10:11 +0200 Subject: [PATCH] Implement remove method --- index.js | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index 5c644c8a..83661b54 100644 --- a/index.js +++ b/index.js @@ -168,7 +168,6 @@ AFRAME.registerComponent('environment', { this.stars = null; // create ground - this.groundMaterial = null; this.ground = document.createElement('a-entity'); this.ground.setAttribute('rotation', '-90 0 0'); this.ground.classList.add('environmentGround'); @@ -405,6 +404,35 @@ AFRAME.registerComponent('environment', { this.dumpParametersDiff(); }, + remove: function() { + if (this.userFog) { + this.el.sceneEl.setAttribute('fog', this.userFog); + } + else { + this.el.sceneEl.removeAttribute('fog'); + } + this.el.removeChild(this.hemilight); + this.el.removeChild(this.sunlight); + if (this.groundTexture) this.groundTexture.dispose(); + if (this.gridTexture) this.gridTexture.dispose(); + if (this.groundMaterial) this.groundMaterial.dispose(); + if (this.groundGeometry) this.groundGeometry.dispose(); + this.el.removeChild(this.ground); + var dressingMesh = this.dressing.getObject3D('mesh'); + if (dressingMesh && dressingMesh.children.length > 0) { + dressingMesh.children[0].material.dispose(); + dressingMesh.children[0].geometry.dispose(); + } + this.el.removeChild(this.dressing); + this.el.removeChild(this.sky); + if (this.stars) { + var mesh = this.stars.getObject3D('mesh'); + mesh.material.dispose(); + mesh.geometry.dispose(); + this.el.removeChild(this.stars); + } + }, + // logs current parameters to console, for saving to a preset logPreset: function () { var str = '{'; @@ -590,12 +618,7 @@ AFRAME.registerComponent('environment', { emissiveMap: this.gridTexture }; - // use .shading for A-Frame < 0.7.0 and .flatShading for A-Frame >= 0.7.0 - if (new THREE.Material().hasOwnProperty('shading')) { - this.groundMaterialProps.shading = this.environmentData.flatShading ? THREE.FlatShading : THREE.SmoothShading; - } else { - this.groundMaterialProps.flatShading = this.environmentData.flatShading; - } + this.groundMaterialProps.flatShading = this.environmentData.flatShading; this.groundMaterial = new THREE.MeshLambertMaterial(this.groundMaterialProps); }