diff --git a/specs/data/box-mixed-attributes-2/box-mixed-attributes-2.mtl b/specs/data/box-mixed-attributes-2/box-mixed-attributes-2.mtl new file mode 100644 index 0000000..d81606d --- /dev/null +++ b/specs/data/box-mixed-attributes-2/box-mixed-attributes-2.mtl @@ -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 diff --git a/specs/data/box-mixed-attributes-2/box-mixed-attributes-2.obj b/specs/data/box-mixed-attributes-2/box-mixed-attributes-2.obj new file mode 100644 index 0000000..2762b61 --- /dev/null +++ b/specs/data/box-mixed-attributes-2/box-mixed-attributes-2.obj @@ -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 diff --git a/specs/data/box-mixed-attributes-2/cesium.png b/specs/data/box-mixed-attributes-2/cesium.png new file mode 100644 index 0000000..3b8baee Binary files /dev/null and b/specs/data/box-mixed-attributes-2/cesium.png differ diff --git a/specs/lib/createGltfSpec.js b/specs/lib/createGltfSpec.js index 87ea212..fd51b20 100644 --- a/specs/lib/createGltfSpec.js +++ b/specs/lib/createGltfSpec.js @@ -12,10 +12,12 @@ var WebGLConstants = Cesium.WebGLConstants; var boxObjUrl = 'specs/data/box/box.obj'; var groupObjUrl = 'specs/data/box-objects-groups-materials/box-objects-groups-materials.obj'; +var mixedAttributesObjUrl = 'specs/data/box-mixed-attributes-2/box-mixed-attributes-2.obj'; var diffuseTextureUrl = 'specs/data/box-textured/cesium.png'; var transparentDiffuseTextureUrl = 'specs/data/box-complex-material/diffuse.png'; var defaultOptions = obj2gltf.defaults; +var defined = Cesium.defined; var checkTransparencyOptions = clone(defaultOptions); checkTransparencyOptions.checkTransparency = true; @@ -23,6 +25,7 @@ describe('createGltf', function() { var boxObjData; var duplicateBoxObjData; var groupObjData; + var mixedAttributesObjData; var diffuseTexture; var transparentDiffuseTexture; @@ -47,7 +50,12 @@ describe('createGltf', function() { loadImage(transparentDiffuseTextureUrl, checkTransparencyOptions) .then(function(image) { transparentDiffuseTexture = image; + }), + loadObj(mixedAttributesObjUrl, defaultOptions) + .then(function(data) { + mixedAttributesObjData = data; }) + ]).then(done); }); @@ -309,6 +317,62 @@ describe('createGltf', function() { expect(attributes.TEXCOORD_0).toBeUndefined(); }); + function getDiffuse(material) { + return material.extensions.KHR_materials_common.values.diffuse; + } + + fit('splits incompatible materials', function() { + var gltf = createGltf(mixedAttributesObjData, defaultOptions); + var materials = gltf.materials; + var materialNames = Object.keys(materials).sort(); + + // Expect three copies of each material for + // * positions/normals/uvs + // * positions/normals + // * positions/uvs + expect(materialNames).toEqual([ + 'Material', + 'Material-2', + 'Material-3', + 'Missing', + 'Missing-2', + 'Missing-3', + 'default', + 'default-2', + 'default-3' + ]); + console.log(materials['Material']); + console.log(materials['Material-2']); + console.log(materials['Material-3']); + + + expect(getDiffuse(materials['Material'])).toBe('texture_cesium'); + expect(getDiffuse(materials['Material-2'])).toEqual('texture_cesium'); + //expect(getDiffuse(materials['Material-3'])).toBe('texture_cesium'); + // expect(getDiffuse(materials['Missing'])).toEqual([0.0, 0.0, 0.0, 1.0]); + // expect(getDiffuse(materials['Missing-2'])).toEqual([0.0, 0.0, 0.0, 1.0]); + // expect(getDiffuse(materials['Missing-3'])).toEqual([0.0, 0.0, 0.0, 1.0]); + // expect(getDiffuse(materials['default'])).toEqual([0.0, 0.0, 0.0, 1.0]); + // expect(getDiffuse(materials['default-2'])).toEqual([0.0, 0.0, 0.0, 1.0]); + // expect(getDiffuse(materials['default-3'])).toEqual([0.0, 0.0, 0.0, 1.0]); + + // // Test that primitives without uvs reference materials without textures + // for (var meshName in meshes) { + // if (meshes.hasOwnProperty(meshName)) { + // var mesh = meshes[meshName]; + // var primitives = mesh.primitives; + // var primitivesLength = primitives.length; + // for (var i = 0; i < primitivesLength; ++i) { + // var primitive = primitives[i]; + // var material = materials[primitive.material]; + // if (!defined(primitive.attributes.TEXCOORD_0)) { + // expect(material.extensions.KHR_materials_common.diffuse).toEqual([ 0.5, 0.5, 0.5, 1 ]); + // } + // } + // } + // } + }); + function expandObjData(objData, duplicatesLength) { var primitive = objData.nodes[0].meshes[0].primitives[0]; var indices = primitive.indices;