Updated tests

This commit is contained in:
Omar Shehata 2018-08-30 15:55:40 -04:00
parent e8fc8ab04e
commit 5ae3175907
3 changed files with 17 additions and 164 deletions

View File

@ -125,11 +125,11 @@ describe('createGltf', function() {
expect(gltf.extensionsRequired).toEqual(['KHR_materials_pbrSpecularGlossiness']); expect(gltf.extensionsRequired).toEqual(['KHR_materials_pbrSpecularGlossiness']);
}); });
it('adds KHR_materials_common extension when materialsCommon is set', function() { it('adds KHR_materials_unlit extension when unlit is set', function() {
options.materialsCommon = true; options.unlit = true;
var gltf = createGltf(noMaterialsObjData, options); var gltf = createGltf(noMaterialsObjData, options);
expect(gltf.extensionsUsed).toEqual(['KHR_materials_common']); expect(gltf.extensionsUsed).toEqual(['KHR_materials_unlit']);
expect(gltf.extensionsRequired).toEqual(['KHR_materials_common']); expect(gltf.extensionsRequired).toEqual(['KHR_materials_unlit']);
}); });
it('runs without normals', function() { it('runs without normals', function() {

View File

@ -468,164 +468,4 @@ describe('loadMtl', function() {
expect(material.doubleSided).toBe(true); expect(material.doubleSided).toBe(true);
}); });
}); });
describe('materialsCommon', function() {
it('creates default material', function() {
options.materialsCommon = true;
var material = loadMtl._createMaterial(undefined, options);
var extension = material.extensions.KHR_materials_common;
var values = extension.values;
expect(extension.technique).toBe('LAMBERT');
expect(extension.transparent).toBe(false);
expect(extension.doubleSided).toBe(false);
expect(values.ambient).toEqual([0.0, 0.0, 0.0, 1.0]);
expect(values.diffuse).toEqual([0.5, 0.5, 0.5, 1.0]);
expect(values.emission).toEqual([0.0, 0.0, 0.0, 1.0]);
expect(values.specular).toEqual([0.0, 0.0, 0.0, 1.0]);
expect(values.shininess).toEqual(0);
expect(values.transparency).toBe(1.0);
expect(values.transparent).toBe(false);
expect(values.doubleSided).toBe(false);
});
it('creates material with textures', function() {
options.materialsCommon = true;
var material = loadMtl._createMaterial({
diffuseTexture : diffuseTexture,
ambientTexture : ambientTexture,
normalTexture : normalTexture,
emissiveTexture : emissiveTexture,
specularTexture : specularTexture,
specularShininessTexture : specularShininessTexture
}, options);
var extension = material.extensions.KHR_materials_common;
var values = extension.values;
expect(extension.technique).toBe('LAMBERT');
expect(extension.transparent).toBe(false);
expect(extension.doubleSided).toBe(false);
expect(values.ambient instanceof Texture).toBe(true);
expect(values.diffuse instanceof Texture).toBe(true);
expect(values.emission instanceof Texture).toBe(true);
expect(values.specular instanceof Texture).toBe(true);
expect(values.shininess).toEqual(0);
expect(values.transparency).toBe(1.0);
expect(values.transparent).toBe(false);
expect(values.doubleSided).toBe(false);
});
it('sets material for alpha less than 1', function() {
options.materialsCommon = true;
var material = loadMtl._createMaterial({
alpha : 0.4
}, options);
var values = material.extensions.KHR_materials_common.values;
expect(values.diffuse).toEqual([0.5, 0.5, 0.5, 0.4]);
expect(values.transparency).toBe(1.0);
expect(values.transparent).toBe(true);
expect(values.doubleSided).toBe(true);
});
it('sets material for diffuse texture and alpha less than 1', function() {
options.materialsCommon = true;
var material = loadMtl._createMaterial({
diffuseTexture : diffuseTexture,
alpha : 0.4
}, options);
var values = material.extensions.KHR_materials_common.values;
expect(values.diffuse instanceof Texture).toBe(true);
expect(values.transparency).toBe(0.4);
expect(values.transparent).toBe(true);
expect(values.doubleSided).toBe(true);
});
it('sets material for transparent diffuse texture', function() {
options.materialsCommon = true;
var material = loadMtl._createMaterial({
diffuseTexture : transparentDiffuseTexture
}, options);
var values = material.extensions.KHR_materials_common.values;
expect(values.diffuse instanceof Texture).toBe(true);
expect(values.transparency).toBe(1.0);
expect(values.transparent).toBe(true);
expect(values.doubleSided).toBe(true);
});
it('sets material for specular', function() {
options.materialsCommon = true;
var material = loadMtl._createMaterial({
specularColor : [0.1, 0.1, 0.2, 1],
specularShininess : 0.1
}, options);
var extension = material.extensions.KHR_materials_common;
var values = extension.values;
expect(extension.technique).toBe('PHONG');
expect(values.specular).toEqual([0.1, 0.1, 0.2, 1]);
expect(values.shininess).toEqual(0.1);
});
it('sets CONSTANT technique when there are no normals', function() {
options.materialsCommon = true;
options.hasNormals = false;
var material = loadMtl._createMaterial({
diffuseColor : [1.0, 1.0, 1.0, 1.0]
}, options);
var extension = material.extensions.KHR_materials_common;
var values = extension.values;
expect(extension.technique).toBe('CONSTANT');
expect(values.emission).toEqual(values.diffuse);
});
it('ambient of [1, 1, 1] is treated as [0, 0, 0]', function() {
options.materialsCommon = true;
var material = loadMtl._createMaterial({
ambientColor : [1.0, 1.0, 1.0, 1.0]
}, options);
var values = material.extensions.KHR_materials_common.values;
expect(values.ambient).toEqual([0.0, 0.0, 0.0, 1.0]);
});
it('packs alpha texture in diffuse texture', function() {
options.materialsCommon = true;
var material = loadMtl._createMaterial({
diffuseTexture : diffuseTexture,
alphaTexture : alphaTexture
}, options);
var values = material.extensions.KHR_materials_common.values;
var hasBlack = false;
var hasWhite = false;
var pixels = values.diffuse.pixels;
var pixelsLength = pixels.length / 4;
for (var i = 0; i < pixelsLength; ++i) {
var alpha = pixels[i * 4 + 3];
hasBlack = hasBlack || (alpha === 0);
hasWhite = hasWhite || (alpha === 255);
}
expect(hasBlack).toBe(true);
expect(hasWhite).toBe(true);
expect(values.transparency).toBe(1.0);
expect(values.transparent).toBe(true);
expect(values.doubleSided).toBe(true);
});
});
}); });

View File

@ -184,4 +184,17 @@ describe('obj2gltf', function() {
obj2gltf(texturedObjPath, options); obj2gltf(texturedObjPath, options);
}).toThrowDeveloperError(); }).toThrowDeveloperError();
}); });
it('adds KHR_materials_unlit to materials if unlit is set', function(done) {
var options = {
unlit : true
};
expect(obj2gltf(texturedObjPath, options)
.then(function(glb) {
for(var i = 0;i < glb.materials.length; i++) {
var material = glb.materials[i];
expect(material.extensions.KHR_materials_unlit).toBeDefined();
}
}), done).toResolve();
});
}); });