Refactor terrain LOD mesh generation to use chunk-based data structure
This commit is contained in:
@@ -596,6 +596,53 @@ export function buildTerrainLodMeshData(
|
||||
startSampleX < maxCellX;
|
||||
startSampleX += chunkSizeCells, chunkX += 1
|
||||
) {
|
||||
const chunk = buildTerrainLodChunkMeshData(
|
||||
terrain,
|
||||
startSampleX,
|
||||
startSampleZ,
|
||||
chunkSizeCells
|
||||
);
|
||||
|
||||
if (chunk === null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
includePointInBounds(localBounds, chunk.localBounds.min);
|
||||
includePointInBounds(localBounds, chunk.localBounds.max);
|
||||
|
||||
chunks.push({
|
||||
...chunk,
|
||||
chunkX,
|
||||
chunkZ
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
chunkSizeCells,
|
||||
chunks,
|
||||
localBounds: cloneBounds(localBounds)
|
||||
};
|
||||
}
|
||||
|
||||
export function buildTerrainLodChunkMeshData(
|
||||
terrain: Terrain,
|
||||
startSampleX: number,
|
||||
startSampleZ: number,
|
||||
chunkSizeCells = TERRAIN_LOD_CHUNK_SIZE_CELLS
|
||||
): TerrainLodChunkMeshData | null {
|
||||
const maxCellX = terrain.sampleCountX - 1;
|
||||
const maxCellZ = terrain.sampleCountZ - 1;
|
||||
|
||||
if (
|
||||
startSampleX < 0 ||
|
||||
startSampleZ < 0 ||
|
||||
startSampleX >= maxCellX ||
|
||||
startSampleZ >= maxCellZ
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const endSampleX = Math.min(startSampleX + chunkSizeCells, maxCellX);
|
||||
const endSampleZ = Math.min(startSampleZ + chunkSizeCells, maxCellZ);
|
||||
const cellCountX = endSampleX - startSampleX;
|
||||
@@ -630,12 +677,9 @@ export function buildTerrainLodMeshData(
|
||||
chunkBounds.max.z - chunkBounds.min.z
|
||||
);
|
||||
|
||||
includePointInBounds(localBounds, chunkBounds.min);
|
||||
includePointInBounds(localBounds, chunkBounds.max);
|
||||
|
||||
chunks.push({
|
||||
chunkX,
|
||||
chunkZ,
|
||||
return {
|
||||
chunkX: Math.floor(startSampleX / chunkSizeCells),
|
||||
chunkZ: Math.floor(startSampleZ / chunkSizeCells),
|
||||
startSampleX,
|
||||
startSampleZ,
|
||||
endSampleX,
|
||||
@@ -646,14 +690,6 @@ export function buildTerrainLodMeshData(
|
||||
localBounds: cloneBounds(chunkBounds),
|
||||
localCenter,
|
||||
diagonal
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
chunkSizeCells,
|
||||
chunks,
|
||||
localBounds: cloneBounds(localBounds)
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user