| | |
| | | destroy = () => { |
| | | cancelAnimationFrame(this.animationFrame); |
| | | window.removeEventListener('resize', this.resizeHandler); |
| | | this.renderer.dispose(); |
| | | this.controls.dispose(); |
| | | if (this.scene) { |
| | | while (this.scene.children.length > 0) { |
| | | this.removeEntity(this.scene.children[0]); |
| | | } |
| | | this.scene = null; |
| | | } |
| | | if (this.renderer) { |
| | | this.renderer.dispose(); |
| | | this.renderer.forceContextLoss(); |
| | | this.renderer.context = null; |
| | | this.renderer.domElement = null; |
| | | this.renderer = null; |
| | | } |
| | | if (this.controls) { |
| | | this.controls.dispose(); |
| | | this.controls = null; |
| | | } |
| | | this.camera = null; |
| | | this.objects = []; |
| | | while (this.dom?.firstChild) { |
| | | this.dom.removeChild(this.dom.firstChild); |
| | | } |
| | | } |
| | | |
| | | removeEntity = (object) => { |
| | | if (object.material) object.material.dispose(); |
| | | if (object.geometry) object.geometry.dispose(); |
| | | if (object.texture) object.texture.dispose(); |
| | | this.scene.remove(object); |
| | | } |
| | | }; |
| | | |