Refactor terrain material presentation update into a dedicated method

This commit is contained in:
2026-04-27 00:11:21 +02:00
parent c02bc1979f
commit 593c45a239

View File

@@ -7930,21 +7930,28 @@ export class ViewportHost {
}
for (const terrain of Object.values(this.currentDocument.terrains)) {
const renderObjects = this.terrainRenderObjects.get(terrain.id);
if (renderObjects === undefined) {
continue;
}
const displayedTerrain =
this.getDisplayedTerrainState(terrain.id) ?? terrain;
const previousMaterial = renderObjects.mesh.material;
renderObjects.mesh.material =
this.createTerrainMaterial(displayedTerrain);
previousMaterial.dispose();
this.refreshTerrainPresentationForId(terrain.id);
}
}
private refreshTerrainPresentationForId(terrainId: string) {
if (this.currentDocument === null) {
return;
}
const terrain = this.currentDocument.terrains[terrainId];
const renderObjects = this.terrainRenderObjects.get(terrainId);
if (terrain === undefined || renderObjects === undefined) {
return;
}
const displayedTerrain = this.getDisplayedTerrainState(terrainId) ?? terrain;
const previousMaterial = renderObjects.mesh.material;
renderObjects.mesh.material = this.createTerrainMaterial(displayedTerrain);
previousMaterial.dispose();
}
private getDisplayedTerrainState(terrainId: string): Terrain | null {
if (
this.activeTerrainBrushStroke !== null &&