mirror of
https://github.com/CesiumGS/obj2gltf.git
synced 2025-03-03 06:51:43 -05:00
Port over #127
This commit is contained in:
parent
9fc526b692
commit
ade20d8c1d
@ -11,6 +11,7 @@ Change Log
|
|||||||
* Fixed loading mtllib paths that contain spaces. [#163](https://github.com/AnalyticalGraphicsInc/obj2gltf/pull/163)
|
* Fixed loading mtllib paths that contain spaces. [#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)
|
* 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)
|
||||||
|
|
||||||
### 1.3.4 2018-10-16
|
### 1.3.4 2018-10-16
|
||||||
|
|
||||||
|
@ -86,10 +86,23 @@ function loadMtl(mtlPath) {
|
|||||||
|
|
||||||
return readLines(mtlPath, parseLine)
|
return readLines(mtlPath, parseLine)
|
||||||
.then(function() {
|
.then(function() {
|
||||||
|
cleanupMaterials(materials);
|
||||||
return materials;
|
return materials;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function cleanupMaterials(materials) {
|
||||||
|
for (var name in materials) {
|
||||||
|
if (materials.hasOwnProperty(name)) {
|
||||||
|
var material = materials[name];
|
||||||
|
if (material.diffuseTexture === material.ambientTexture) {
|
||||||
|
// OBJ models are often exported with the same texture in the diffuse and ambient slots but this is usually not desirable
|
||||||
|
material.ambientTexture = undefined;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
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
|
||||||
|
@ -0,0 +1,14 @@
|
|||||||
|
# Blender MTL File: 'box.blend'
|
||||||
|
# Material Count: 1
|
||||||
|
|
||||||
|
newmtl Material
|
||||||
|
Ns 96.078431
|
||||||
|
Ka 0.000000 0.000000 0.000000
|
||||||
|
Kd 0.640000 0.640000 0.640000
|
||||||
|
Ks 0.500000 0.500000 0.500000
|
||||||
|
Ke 0.000000 0.000000 0.000000
|
||||||
|
Ni 1.000000
|
||||||
|
d 1.000000
|
||||||
|
illum 2
|
||||||
|
map_Kd cesium.png
|
||||||
|
map_Ka cesium.png
|
@ -0,0 +1,46 @@
|
|||||||
|
# Blender v2.78 (sub 0) OBJ File: 'box.blend'
|
||||||
|
# www.blender.org
|
||||||
|
mtllib box-diffuse-ambient-same.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
|
BIN
specs/data/box-diffuse-ambient-same/cesium.png
Normal file
BIN
specs/data/box-diffuse-ambient-same/cesium.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 7.5 KiB |
@ -3,6 +3,7 @@ var path = require('path');
|
|||||||
var loadMtl = require('../../lib/loadMtl');
|
var loadMtl = require('../../lib/loadMtl');
|
||||||
|
|
||||||
var complexMaterialUrl = 'specs/data/box-complex-material/box-complex-material.mtl';
|
var complexMaterialUrl = 'specs/data/box-complex-material/box-complex-material.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';
|
||||||
|
|
||||||
@ -63,4 +64,14 @@ describe('loadMtl', function() {
|
|||||||
expect(material.doubleSided).toBe(true);
|
expect(material.doubleSided).toBe(true);
|
||||||
}), done).toResolve();
|
}), done).toResolve();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('ambient texture is ignored if it is the same as the diffuse texture', function(done) {
|
||||||
|
expect(loadMtl(diffuseAmbientSameMaterialUrl, options)
|
||||||
|
.then(function(materials) {
|
||||||
|
expect(Object.keys(materials).length).toBe(1);
|
||||||
|
var material = materials['Material'];
|
||||||
|
expect(material.diffuseTexture).toBeDefined();
|
||||||
|
expect(material.ambientTexture).toBeUndefined();
|
||||||
|
}), done).toResolve();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user