Refactor chunk LOD handling to use a single mesh and geometry array
This commit is contained in:
@@ -4064,18 +4064,17 @@ export class RuntimeHost {
|
|||||||
group.visible = terrain.visible;
|
group.visible = terrain.visible;
|
||||||
|
|
||||||
for (const chunk of lodMeshData.chunks) {
|
for (const chunk of lodMeshData.chunks) {
|
||||||
const levels = chunk.levels.map((level) => {
|
const levelGeometries = chunk.levels.map((level) => level.geometry);
|
||||||
const mesh = new Mesh(level.geometry, material);
|
const mesh = new Mesh(levelGeometries[0]!, material);
|
||||||
mesh.castShadow = false;
|
mesh.castShadow = false;
|
||||||
mesh.receiveShadow = true;
|
mesh.receiveShadow = true;
|
||||||
mesh.visible = level.level === 0;
|
mesh.userData.terrainLodLevel = 0;
|
||||||
applyRendererRenderCategory(mesh, "ao-world");
|
applyRendererRenderCategory(mesh, "ao-world");
|
||||||
group.add(mesh);
|
group.add(mesh);
|
||||||
return mesh;
|
|
||||||
});
|
|
||||||
|
|
||||||
chunks.push({
|
chunks.push({
|
||||||
levels,
|
mesh,
|
||||||
|
levelGeometries,
|
||||||
activeLevelIndex: 0,
|
activeLevelIndex: 0,
|
||||||
worldCenter: new Vector3(
|
worldCenter: new Vector3(
|
||||||
terrain.position.x + chunk.localCenter.x,
|
terrain.position.x + chunk.localCenter.x,
|
||||||
@@ -4108,7 +4107,7 @@ export class RuntimeHost {
|
|||||||
for (const renderObjects of this.terrainMeshes.values()) {
|
for (const renderObjects of this.terrainMeshes.values()) {
|
||||||
for (const chunk of renderObjects.chunks) {
|
for (const chunk of renderObjects.chunks) {
|
||||||
const nextLevelIndex = resolveTerrainLodLevelIndex({
|
const nextLevelIndex = resolveTerrainLodLevelIndex({
|
||||||
levelCount: chunk.levels.length,
|
levelCount: chunk.levelGeometries.length,
|
||||||
chunkDiagonal: chunk.diagonal,
|
chunkDiagonal: chunk.diagonal,
|
||||||
cameraPosition,
|
cameraPosition,
|
||||||
chunkWorldCenter: {
|
chunkWorldCenter: {
|
||||||
@@ -4124,10 +4123,8 @@ export class RuntimeHost {
|
|||||||
}
|
}
|
||||||
|
|
||||||
chunk.activeLevelIndex = nextLevelIndex;
|
chunk.activeLevelIndex = nextLevelIndex;
|
||||||
|
chunk.mesh.geometry = chunk.levelGeometries[nextLevelIndex]!;
|
||||||
for (let levelIndex = 0; levelIndex < chunk.levels.length; levelIndex += 1) {
|
chunk.mesh.userData.terrainLodLevel = nextLevelIndex;
|
||||||
chunk.levels[levelIndex]!.visible = levelIndex === nextLevelIndex;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user