mirror of
https://github.com/CesiumGS/obj2gltf.git
synced 2024-11-23 08:34:14 -05:00
Merge pull request #127 from AnalyticalGraphicsInc/diffuse-ambient
Ignore ambient texture if it is the same as the diffuse texture
This commit is contained in:
commit
dc2196e937
@ -3,6 +3,7 @@ Change Log
|
||||
|
||||
### 2.2.0 ???
|
||||
|
||||
* Fixed handling of materials where the diffuse and ambient texture are the same. [#127](https://github.com/AnalyticalGraphicsInc/obj2gltf/pull/127)
|
||||
* Added ability to load alpha textures. [#124](https://github.com/AnalyticalGraphicsInc/obj2gltf/pull/124)
|
||||
* Fixed handling of `usemtl` when appearing before an `o` or `g` token. [#123](https://github.com/AnalyticalGraphicsInc/obj2gltf/pull/123)
|
||||
* Fixed output name when running from the command line. [#126](https://github.com/AnalyticalGraphicsInc/obj2gltf/pull/126)
|
||||
|
@ -177,6 +177,12 @@ function loadMtl(mtlPath, options) {
|
||||
// If an alpha texture is present the diffuse texture needs to be decoded so they can be packed together
|
||||
var diffuseAlphaTextureOptions = defined(material.alphaTexture) ? alphaTextureOptions : diffuseTextureOptions;
|
||||
|
||||
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', diffuseAlphaTextureOptions, mtlDirectory, texturePromiseMap, texturePromises, options);
|
||||
loadMaterialTexture(material, 'ambientTexture', ambientTextureOptions, mtlDirectory, texturePromiseMap, texturePromises, options);
|
||||
loadMaterialTexture(material, 'emissiveTexture', emissiveTextureOptions, mtlDirectory, texturePromiseMap, texturePromises, options);
|
||||
|
@ -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
|
@ -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
|
BIN
specs/data/box-diffuse-ambient-same/cesium.png
Normal file
BIN
specs/data/box-diffuse-ambient-same/cesium.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 7.5 KiB |
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user