Made alpha images work if same as diffuse

This commit is contained in:
Tom Fili 2019-07-19 14:52:12 -04:00
parent b0de7d1bc1
commit 0fa1ec528d
2 changed files with 30 additions and 9 deletions

View File

@ -388,6 +388,7 @@ function createDiffuseAlphaTexture(diffuseTexture, alphaTexture, options) {
}
if (diffuseTexture.path === alphaTexture.path) {
diffuseTexture.transparent = true;
return diffuseTexture;
}
@ -590,7 +591,7 @@ function createSpecularGlossinessMaterial(material, options) {
emissiveFactor = [1.0, 1.0, 1.0];
}
if (defined(diffuseTexture)) {
if (defined(diffuseAlphaTexture)) {
diffuseFactor = [1.0, 1.0, 1.0, 1.0];
}
@ -611,8 +612,8 @@ function createSpecularGlossinessMaterial(material, options) {
transparent = alpha < 1.0;
}
if (defined(diffuseTexture)) {
transparent = transparent || diffuseTexture.transparent;
if (defined(diffuseAlphaTexture)) {
transparent = transparent || diffuseAlphaTexture.transparent;
}
const doubleSided = transparent;
@ -662,7 +663,7 @@ function createMetallicRoughnessMaterial(material, options) {
emissiveFactor = [1.0, 1.0, 1.0];
}
if (defined(baseColorTexture)) {
if (defined(diffuseAlphaTexture)) {
baseColorFactor = [1.0, 1.0, 1.0, 1.0];
}
@ -683,8 +684,8 @@ function createMetallicRoughnessMaterial(material, options) {
transparent = alpha < 1.0;
}
if (defined(baseColorTexture)) {
transparent = transparent || baseColorTexture.transparent;
if (defined(diffuseAlphaTexture)) {
transparent = transparent || diffuseAlphaTexture.transparent;
}
const doubleSided = transparent;

View File

@ -322,16 +322,20 @@ describe('loadMtl', () => {
expect(material.doubleSided).toBe(true);
});
it('uses diffuse texture if diffuse and alpha are the same', () => {
it('uses diffuse texture if diffuse and alpha are the same', async () => {
options.metallicRoughness = true;
// The transparent property will be modified so make a copy
const diffuseTextureCopy = await loadTexture(diffuseTexturePath, decodeOptions);
const material = loadMtl._createMaterial({
diffuseTexture : diffuseTexture,
diffuseTexture : diffuseTextureCopy,
alphaTexture : diffuseTexture
}, options);
const pbr = material.pbrMetallicRoughness;
expect(pbr.baseColorTexture).toBe(diffuseTexture);
expect(pbr.baseColorTexture).toBe(diffuseTextureCopy);
expect(material.alphaMode).toBe('BLEND');
expect(material.doubleSided).toBe(true);
});
});
@ -428,5 +432,21 @@ describe('loadMtl', () => {
expect(material.alphaMode).toBe('BLEND');
expect(material.doubleSided).toBe(true);
});
it('uses diffuse texture if diffuse and alpha are the same', async () => {
options.specularGlossiness = true;
// The transparent property will be modified so make a copy
const diffuseTextureCopy = await loadTexture(diffuseTexturePath, decodeOptions);
const material = loadMtl._createMaterial({
diffuseTexture : diffuseTextureCopy,
alphaTexture : diffuseTexture
}, options);
const pbr = material.extensions.KHR_materials_pbrSpecularGlossiness;
expect(pbr.diffuseTexture).toEqual(diffuseTextureCopy);
expect(material.alphaMode).toBe('BLEND');
expect(material.doubleSided).toBe(true);
});
});
});