From a524995f73ec5e246ed395c248f36c77b7ebc7ec Mon Sep 17 00:00:00 2001 From: fallenoak Date: Wed, 3 Jan 2024 00:42:36 -0600 Subject: [PATCH] feat(terrain): improve terrain loading speed --- src/lib/terrain/TerrainManager.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/lib/terrain/TerrainManager.ts b/src/lib/terrain/TerrainManager.ts index 820931f..530e079 100644 --- a/src/lib/terrain/TerrainManager.ts +++ b/src/lib/terrain/TerrainManager.ts @@ -51,12 +51,10 @@ class TerrainManager { group.matrixAutoUpdate = false; group.matrixWorldAutoUpdate = false; - for (const chunk of area.chunks) { - if (chunk.layers.length === 0) { - continue; - } + const renderableChunks = area.chunks.filter((chunk) => chunk.layers.length > 0); + const meshes = await Promise.all(renderableChunks.map((chunk) => this.#createMesh(chunk))); - const mesh = await this.#createMesh(chunk); + for (const mesh of meshes) { group.add(mesh); }