mirror of
https://github.com/CesiumGS/obj2gltf.git
synced 2025-03-03 06:51:43 -05:00
Merge branch '1.0' into fixes-from-master
This commit is contained in:
commit
9280038371
@ -12,6 +12,7 @@ Change Log
|
|||||||
* Attempt to load missing materials and textures from within the same directory as the obj. [#163](https://github.com/AnalyticalGraphicsInc/obj2gltf/pull/163)
|
* Attempt to load missing materials and textures from within the same directory as the obj. [#163](https://github.com/AnalyticalGraphicsInc/obj2gltf/pull/163)
|
||||||
* Fixed handling of `usemtl` when appearing before an `o` or `g` token. [#163](https://github.com/AnalyticalGraphicsInc/obj2gltf/pull/163)
|
* Fixed handling of `usemtl` when appearing before an `o` or `g` token. [#163](https://github.com/AnalyticalGraphicsInc/obj2gltf/pull/163)
|
||||||
* Fixed handling of materials where the diffuse and ambient texture are the same. [#163](https://github.com/AnalyticalGraphicsInc/obj2gltf/pull/163)
|
* Fixed handling of materials where the diffuse and ambient texture are the same. [#163](https://github.com/AnalyticalGraphicsInc/obj2gltf/pull/163)
|
||||||
|
* Improved handling of materials with alpha. If the alpha value is 0.0 it is now treated as 1.0. [#164](https://github.com/AnalyticalGraphicsInc/obj2gltf/pull/164)
|
||||||
|
|
||||||
### 1.3.4 2018-10-16
|
### 1.3.4 2018-10-16
|
||||||
|
|
||||||
|
@ -63,10 +63,10 @@ function loadMtl(mtlPath) {
|
|||||||
material.specularShininess = parseFloat(value);
|
material.specularShininess = parseFloat(value);
|
||||||
} else if (/^d /i.test(line)) {
|
} else if (/^d /i.test(line)) {
|
||||||
value = line.substring(2).trim();
|
value = line.substring(2).trim();
|
||||||
material.alpha = parseFloat(value);
|
material.alpha = correctAlpha(parseFloat(value));
|
||||||
} else if (/^Tr /i.test(line)) {
|
} else if (/^Tr /i.test(line)) {
|
||||||
value = line.substring(3).trim();
|
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)) {
|
} else if (/^map_Ka /i.test(line)) {
|
||||||
material.ambientTexture = normalizeTexturePath(line.substring(7).trim(), mtlDirectory);
|
material.ambientTexture = normalizeTexturePath(line.substring(7).trim(), mtlDirectory);
|
||||||
} else if (/^map_Ke /i.test(line)) {
|
} else if (/^map_Ke /i.test(line)) {
|
||||||
@ -103,6 +103,11 @@ function cleanupMaterials(materials) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 normalizeTexturePath(texturePath, mtlDirectory) {
|
function normalizeTexturePath(texturePath, mtlDirectory) {
|
||||||
// Removes texture options from texture name
|
// Removes texture options from texture name
|
||||||
// Assumes no spaces in texture name
|
// Assumes no spaces in texture name
|
||||||
|
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
|
@ -6,6 +6,7 @@ var complexMaterialUrl = 'specs/data/box-complex-material/box-complex-material.m
|
|||||||
var diffuseAmbientSameMaterialUrl = 'specs/data/box-diffuse-ambient-same/box-diffuse-ambient-same.mtl';
|
var diffuseAmbientSameMaterialUrl = 'specs/data/box-diffuse-ambient-same/box-diffuse-ambient-same.mtl';
|
||||||
var multipleMaterialsUrl = 'specs/data/box-multiple-materials/box-multiple-materials.mtl';
|
var multipleMaterialsUrl = 'specs/data/box-multiple-materials/box-multiple-materials.mtl';
|
||||||
var texturedWithOptionsMaterialUrl = 'specs/data/box-texture-options/box-texture-options.mtl';
|
var texturedWithOptionsMaterialUrl = 'specs/data/box-texture-options/box-texture-options.mtl';
|
||||||
|
var transparentMaterialUrl = 'specs/data/box-transparent/box-transparent.mtl';
|
||||||
|
|
||||||
function getImagePath(objPath, relativePath) {
|
function getImagePath(objPath, relativePath) {
|
||||||
return path.normalize(path.join(path.dirname(objPath), relativePath));
|
return path.normalize(path.join(path.dirname(objPath), relativePath));
|
||||||
@ -74,4 +75,12 @@ describe('loadMtl', function() {
|
|||||||
expect(material.ambientTexture).toBeUndefined();
|
expect(material.ambientTexture).toBeUndefined();
|
||||||
}), done).toResolve();
|
}), done).toResolve();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('alpha of 0.0 is treated as 1.0', function(done) {
|
||||||
|
expect(loadMtl(transparentMaterialUrl)
|
||||||
|
.then(function(materials) {
|
||||||
|
var material = materials.Material;
|
||||||
|
expect(material.alpha).toBe(1.0);
|
||||||
|
}), done).toResolve();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user