Refactor road material generation and improve resource cleanup logic

This commit is contained in:
2026-05-13 02:57:12 +02:00
parent e0ad7201dc
commit a83e5de56f

View File

@@ -7282,18 +7282,21 @@ export class ViewportHost {
return material; return material;
} }
private createRoadSurfaceMaterial(path: ScenePath): Material { private createRoadGeneratedMaterial(
materialId: string | null,
fallbackColor: number
): Material {
const materialDef = const materialDef =
path.road.materialId === null || this.currentDocument === null materialId === null || this.currentDocument === null
? null ? null
: (this.currentDocument.materials[path.road.materialId] ?? null); : (this.currentDocument.materials[materialId] ?? null);
if (this.displayMode === "wireframe") { if (this.displayMode === "wireframe") {
return this.configureRoadSurfaceMaterial( return this.configureRoadSurfaceMaterial(
new MeshBasicMaterial({ new MeshBasicMaterial({
color: color:
materialDef === null materialDef === null
? PATH_ROAD_PREVIEW_COLOR ? fallbackColor
: Number.parseInt(materialDef.swatchColorHex.replace("#", ""), 16), : Number.parseInt(materialDef.swatchColorHex.replace("#", ""), 16),
wireframe: true, wireframe: true,
side: DoubleSide side: DoubleSide
@@ -7304,7 +7307,7 @@ export class ViewportHost {
if (materialDef === null) { if (materialDef === null) {
return this.configureRoadSurfaceMaterial( return this.configureRoadSurfaceMaterial(
new MeshStandardMaterial({ new MeshStandardMaterial({
color: PATH_ROAD_PREVIEW_COLOR, color: fallbackColor,
roughness: 1, roughness: 1,
metalness: 0, metalness: 0,
side: DoubleSide side: DoubleSide
@@ -7331,6 +7334,20 @@ export class ViewportHost {
); );
} }
private createRoadSurfaceMaterial(path: ScenePath): Material {
return this.createRoadGeneratedMaterial(
path.road.materialId,
PATH_ROAD_PREVIEW_COLOR
);
}
private createRoadEdgeMaterial(edge: ScenePathRoadEdgeSettings): Material {
return this.createRoadGeneratedMaterial(
edge.materialId,
PATH_ROAD_EDGE_FALLBACK_COLORS[edge.kind]
);
}
private createRoadSurfaceRenderObjects( private createRoadSurfaceRenderObjects(
path: ScenePath, path: ScenePath,
terrains: readonly Terrain[] terrains: readonly Terrain[]
@@ -11511,9 +11528,11 @@ export class ViewportHost {
private clearRoadSurfaces() { private clearRoadSurfaces() {
for (const renderObjects of this.roadSurfaceRenderObjects.values()) { for (const renderObjects of this.roadSurfaceRenderObjects.values()) {
this.roadSurfaceGroup.remove(renderObjects.mesh); for (const mesh of renderObjects.meshes) {
renderObjects.mesh.geometry.dispose(); this.roadSurfaceGroup.remove(mesh);
renderObjects.mesh.material.dispose(); mesh.geometry.dispose();
mesh.material.dispose();
}
} }
this.roadSurfaceRenderObjects.clear(); this.roadSurfaceRenderObjects.clear();