mirror of
https://github.com/CesiumGS/obj2gltf.git
synced 2024-11-23 08:34:14 -05:00
Made alpha images work if same as diffuse
This commit is contained in:
parent
b0de7d1bc1
commit
0fa1ec528d
@ -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;
|
||||
|
@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user