mirror of
https://github.com/CesiumGS/obj2gltf.git
synced 2025-02-06 23:13:02 -05:00
Merge pull request #107 from AnalyticalGraphicsInc/alpha-0
Treat alpha of 0 as 1
This commit is contained in:
commit
3934450b56
@ -1,6 +1,10 @@
|
||||
Change Log
|
||||
==========
|
||||
|
||||
### 2.1.0 ???
|
||||
|
||||
* Improved handling of materials with alpha. If the alpha value is 0.0 it is now treated as 1.0. [#107](https://github.com/AnalyticalGraphicsInc/obj2gltf/pull/107)
|
||||
|
||||
### 2.0.0 2017-08-11
|
||||
|
||||
* Breaking changes
|
||||
|
@ -118,10 +118,10 @@ function loadMtl(mtlPath, options) {
|
||||
material.specularShininess = parseFloat(value);
|
||||
} else if (/^d /i.test(line)) {
|
||||
value = line.substring(2).trim();
|
||||
material.alpha = parseFloat(value);
|
||||
material.alpha = correctAlpha(parseFloat(value));
|
||||
} else if (/^Tr /i.test(line)) {
|
||||
value = line.substring(3).trim();
|
||||
material.alpha = 1.0 - parseFloat(value);
|
||||
material.alpha = correctAlpha(1.0 - parseFloat(value));
|
||||
} else if (/^map_Ka /i.test(line)) {
|
||||
if (!defined(overridingAmbientTexture)) {
|
||||
texturePath = path.resolve(mtlDirectory, line.substring(7).trim());
|
||||
@ -164,6 +164,11 @@ function loadMtl(mtlPath, options) {
|
||||
});
|
||||
}
|
||||
|
||||
function correctAlpha(alpha) {
|
||||
// An alpha of 0.0 usually implies a problem in the export, change to 1.0 instead
|
||||
return alpha === 0.0 ? 1.0 : alpha;
|
||||
}
|
||||
|
||||
function Material() {
|
||||
this.name = undefined;
|
||||
this.ambientColor = [0.0, 0.0, 0.0, 1.0]; // Ka
|
||||
|
12
specs/data/box-transparent/box-transparent.mtl
Normal file
12
specs/data/box-transparent/box-transparent.mtl
Normal file
@ -0,0 +1,12 @@
|
||||
# Blender MTL File: 'None'
|
||||
# Material Count: 1
|
||||
|
||||
newmtl Material
|
||||
Ns 96.078431
|
||||
Ka 0.100000 0.000000 0.000000
|
||||
Kd 0.640000 0.640000 0.640000
|
||||
Ks 0.500000 0.500000 0.500000
|
||||
Ke 0.000000 0.000000 0.100000
|
||||
Ni 1.000000
|
||||
d 0.000000
|
||||
illum 2
|
46
specs/data/box-transparent/box-transparent.obj
Normal file
46
specs/data/box-transparent/box-transparent.obj
Normal file
@ -0,0 +1,46 @@
|
||||
# Blender v2.78 (sub 0) OBJ File: ''
|
||||
# www.blender.org
|
||||
mtllib box-transparent.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
|
@ -13,6 +13,7 @@ var coloredMaterialPath = 'specs/data/box/box.mtl';
|
||||
var texturedMaterialPath = 'specs/data/box-complex-material/box-complex-material.mtl';
|
||||
var multipleMaterialsPath = 'specs/data/box-multiple-materials/box-multiple-materials.mtl';
|
||||
var externalMaterialPath = 'specs/data/box-external-resources/box-external-resources.mtl';
|
||||
var transparentMaterialPath = 'specs/data/box-transparent/box-transparent.mtl';
|
||||
|
||||
var diffuseTexturePath = 'specs/data/box-textured/cesium.png';
|
||||
var transparentDiffuseTexturePath = 'specs/data/box-complex-material/diffuse.png';
|
||||
@ -186,6 +187,20 @@ describe('loadMtl', function() {
|
||||
}), done).toResolve();
|
||||
});
|
||||
|
||||
it('alpha of 0.0 is treated as 1.0', function(done) {
|
||||
expect(loadMtl(transparentMaterialPath, options)
|
||||
.then(function(materials) {
|
||||
expect(materials.length).toBe(1);
|
||||
var material = materials[0];
|
||||
var pbr = material.pbrMetallicRoughness;
|
||||
expect(pbr.baseColorTexture).toBeUndefined();
|
||||
expect(pbr.metallicRoughnessTexture).toBeUndefined();
|
||||
expect(pbr.baseColorFactor[3]).toEqual(1.0);
|
||||
expect(material.alphaMode).toBe('OPAQUE');
|
||||
expect(material.doubleSided).toBe(false);
|
||||
}), done).toResolve();
|
||||
});
|
||||
|
||||
describe('metallicRoughness', function() {
|
||||
it('creates default material', function() {
|
||||
var material = loadMtl._createMaterial(undefined, options);
|
||||
|
Loading…
x
Reference in New Issue
Block a user