mirror of
https://github.com/CesiumGS/obj2gltf.git
synced 2025-03-01 22:13:49 -05:00
parent
d42e2548c8
commit
99806cc4a7
@ -5,6 +5,9 @@ Change Log
|
||||
* Improved handling of primitives with different attributes using the same material. Materials are now duplicated. [#163](https://github.com/AnalyticalGraphicsInc/obj2gltf/pull/163)
|
||||
* Fixed a bug where primitives without texture coordinates could use materials containing textures. Those textures are now removed. [#163](https://github.com/AnalyticalGraphicsInc/obj2gltf/pull/163)
|
||||
* Improved parsing of faces with mismatching attributes. [#163](https://github.com/AnalyticalGraphicsInc/obj2gltf/pull/163)
|
||||
* Fixed handling of unnormalized input normals. [#163](https://github.com/AnalyticalGraphicsInc/obj2gltf/pull/163)
|
||||
* Added ability to use the first material in the mtl file when the obj is missing `usemtl`. [#163](https://github.com/AnalyticalGraphicsInc/obj2gltf/pull/163)
|
||||
* Fixed loading faces that contain less than 3 vertices. [#163](https://github.com/AnalyticalGraphicsInc/obj2gltf/pull/163)
|
||||
|
||||
### 1.3.4 2018-10-16
|
||||
|
||||
|
@ -426,7 +426,7 @@ function finishLoading(nodes, mtlPaths, objPath, usesMaterials, options) {
|
||||
}
|
||||
return loadMaterials(mtlPaths, objPath, options)
|
||||
.then(function(materials) {
|
||||
if (materials.length > 0 && !usesMaterials) {
|
||||
if (Object.keys(materials).length > 0 && !usesMaterials) {
|
||||
assignDefaultMaterial(nodes, materials, usesMaterials);
|
||||
}
|
||||
var imagePaths = getImagePaths(materials);
|
||||
@ -455,6 +455,12 @@ function loadMaterials(mtlPaths, objPath, options) {
|
||||
var logger = options.logger;
|
||||
var objDirectory = path.dirname(objPath);
|
||||
var materials = {};
|
||||
|
||||
// Remove duplicates
|
||||
mtlPaths = mtlPaths.filter(function(value, index, self) {
|
||||
return self.indexOf(value) === index;
|
||||
});
|
||||
|
||||
return Promise.map(mtlPaths, function(mtlPath) {
|
||||
mtlPath = normalizeMtlPath(mtlPath, objDirectory);
|
||||
if (secure && outsideDirectory(mtlPath, objPath)) {
|
||||
@ -515,7 +521,7 @@ function getImagePaths(materials) {
|
||||
}
|
||||
|
||||
function assignDefaultMaterial(nodes, materials) {
|
||||
var defaultMaterial = materials[0].name;
|
||||
var defaultMaterial = Object.keys(materials)[0];
|
||||
var nodesLength = nodes.length;
|
||||
for (var i = 0; i < nodesLength; ++i) {
|
||||
var meshes = nodes[i].meshes;
|
||||
|
12
specs/data/box-missing-usemtl/box-missing-usemtl.mtl
Normal file
12
specs/data/box-missing-usemtl/box-missing-usemtl.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 1.000000
|
||||
illum 2
|
45
specs/data/box-missing-usemtl/box-missing-usemtl.obj
Normal file
45
specs/data/box-missing-usemtl/box-missing-usemtl.obj
Normal file
@ -0,0 +1,45 @@
|
||||
# Blender v2.78 (sub 0) OBJ File: ''
|
||||
# www.blender.org
|
||||
mtllib box-missing-usemtl.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
|
||||
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
|
12
specs/data/box-unnormalized/box-unnormalized.mtl
Normal file
12
specs/data/box-unnormalized/box-unnormalized.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 1.000000
|
||||
illum 2
|
46
specs/data/box-unnormalized/box-unnormalized.obj
Normal file
46
specs/data/box-unnormalized/box-unnormalized.obj
Normal file
@ -0,0 +1,46 @@
|
||||
# Blender v2.78 (sub 0) OBJ File: ''
|
||||
# www.blender.org
|
||||
mtllib box-unnormalized.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 0.0000 0.0000 0.0000
|
||||
vn 0.0000 0.0000 0.5
|
||||
vn 1.0000 0.1000 0.0000
|
||||
vn 0.0000 0.0000 -0.9
|
||||
vn 0.0000 1.0000 0.0000
|
||||
vn 10.0000 -10.0000 5.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
|
@ -7,6 +7,7 @@ var obj2gltf = require('../../lib/obj2gltf');
|
||||
|
||||
var Cartesian3 = Cesium.Cartesian3;
|
||||
var clone = Cesium.clone;
|
||||
var CesiumMath = Cesium.Math;
|
||||
var RuntimeError = Cesium.RuntimeError;
|
||||
|
||||
var objUrl = 'specs/data/box/box.obj';
|
||||
@ -20,12 +21,14 @@ var objObjectsUrl = 'specs/data/box-objects/box-objects.obj';
|
||||
var objGroupsUrl = 'specs/data/box-groups/box-groups.obj';
|
||||
var objObjectsGroupsUrl = 'specs/data/box-objects-groups/box-objects-groups.obj';
|
||||
var objConcaveUrl = 'specs/data/concave/concave.obj';
|
||||
var objUnnormalizedUrl = 'specs/data/box-unnormalized/box-unnormalized.obj';
|
||||
var objUsemtlUrl = 'specs/data/box-usemtl/box-usemtl.obj';
|
||||
var objNoMaterialsUrl = 'specs/data/box-no-materials/box-no-materials.obj';
|
||||
var objMultipleMaterialsUrl = 'specs/data/box-multiple-materials/box-multiple-materials.obj';
|
||||
var objUncleanedUrl = 'specs/data/box-uncleaned/box-uncleaned.obj';
|
||||
var objMtllibUrl = 'specs/data/box-mtllib/box-mtllib.obj';
|
||||
var objMissingMtllibUrl = 'specs/data/box-missing-mtllib/box-missing-mtllib.obj';
|
||||
var objMissingUsemtlUrl = 'specs/data/box-missing-usemtl/box-missing-usemtl.obj';
|
||||
var objExternalResourcesUrl = 'specs/data/box-external-resources/box-external-resources.obj';
|
||||
var objTexturedUrl = 'specs/data/box-textured/box-textured.obj';
|
||||
var objMissingTextureUrl = 'specs/data/box-missing-texture/box-missing-texture.obj';
|
||||
@ -110,6 +113,23 @@ describe('loadObj', function() {
|
||||
}), done).toResolve();
|
||||
});
|
||||
|
||||
it('normalizes normals', function(done) {
|
||||
expect(loadObj(objUnnormalizedUrl, defaultOptions)
|
||||
.then(function(data) {
|
||||
var scratchNormal = new Cesium.Cartesian3();
|
||||
var mesh = getMeshes(data)[0];
|
||||
var normals = mesh.normals;
|
||||
var normalsLength = normals.length / 3;
|
||||
for (var i = 0; i < normalsLength; ++i) {
|
||||
var normalX = normals.get(i * 3);
|
||||
var normalY = normals.get(i * 3 + 1);
|
||||
var normalZ = normals.get(i * 3 + 2);
|
||||
var normal = Cartesian3.fromElements(normalX, normalY, normalZ, scratchNormal);
|
||||
expect(Cartesian3.magnitude(normal)).toEqualEpsilon(1.0, CesiumMath.EPSILON5);
|
||||
}
|
||||
}), done).toResolve();
|
||||
});
|
||||
|
||||
it('loads obj with uvs', function(done) {
|
||||
expect(loadObj(objUvsUrl, defaultOptions)
|
||||
.then(function(data) {
|
||||
@ -301,6 +321,14 @@ describe('loadObj', function() {
|
||||
}), done).toResolve();
|
||||
});
|
||||
|
||||
it('loads obj with missing usemtl', function(done) {
|
||||
expect(loadObj(objMissingUsemtlUrl, defaultOptions)
|
||||
.then(function(data) {
|
||||
expect(data.materials.length).toBe(1);
|
||||
expect(data.nodes[0].meshes[0].primitives[0].material).toBe('Material');
|
||||
}), done).toResolve();
|
||||
});
|
||||
|
||||
it('loads resources outside of the obj directory', function(done) {
|
||||
expect(loadObj(objExternalResourcesUrl, defaultOptions)
|
||||
.then(function(data) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user