diff --git a/src/runtime-three/runtime-host.ts b/src/runtime-three/runtime-host.ts index 6bb46a83..497b2657 100644 --- a/src/runtime-three/runtime-host.ts +++ b/src/runtime-three/runtime-host.ts @@ -811,6 +811,7 @@ export class RuntimeHost { this.resizeObserver = null; this.clearLocalLights(); this.clearBrushMeshes(); + this.clearTerrainMeshes(); this.clearModelRenderObjects(); this.collisionWorldRequestId += 1; this.clearCollisionWorld(); @@ -2702,6 +2703,16 @@ export class RuntimeHost { this.runtimeWaterContactUniforms.length = 0; } + private clearTerrainMeshes() { + for (const mesh of this.terrainMeshes.values()) { + this.terrainGroup.remove(mesh); + mesh.geometry.dispose(); + mesh.material.dispose(); + } + + this.terrainMeshes.clear(); + } + private disposeUniqueMaterials(materials: Material[]) { for (const material of new Set(materials)) { material.dispose();