obj2gltf/specs/lib/loadMtlSpec.js

44 lines
2.3 KiB
JavaScript
Raw Normal View History

2017-03-13 15:28:51 -04:00
'use strict';
var path = require('path');
2017-04-12 16:55:03 -04:00
var loadMtl = require('../../lib/loadMtl');
2017-03-13 15:28:51 -04:00
var complexMaterialUrl = 'specs/data/box-complex-material/box-complex-material.mtl';
var multipleMaterialsUrl = 'specs/data/box-multiple-materials/box-multiple-materials.mtl';
function getImagePath(objPath, relativePath) {
2017-04-10 17:57:56 -04:00
return path.resolve(path.dirname(objPath), relativePath);
2017-03-13 15:28:51 -04:00
}
2017-04-19 15:48:07 -04:00
describe('loadMtl', function() {
2017-03-13 15:28:51 -04:00
it('loads complex material', function(done) {
expect(loadMtl(complexMaterialUrl)
.then(function(materials) {
var material = materials.Material;
expect(material).toBeDefined();
expect(material.ambientColor).toEqual([0.2, 0.2, 0.2, 1.0]);
expect(material.emissionColor).toEqual([0.1, 0.1, 0.1, 1.0]);
expect(material.diffuseColor).toEqual([0.64, 0.64, 0.64, 1.0]);
expect(material.specularColor).toEqual([0.5, 0.5, 0.5, 1.0]);
expect(material.specularShininess).toEqual(96.078431);
expect(material.alpha).toEqual(0.9);
2017-04-10 17:57:56 -04:00
expect(material.ambientTexture).toEqual(getImagePath(complexMaterialUrl, 'ambient.gif'));
expect(material.emissionTexture).toEqual(getImagePath(complexMaterialUrl, 'emission.jpg'));
expect(material.diffuseTexture).toEqual(getImagePath(complexMaterialUrl, 'diffuse.png'));
expect(material.specularTexture).toEqual(getImagePath(complexMaterialUrl, 'specular.jpeg'));
2017-03-13 15:28:51 -04:00
expect(material.specularShininessMap).toEqual(getImagePath(complexMaterialUrl, 'shininess.png'));
expect(material.normalMap).toEqual(getImagePath(complexMaterialUrl, 'bump.png'));
expect(material.alphaMap).toEqual(getImagePath(complexMaterialUrl, 'alpha.png'));
}), done).toResolve();
});
it('loads mtl with multiple materials', function(done) {
expect(loadMtl(multipleMaterialsUrl)
.then(function(materials) {
expect(Object.keys(materials).length).toBe(3);
expect(materials.Red.diffuseColor).toEqual([0.64, 0.0, 0.0, 1.0]);
expect(materials.Green.diffuseColor).toEqual([0.0, 0.64, 0.0, 1.0]);
expect(materials.Blue.diffuseColor).toEqual([0.0, 0.0, 0.64, 1.0]);
}), done).toResolve();
});
});