Skip to content

Commit

Permalink
feat(terrain): dispose of terrain geometry and materials when no long…
Browse files Browse the repository at this point in the history
…er in use
  • Loading branch information
fallenoak committed Dec 29, 2023
1 parent f316e96 commit 6f5f049
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/lib/terrain/TerrainMaterial.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions src/lib/terrain/TerrainMesh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 6f5f049

Please sign in to comment.