diff --git a/src/lib/terrain/TerrainMaterial.ts b/src/lib/terrain/TerrainMaterial.ts index 6475470..228d1e4 100644 --- a/src/lib/terrain/TerrainMaterial.ts +++ b/src/lib/terrain/TerrainMaterial.ts @@ -19,6 +19,18 @@ class TerrainMaterial extends THREE.RawShaderMaterial { this.side = THREE.FrontSide; this.blending = 0; } + + dispose() { + // Layer textures + for (const texture of this.uniforms.layers.value) { + texture.dispose(); + } + + // Splat texture + this.uniforms.splat.value.dispose(); + + super.dispose(); + } } export default TerrainMaterial; diff --git a/src/lib/terrain/TerrainMesh.ts b/src/lib/terrain/TerrainMesh.ts index 5927fc8..ea62654 100644 --- a/src/lib/terrain/TerrainMesh.ts +++ b/src/lib/terrain/TerrainMesh.ts @@ -12,6 +12,11 @@ class TerrainMesh extends THREE.Mesh { this.position.set(position[0], position[1], position[2]); this.updateMatrixWorld(); } + + dispose() { + this.geometry.dispose(); + (this.material as THREE.Material).dispose(); + } } export default TerrainMesh;