Dynamically configure physical materials using custom material properties

This commit is contained in:
2026-05-18 16:07:23 +02:00
parent a86261dd4c
commit 41d09ebc18
2 changed files with 50 additions and 26 deletions

View File

@@ -7728,29 +7728,35 @@ export class ViewportHost {
const materialTransparent =
isCustomMaterial &&
(materialDef.opacity < 0.999 || textureSet.albedoHasAlpha);
const roadMaterial = new MeshPhysicalMaterial({
color: isCustomMaterial ? materialDef.albedoColorHex : 0xffffff,
map: textureSet.baseColor,
normalMap: textureSet.normal,
roughnessMap: textureSet.roughness,
roughness: isCustomMaterial ? materialDef.roughness : 1,
metalnessMap: textureSet.metallic,
metalness: isCustomMaterial
? materialDef.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 ? materialDef.opacity : 1,
depthWrite: !materialTransparent,
side: DoubleSide
});
return this.configureRoadSurfaceMaterial(
new MeshPhysicalMaterial({
color: isCustomMaterial ? materialDef.albedoColorHex : 0xffffff,
map: textureSet.baseColor,
normalMap: textureSet.normal,
roughnessMap: textureSet.roughness,
roughness: isCustomMaterial ? materialDef.roughness : 1,
metalnessMap: textureSet.metallic,
metalness: isCustomMaterial
? materialDef.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 ? materialDef.opacity : 1,
depthWrite: !materialTransparent,
side: DoubleSide
})
);
if (isCustomMaterial && textureSet.normal !== null) {
roadMaterial.normalScale.set(
materialDef.normalStrength,
materialDef.normalStrength
);
}
return this.configureRoadSurfaceMaterial(roadMaterial);
}
private createRoadSurfaceMaterial(path: ScenePath): Material {