From b056b84ec69140c22f4c021a518002ae8e7ed541 Mon Sep 17 00:00:00 2001 From: Janusz Bossy Date: Tue, 7 Jul 2020 15:58:29 +0200 Subject: [PATCH] Fixes errors when `materialOverrides` is not passed to `loadMtl` --- lib/loadMtl.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/loadMtl.js b/lib/loadMtl.js index 77c72fb..5a9d829 100644 --- a/lib/loadMtl.js +++ b/lib/loadMtl.js @@ -48,6 +48,7 @@ function loadMtl(mtlPath, options) { const overridingDiffuseTexture = overridingTextures.baseColorTexture; const overridingEmissiveTexture = overridingTextures.emissiveTexture; const overridingAlphaTexture = overridingTextures.alphaTexture; + const materialOverrides = defined(options.materialOverrides) ? options.materialOverrides : {}; // Textures that are packed into PBR textures need to be decoded first const decodeOptions = { @@ -68,17 +69,17 @@ function loadMtl(mtlPath, options) { }; function createMaterial(name) { - const materialOverrides = options.materialOverrides[name] || {}; + const thisMaterialOverrides = defined(materialOverrides[name]) ? materialOverrides[name] : {}; material = new Material(); material.name = name; material.specularShininess = options.metallicRoughness ? 1.0 : 0.0; - material.specularTexture = materialOverrides.specularTexture || overridingSpecularTexture; - material.specularShininessTexture = materialOverrides.specularShininessTexture || overridingSpecularShininessTexture; - material.diffuseTexture = materialOverrides.diffuseTexture || overridingDiffuseTexture; - material.ambientTexture = materialOverrides.ambientTexture || overridingAmbientTexture; - material.normalTexture = materialOverrides.normalTexture || overridingNormalTexture; - material.emissiveTexture = materialOverrides.emissiveTexture || overridingEmissiveTexture; - material.alphaTexture = materialOverrides.alphaTexture || overridingAlphaTexture; + material.specularTexture = thisMaterialOverrides.specularTexture || overridingSpecularTexture; + material.specularShininessTexture = thisMaterialOverrides.specularShininessTexture || overridingSpecularShininessTexture; + material.diffuseTexture = thisMaterialOverrides.diffuseTexture || overridingDiffuseTexture; + material.ambientTexture = thisMaterialOverrides.ambientTexture || overridingAmbientTexture; + material.normalTexture = thisMaterialOverrides.normalTexture || overridingNormalTexture; + material.emissiveTexture = thisMaterialOverrides.emissiveTexture || overridingEmissiveTexture; + material.alphaTexture = thisMaterialOverrides.alphaTexture || overridingAlphaTexture; materials.push(material); }