Add transparency support to vehicle part rendering

Apply mesh alpha values from WDB to Three.js materials. In the original
game, alpha=0 means opaque while alpha>0 enables transparency. Disable
depthWrite for transparent meshes to prevent z-fighting.
This commit is contained in:
Christian Semmler 2026-02-01 15:53:47 -08:00
parent a86013e552
commit 94f857a695
No known key found for this signature in database
GPG Key ID: 086DAA1360BEEE5C

View File

@ -137,13 +137,22 @@ export class VehiclePartRenderer {
let material; let material;
// Get alpha from mesh properties
// In the original game: alpha = 0 means opaque, alpha > 0 means transparent
const meshAlpha = mesh.properties?.alpha || 0;
const isTransparent = meshAlpha > 0;
const opacity = isTransparent ? meshAlpha : 1;
if (isColorable) { if (isColorable) {
// Mesh has INH prefix - use the LEGO color // Mesh has INH prefix - use the LEGO color
material = new THREE.MeshStandardMaterial({ material = new THREE.MeshStandardMaterial({
color: legoColor, color: legoColor,
side: THREE.DoubleSide, side: THREE.DoubleSide,
roughness: 0.7, roughness: 0.7,
metalness: 0.1 metalness: 0.1,
transparent: isTransparent,
opacity: opacity,
depthWrite: !isTransparent
}); });
this.colorableMeshes.push(null); // Placeholder, will set after mesh creation this.colorableMeshes.push(null); // Placeholder, will set after mesh creation
} else if (hasUVs && meshTextureName && this.textures.has(meshTextureName)) { } else if (hasUVs && meshTextureName && this.textures.has(meshTextureName)) {
@ -152,7 +161,10 @@ export class VehiclePartRenderer {
map: this.textures.get(meshTextureName), map: this.textures.get(meshTextureName),
side: THREE.DoubleSide, side: THREE.DoubleSide,
roughness: 0.8, roughness: 0.8,
metalness: 0.1 metalness: 0.1,
transparent: isTransparent,
opacity: opacity,
depthWrite: !isTransparent
}); });
} else { } else {
// Fallback to mesh's vertex color // Fallback to mesh's vertex color
@ -161,7 +173,10 @@ export class VehiclePartRenderer {
color: new THREE.Color(meshColor.r / 255, meshColor.g / 255, meshColor.b / 255), color: new THREE.Color(meshColor.r / 255, meshColor.g / 255, meshColor.b / 255),
side: THREE.DoubleSide, side: THREE.DoubleSide,
roughness: 0.8, roughness: 0.8,
metalness: 0.1 metalness: 0.1,
transparent: isTransparent,
opacity: opacity,
depthWrite: !isTransparent
}); });
} }