2017-03-13 15:28:51 -04:00
'use strict' ;
2017-07-29 13:23:33 -04:00
var Cesium = require ( 'cesium' ) ;
var Promise = require ( 'bluebird' ) ;
var fsExtra = require ( 'fs-extra' ) ;
2017-04-12 16:55:03 -04:00
var loadMtl = require ( '../../lib/loadMtl' ) ;
2017-07-29 13:23:33 -04:00
var loadTexture = require ( '../../lib/loadTexture' ) ;
2017-05-04 17:58:13 -04:00
var obj2gltf = require ( '../../lib/obj2gltf' ) ;
2017-07-29 13:23:33 -04:00
var Texture = require ( '../../lib/Texture' ) ;
2017-03-13 15:28:51 -04:00
2017-07-29 13:23:33 -04:00
var clone = Cesium . clone ;
2017-03-13 15:28:51 -04:00
2017-07-29 13:23:33 -04:00
var coloredMaterialPath = 'specs/data/box/box.mtl' ;
var texturedMaterialPath = 'specs/data/box-complex-material/box-complex-material.mtl' ;
2017-10-10 13:23:09 +02:00
var texturedWithOptionsMaterialPath = 'specs/data/box-texture-options/box-texture-options.mtl' ;
2017-07-29 13:23:33 -04:00
var multipleMaterialsPath = 'specs/data/box-multiple-materials/box-multiple-materials.mtl' ;
var externalMaterialPath = 'specs/data/box-external-resources/box-external-resources.mtl' ;
2017-11-29 14:21:59 -05:00
var resourcesInRootMaterialPath = 'specs/data/box-resources-in-root/box-resources-in-root.mtl' ;
var externalInRootMaterialPath = 'specs/data/box-external-resources-in-root/box-external-resources-in-root.mtl' ;
2017-09-19 13:09:58 -04:00
var transparentMaterialPath = 'specs/data/box-transparent/box-transparent.mtl' ;
2017-03-13 15:28:51 -04:00
2017-07-29 13:23:33 -04:00
var diffuseTexturePath = 'specs/data/box-textured/cesium.png' ;
var transparentDiffuseTexturePath = 'specs/data/box-complex-material/diffuse.png' ;
var alphaTexturePath = 'specs/data/box-complex-material/alpha.png' ;
var ambientTexturePath = 'specs/data/box-complex-material/ambient.gif' ;
var normalTexturePath = 'specs/data/box-complex-material/bump.png' ;
var emissiveTexturePath = 'specs/data/box-complex-material/emission.jpg' ;
var specularTexturePath = 'specs/data/box-complex-material/specular.jpeg' ;
var specularShininessTexturePath = 'specs/data/box-complex-material/shininess.png' ;
var diffuseTexture ;
var transparentDiffuseTexture ;
var alphaTexture ;
var ambientTexture ;
var normalTexture ;
var emissiveTexture ;
var specularTexture ;
var specularShininessTexture ;
var checkTransparencyOptions = {
checkTransparency : true
} ;
var decodeOptions = {
decode : true
} ;
var options ;
2017-05-04 17:58:13 -04:00
2017-04-18 11:56:08 -04:00
describe ( 'loadMtl' , function ( ) {
2017-07-29 13:23:33 -04:00
beforeAll ( function ( done ) {
return Promise . all ( [
loadTexture ( diffuseTexturePath )
. then ( function ( texture ) {
diffuseTexture = texture ;
} ) ,
loadTexture ( transparentDiffuseTexturePath , checkTransparencyOptions )
. then ( function ( texture ) {
transparentDiffuseTexture = texture ;
} ) ,
loadTexture ( alphaTexturePath , decodeOptions )
. then ( function ( texture ) {
alphaTexture = texture ;
} ) ,
loadTexture ( ambientTexturePath )
. then ( function ( texture ) {
ambientTexture = texture ;
} ) ,
loadTexture ( normalTexturePath )
. then ( function ( texture ) {
normalTexture = texture ;
} ) ,
loadTexture ( emissiveTexturePath )
. then ( function ( texture ) {
emissiveTexture = texture ;
} ) ,
loadTexture ( specularTexturePath , decodeOptions )
. then ( function ( texture ) {
specularTexture = texture ;
} ) ,
loadTexture ( specularShininessTexturePath , decodeOptions )
. then ( function ( texture ) {
specularShininessTexture = texture ;
} )
] ) . then ( done ) ;
} ) ;
beforeEach ( function ( ) {
options = clone ( obj2gltf . defaults ) ;
options . overridingTextures = { } ;
options . logger = function ( ) { } ;
2017-09-21 10:37:50 -04:00
options . hasNormals = true ;
2017-07-29 13:23:33 -04:00
} ) ;
it ( 'loads mtl' , function ( done ) {
options . metallicRoughness = true ;
expect ( loadMtl ( coloredMaterialPath , options )
2017-03-13 15:28:51 -04:00
. then ( function ( materials ) {
2017-07-29 13:23:33 -04:00
expect ( materials . length ) . toBe ( 1 ) ;
2017-05-04 17:58:13 -04:00
var material = materials [ 0 ] ;
2017-07-29 13:23:33 -04:00
var pbr = material . pbrMetallicRoughness ;
expect ( pbr . baseColorTexture ) . toBeUndefined ( ) ;
expect ( pbr . metallicRoughnessTexture ) . toBeUndefined ( ) ;
expect ( pbr . baseColorFactor ) . toEqual ( [ 0.64 , 0.64 , 0.64 , 1.0 ] ) ;
expect ( pbr . metallicFactor ) . toBe ( 0.5 ) ;
expect ( pbr . roughnessFactor ) . toBe ( 96.078431 ) ;
2017-05-04 17:58:13 -04:00
expect ( material . name ) . toBe ( 'Material' ) ;
2017-07-29 13:23:33 -04:00
expect ( material . emissiveTexture ) . toBeUndefined ( ) ;
expect ( material . normalTexture ) . toBeUndefined ( ) ;
expect ( material . ambientTexture ) . toBeUndefined ( ) ;
expect ( material . emissiveFactor ) . toEqual ( [ 0.0 , 0.0 , 0.1 ] ) ;
expect ( material . alphaMode ) . toBe ( 'OPAQUE' ) ;
expect ( material . doubleSided ) . toBe ( false ) ;
} ) , done ) . toResolve ( ) ;
} ) ;
it ( 'loads mtl with textures' , function ( done ) {
options . metallicRoughness = true ;
expect ( loadMtl ( texturedMaterialPath , options )
. then ( function ( materials ) {
expect ( materials . length ) . toBe ( 1 ) ;
var material = materials [ 0 ] ;
var pbr = material . pbrMetallicRoughness ;
expect ( pbr . baseColorTexture ) . toBeDefined ( ) ;
expect ( pbr . metallicRoughnessTexture ) . toBeDefined ( ) ;
expect ( pbr . baseColorFactor ) . toEqual ( [ 1.0 , 1.0 , 1.0 , 0.9 ] ) ;
expect ( pbr . metallicFactor ) . toBe ( 1.0 ) ;
expect ( pbr . roughnessFactor ) . toBe ( 1.0 ) ;
expect ( material . name ) . toBe ( 'Material' ) ;
2017-10-10 13:23:09 +02:00
expect ( material . emissiveTexture ) . toBeDefined ( ) ;
expect ( material . normalTexture ) . toBeDefined ( ) ;
expect ( material . occlusionTexture ) . toBeDefined ( ) ;
expect ( material . emissiveFactor ) . toEqual ( [ 1.0 , 1.0 , 1.0 ] ) ;
expect ( material . alphaMode ) . toBe ( 'BLEND' ) ;
expect ( material . doubleSided ) . toBe ( true ) ;
} ) , done ) . toResolve ( ) ;
} ) ;
it ( 'loads mtl with textures having options' , function ( done ) {
options . metallicRoughness = true ;
expect ( loadMtl ( texturedWithOptionsMaterialPath , options )
. then ( function ( materials ) {
expect ( materials . length ) . toBe ( 1 ) ;
var material = materials [ 0 ] ;
var pbr = material . pbrMetallicRoughness ;
expect ( pbr . baseColorTexture ) . toBeDefined ( ) ;
expect ( pbr . metallicRoughnessTexture ) . toBeDefined ( ) ;
expect ( pbr . baseColorFactor ) . toEqual ( [ 1.0 , 1.0 , 1.0 , 0.9 ] ) ;
expect ( pbr . metallicFactor ) . toBe ( 1.0 ) ;
expect ( pbr . roughnessFactor ) . toBe ( 1.0 ) ;
expect ( material . name ) . toBe ( 'Material' ) ;
2017-07-29 13:23:33 -04:00
expect ( material . emissiveTexture ) . toBeDefined ( ) ;
expect ( material . normalTexture ) . toBeDefined ( ) ;
expect ( material . occlusionTexture ) . toBeDefined ( ) ;
expect ( material . emissiveFactor ) . toEqual ( [ 1.0 , 1.0 , 1.0 ] ) ;
expect ( material . alphaMode ) . toBe ( 'BLEND' ) ;
expect ( material . doubleSided ) . toBe ( true ) ;
2017-03-13 15:28:51 -04:00
} ) , done ) . toResolve ( ) ;
} ) ;
it ( 'loads mtl with multiple materials' , function ( done ) {
2017-07-29 13:23:33 -04:00
options . metallicRoughness = true ;
expect ( loadMtl ( multipleMaterialsPath , options )
2017-03-13 15:28:51 -04:00
. then ( function ( materials ) {
2017-05-04 17:58:13 -04:00
expect ( materials . length ) . toBe ( 3 ) ;
expect ( materials [ 0 ] . name ) . toBe ( 'Blue' ) ;
2017-07-29 13:23:33 -04:00
expect ( materials [ 0 ] . pbrMetallicRoughness . baseColorFactor ) . toEqual ( [ 0.0 , 0.0 , 0.64 , 1.0 ] ) ;
2017-05-04 17:58:13 -04:00
expect ( materials [ 1 ] . name ) . toBe ( 'Green' ) ;
2017-07-29 13:23:33 -04:00
expect ( materials [ 1 ] . pbrMetallicRoughness . baseColorFactor ) . toEqual ( [ 0.0 , 0.64 , 0.0 , 1.0 ] ) ;
2017-05-04 17:58:13 -04:00
expect ( materials [ 2 ] . name ) . toBe ( 'Red' ) ;
2017-07-29 13:23:33 -04:00
expect ( materials [ 2 ] . pbrMetallicRoughness . baseColorFactor ) . toEqual ( [ 0.64 , 0.0 , 0.0 , 1.0 ] ) ;
} ) , done ) . toResolve ( ) ;
} ) ;
it ( 'sets overriding textures' , function ( done ) {
spyOn ( fsExtra , 'readFile' ) . and . callThrough ( ) ;
options . overridingTextures = {
metallicRoughnessOcclusionTexture : alphaTexturePath ,
baseColorTexture : alphaTexturePath ,
emissiveTexture : emissiveTexturePath
} ;
expect ( loadMtl ( texturedMaterialPath , options )
. then ( function ( materials ) {
var material = materials [ 0 ] ;
var pbr = material . pbrMetallicRoughness ;
expect ( pbr . baseColorTexture . name ) . toBe ( 'alpha' ) ;
expect ( pbr . metallicRoughnessTexture . name ) . toBe ( 'alpha' ) ;
expect ( material . emissiveTexture . name ) . toBe ( 'emission' ) ;
expect ( material . normalTexture . name ) . toBe ( 'bump' ) ;
expect ( fsExtra . readFile . calls . count ( ) ) . toBe ( 3 ) ;
} ) , done ) . toResolve ( ) ;
} ) ;
it ( 'loads texture outside of the mtl directory' , function ( done ) {
expect ( loadMtl ( externalMaterialPath , options )
. then ( function ( materials ) {
var material = materials [ 0 ] ;
var baseColorTexture = material . pbrMetallicRoughness . baseColorTexture ;
expect ( baseColorTexture . source ) . toBeDefined ( ) ;
expect ( baseColorTexture . name ) . toBe ( 'cesium' ) ;
} ) , done ) . toResolve ( ) ;
} ) ;
it ( 'does not load texture outside of the mtl directory when secure is true' , function ( done ) {
var spy = jasmine . createSpy ( 'logger' ) ;
options . logger = spy ;
options . secure = true ;
expect ( loadMtl ( externalMaterialPath , options )
. then ( function ( materials ) {
var material = materials [ 0 ] ;
var baseColorTexture = material . pbrMetallicRoughness . baseColorTexture ;
expect ( baseColorTexture ) . toBeUndefined ( ) ;
2017-12-21 22:19:52 -05:00
expect ( spy . calls . argsFor ( 0 ) [ 0 ] . indexOf ( 'Texture file is outside of the mtl directory and the secure flag is true. Attempting to read the texture file from within the obj directory instead' ) >= 0 ) . toBe ( true ) ;
expect ( spy . calls . argsFor ( 1 ) [ 0 ] . indexOf ( 'ENOENT' ) >= 0 ) . toBe ( true ) ;
expect ( spy . calls . argsFor ( 2 ) [ 0 ] . indexOf ( 'Could not read texture file' ) >= 0 ) . toBe ( true ) ;
2017-03-13 15:28:51 -04:00
} ) , done ) . toResolve ( ) ;
} ) ;
2017-07-29 13:23:33 -04:00
2017-11-17 15:07:52 -05:00
it ( 'loads textures from root directory when the texture paths do not exist' , function ( done ) {
2017-11-29 14:21:59 -05:00
expect ( loadMtl ( resourcesInRootMaterialPath , options )
. then ( function ( materials ) {
var material = materials [ 0 ] ;
var baseColorTexture = material . pbrMetallicRoughness . baseColorTexture ;
expect ( baseColorTexture . source ) . toBeDefined ( ) ;
expect ( baseColorTexture . name ) . toBe ( 'cesium' ) ;
} ) , done ) . toResolve ( ) ;
} ) ;
it ( 'loads textures from root directory when texture is outside of the mtl directory and secure is true' , function ( done ) {
options . secure = true ;
expect ( loadMtl ( externalInRootMaterialPath , options )
2017-11-17 15:07:52 -05:00
. then ( function ( materials ) {
var material = materials [ 0 ] ;
var baseColorTexture = material . pbrMetallicRoughness . baseColorTexture ;
expect ( baseColorTexture . source ) . toBeDefined ( ) ;
expect ( baseColorTexture . name ) . toBe ( 'cesium' ) ;
} ) , done ) . toResolve ( ) ;
} ) ;
2017-09-19 13:09:58 -04:00
it ( 'alpha of 0.0 is treated as 1.0' , function ( done ) {
expect ( loadMtl ( transparentMaterialPath , options )
. then ( function ( materials ) {
expect ( materials . length ) . toBe ( 1 ) ;
var material = materials [ 0 ] ;
var pbr = material . pbrMetallicRoughness ;
expect ( pbr . baseColorTexture ) . toBeUndefined ( ) ;
expect ( pbr . metallicRoughnessTexture ) . toBeUndefined ( ) ;
expect ( pbr . baseColorFactor [ 3 ] ) . toEqual ( 1.0 ) ;
expect ( material . alphaMode ) . toBe ( 'OPAQUE' ) ;
expect ( material . doubleSided ) . toBe ( false ) ;
} ) , done ) . toResolve ( ) ;
} ) ;
2017-07-29 13:23:33 -04:00
describe ( 'metallicRoughness' , function ( ) {
it ( 'creates default material' , function ( ) {
var material = loadMtl . _createMaterial ( undefined , options ) ;
var pbr = material . pbrMetallicRoughness ;
expect ( pbr . baseColorTexture ) . toBeUndefined ( ) ;
expect ( pbr . metallicRoughnessTexture ) . toBeUndefined ( ) ;
expect ( pbr . baseColorFactor ) . toEqual ( [ 0.5 , 0.5 , 0.5 , 1.0 ] ) ;
expect ( pbr . metallicFactor ) . toBe ( 0.0 ) ; // No metallic
expect ( pbr . roughnessFactor ) . toBe ( 1.0 ) ; // Fully rough
expect ( material . emissiveTexture ) . toBeUndefined ( ) ;
expect ( material . normalTexture ) . toBeUndefined ( ) ;
expect ( material . ambientTexture ) . toBeUndefined ( ) ;
expect ( material . emissiveFactor ) . toEqual ( [ 0.0 , 0.0 , 0.0 ] ) ;
expect ( material . alphaMode ) . toBe ( 'OPAQUE' ) ;
expect ( material . doubleSided ) . toBe ( false ) ;
} ) ;
it ( 'creates material with textures' , function ( ) {
options . metallicRoughness = true ;
var material = loadMtl . _createMaterial ( {
diffuseTexture : diffuseTexture ,
ambientTexture : ambientTexture ,
normalTexture : normalTexture ,
emissiveTexture : emissiveTexture ,
specularTexture : specularTexture ,
specularShininessTexture : specularShininessTexture
} , options ) ;
var pbr = material . pbrMetallicRoughness ;
expect ( pbr . baseColorTexture ) . toBeDefined ( ) ;
expect ( pbr . metallicRoughnessTexture ) . toBeDefined ( ) ;
expect ( pbr . baseColorFactor ) . toEqual ( [ 1.0 , 1.0 , 1.0 , 1.0 ] ) ;
expect ( pbr . metallicFactor ) . toBe ( 1.0 ) ;
expect ( pbr . roughnessFactor ) . toBe ( 1.0 ) ;
expect ( material . emissiveTexture ) . toBeDefined ( ) ;
expect ( material . normalTexture ) . toBeDefined ( ) ;
expect ( material . occlusionTexture ) . toBeDefined ( ) ;
expect ( material . emissiveFactor ) . toEqual ( [ 1.0 , 1.0 , 1.0 ] ) ;
expect ( material . alphaMode ) . toBe ( 'OPAQUE' ) ;
expect ( material . doubleSided ) . toBe ( false ) ;
} ) ;
it ( 'packs occlusion in metallic roughness texture' , function ( ) {
options . metallicRoughness = true ;
options . packOcclusion = true ;
var material = loadMtl . _createMaterial ( {
ambientTexture : alphaTexture ,
specularTexture : specularTexture ,
specularShininessTexture : specularShininessTexture
} , options ) ;
var pbr = material . pbrMetallicRoughness ;
expect ( pbr . metallicRoughnessTexture ) . toBeDefined ( ) ;
expect ( pbr . metallicRoughnessTexture ) . toBe ( material . occlusionTexture ) ;
} ) ;
it ( 'does not create metallic roughness texture if decoded texture data is not available' , function ( ) {
options . metallicRoughness = true ;
options . packOcclusion = true ;
var material = loadMtl . _createMaterial ( {
ambientTexture : ambientTexture , // Is a .gif which can't be decoded
specularTexture : specularTexture ,
specularShininessTexture : specularShininessTexture
} , options ) ;
var pbr = material . pbrMetallicRoughness ;
expect ( pbr . metallicRoughnessTexture ) . toBeUndefined ( ) ;
expect ( material . occlusionTexture ) . toBeUndefined ( ) ;
} ) ;
it ( 'sets material for transparent diffuse texture' , function ( ) {
options . metallicRoughness = true ;
var material = loadMtl . _createMaterial ( {
diffuseTexture : transparentDiffuseTexture
} , options ) ;
expect ( material . alphaMode ) . toBe ( 'BLEND' ) ;
expect ( material . doubleSided ) . toBe ( true ) ;
} ) ;
} ) ;
describe ( 'specularGlossiness' , function ( ) {
it ( 'creates default material' , function ( ) {
options . specularGlossiness = true ;
var material = loadMtl . _createMaterial ( undefined , options ) ;
var pbr = material . extensions . KHR _materials _pbrSpecularGlossiness ;
expect ( pbr . diffuseTexture ) . toBeUndefined ( ) ;
expect ( pbr . specularGlossinessTexture ) . toBeUndefined ( ) ;
expect ( pbr . diffuseFactor ) . toEqual ( [ 0.5 , 0.5 , 0.5 , 1.0 ] ) ;
expect ( pbr . specularFactor ) . toEqual ( [ 0.0 , 0.0 , 0.0 ] ) ; // No specular color
expect ( pbr . glossinessFactor ) . toEqual ( 0.0 ) ; // Rough surface
expect ( material . emissiveTexture ) . toBeUndefined ( ) ;
expect ( material . normalTexture ) . toBeUndefined ( ) ;
expect ( material . occlusionTexture ) . toBeUndefined ( ) ;
expect ( material . emissiveFactor ) . toEqual ( [ 0.0 , 0.0 , 0.0 ] ) ;
expect ( material . alphaMode ) . toBe ( 'OPAQUE' ) ;
expect ( material . doubleSided ) . toBe ( false ) ;
} ) ;
it ( 'creates material with textures' , function ( ) {
options . specularGlossiness = true ;
var material = loadMtl . _createMaterial ( {
diffuseTexture : diffuseTexture ,
ambientTexture : ambientTexture ,
normalTexture : normalTexture ,
emissiveTexture : emissiveTexture ,
specularTexture : specularTexture ,
specularShininessTexture : specularShininessTexture
} , options ) ;
var pbr = material . extensions . KHR _materials _pbrSpecularGlossiness ;
expect ( pbr . diffuseTexture ) . toBeDefined ( ) ;
expect ( pbr . specularGlossinessTexture ) . toBeDefined ( ) ;
expect ( pbr . diffuseFactor ) . toEqual ( [ 1.0 , 1.0 , 1.0 , 1.0 ] ) ;
expect ( pbr . specularFactor ) . toEqual ( [ 1.0 , 1.0 , 1.0 ] ) ;
expect ( pbr . glossinessFactor ) . toEqual ( 1.0 ) ;
expect ( material . emissiveTexture ) . toBeDefined ( ) ;
expect ( material . normalTexture ) . toBeDefined ( ) ;
expect ( material . occlusionTexture ) . toBeDefined ( ) ;
expect ( material . emissiveFactor ) . toEqual ( [ 1.0 , 1.0 , 1.0 ] ) ;
expect ( material . alphaMode ) . toBe ( 'OPAQUE' ) ;
expect ( material . doubleSided ) . toBe ( false ) ;
} ) ;
it ( 'does not create specular glossiness texture if decoded texture data is not available' , function ( ) {
options . specularGlossiness = true ;
var material = loadMtl . _createMaterial ( {
specularTexture : ambientTexture , // Is a .gif which can't be decoded
specularShininessTexture : specularShininessTexture
} , options ) ;
var pbr = material . extensions . KHR _materials _pbrSpecularGlossiness ;
expect ( pbr . specularGlossinessTexture ) . toBeUndefined ( ) ;
} ) ;
it ( 'sets material for transparent diffuse texture' , function ( ) {
options . specularGlossiness = true ;
var material = loadMtl . _createMaterial ( {
diffuseTexture : transparentDiffuseTexture
} , options ) ;
expect ( material . alphaMode ) . toBe ( 'BLEND' ) ;
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 ) ;
} ) ;
2017-09-21 10:37:50 -04:00
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 ) ;
} ) ;
2017-07-29 13:23:33 -04:00
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 ] ) ;
} ) ;
} ) ;
2017-03-13 15:28:51 -04:00
} ) ;