From a86261dd4c94c93ecfb27e833151c1f0b6bcd55c Mon Sep 17 00:00:00 2001 From: Victor Giers Date: Mon, 18 May 2026 16:07:07 +0200 Subject: [PATCH] Improve road surface material creation to support custom material properties --- src/runtime-three/runtime-host.ts | 47 +++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 15 deletions(-) diff --git a/src/runtime-three/runtime-host.ts b/src/runtime-three/runtime-host.ts index f6cbe9b6..256b2838 100644 --- a/src/runtime-three/runtime-host.ts +++ b/src/runtime-three/runtime-host.ts @@ -4309,22 +4309,39 @@ export class RuntimeHost { } const textureSet = this.getOrCreateTextureSet(material); + const isCustomMaterial = material.kind === "custom"; + const materialTransparent = + isCustomMaterial && + (material.opacity < 0.999 || textureSet.albedoHasAlpha); + const roadMaterial = new MeshPhysicalMaterial({ + color: isCustomMaterial ? material.albedoColorHex : 0xffffff, + map: textureSet.baseColor, + normalMap: textureSet.normal, + roughnessMap: textureSet.roughness, + roughness: isCustomMaterial ? material.roughness : 1, + metalnessMap: textureSet.metallic, + metalness: isCustomMaterial + ? material.metallic + : textureSet.metallic === null + ? 0.03 + : 1, + specularColorMap: textureSet.specular, + specularColor: new Color(0xffffff), + specularIntensity: textureSet.specular === null ? 0.2 : 1, + transparent: materialTransparent, + opacity: isCustomMaterial ? material.opacity : 1, + depthWrite: !materialTransparent, + side: DoubleSide + }); - return this.configureRoadSurfaceMaterial( - new MeshPhysicalMaterial({ - color: 0xffffff, - map: textureSet.baseColor, - normalMap: textureSet.normal, - roughnessMap: textureSet.roughness, - roughness: 1, - metalnessMap: textureSet.metallic, - metalness: textureSet.metallic === null ? 0.03 : 1, - specularColorMap: textureSet.specular, - specularColor: new Color(0xffffff), - specularIntensity: textureSet.specular === null ? 0.2 : 1, - side: DoubleSide - }) - ); + if (isCustomMaterial && textureSet.normal !== null) { + roadMaterial.normalScale.set( + material.normalStrength, + material.normalStrength + ); + } + + return this.configureRoadSurfaceMaterial(roadMaterial); } private createRuntimeRoadSurfaceMaterial(path: RuntimePath): Material {