mirror of
https://github.com/CesiumGS/obj2gltf.git
synced 2024-11-27 02:24:04 -05:00
Merge pull request #205 from AnalyticalGraphicsInc/diffuse-alpha-same
Short circuits the image combining if diffuse and alpha textures are the same
This commit is contained in:
commit
64a12c70b3
@ -387,6 +387,10 @@ function createDiffuseAlphaTexture(diffuseTexture, alphaTexture, options) {
|
|||||||
return diffuseTexture;
|
return diffuseTexture;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (diffuseTexture.path === alphaTexture.path) {
|
||||||
|
return diffuseTexture;
|
||||||
|
}
|
||||||
|
|
||||||
if (!defined(diffuseTexture.pixels) || !defined(alphaTexture.pixels)) {
|
if (!defined(diffuseTexture.pixels) || !defined(alphaTexture.pixels)) {
|
||||||
options.logger('Could not get decoded texture data for ' + diffuseTexture.path + ' or ' + alphaTexture.path + '. The material will be created without an alpha texture.');
|
options.logger('Could not get decoded texture data for ' + diffuseTexture.path + ' or ' + alphaTexture.path + '. The material will be created without an alpha texture.');
|
||||||
return diffuseTexture;
|
return diffuseTexture;
|
||||||
@ -586,7 +590,7 @@ function createSpecularGlossinessMaterial(material, options) {
|
|||||||
emissiveFactor = [1.0, 1.0, 1.0];
|
emissiveFactor = [1.0, 1.0, 1.0];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (defined(diffuseTexture)) {
|
if (defined(diffuseAlphaTexture)) {
|
||||||
diffuseFactor = [1.0, 1.0, 1.0, 1.0];
|
diffuseFactor = [1.0, 1.0, 1.0, 1.0];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -607,8 +611,8 @@ function createSpecularGlossinessMaterial(material, options) {
|
|||||||
transparent = alpha < 1.0;
|
transparent = alpha < 1.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (defined(diffuseTexture)) {
|
if (defined(diffuseAlphaTexture)) {
|
||||||
transparent = transparent || diffuseTexture.transparent;
|
transparent = transparent || diffuseAlphaTexture.transparent;
|
||||||
}
|
}
|
||||||
|
|
||||||
const doubleSided = transparent;
|
const doubleSided = transparent;
|
||||||
@ -658,7 +662,7 @@ function createMetallicRoughnessMaterial(material, options) {
|
|||||||
emissiveFactor = [1.0, 1.0, 1.0];
|
emissiveFactor = [1.0, 1.0, 1.0];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (defined(baseColorTexture)) {
|
if (defined(diffuseAlphaTexture)) {
|
||||||
baseColorFactor = [1.0, 1.0, 1.0, 1.0];
|
baseColorFactor = [1.0, 1.0, 1.0, 1.0];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -679,8 +683,8 @@ function createMetallicRoughnessMaterial(material, options) {
|
|||||||
transparent = alpha < 1.0;
|
transparent = alpha < 1.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (defined(baseColorTexture)) {
|
if (defined(diffuseAlphaTexture)) {
|
||||||
transparent = transparent || baseColorTexture.transparent;
|
transparent = transparent || diffuseAlphaTexture.transparent;
|
||||||
}
|
}
|
||||||
|
|
||||||
const doubleSided = transparent;
|
const doubleSided = transparent;
|
||||||
|
@ -321,6 +321,22 @@ describe('loadMtl', () => {
|
|||||||
expect(material.alphaMode).toBe('BLEND');
|
expect(material.alphaMode).toBe('BLEND');
|
||||||
expect(material.doubleSided).toBe(true);
|
expect(material.doubleSided).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
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 : diffuseTextureCopy,
|
||||||
|
alphaTexture : diffuseTexture
|
||||||
|
}, options);
|
||||||
|
|
||||||
|
const pbr = material.pbrMetallicRoughness;
|
||||||
|
expect(pbr.baseColorTexture).toBe(diffuseTextureCopy);
|
||||||
|
expect(material.alphaMode).toBe('BLEND');
|
||||||
|
expect(material.doubleSided).toBe(true);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('specularGlossiness', () => {
|
describe('specularGlossiness', () => {
|
||||||
@ -416,5 +432,21 @@ describe('loadMtl', () => {
|
|||||||
expect(material.alphaMode).toBe('BLEND');
|
expect(material.alphaMode).toBe('BLEND');
|
||||||
expect(material.doubleSided).toBe(true);
|
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);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user