| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348 |
- import { ObjectLoader } from '../../../src/loaders/ObjectLoader.js';
- export default QUnit.module( 'JSON4 Format', () => {
- QUnit.module( 'Scene', () => {
- QUnit.test( 'Scene type', ( assert ) => {
- const json = {
- metadata: { version: 4.7, type: 'Object', generator: 'Object3D.toJSON' },
- object: {
- uuid: 'scene-1',
- type: 'Scene',
- matrix: [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ],
- layers: 1
- }
- };
- const loader = new ObjectLoader();
- const scene = loader.parse( json );
- assert.ok( scene.isScene, 'Is Scene' );
- assert.strictEqual( scene.type, 'Scene', 'Type is Scene' );
- } );
- QUnit.test( 'Background as Color (hex integer)', ( assert ) => {
- const json = {
- metadata: { version: 4.7, type: 'Object', generator: 'Object3D.toJSON' },
- object: {
- uuid: 'scene-1',
- type: 'Scene',
- background: 8900331,
- matrix: [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ],
- layers: 1
- }
- };
- const loader = new ObjectLoader();
- const scene = loader.parse( json );
- assert.ok( scene.background.isColor, 'Background is Color' );
- assert.strictEqual( scene.background.getHex(), 0x87ceeb, 'Background color value' );
- } );
- QUnit.test( 'Background as Texture reference', ( assert ) => {
- const json = {
- metadata: { version: 4.7, type: 'Object', generator: 'Object3D.toJSON' },
- images: [ {
- uuid: 'image-1',
- url: {
- data: [ 255, 0, 0, 255 ],
- width: 1,
- height: 1,
- type: 'Uint8Array'
- }
- } ],
- textures: [ {
- uuid: 'tex-1',
- image: 'image-1'
- } ],
- object: {
- uuid: 'scene-1',
- type: 'Scene',
- background: 'tex-1',
- matrix: [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ],
- layers: 1
- }
- };
- const loader = new ObjectLoader();
- const scene = loader.parse( json );
- assert.ok( scene.background.isTexture, 'Background is Texture' );
- } );
- QUnit.test( 'Environment texture', ( assert ) => {
- const json = {
- metadata: { version: 4.7, type: 'Object', generator: 'Object3D.toJSON' },
- images: [ {
- uuid: 'image-1',
- url: {
- data: [ 128, 128, 128, 255 ],
- width: 1,
- height: 1,
- type: 'Uint8Array'
- }
- } ],
- textures: [ {
- uuid: 'env-tex-1',
- image: 'image-1'
- } ],
- object: {
- uuid: 'scene-1',
- type: 'Scene',
- environment: 'env-tex-1',
- matrix: [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ],
- layers: 1
- }
- };
- const loader = new ObjectLoader();
- const scene = loader.parse( json );
- assert.ok( scene.environment.isTexture, 'Environment is Texture' );
- } );
- QUnit.test( 'Fog - color, near, far', ( assert ) => {
- const json = {
- metadata: { version: 4.7, type: 'Object', generator: 'Object3D.toJSON' },
- object: {
- uuid: 'scene-1',
- type: 'Scene',
- fog: {
- type: 'Fog',
- name: '',
- color: 16777215,
- near: 1,
- far: 100
- },
- matrix: [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ],
- layers: 1
- }
- };
- const loader = new ObjectLoader();
- const scene = loader.parse( json );
- assert.ok( scene.fog.isFog, 'Has Fog' );
- assert.strictEqual( scene.fog.color.getHex(), 0xffffff, 'Fog color' );
- assert.strictEqual( scene.fog.near, 1, 'Fog near' );
- assert.strictEqual( scene.fog.far, 100, 'Fog far' );
- } );
- QUnit.test( 'FogExp2 - color, density', ( assert ) => {
- const json = {
- metadata: { version: 4.7, type: 'Object', generator: 'Object3D.toJSON' },
- object: {
- uuid: 'scene-1',
- type: 'Scene',
- fog: {
- type: 'FogExp2',
- name: '',
- color: 8421504,
- density: 0.02
- },
- matrix: [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ],
- layers: 1
- }
- };
- const loader = new ObjectLoader();
- const scene = loader.parse( json );
- assert.ok( scene.fog.isFogExp2, 'Has FogExp2' );
- assert.strictEqual( scene.fog.color.getHex(), 0x808080, 'FogExp2 color' );
- assert.strictEqual( scene.fog.density, 0.02, 'FogExp2 density' );
- } );
- QUnit.test( 'Fog with name', ( assert ) => {
- const json = {
- metadata: { version: 4.7, type: 'Object', generator: 'Object3D.toJSON' },
- object: {
- uuid: 'scene-1',
- type: 'Scene',
- fog: {
- type: 'Fog',
- name: 'MyFog',
- color: 16777215,
- near: 10,
- far: 200
- },
- matrix: [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ],
- layers: 1
- }
- };
- const loader = new ObjectLoader();
- const scene = loader.parse( json );
- assert.strictEqual( scene.fog.name, 'MyFog', 'Fog name' );
- } );
- QUnit.test( 'backgroundBlurriness', ( assert ) => {
- const json = {
- metadata: { version: 4.7, type: 'Object', generator: 'Object3D.toJSON' },
- object: {
- uuid: 'scene-1',
- type: 'Scene',
- backgroundBlurriness: 0.5,
- matrix: [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ],
- layers: 1
- }
- };
- const loader = new ObjectLoader();
- const scene = loader.parse( json );
- assert.strictEqual( scene.backgroundBlurriness, 0.5, 'backgroundBlurriness' );
- } );
- QUnit.test( 'backgroundIntensity', ( assert ) => {
- const json = {
- metadata: { version: 4.7, type: 'Object', generator: 'Object3D.toJSON' },
- object: {
- uuid: 'scene-1',
- type: 'Scene',
- backgroundIntensity: 0.8,
- matrix: [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ],
- layers: 1
- }
- };
- const loader = new ObjectLoader();
- const scene = loader.parse( json );
- assert.strictEqual( scene.backgroundIntensity, 0.8, 'backgroundIntensity' );
- } );
- QUnit.test( 'backgroundRotation', ( assert ) => {
- const json = {
- metadata: { version: 4.7, type: 'Object', generator: 'Object3D.toJSON' },
- object: {
- uuid: 'scene-1',
- type: 'Scene',
- backgroundRotation: [ Math.PI / 4, 0, 0, 'XYZ' ],
- matrix: [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ],
- layers: 1
- }
- };
- const loader = new ObjectLoader();
- const scene = loader.parse( json );
- assert.ok( Math.abs( scene.backgroundRotation.x - Math.PI / 4 ) < 0.0001, 'backgroundRotation.x' );
- } );
- QUnit.test( 'environmentIntensity', ( assert ) => {
- const json = {
- metadata: { version: 4.7, type: 'Object', generator: 'Object3D.toJSON' },
- object: {
- uuid: 'scene-1',
- type: 'Scene',
- environmentIntensity: 1.5,
- matrix: [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ],
- layers: 1
- }
- };
- const loader = new ObjectLoader();
- const scene = loader.parse( json );
- assert.strictEqual( scene.environmentIntensity, 1.5, 'environmentIntensity' );
- } );
- QUnit.test( 'environmentRotation', ( assert ) => {
- const json = {
- metadata: { version: 4.7, type: 'Object', generator: 'Object3D.toJSON' },
- object: {
- uuid: 'scene-1',
- type: 'Scene',
- environmentRotation: [ 0, Math.PI / 2, 0, 'XYZ' ],
- matrix: [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ],
- layers: 1
- }
- };
- const loader = new ObjectLoader();
- const scene = loader.parse( json );
- assert.ok( Math.abs( scene.environmentRotation.y - Math.PI / 2 ) < 0.0001, 'environmentRotation.y' );
- } );
- QUnit.test( 'Scene with children', ( assert ) => {
- const json = {
- metadata: { version: 4.7, type: 'Object', generator: 'Object3D.toJSON' },
- geometries: [ {
- uuid: 'geom-1',
- type: 'BoxGeometry',
- width: 1,
- height: 1,
- depth: 1
- } ],
- materials: [ {
- uuid: 'mat-1',
- type: 'MeshBasicMaterial',
- color: 16711680
- } ],
- object: {
- uuid: 'scene-1',
- type: 'Scene',
- background: 0,
- children: [
- {
- uuid: 'mesh-1',
- type: 'Mesh',
- geometry: 'geom-1',
- material: 'mat-1',
- matrix: [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ],
- layers: 1
- },
- {
- uuid: 'light-1',
- type: 'AmbientLight',
- color: 16777215,
- intensity: 0.5,
- matrix: [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ],
- layers: 1
- }
- ]
- }
- };
- const loader = new ObjectLoader();
- const scene = loader.parse( json );
- assert.strictEqual( scene.children.length, 2, 'Has 2 children' );
- assert.ok( scene.children[ 0 ].isMesh, 'First child is Mesh' );
- assert.ok( scene.children[ 1 ].isAmbientLight, 'Second child is AmbientLight' );
- } );
- } );
- } );
|