Fixes errors when `materialOverrides` is not passed to `loadMtl`

This commit is contained in:
Janusz Bossy 2020-07-07 15:58:29 +02:00
parent 4251c8491c
commit b056b84ec6
1 changed files with 9 additions and 8 deletions

View File

@ -48,6 +48,7 @@ function loadMtl(mtlPath, options) {
const overridingDiffuseTexture = overridingTextures.baseColorTexture; const overridingDiffuseTexture = overridingTextures.baseColorTexture;
const overridingEmissiveTexture = overridingTextures.emissiveTexture; const overridingEmissiveTexture = overridingTextures.emissiveTexture;
const overridingAlphaTexture = overridingTextures.alphaTexture; const overridingAlphaTexture = overridingTextures.alphaTexture;
const materialOverrides = defined(options.materialOverrides) ? options.materialOverrides : {};
// Textures that are packed into PBR textures need to be decoded first // Textures that are packed into PBR textures need to be decoded first
const decodeOptions = { const decodeOptions = {
@ -68,17 +69,17 @@ function loadMtl(mtlPath, options) {
}; };
function createMaterial(name) { function createMaterial(name) {
const materialOverrides = options.materialOverrides[name] || {}; const thisMaterialOverrides = defined(materialOverrides[name]) ? materialOverrides[name] : {};
material = new Material(); material = new Material();
material.name = name; material.name = name;
material.specularShininess = options.metallicRoughness ? 1.0 : 0.0; material.specularShininess = options.metallicRoughness ? 1.0 : 0.0;
material.specularTexture = materialOverrides.specularTexture || overridingSpecularTexture; material.specularTexture = thisMaterialOverrides.specularTexture || overridingSpecularTexture;
material.specularShininessTexture = materialOverrides.specularShininessTexture || overridingSpecularShininessTexture; material.specularShininessTexture = thisMaterialOverrides.specularShininessTexture || overridingSpecularShininessTexture;
material.diffuseTexture = materialOverrides.diffuseTexture || overridingDiffuseTexture; material.diffuseTexture = thisMaterialOverrides.diffuseTexture || overridingDiffuseTexture;
material.ambientTexture = materialOverrides.ambientTexture || overridingAmbientTexture; material.ambientTexture = thisMaterialOverrides.ambientTexture || overridingAmbientTexture;
material.normalTexture = materialOverrides.normalTexture || overridingNormalTexture; material.normalTexture = thisMaterialOverrides.normalTexture || overridingNormalTexture;
material.emissiveTexture = materialOverrides.emissiveTexture || overridingEmissiveTexture; material.emissiveTexture = thisMaterialOverrides.emissiveTexture || overridingEmissiveTexture;
material.alphaTexture = materialOverrides.alphaTexture || overridingAlphaTexture; material.alphaTexture = thisMaterialOverrides.alphaTexture || overridingAlphaTexture;
materials.push(material); materials.push(material);
} }