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

View File

@ -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);
}