diff --git a/lib/loadMtl.js b/lib/loadMtl.js index c2cfb62..1beb037 100644 --- a/lib/loadMtl.js +++ b/lib/loadMtl.js @@ -165,6 +165,11 @@ function loadMtl(mtlPath, options) { } function loadMaterialTextures(material) { + if (material.diffuseTexture === material.ambientTexture) { + // OBJ models are often exported with the same texture in the diffuse and ambient slots but this is typically not desirable, particularly + // when saving with PBR materials where the ambient texture is treated as the occlusion texture. + material.ambientTexture = undefined; + } loadMaterialTexture(material, 'diffuseTexture', diffuseTextureOptions, mtlDirectory, texturePromiseMap, texturePromises, options); loadMaterialTexture(material, 'ambientTexture', ambientTextureOptions, mtlDirectory, texturePromiseMap, texturePromises, options); loadMaterialTexture(material, 'emissiveTexture', emissiveTextureOptions, mtlDirectory, texturePromiseMap, texturePromises, options); diff --git a/specs/data/box-diffuse-ambient-same/box-diffuse-ambient-same.mtl b/specs/data/box-diffuse-ambient-same/box-diffuse-ambient-same.mtl new file mode 100644 index 0000000..cb21081 --- /dev/null +++ b/specs/data/box-diffuse-ambient-same/box-diffuse-ambient-same.mtl @@ -0,0 +1,14 @@ +# Blender MTL File: 'box.blend' +# Material Count: 1 + +newmtl Material +Ns 96.078431 +Ka 0.000000 0.000000 0.000000 +Kd 0.640000 0.640000 0.640000 +Ks 0.500000 0.500000 0.500000 +Ke 0.000000 0.000000 0.000000 +Ni 1.000000 +d 1.000000 +illum 2 +map_Kd cesium.png +map_Ka cesium.png diff --git a/specs/data/box-diffuse-ambient-same/box-diffuse-ambient-same.obj b/specs/data/box-diffuse-ambient-same/box-diffuse-ambient-same.obj new file mode 100644 index 0000000..5d52f28 --- /dev/null +++ b/specs/data/box-diffuse-ambient-same/box-diffuse-ambient-same.obj @@ -0,0 +1,46 @@ +# Blender v2.78 (sub 0) OBJ File: 'box.blend' +# www.blender.org +mtllib box-diffuse-ambient-same.mtl +o Cube +v -1.000000 -1.000000 1.000000 +v -1.000000 1.000000 1.000000 +v -1.000000 -1.000000 -1.000000 +v -1.000000 1.000000 -1.000000 +v 1.000000 -1.000000 1.000000 +v 1.000000 1.000000 1.000000 +v 1.000000 -1.000000 -1.000000 +v 1.000000 1.000000 -1.000000 +vt 0.0000 0.0000 +vt 1.0000 0.0000 +vt 1.0000 1.0000 +vt 0.0000 1.0000 +vt 0.0000 0.0000 +vt 1.0000 0.0000 +vt 1.0000 1.0000 +vt 0.0000 1.0000 +vt 0.0000 0.0000 +vt 1.0000 0.0000 +vt 1.0000 1.0000 +vt 0.0000 1.0000 +vt 0.0000 0.0000 +vt 1.0000 0.0000 +vt 1.0000 1.0000 +vt 0.0000 1.0000 +vt 1.0000 0.0000 +vt 1.0000 1.0000 +vt 0.0000 0.0000 +vt 0.0000 1.0000 +vn -1.0000 0.0000 0.0000 +vn 0.0000 0.0000 -1.0000 +vn 1.0000 0.0000 0.0000 +vn 0.0000 0.0000 1.0000 +vn 0.0000 -1.0000 0.0000 +vn 0.0000 1.0000 0.0000 +usemtl Material +s off +f 1/1/1 2/2/1 4/3/1 3/4/1 +f 3/5/2 4/6/2 8/7/2 7/8/2 +f 7/9/3 8/10/3 6/11/3 5/12/3 +f 5/13/4 6/14/4 2/15/4 1/16/4 +f 3/5/5 7/17/5 5/18/5 1/16/5 +f 8/19/6 4/6/6 2/15/6 6/20/6 diff --git a/specs/data/box-diffuse-ambient-same/cesium.png b/specs/data/box-diffuse-ambient-same/cesium.png new file mode 100644 index 0000000..3b8baee Binary files /dev/null and b/specs/data/box-diffuse-ambient-same/cesium.png differ diff --git a/specs/lib/loadMtlSpec.js b/specs/lib/loadMtlSpec.js index f491e90..df70777 100644 --- a/specs/lib/loadMtlSpec.js +++ b/specs/lib/loadMtlSpec.js @@ -17,6 +17,7 @@ var externalMaterialPath = 'specs/data/box-external-resources/box-external-resou var resourcesInRootMaterialPath = 'specs/data/box-resources-in-root/box-resources-in-root.mtl'; var externalInRootMaterialPath = 'specs/data/box-external-resources-in-root/box-external-resources-in-root.mtl'; var transparentMaterialPath = 'specs/data/box-transparent/box-transparent.mtl'; +var diffuseAmbientSameMaterialPath = 'specs/data/box-diffuse-ambient-same/box-diffuse-ambient-same.mtl'; var diffuseTexturePath = 'specs/data/box-textured/cesium.png'; var transparentDiffuseTexturePath = 'specs/data/box-complex-material/diffuse.png'; @@ -251,6 +252,17 @@ describe('loadMtl', function() { }), done).toResolve(); }); + it('ambient texture is ignored if it is the same as the diffuse texture', function(done) { + expect(loadMtl(diffuseAmbientSameMaterialPath, options) + .then(function(materials) { + expect(materials.length).toBe(1); + var material = materials[0]; + var pbr = material.pbrMetallicRoughness; + expect(pbr.baseColorTexture).toBeDefined(); + expect(pbr.occlusionTexture).toBeUndefined(); + }), done).toResolve(); + }); + describe('metallicRoughness', function() { it('creates default material', function() { var material = loadMtl._createMaterial(undefined, options);