123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174 |
- /* global QUnit */
- import { GLTFExporter } from '../../../../examples/jsm/exporters/GLTFExporter.js';
- import { GLTFLoader } from '../../../../examples/jsm/loaders/GLTFLoader.js';
- import { AnimationClip } from '../../../../src/animation/AnimationClip.js';
- import { BufferAttribute } from '../../../../src/core/BufferAttribute.js';
- import { BufferGeometry } from '../../../../src/core/BufferGeometry.js';
- import { BoxBufferGeometry } from '../../../../src/geometries/BoxGeometry.js';
- import { Mesh } from '../../../../src/objects/Mesh.js';
- import { MeshStandardMaterial } from '../../../../src/materials/MeshStandardMaterial.js';
- import { Object3D } from '../../../../src/core/Object3D.js';
- import { Scene } from '../../../../src/scenes/Scene.js';
- import { DataTexture } from '../../../../src/textures/DataTexture.js';
- import { VectorKeyframeTrack } from '../../../../src/animation/tracks/VectorKeyframeTrack.js';
- export default QUnit.module( 'Loaders', () => {
- QUnit.module( 'GLTFLoader', () => {
- QUnit.test( 'constructor', ( assert ) => {
- assert.ok( new GLTFLoader(), 'Can instantiate a loader.' );
- } );
- } );
- QUnit.module( 'GLTFLoader-webonly', () => {
- QUnit.test( 'parse - basic', ( assert ) => {
- var done = assert.async();
- var geometry = new BufferGeometry();
- var array = new Float32Array( [
- - 1, - 1, - 1,
- 1, 1, 1,
- 4, 4, 4
- ] );
- geometry.setAttribute( 'position', new BufferAttribute( array, 3 ) );
- var meshIn = new Mesh( geometry, new MeshStandardMaterial( { color: 0xFF0000 } ) );
- meshIn.name = 'test_mesh';
- var exporter = new GLTFExporter();
- var loader = new GLTFLoader();
- exporter.parse( meshIn, function ( binary ) {
- loader.parse( binary, './', function ( gltf ) {
- var meshOut = gltf.scene.children[ 0 ];
- var attrsIn = meshIn.geometry.attributes;
- var attrsOut = meshOut.geometry.attributes;
- assert.equal( meshIn.name, meshOut.name, 'loads names' );
- assert.equal( meshIn.material.color.getHex(), meshOut.material.color.getHex(), 'loads color' );
- assert.smartEqual( attrsIn.position.array, attrsOut.position.array, 'loads positions' );
- assert.equal( undefined, attrsOut.normal, 'ignores missing attributes' );
- done();
- }, undefined, function ( e ) {
- console.error( e );
- } );
- }, { binary: true } );
- } );
- QUnit.test( 'parse - animation', ( assert ) => {
- var done = assert.async();
- var node1 = new Object3D();
- node1.name = 'node1';
- var node2 = new Object3D();
- node2.name = 'node2';
- var scene = new Scene();
- scene.add( node1, node2 );
- var clip = new AnimationClip( 'clip', undefined, [
- new VectorKeyframeTrack( 'node1.position', [ 0, 1, 2 ], [ 0, 0, 0, 30, 0, 0, 0, 0, 0 ] )
- ] );
- var exporter = new GLTFExporter();
- var loader = new GLTFLoader();
- exporter.parse( scene, function ( binary ) {
- loader.parse( binary, './', function ( gltf ) {
- var clipOut = gltf.animations[ 0 ];
- assert.equal( 'node1.position', clipOut.tracks[ 0 ].name, 'track name' );
- assert.smartEqual( clip.tracks[ 0 ].times, clipOut.tracks[ 0 ].times, 'track times' );
- assert.smartEqual( clip.tracks[ 0 ].values, clipOut.tracks[ 0 ].values, 'track values' );
- done();
- }, undefined, function ( e ) {
- console.error( e );
- } );
- }, { binary: true, animations: [ clip ] } );
- } );
- QUnit.test( 'parser - associations', ( assert ) => {
- var done = assert.async();
- var scene = new Scene();
- scene.add( new Mesh(
- new BoxBufferGeometry(),
- new MeshStandardMaterial( { map: new DataTexture( new Uint8ClampedArray( [ 0, 0, 0, 0 ] ), 1, 1 ) } )
- ) );
- var exporter = new GLTFExporter();
- var loader = new GLTFLoader();
- exporter.parse( scene, function ( binary ) {
- loader.parse( binary, './', function ( gltf ) {
- var parser = gltf.parser;
- var associations = parser.associations;
- gltf.scene.traverse( function ( object ) {
- if ( object.isMesh ) {
- assert.smartEqual( associations.get( object ), {
- meshes: 0,
- nodes: 0,
- primitives: 0
- }, 'Mesh has a proper association' );
- assert.smartEqual( associations.get( object.material ), {
- materials: 0
- }, 'Material has a proper association' );
- assert.smartEqual( associations.get( object.material.map ), {
- textures: 0
- }, 'Texture has a proper association' );
- }
- } );
- done();
- }, undefined, function ( e ) {
- console.error( e );
- } );
- }, { binary: true } );
- } );
- } );
- } );
|