mirror of
https://github.com/CesiumGS/obj2gltf.git
synced 2024-11-23 08:34:14 -05:00
Added test
This commit is contained in:
parent
9cc1ba8ec5
commit
1bca54c376
13
specs/data/box-mixed-attributes-2/box-mixed-attributes-2.mtl
Normal file
13
specs/data/box-mixed-attributes-2/box-mixed-attributes-2.mtl
Normal file
@ -0,0 +1,13 @@
|
||||
# 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
|
||||
map_Kd cesium.png
|
67
specs/data/box-mixed-attributes-2/box-mixed-attributes-2.obj
Normal file
67
specs/data/box-mixed-attributes-2/box-mixed-attributes-2.obj
Normal file
@ -0,0 +1,67 @@
|
||||
# Blender v2.78 (sub 0) OBJ File: ''
|
||||
# www.blender.org
|
||||
mtllib box-mixed-attributes-2.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
|
||||
# Using default material
|
||||
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 8/10 6/11 5/12
|
||||
f 5/13 6/14 2/15 1/16
|
||||
f 3//5 7//5 5//5 1//5
|
||||
f 8//6 4//6 2//6 6//6
|
||||
usemtl Material
|
||||
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 8/10 6/11 5/12
|
||||
f 5/13 6/14 2/15 1/16
|
||||
f 3//5 7//5 5//5 1//5
|
||||
f 8//6 4//6 2//6 6//6
|
||||
usemtl Missing
|
||||
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 8/10 6/11 5/12
|
||||
f 5/13 6/14 2/15 1/16
|
||||
f 3//5 7//5 5//5 1//5
|
||||
f 8//6 4//6 2//6 6//6
|
||||
o CubeCopy
|
||||
usemtl Material
|
||||
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 8/10 6/11 5/12
|
||||
f 5/13 6/14 2/15 1/16
|
||||
f 3//5 7//5 5//5 1//5
|
||||
f 8//6 4//6 2//6 6//6
|
BIN
specs/data/box-mixed-attributes-2/cesium.png
Normal file
BIN
specs/data/box-mixed-attributes-2/cesium.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 7.5 KiB |
@ -4,14 +4,17 @@ var Promise = require('bluebird');
|
||||
var obj2gltf = require('../../lib/obj2gltf');
|
||||
var createGltf = require('../../lib/createGltf');
|
||||
var loadObj = require('../../lib/loadObj');
|
||||
var getDefaultMaterial = require('../../lib/loadMtl').getDefaultMaterial;
|
||||
|
||||
var clone = Cesium.clone;
|
||||
var defined = Cesium.defined;
|
||||
var WebGLConstants = Cesium.WebGLConstants;
|
||||
|
||||
var boxObjPath = 'specs/data/box/box.obj';
|
||||
var groupObjPath = 'specs/data/box-objects-groups-materials/box-objects-groups-materials.obj';
|
||||
var complexObjPath = 'specs/data/box-complex-material/box-complex-material.obj';
|
||||
var noMaterialsObjPath = 'specs/data/box-no-materials/box-no-materials.obj';
|
||||
var mixedAttributesObjPath = 'specs/data/box-mixed-attributes-2/box-mixed-attributes-2.obj';
|
||||
|
||||
var options;
|
||||
|
||||
@ -20,6 +23,7 @@ describe('createGltf', function() {
|
||||
var groupObjData;
|
||||
var complexObjData;
|
||||
var noMaterialsObjData;
|
||||
var mixedAttributesObjData;
|
||||
|
||||
beforeEach(function(done) {
|
||||
options = clone(obj2gltf.defaults);
|
||||
@ -42,6 +46,10 @@ describe('createGltf', function() {
|
||||
loadObj(noMaterialsObjPath, options)
|
||||
.then(function(data) {
|
||||
noMaterialsObjData = data;
|
||||
}),
|
||||
loadObj(mixedAttributesObjPath, options)
|
||||
.then(function(data) {
|
||||
mixedAttributesObjData = data;
|
||||
})
|
||||
]).then(done);
|
||||
});
|
||||
@ -163,6 +171,74 @@ describe('createGltf', function() {
|
||||
expect(attributes.TEXCOORD_0).toBeUndefined();
|
||||
});
|
||||
|
||||
it('splits incompatible materials', function() {
|
||||
var gltf = createGltf(mixedAttributesObjData, options);
|
||||
var materials = gltf.materials;
|
||||
var meshes = gltf.meshes;
|
||||
var i;
|
||||
var material;
|
||||
|
||||
var referenceMaterial = mixedAttributesObjData.materials[0];
|
||||
delete referenceMaterial.name;
|
||||
referenceMaterial.pbrMetallicRoughness.baseColorTexture = {
|
||||
index : 0
|
||||
};
|
||||
|
||||
var referenceMaterialNoTextures = clone(referenceMaterial, true);
|
||||
referenceMaterialNoTextures.pbrMetallicRoughness.baseColorTexture = undefined;
|
||||
|
||||
var defaultMaterial = getDefaultMaterial(options);
|
||||
delete defaultMaterial.name;
|
||||
|
||||
var materialNames = materials.map(function(material) {
|
||||
var name = material.name;
|
||||
delete material.name;
|
||||
return name;
|
||||
});
|
||||
|
||||
// Expect three copies of each material for
|
||||
// * positions/normals/uvs
|
||||
// * positions/normals
|
||||
// * positions/uvs
|
||||
expect(materialNames).toEqual([
|
||||
'default',
|
||||
'default-2',
|
||||
'default-3',
|
||||
'Material',
|
||||
'Material-2',
|
||||
'Material-3',
|
||||
'Missing',
|
||||
'Missing-2',
|
||||
'Missing-3'
|
||||
]);
|
||||
|
||||
expect(materials.length).toBe(9);
|
||||
expect(materials[0]).toEqual(defaultMaterial);
|
||||
expect(materials[1]).toEqual(defaultMaterial);
|
||||
expect(materials[2]).toEqual(defaultMaterial);
|
||||
expect(materials[3]).toEqual(referenceMaterial);
|
||||
expect(materials[4]).toEqual(referenceMaterial);
|
||||
expect(materials[5]).toEqual(referenceMaterialNoTextures);
|
||||
expect(materials[6]).toEqual(defaultMaterial);
|
||||
expect(materials[7]).toEqual(defaultMaterial);
|
||||
expect(materials[8]).toEqual(defaultMaterial);
|
||||
|
||||
// Test that primitives without uvs reference materials without textures
|
||||
var meshesLength = meshes.length;
|
||||
for (i = 0; i < meshesLength; ++i) {
|
||||
var mesh = meshes[i];
|
||||
var primitives = mesh.primitives;
|
||||
var primitivesLength = primitives.length;
|
||||
for (var j = 0; j < primitivesLength; ++j) {
|
||||
var primitive = primitives[j];
|
||||
material = materials[primitive.material];
|
||||
if (!defined(primitive.attributes.TEXCOORD_0)) {
|
||||
expect(material.pbrMetallicRoughness.baseColorTexture).toBeUndefined();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
function expandObjData(objData, duplicatesLength) {
|
||||
var primitive = objData.nodes[0].meshes[0].primitives[0];
|
||||
var indices = primitive.indices;
|
||||
|
Loading…
Reference in New Issue
Block a user