| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315 |
- import { ObjectLoader } from '../../../src/loaders/ObjectLoader.js';
- export default QUnit.module( 'JSON4 Format', () => {
- QUnit.module( 'Morph Targets', () => {
- QUnit.test( 'morphAttributes on geometry', ( assert ) => {
- const json = {
- metadata: { version: 4.7, type: 'Object', generator: 'Object3D.toJSON' },
- geometries: [ {
- uuid: 'geom-1',
- type: 'BufferGeometry',
- data: {
- attributes: {
- position: {
- itemSize: 3,
- type: 'Float32Array',
- array: [ 0, 0, 0, 1, 0, 0, 0, 1, 0 ],
- normalized: false
- }
- },
- morphAttributes: {
- position: [
- {
- itemSize: 3,
- type: 'Float32Array',
- array: [ 0, 0, 0, 2, 0, 0, 0, 2, 0 ],
- normalized: false
- }
- ]
- }
- }
- } ],
- materials: [ {
- uuid: 'mat-1',
- type: 'MeshBasicMaterial',
- color: 16711680,
- morphTargets: 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
- }
- };
- const loader = new ObjectLoader();
- const mesh = loader.parse( json );
- assert.ok( mesh.geometry.morphAttributes.position, 'Has morphAttributes.position' );
- assert.strictEqual( mesh.geometry.morphAttributes.position.length, 1, 'Has 1 morph target' );
- assert.strictEqual( mesh.geometry.morphAttributes.position[ 0 ].count, 3, 'Morph target has 3 vertices' );
- } );
- QUnit.test( 'morphTargetsRelative flag', ( assert ) => {
- const json = {
- metadata: { version: 4.7, type: 'Object', generator: 'Object3D.toJSON' },
- geometries: [ {
- uuid: 'geom-1',
- type: 'BufferGeometry',
- data: {
- attributes: {
- position: {
- itemSize: 3,
- type: 'Float32Array',
- array: [ 0, 0, 0, 1, 0, 0, 0, 1, 0 ],
- normalized: false
- }
- },
- morphAttributes: {
- position: [
- {
- itemSize: 3,
- type: 'Float32Array',
- array: [ 0, 0, 0, 1, 0, 0, 0, 1, 0 ],
- normalized: false
- }
- ]
- },
- morphTargetsRelative: true
- }
- } ],
- materials: [ {
- uuid: 'mat-1',
- type: 'MeshBasicMaterial',
- color: 16711680
- } ],
- 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
- }
- };
- const loader = new ObjectLoader();
- const mesh = loader.parse( json );
- assert.strictEqual( mesh.geometry.morphTargetsRelative, true, 'morphTargetsRelative is true' );
- } );
- QUnit.test( 'Multiple morph targets per attribute', ( assert ) => {
- const json = {
- metadata: { version: 4.7, type: 'Object', generator: 'Object3D.toJSON' },
- geometries: [ {
- uuid: 'geom-1',
- type: 'BufferGeometry',
- data: {
- attributes: {
- position: {
- itemSize: 3,
- type: 'Float32Array',
- array: [ 0, 0, 0, 1, 0, 0, 0, 1, 0 ],
- normalized: false
- }
- },
- morphAttributes: {
- position: [
- {
- name: 'smile',
- itemSize: 3,
- type: 'Float32Array',
- array: [ 0, 0, 0, 1.5, 0, 0, 0, 1.5, 0 ],
- normalized: false
- },
- {
- name: 'frown',
- itemSize: 3,
- type: 'Float32Array',
- array: [ 0, 0, 0, 0.5, 0, 0, 0, 0.5, 0 ],
- normalized: false
- },
- {
- name: 'blink',
- itemSize: 3,
- type: 'Float32Array',
- array: [ 0, - 0.1, 0, 1, - 0.1, 0, 0, 0.9, 0 ],
- normalized: false
- }
- ]
- }
- }
- } ],
- materials: [ {
- uuid: 'mat-1',
- type: 'MeshBasicMaterial',
- color: 16711680
- } ],
- 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
- }
- };
- const loader = new ObjectLoader();
- const mesh = loader.parse( json );
- assert.strictEqual( mesh.geometry.morphAttributes.position.length, 3, 'Has 3 morph targets' );
- assert.strictEqual( mesh.geometry.morphAttributes.position[ 0 ].name, 'smile', 'First target name' );
- assert.strictEqual( mesh.geometry.morphAttributes.position[ 1 ].name, 'frown', 'Second target name' );
- assert.strictEqual( mesh.geometry.morphAttributes.position[ 2 ].name, 'blink', 'Third target name' );
- } );
- QUnit.test( 'Morph targets for normal attribute', ( assert ) => {
- const json = {
- metadata: { version: 4.7, type: 'Object', generator: 'Object3D.toJSON' },
- geometries: [ {
- uuid: 'geom-1',
- type: 'BufferGeometry',
- data: {
- attributes: {
- position: {
- itemSize: 3,
- type: 'Float32Array',
- array: [ 0, 0, 0, 1, 0, 0, 0, 1, 0 ],
- normalized: false
- },
- normal: {
- itemSize: 3,
- type: 'Float32Array',
- array: [ 0, 0, 1, 0, 0, 1, 0, 0, 1 ],
- normalized: false
- }
- },
- morphAttributes: {
- position: [
- {
- itemSize: 3,
- type: 'Float32Array',
- array: [ 0, 0, 0.5, 1, 0, 0.5, 0, 1, 0.5 ],
- normalized: false
- }
- ],
- normal: [
- {
- itemSize: 3,
- type: 'Float32Array',
- array: [ 0.5, 0, 0.866, 0.5, 0, 0.866, 0.5, 0, 0.866 ],
- normalized: false
- }
- ]
- }
- }
- } ],
- materials: [ {
- uuid: 'mat-1',
- type: 'MeshStandardMaterial',
- color: 16711680,
- morphTargets: true,
- morphNormals: 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
- }
- };
- const loader = new ObjectLoader();
- const mesh = loader.parse( json );
- assert.ok( mesh.geometry.morphAttributes.position, 'Has morphAttributes.position' );
- assert.ok( mesh.geometry.morphAttributes.normal, 'Has morphAttributes.normal' );
- assert.strictEqual( mesh.geometry.morphAttributes.normal.length, 1, 'Has 1 normal morph target' );
- } );
- QUnit.test( 'Morph targets for color attribute', ( assert ) => {
- const json = {
- metadata: { version: 4.7, type: 'Object', generator: 'Object3D.toJSON' },
- geometries: [ {
- uuid: 'geom-1',
- type: 'BufferGeometry',
- data: {
- attributes: {
- position: {
- itemSize: 3,
- type: 'Float32Array',
- array: [ 0, 0, 0, 1, 0, 0, 0, 1, 0 ],
- normalized: false
- },
- color: {
- itemSize: 3,
- type: 'Float32Array',
- array: [ 1, 0, 0, 1, 0, 0, 1, 0, 0 ],
- normalized: false
- }
- },
- morphAttributes: {
- position: [
- {
- itemSize: 3,
- type: 'Float32Array',
- array: [ 0, 0, 0, 2, 0, 0, 0, 2, 0 ],
- normalized: false
- }
- ],
- color: [
- {
- itemSize: 3,
- type: 'Float32Array',
- array: [ 0, 1, 0, 0, 1, 0, 0, 1, 0 ],
- normalized: false
- }
- ]
- }
- }
- } ],
- materials: [ {
- uuid: 'mat-1',
- type: 'MeshBasicMaterial',
- color: 16777215,
- vertexColors: 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
- }
- };
- const loader = new ObjectLoader();
- const mesh = loader.parse( json );
- assert.ok( mesh.geometry.morphAttributes.color, 'Has morphAttributes.color' );
- assert.strictEqual( mesh.geometry.morphAttributes.color.length, 1, 'Has 1 color morph target' );
- } );
- } );
- } );
|