| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487 |
- import { ObjectLoader } from '../../../src/loaders/ObjectLoader.js';
- import { InterpolateLinear, InterpolateSmooth, InterpolateDiscrete } from '../../../src/constants.js';
- export default QUnit.module( 'JSON4 Format', () => {
- QUnit.module( 'Animation', () => {
- QUnit.test( 'AnimationClip - name, duration, tracks', ( 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
- } ],
- animations: [ {
- uuid: 'anim-1',
- name: 'MoveRight',
- duration: 2,
- tracks: [
- {
- name: '.position',
- type: 'vector',
- times: [ 0, 1, 2 ],
- values: [ 0, 0, 0, 5, 0, 0, 10, 0, 0 ]
- }
- ]
- } ],
- object: {
- 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,
- animations: [ 'anim-1' ]
- }
- };
- const loader = new ObjectLoader();
- const mesh = loader.parse( json );
- assert.strictEqual( mesh.animations.length, 1, 'Has 1 animation' );
- assert.strictEqual( mesh.animations[ 0 ].name, 'MoveRight', 'Animation name' );
- assert.strictEqual( mesh.animations[ 0 ].duration, 2, 'Animation duration' );
- assert.strictEqual( mesh.animations[ 0 ].tracks.length, 1, 'Has 1 track' );
- } );
- QUnit.test( 'VectorKeyframeTrack (position)', ( 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
- } ],
- animations: [ {
- uuid: 'anim-1',
- name: 'Position',
- duration: 1,
- tracks: [
- {
- name: '.position',
- type: 'vector',
- times: [ 0, 0.5, 1 ],
- values: [ 0, 0, 0, 0, 5, 0, 0, 0, 0 ]
- }
- ]
- } ],
- object: {
- 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,
- animations: [ 'anim-1' ]
- }
- };
- const loader = new ObjectLoader();
- const mesh = loader.parse( json );
- const track = mesh.animations[ 0 ].tracks[ 0 ];
- assert.strictEqual( track.name, '.position', 'Track name' );
- assert.strictEqual( track.times.length, 3, 'Has 3 keyframes' );
- assert.strictEqual( track.values.length, 9, 'Has 9 values (3 vec3)' );
- } );
- QUnit.test( 'QuaternionKeyframeTrack (rotation)', ( 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
- } ],
- animations: [ {
- uuid: 'anim-1',
- name: 'Rotation',
- duration: 1,
- tracks: [
- {
- name: '.quaternion',
- type: 'quaternion',
- times: [ 0, 1 ],
- values: [ 0, 0, 0, 1, 0, 0.7071, 0, 0.7071 ]
- }
- ]
- } ],
- object: {
- 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,
- animations: [ 'anim-1' ]
- }
- };
- const loader = new ObjectLoader();
- const mesh = loader.parse( json );
- const track = mesh.animations[ 0 ].tracks[ 0 ];
- assert.strictEqual( track.name, '.quaternion', 'Track name' );
- assert.strictEqual( track.times.length, 2, 'Has 2 keyframes' );
- assert.strictEqual( track.values.length, 8, 'Has 8 values (2 quat)' );
- } );
- QUnit.test( 'NumberKeyframeTrack (opacity)', ( 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,
- transparent: true
- } ],
- animations: [ {
- uuid: 'anim-1',
- name: 'Fade',
- duration: 1,
- tracks: [
- {
- name: '.material.opacity',
- type: 'number',
- times: [ 0, 0.5, 1 ],
- values: [ 1, 0, 1 ]
- }
- ]
- } ],
- object: {
- 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,
- animations: [ 'anim-1' ]
- }
- };
- const loader = new ObjectLoader();
- const mesh = loader.parse( json );
- const track = mesh.animations[ 0 ].tracks[ 0 ];
- assert.strictEqual( track.name, '.material.opacity', 'Track name' );
- assert.strictEqual( track.times.length, 3, 'Has 3 keyframes' );
- assert.strictEqual( track.values.length, 3, 'Has 3 values' );
- } );
- QUnit.test( 'Track interpolation modes', ( 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
- } ],
- animations: [ {
- uuid: 'anim-1',
- name: 'Interpolation',
- duration: 3,
- tracks: [
- {
- name: '.position[x]',
- type: 'number',
- times: [ 0, 1 ],
- values: [ 0, 10 ],
- interpolation: InterpolateLinear
- },
- {
- name: '.position[y]',
- type: 'number',
- times: [ 0, 1 ],
- values: [ 0, 10 ],
- interpolation: InterpolateSmooth
- },
- {
- name: '.position[z]',
- type: 'number',
- times: [ 0, 1 ],
- values: [ 0, 10 ],
- interpolation: InterpolateDiscrete
- }
- ]
- } ],
- object: {
- 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,
- animations: [ 'anim-1' ]
- }
- };
- const loader = new ObjectLoader();
- const mesh = loader.parse( json );
- const tracks = mesh.animations[ 0 ].tracks;
- assert.strictEqual( tracks[ 0 ].getInterpolation(), InterpolateLinear, 'Linear interpolation' );
- assert.strictEqual( tracks[ 1 ].getInterpolation(), InterpolateSmooth, 'Smooth interpolation' );
- assert.strictEqual( tracks[ 2 ].getInterpolation(), InterpolateDiscrete, 'Discrete interpolation' );
- } );
- QUnit.test( 'ColorKeyframeTrack', ( 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
- } ],
- animations: [ {
- uuid: 'anim-1',
- name: 'ColorChange',
- duration: 1,
- tracks: [
- {
- name: '.material.color',
- type: 'color',
- times: [ 0, 1 ],
- values: [ 1, 0, 0, 0, 0, 1 ]
- }
- ]
- } ],
- object: {
- 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,
- animations: [ 'anim-1' ]
- }
- };
- const loader = new ObjectLoader();
- const mesh = loader.parse( json );
- const track = mesh.animations[ 0 ].tracks[ 0 ];
- assert.strictEqual( track.name, '.material.color', 'Track name' );
- assert.strictEqual( track.values.length, 6, 'Has 6 values (2 rgb)' );
- } );
- QUnit.test( 'BooleanKeyframeTrack', ( 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
- } ],
- animations: [ {
- uuid: 'anim-1',
- name: 'Visibility',
- duration: 2,
- tracks: [
- {
- name: '.visible',
- type: 'bool',
- times: [ 0, 1, 2 ],
- values: [ true, false, true ]
- }
- ]
- } ],
- object: {
- 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,
- animations: [ 'anim-1' ]
- }
- };
- const loader = new ObjectLoader();
- const mesh = loader.parse( json );
- const track = mesh.animations[ 0 ].tracks[ 0 ];
- assert.strictEqual( track.name, '.visible', 'Track name' );
- assert.strictEqual( track.times.length, 3, 'Has 3 keyframes' );
- } );
- QUnit.test( 'Multiple animations on object', ( 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
- } ],
- animations: [
- {
- uuid: 'anim-1',
- name: 'Walk',
- duration: 1,
- tracks: [
- {
- name: '.position',
- type: 'vector',
- times: [ 0, 1 ],
- values: [ 0, 0, 0, 1, 0, 0 ]
- }
- ]
- },
- {
- uuid: 'anim-2',
- name: 'Run',
- duration: 0.5,
- tracks: [
- {
- name: '.position',
- type: 'vector',
- times: [ 0, 0.5 ],
- values: [ 0, 0, 0, 2, 0, 0 ]
- }
- ]
- }
- ],
- object: {
- 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,
- animations: [ 'anim-1', 'anim-2' ]
- }
- };
- const loader = new ObjectLoader();
- const mesh = loader.parse( json );
- assert.strictEqual( mesh.animations.length, 2, 'Has 2 animations' );
- assert.strictEqual( mesh.animations[ 0 ].name, 'Walk', 'First animation name' );
- assert.strictEqual( mesh.animations[ 1 ].name, 'Run', 'Second animation name' );
- } );
- QUnit.test( 'StringKeyframeTrack', ( 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
- } ],
- animations: [ {
- uuid: 'anim-1',
- name: 'NameChange',
- duration: 2,
- tracks: [
- {
- name: '.name',
- type: 'string',
- times: [ 0, 1, 2 ],
- values: [ 'First', 'Second', 'Third' ]
- }
- ]
- } ],
- object: {
- 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,
- animations: [ 'anim-1' ]
- }
- };
- const loader = new ObjectLoader();
- const mesh = loader.parse( json );
- const track = mesh.animations[ 0 ].tracks[ 0 ];
- assert.strictEqual( track.name, '.name', 'Track name' );
- assert.strictEqual( track.times.length, 3, 'Has 3 keyframes' );
- } );
- } );
- } );
|