Browse Source

Tests: Ensure example tests use modules.

Mugen87 6 years ago
parent
commit
d28c8917b9

+ 227 - 218
test/unit/example/exporters/GLTFExporter.tests.js

@@ -3,338 +3,347 @@
  */
 /* global QUnit */
 
-import * as GLTFExporter from '../../../../examples/js/exporters/GLTFExporter';
+import { GLTFExporter } from '../../../../examples/jsm/exporters/GLTFExporter';
 
 import { AnimationClip } from '../../../../src/animation/AnimationClip';
+import { BoxGeometry } from '../../../../src/geometries/BoxGeometry';
 import { BufferAttribute } from '../../../../src/core/BufferAttribute';
 import { BufferGeometry } from '../../../../src/core/BufferGeometry';
 import { Mesh } from '../../../../src/objects/Mesh';
+import { MeshBasicMaterial } from '../../../../src/materials/MeshBasicMaterial';
+import { MeshStandardMaterial } from '../../../../src/materials/MeshStandardMaterial';
 import { Object3D } from '../../../../src/core/Object3D';
 import { NumberKeyframeTrack } from '../../../../src/animation/tracks/NumberKeyframeTrack';
+import { Scene } from '../../../../src/scenes/Scene';
 import { VectorKeyframeTrack } from '../../../../src/animation/tracks/VectorKeyframeTrack';
 import {
-  InterpolateLinear,
-  InterpolateSmooth,
-  InterpolateDiscrete
+	DoubleSide,
+	InterpolateLinear,
+	InterpolateDiscrete,
+	VertexColors,
 } from '../../../../src/constants.js';
 
 export default QUnit.module( 'Exporters', () => {
 
-  QUnit.module( 'GLTFExporter', () => {
+	QUnit.module( 'GLTFExporter', () => {
 
-    QUnit.test( 'constructor', ( assert ) => {
+		QUnit.test( 'constructor', ( assert ) => {
 
-      assert.ok( new THREE.GLTFExporter(), 'Can instantiate an exporter.' );
+			assert.ok( new GLTFExporter(), 'Can instantiate an exporter.' );
 
-    } );
+		} );
 
-    QUnit.test( 'parse - metadata', ( assert ) => {
+		QUnit.test( 'parse - metadata', ( assert ) => {
 
-      var done = assert.async();
+			var done = assert.async();
 
-      var object = new THREE.Object3D();
+			var object = new Object3D();
 
-      var exporter = new THREE.GLTFExporter();
+			var exporter = new GLTFExporter();
 
-      exporter.parse( object, function ( gltf ) {
+			exporter.parse( object, function ( gltf ) {
 
-        assert.equal( '2.0', gltf.asset.version, 'asset.version' );
-        assert.equal( 'THREE.GLTFExporter', gltf.asset.generator, 'asset.generator' );
+				console.log( gltf );
 
-        done();
+				assert.equal( '2.0', gltf.asset.version, 'asset.version' );
+				assert.equal( 'GLTFExporter', gltf.asset.generator, 'asset.generator' );
 
-      } );
+				done();
 
-    } );
+			} );
 
-    QUnit.test( 'parse - basic', ( assert ) => {
+		} );
 
-      var done = assert.async();
+		QUnit.test( 'parse - basic', ( assert ) => {
 
-      var box = new THREE.Mesh(
-        new THREE.CubeGeometry( 1, 1, 1 ),
-        new THREE.MeshStandardMaterial( { color: 0xFF0000 } )
-      );
+			var done = assert.async();
 
-      var exporter = new THREE.GLTFExporter();
+			var box = new Mesh(
+				new BoxGeometry( 1, 1, 1 ),
+				new MeshStandardMaterial( { color: 0xFF0000 } )
+			);
 
-      exporter.parse( box, function ( gltf ) {
+			var exporter = new GLTFExporter();
 
-        assert.equal( 1, gltf.nodes.length, 'correct number of nodes' );
-        assert.equal( 0, gltf.nodes[ 0 ].mesh, 'node references mesh' );
-        assert.equal( 1, gltf.meshes[ 0 ].primitives.length, 'correct number of primitives' );
+			exporter.parse( box, function ( gltf ) {
 
-        var primitive = gltf.meshes[ 0 ].primitives[ 0 ];
-        var material = gltf.materials[ primitive.material ];
+				assert.equal( 1, gltf.nodes.length, 'correct number of nodes' );
+				assert.equal( 0, gltf.nodes[ 0 ].mesh, 'node references mesh' );
+				assert.equal( 1, gltf.meshes[ 0 ].primitives.length, 'correct number of primitives' );
 
-        assert.equal( 4, primitive.mode, 'mesh uses TRIANGLES mode' );
-        assert.ok( primitive.attributes.POSITION !== undefined, 'mesh contains position data' );
-        assert.ok( primitive.attributes.NORMAL !== undefined, 'mesh contains normal data' );
+				var primitive = gltf.meshes[ 0 ].primitives[ 0 ];
+				var material = gltf.materials[ primitive.material ];
 
-        assert.smartEqual( {
+				assert.equal( 4, primitive.mode, 'mesh uses TRIANGLES mode' );
+				assert.ok( primitive.attributes.POSITION !== undefined, 'mesh contains position data' );
+				assert.ok( primitive.attributes.NORMAL !== undefined, 'mesh contains normal data' );
 
-          baseColorFactor: [ 1, 0, 0, 1 ],
-          metallicFactor: 0.5,
-          roughnessFactor: 0.5
+				assert.smartEqual( {
 
-        }, material.pbrMetallicRoughness, 'material' );
+					baseColorFactor: [ 1, 0, 0, 1 ],
+					metallicFactor: 0.5,
+					roughnessFactor: 0.5
 
-        done();
+				}, material.pbrMetallicRoughness, 'material' );
 
-      } );
+				done();
 
-    } );
+			} );
 
-    QUnit.test( 'parse - animation', ( assert ) => {
+		} );
 
-      var done = assert.async();
+		QUnit.test( 'parse - animation', ( assert ) => {
 
-      var mesh1 = new THREE.Mesh();
-      mesh1.name = 'mesh1';
+			var done = assert.async();
 
-      var mesh2 = new THREE.Mesh();
-      mesh2.name = 'mesh2';
+			var mesh1 = new Mesh();
+			mesh1.name = 'mesh1';
 
-      var mesh3 = new THREE.Mesh();
-      mesh3.name = 'mesh3';
+			var mesh2 = new Mesh();
+			mesh2.name = 'mesh2';
 
-      var scene = new THREE.Scene();
-      scene.add( mesh1, mesh2, mesh3 );
+			var mesh3 = new Mesh();
+			mesh3.name = 'mesh3';
 
-      var clip1 = new THREE.AnimationClip( 'clip1', undefined, [
+			var scene = new Scene();
+			scene.add( mesh1, mesh2, mesh3 );
 
-        new THREE.VectorKeyframeTrack( 'mesh1.position', [ 0, 1, 2 ], [ 0, 0, 0, 30, 0, 0, 0, 0, 0 ] )
+			var clip1 = new AnimationClip( 'clip1', undefined, [
 
-      ] );
+				new VectorKeyframeTrack( 'mesh1.position', [ 0, 1, 2 ], [ 0, 0, 0, 30, 0, 0, 0, 0, 0 ] )
 
-      var clip2 = new THREE.AnimationClip( 'clip2', undefined, [
+			] );
 
-        new THREE.VectorKeyframeTrack( 'mesh3.scale', [ 0, 1, 2 ], [ 1, 1, 1, 2, 2, 2, 1, 1, 1 ] )
+			var clip2 = new AnimationClip( 'clip2', undefined, [
 
-      ] );
+				new VectorKeyframeTrack( 'mesh3.scale', [ 0, 1, 2 ], [ 1, 1, 1, 2, 2, 2, 1, 1, 1 ] )
 
-      var exporter = new THREE.GLTFExporter();
+			] );
 
-      exporter.parse( scene, function ( gltf ) {
+			var exporter = new GLTFExporter();
 
-        assert.equal( 2, gltf.animations.length, 'one animation per clip' );
+			exporter.parse( scene, function ( gltf ) {
 
-        var target1 = gltf.animations[ 0 ].channels[ 0 ].target;
-        var target2 = gltf.animations[ 1 ].channels[ 0 ].target;
+				assert.equal( 2, gltf.animations.length, 'one animation per clip' );
 
-        assert.equal( 'mesh1', gltf.nodes[ target1.node ].name, 'clip1 node' );
-        assert.equal( 'translation', target1.path, 'clip1 property' );
-        assert.equal( 'mesh3', gltf.nodes[ target2.node ].name, 'clip2 node' );
-        assert.equal( 'scale', target2.path, 'clip2 property' );
+				var target1 = gltf.animations[ 0 ].channels[ 0 ].target;
+				var target2 = gltf.animations[ 1 ].channels[ 0 ].target;
 
-        done();
+				assert.equal( 'mesh1', gltf.nodes[ target1.node ].name, 'clip1 node' );
+				assert.equal( 'translation', target1.path, 'clip1 property' );
+				assert.equal( 'mesh3', gltf.nodes[ target2.node ].name, 'clip2 node' );
+				assert.equal( 'scale', target2.path, 'clip2 property' );
 
-      }, { animations: [ clip1, clip2 ] } );
+				done();
 
-    } );
+			}, { animations: [ clip1, clip2 ] } );
 
-    QUnit.test( 'parse - empty buffergeometry', ( assert ) => {
+		} );
 
-      var done = assert.async();
+		QUnit.test( 'parse - empty buffergeometry', ( assert ) => {
 
-      var scene = new THREE.Scene();
-      var geometry = new THREE.BufferGeometry();
-      var numElements = 6;
+			var done = assert.async();
 
-      var positions = new Float32Array( ( numElements ) * 3 );
-      var colors = new Float32Array( ( numElements ) * 3 );
+			var scene = new Scene();
+			var geometry = new BufferGeometry();
+			var numElements = 6;
 
-      geometry.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ) );
-      geometry.addAttribute( 'color', new THREE.BufferAttribute( colors, 3 ) );
-      geometry.setDrawRange( 0, 0 );
+			var positions = new Float32Array( ( numElements ) * 3 );
+			var colors = new Float32Array( ( numElements ) * 3 );
 
-      var empty = new THREE.Mesh( geometry, new THREE.MeshBasicMaterial( { side: THREE.DoubleSide, vertexColors: THREE.VertexColors } ) );
-      empty.name = 'Custom buffered empty (drawrange)';
-      scene.add( empty );
+			geometry.addAttribute( 'position', new BufferAttribute( positions, 3 ) );
+			geometry.addAttribute( 'color', new BufferAttribute( colors, 3 ) );
+			geometry.setDrawRange( 0, 0 );
 
-      var exporter = new THREE.GLTFExporter();
+			var empty = new Mesh( geometry, new MeshBasicMaterial( { side: DoubleSide, vertexColors: VertexColors } ) );
+			empty.name = 'Custom buffered empty (drawrange)';
+			scene.add( empty );
 
-      exporter.parse( scene, function ( gltf ) {
+			var exporter = new GLTFExporter();
 
-        assert.equal( gltf.meshes, undefined, 'empty meshes');
-        assert.equal( gltf.materials, undefined, 'empty materials');
-        assert.equal( gltf.bufferViews, undefined, 'empty bufferViews');
-        assert.equal( gltf.buffers, undefined, 'buffers');
-        assert.equal( gltf.accessors, undefined, 'accessors');
-        assert.equal( gltf.nodes[0].mesh, undefined, 'nodes[0].mesh');
+			exporter.parse( scene, function ( gltf ) {
 
-        done();
+				assert.equal( gltf.meshes, undefined, 'empty meshes' );
+				assert.equal( gltf.materials, undefined, 'empty materials' );
+				assert.equal( gltf.bufferViews, undefined, 'empty bufferViews' );
+				assert.equal( gltf.buffers, undefined, 'buffers' );
+				assert.equal( gltf.accessors, undefined, 'accessors' );
+				assert.equal( gltf.nodes[ 0 ].mesh, undefined, 'nodes[0].mesh' );
 
-      });
+				done();
 
-    } );
+			} );
 
-    QUnit.test( 'parse - individual morph targets', ( assert ) => {
+		} );
 
-      var done = assert.async();
+		QUnit.test( 'parse - individual morph targets', ( assert ) => {
 
-      // Creates a geometry with four (4) morph targets, three (3) of which are
-      // animated by an animation clip. Because glTF requires all morph targets
-      // to be animated in unison, the exporter should write an empty track for
-      // the fourth target.
+			var done = assert.async();
 
-      var geometry = new THREE.BufferGeometry();
-      var position = new THREE.BufferAttribute( new Float32Array( [ 0, 0, 0, 0, 0, 1, 1, 0, 1 ] ), 3 );
-      geometry.addAttribute( 'position',  position );
-      geometry.morphAttributes.position = [ position, position, position, position ];
+			// Creates a geometry with four (4) morph targets, three (3) of which are
+			// animated by an animation clip. Because glTF requires all morph targets
+			// to be animated in unison, the exporter should write an empty track for
+			// the fourth target.
 
-      var mesh = new THREE.Mesh( geometry );
-      mesh.morphTargetDictionary.a = 0;
-      mesh.morphTargetDictionary.b = 1;
-      mesh.morphTargetDictionary.c = 2;
-      mesh.morphTargetDictionary.d = 3;
+			var geometry = new BufferGeometry();
+			var position = new BufferAttribute( new Float32Array( [ 0, 0, 0, 0, 0, 1, 1, 0, 1 ] ), 3 );
+			geometry.addAttribute( 'position',	position );
+			geometry.morphAttributes.position = [ position, position, position, position ];
 
-      var timesA =  [ 0, 1, 2 ];
-      var timesB =  [       2, 3, 4 ];
-      var timesC =  [             4, 5, 6 ];
-      var valuesA = [ 0, 1, 0 ];
-      var valuesB = [       0, 1, 0 ];
-      var valuesC = [             0, 1, 0 ];
-      var trackA = new THREE.VectorKeyframeTrack( '.morphTargetInfluences[a]', timesA, valuesA, THREE.InterpolateLinear );
-      var trackB = new THREE.VectorKeyframeTrack( '.morphTargetInfluences[b]', timesB, valuesB, THREE.InterpolateLinear );
-      var trackC = new THREE.VectorKeyframeTrack( '.morphTargetInfluences[c]', timesC, valuesC, THREE.InterpolateLinear );
+			var mesh = new Mesh( geometry );
+			mesh.morphTargetDictionary.a = 0;
+			mesh.morphTargetDictionary.b = 1;
+			mesh.morphTargetDictionary.c = 2;
+			mesh.morphTargetDictionary.d = 3;
 
-      var clip = new THREE.AnimationClip( 'clip1', undefined, [ trackA, trackB, trackC ] );
+			var timesA =	[ 0, 1, 2 ];
+			var timesB =	[			 2, 3, 4 ];
+			var timesC =	[						 4, 5, 6 ];
+			var valuesA = [ 0, 1, 0 ];
+			var valuesB = [			 0, 1, 0 ];
+			var valuesC = [						 0, 1, 0 ];
+			var trackA = new VectorKeyframeTrack( '.morphTargetInfluences[a]', timesA, valuesA, InterpolateLinear );
+			var trackB = new VectorKeyframeTrack( '.morphTargetInfluences[b]', timesB, valuesB, InterpolateLinear );
+			var trackC = new VectorKeyframeTrack( '.morphTargetInfluences[c]', timesC, valuesC, InterpolateLinear );
 
-      var exporter = new THREE.GLTFExporter();
+			var clip = new AnimationClip( 'clip1', undefined, [ trackA, trackB, trackC ] );
 
-      exporter.parse( mesh, function ( gltf ) {
+			var exporter = new GLTFExporter();
 
-        assert.equal( 1, gltf.animations.length, 'one animation' );
-        assert.equal( 1, gltf.animations[ 0 ].channels.length, 'one channel' );
-        assert.equal( 1, gltf.animations[ 0 ].samplers.length, 'one sampler' );
+			exporter.parse( mesh, function ( gltf ) {
 
-        var channel = gltf.animations[ 0 ].channels[ 0 ];
-        var sampler = gltf.animations[ 0 ].samplers[ 0 ];
+				assert.equal( 1, gltf.animations.length, 'one animation' );
+				assert.equal( 1, gltf.animations[ 0 ].channels.length, 'one channel' );
+				assert.equal( 1, gltf.animations[ 0 ].samplers.length, 'one sampler' );
 
-        assert.smartEqual( channel, { sampler: 0, target: { node: 0, path: 'weights' } } );
-        assert.equal( sampler.interpolation, 'LINEAR' );
+				var channel = gltf.animations[ 0 ].channels[ 0 ];
+				var sampler = gltf.animations[ 0 ].samplers[ 0 ];
 
-        var input = gltf.accessors[ sampler.input ];
-        var output = gltf.accessors[ sampler.output ];
+				assert.smartEqual( channel, { sampler: 0, target: { node: 0, path: 'weights' } } );
+				assert.equal( sampler.interpolation, 'LINEAR' );
 
-        assert.equal( input.count, 7 );
-        assert.equal( input.type, 'SCALAR' );
-        assert.smartEqual( input.min, [ 0 ] );
-        assert.smartEqual( input.max, [ 6 ] );
+				var input = gltf.accessors[ sampler.input ];
+				var output = gltf.accessors[ sampler.output ];
 
-        assert.equal( output.count, 28 ); // 4 targets * 7 frames
-        assert.equal( output.type, 'SCALAR' );
-        assert.smartEqual( output.min, [ 0 ] );
-        assert.smartEqual( output.max, [ 1 ] );
+				assert.equal( input.count, 7 );
+				assert.equal( input.type, 'SCALAR' );
+				assert.smartEqual( input.min, [ 0 ] );
+				assert.smartEqual( input.max, [ 6 ] );
 
-        done();
+				assert.equal( output.count, 28 ); // 4 targets * 7 frames
+				assert.equal( output.type, 'SCALAR' );
+				assert.smartEqual( output.min, [ 0 ] );
+				assert.smartEqual( output.max, [ 1 ] );
 
-      }, { animations: [ clip ] } );
+				done();
 
-    } );
+			}, { animations: [ clip ] } );
 
-    QUnit.test( 'utils - insertKeyframe', ( assert ) => {
+		} );
 
-      var track;
-      var index;
+		QUnit.test( 'utils - insertKeyframe', ( assert ) => {
 
-      function createTrack () {
-        return new VectorKeyframeTrack(
-          'foo.bar',
-          [ 5,    10,   15,   20,   25,   30 ],
-          [ 0, 5, 1, 4, 2, 3, 3, 2, 4, 1, 5, 0 ],
-          InterpolateLinear
-        );
-      }
+			var track;
+			var index;
 
-      track = createTrack();
-      index = THREE.GLTFExporter.Utils.insertKeyframe( track, 0 );
-      assert.equal( index, 0, 'prepend - index' );
-      assert.smartEqual( Array.from( track.times ), [ 0, 5, 10, 15, 20, 25, 30 ], 'prepend - time' );
-      assert.smartEqual( Array.from( track.values ), [ 0, 5, 0, 5, 1, 4, 2, 3, 3, 2, 4, 1, 5, 0 ], 'prepend - value' );
+			function createTrack() {
 
-      track = createTrack();
-      index = THREE.GLTFExporter.Utils.insertKeyframe( track, 7.5 );
-      assert.equal( index, 1, 'insert - index (linear)' );
-      assert.smartEqual( Array.from( track.times ), [ 5, 7.5, 10, 15, 20, 25, 30 ], 'insert - time (linear)' );
-      assert.smartEqual( Array.from( track.values ), [ 0, 5, 0.5, 4.5, 1, 4, 2, 3, 3, 2, 4, 1, 5, 0 ], 'insert - value (linear)' );
+				return new VectorKeyframeTrack(
+					'foo.bar',
+					[ 5,		10,	 15,	 20,	 25,	 30 ],
+					[ 0, 5, 1, 4, 2, 3, 3, 2, 4, 1, 5, 0 ],
+					InterpolateLinear
+				);
 
-      track = createTrack();
-      track.setInterpolation( InterpolateDiscrete );
-      index = THREE.GLTFExporter.Utils.insertKeyframe( track, 16 );
-      assert.equal( index, 3, 'insert - index (linear)' );
-      assert.smartEqual( Array.from( track.times ), [ 5, 10, 15, 16, 20, 25, 30 ], 'insert - time (discrete)' );
-      assert.smartEqual( Array.from( track.values ), [ 0, 5, 1, 4, 2, 3, 2, 3, 3, 2, 4, 1, 5, 0 ], 'insert - value (discrete)' );
+			}
 
-      track = createTrack();
-      index = THREE.GLTFExporter.Utils.insertKeyframe( track, 100 );
-      assert.equal( index, 6, 'append - index' );
-      assert.smartEqual( Array.from( track.times ), [ 5, 10, 15, 20, 25, 30, 100 ], 'append time' );
-      assert.smartEqual( Array.from( track.values ), [ 0, 5, 1, 4, 2, 3, 3, 2, 4, 1, 5, 0, 5, 0 ], 'append value' );
+			track = createTrack();
+			index = GLTFExporter.Utils.insertKeyframe( track, 0 );
+			assert.equal( index, 0, 'prepend - index' );
+			assert.smartEqual( Array.from( track.times ), [ 0, 5, 10, 15, 20, 25, 30 ], 'prepend - time' );
+			assert.smartEqual( Array.from( track.values ), [ 0, 5, 0, 5, 1, 4, 2, 3, 3, 2, 4, 1, 5, 0 ], 'prepend - value' );
 
-      track = createTrack();
-      index = THREE.GLTFExporter.Utils.insertKeyframe( track, 15 );
-      assert.equal( index, 2, 'existing - index' );
-      assert.smartEqual( Array.from( track.times ), [ 5, 10, 15, 20, 25, 30 ], 'existing - time' );
-      assert.smartEqual( Array.from( track.values ), [ 0, 5, 1, 4, 2, 3, 3, 2, 4, 1, 5, 0 ], 'existing - value' );
+			track = createTrack();
+			index = GLTFExporter.Utils.insertKeyframe( track, 7.5 );
+			assert.equal( index, 1, 'insert - index (linear)' );
+			assert.smartEqual( Array.from( track.times ), [ 5, 7.5, 10, 15, 20, 25, 30 ], 'insert - time (linear)' );
+			assert.smartEqual( Array.from( track.values ), [ 0, 5, 0.5, 4.5, 1, 4, 2, 3, 3, 2, 4, 1, 5, 0 ], 'insert - value (linear)' );
 
-      track = createTrack();
-      index = THREE.GLTFExporter.Utils.insertKeyframe( track, 20.000005 );
-      assert.equal( index, 3, 'tolerance - index' );
-      assert.smartEqual( Array.from( track.times ), [ 5, 10, 15, 20, 25, 30 ], 'tolerance - time' );
-      assert.smartEqual( Array.from( track.values ), [ 0, 5, 1, 4, 2, 3, 3, 2, 4, 1, 5, 0 ], 'tolerance - value' );
+			track = createTrack();
+			track.setInterpolation( InterpolateDiscrete );
+			index = GLTFExporter.Utils.insertKeyframe( track, 16 );
+			assert.equal( index, 3, 'insert - index (linear)' );
+			assert.smartEqual( Array.from( track.times ), [ 5, 10, 15, 16, 20, 25, 30 ], 'insert - time (discrete)' );
+			assert.smartEqual( Array.from( track.values ), [ 0, 5, 1, 4, 2, 3, 2, 3, 3, 2, 4, 1, 5, 0 ], 'insert - value (discrete)' );
 
-    } );
+			track = createTrack();
+			index = GLTFExporter.Utils.insertKeyframe( track, 100 );
+			assert.equal( index, 6, 'append - index' );
+			assert.smartEqual( Array.from( track.times ), [ 5, 10, 15, 20, 25, 30, 100 ], 'append time' );
+			assert.smartEqual( Array.from( track.values ), [ 0, 5, 1, 4, 2, 3, 3, 2, 4, 1, 5, 0, 5, 0 ], 'append value' );
 
-    QUnit.test( 'utils - mergeMorphTargetTracks', ( assert ) => {
+			track = createTrack();
+			index = GLTFExporter.Utils.insertKeyframe( track, 15 );
+			assert.equal( index, 2, 'existing - index' );
+			assert.smartEqual( Array.from( track.times ), [ 5, 10, 15, 20, 25, 30 ], 'existing - time' );
+			assert.smartEqual( Array.from( track.values ), [ 0, 5, 1, 4, 2, 3, 3, 2, 4, 1, 5, 0 ], 'existing - value' );
 
-      var trackA = new NumberKeyframeTrack(
-        'foo.morphTargetInfluences[a]',
-        [ 5, 10, 15, 20, 25, 30 ],
-        [ 0, 0.2, 0.4, 0.6, 0.8, 1.0 ],
-        InterpolateLinear
-      );
+			track = createTrack();
+			index = GLTFExporter.Utils.insertKeyframe( track, 20.000005 );
+			assert.equal( index, 3, 'tolerance - index' );
+			assert.smartEqual( Array.from( track.times ), [ 5, 10, 15, 20, 25, 30 ], 'tolerance - time' );
+			assert.smartEqual( Array.from( track.values ), [ 0, 5, 1, 4, 2, 3, 3, 2, 4, 1, 5, 0 ], 'tolerance - value' );
 
-      var trackB = new NumberKeyframeTrack(
-        'foo.morphTargetInfluences[b]',
-        [ 10, 50 ],
-        [ 0.25, 0.75 ],
-        InterpolateLinear
-      );
+		} );
 
-      var geometry = new BufferGeometry();
-      var position = new BufferAttribute( new Float32Array( [ 0, 0, 0, 0, 0, 1, 1, 0, 1 ] ), 3 );
-      geometry.addAttribute( 'position',  position );
-      geometry.morphAttributes.position = [ position, position ];
+		QUnit.test( 'utils - mergeMorphTargetTracks', ( assert ) => {
 
-      var mesh = new Mesh( geometry );
-      mesh.name = 'foo';
-      mesh.morphTargetDictionary.a = 0;
-      mesh.morphTargetDictionary.b = 1;
+			var trackA = new NumberKeyframeTrack(
+				'foo.morphTargetInfluences[a]',
+				[ 5, 10, 15, 20, 25, 30 ],
+				[ 0, 0.2, 0.4, 0.6, 0.8, 1.0 ],
+				InterpolateLinear
+			);
 
-      var root = new Object3D();
-      root.add( mesh );
+			var trackB = new NumberKeyframeTrack(
+				'foo.morphTargetInfluences[b]',
+				[ 10, 50 ],
+				[ 0.25, 0.75 ],
+				InterpolateLinear
+			);
 
-      var clip = new AnimationClip( 'waltz', undefined, [ trackA, trackB ] );
-      clip = THREE.GLTFExporter.Utils.mergeMorphTargetTracks( clip, root );
+			var geometry = new BufferGeometry();
+			var position = new BufferAttribute( new Float32Array( [ 0, 0, 0, 0, 0, 1, 1, 0, 1 ] ), 3 );
+			geometry.addAttribute( 'position',	position );
+			geometry.morphAttributes.position = [ position, position ];
 
-      assert.equal( clip.tracks.length, 1, 'tracks are merged' );
+			var mesh = new Mesh( geometry );
+			mesh.name = 'foo';
+			mesh.morphTargetDictionary.a = 0;
+			mesh.morphTargetDictionary.b = 1;
 
-      var track = clip.tracks[ 0 ];
+			var root = new Object3D();
+			root.add( mesh );
 
-      assert.smartEqual( Array.from( track.times ), [ 5, 10, 15, 20, 25, 30, 50 ], 'all keyframes are present' );
+			var clip = new AnimationClip( 'waltz', undefined, [ trackA, trackB ] );
+			clip = GLTFExporter.Utils.mergeMorphTargetTracks( clip, root );
 
-      var expectedValues = [ 0, 0.25, 0.2, 0.25, 0.4, 0.3125, 0.6, 0.375, 0.8, 0.4375, 1.0, 0.5, 1.0, 0.75 ];
+			assert.equal( clip.tracks.length, 1, 'tracks are merged' );
 
-      for ( var i = 0; i < track.values.length; i ++ ) {
+			var track = clip.tracks[ 0 ];
 
-        assert.numEqual( track.values[ i ], expectedValues[ i ], 'all values are merged or interpolated - ' + i );
+			assert.smartEqual( Array.from( track.times ), [ 5, 10, 15, 20, 25, 30, 50 ], 'all keyframes are present' );
 
-      }
+			var expectedValues = [ 0, 0.25, 0.2, 0.25, 0.4, 0.3125, 0.6, 0.375, 0.8, 0.4375, 1.0, 0.5, 1.0, 0.75 ];
 
-    } );
+			for ( var i = 0; i < track.values.length; i ++ ) {
 
-  } );
+				assert.numEqual( track.values[ i ], expectedValues[ i ], 'all values are merged or interpolated - ' + i );
+
+			}
+
+		} );
+
+	} );
 
 } );

+ 26 - 17
test/unit/example/loaders/GLTFLoader.tests.js

@@ -3,8 +3,17 @@
  */
 /* global QUnit */
 
-import * as GLTFExporter from '../../../../examples/js/exporters/GLTFExporter';
-import * as GLTFLoader from '../../../../examples/js/loaders/GLTFLoader';
+import { GLTFExporter } from '../../../../examples/jsm/exporters/GLTFExporter';
+import { GLTFLoader } from '../../../../examples/jsm/loaders/GLTFLoader';
+
+import { AnimationClip } from '../../../../src/animation/AnimationClip';
+import { BufferAttribute } from '../../../../src/core/BufferAttribute';
+import { BufferGeometry } from '../../../../src/core/BufferGeometry';
+import { Mesh } from '../../../../src/objects/Mesh';
+import { MeshStandardMaterial } from '../../../../src/materials/MeshStandardMaterial';
+import { Object3D } from '../../../../src/core/Object3D';
+import { Scene } from '../../../../src/scenes/Scene';
+import { VectorKeyframeTrack } from '../../../../src/animation/tracks/VectorKeyframeTrack';
 
 export default QUnit.module( 'Loaders', () => {
 
@@ -12,7 +21,7 @@ export default QUnit.module( 'Loaders', () => {
 
 		QUnit.test( 'constructor', ( assert ) => {
 
-			assert.ok( new THREE.GLTFLoader(), 'Can instantiate a loader.' );
+			assert.ok( new GLTFLoader(), 'Can instantiate a loader.' );
 
 		} );
 
@@ -20,19 +29,19 @@ export default QUnit.module( 'Loaders', () => {
 
 			var done = assert.async();
 
-			var geometry = new THREE.BufferGeometry();
+			var geometry = new BufferGeometry();
 			var array = new Float32Array( [
 				- 1, - 1, - 1,
 				1, 1, 1,
 				4, 4, 4
 			] );
-			geometry.addAttribute( 'position', new THREE.BufferAttribute( array, 3 ) );
+			geometry.addAttribute( 'position', new BufferAttribute( array, 3 ) );
 
-			var meshIn = new THREE.Mesh( geometry, new THREE.MeshStandardMaterial( { color: 0xFF0000 } ) );
+			var meshIn = new Mesh( geometry, new MeshStandardMaterial( { color: 0xFF0000 } ) );
 			meshIn.name = 'test_mesh';
 
-			var exporter = new THREE.GLTFExporter();
-			var loader = new THREE.GLTFLoader();
+			var exporter = new GLTFExporter();
+			var loader = new GLTFLoader();
 
 			exporter.parse( meshIn, function ( binary ) {
 
@@ -51,7 +60,7 @@ export default QUnit.module( 'Loaders', () => {
 
 				}, undefined, function ( e ) {
 
-					console.error(e);
+					console.error( e );
 
 				} );
 
@@ -63,23 +72,23 @@ export default QUnit.module( 'Loaders', () => {
 
 			var done = assert.async();
 
-			var node1 = new THREE.Object3D();
+			var node1 = new Object3D();
 			node1.name = 'node1';
 
-			var node2 = new THREE.Object3D();
+			var node2 = new Object3D();
 			node2.name = 'node2';
 
-			var scene = new THREE.Scene();
+			var scene = new Scene();
 			scene.add( node1, node2 );
 
-			var clip = new THREE.AnimationClip( 'clip', undefined, [
+			var clip = new AnimationClip( 'clip', undefined, [
 
-				new THREE.VectorKeyframeTrack( 'node1.position', [ 0, 1, 2 ], [ 0, 0, 0, 30, 0, 0, 0, 0, 0 ] )
+				new VectorKeyframeTrack( 'node1.position', [ 0, 1, 2 ], [ 0, 0, 0, 30, 0, 0, 0, 0, 0 ] )
 
 			] );
 
-			var exporter = new THREE.GLTFExporter();
-			var loader = new THREE.GLTFLoader();
+			var exporter = new GLTFExporter();
+			var loader = new GLTFLoader();
 
 			exporter.parse( scene, function ( binary ) {
 
@@ -95,7 +104,7 @@ export default QUnit.module( 'Loaders', () => {
 
 				}, undefined, function ( e ) {
 
-					console.error(e);
+					console.error( e );
 
 				} );
 

+ 1 - 1
test/unit/example/objects/Lensflare.tests.js

@@ -3,7 +3,7 @@
  */
 /* global QUnit */
 
-import * as Lensflare from '../../../../examples/js/objects/Lensflare';
+import { Lensflare } from '../../../../examples/jsm/objects/Lensflare';
 
 export default QUnit.module( 'Objects', () => {
 

+ 81 - 78
test/unit/example/utils/BufferGeometryUtils.tests.js

@@ -3,127 +3,130 @@
  */
 /* global QUnit */
 
-import * as BufferGeometryUtils from '../../../../examples/js/utils/BufferGeometryUtils';
+import { BufferGeometryUtils } from '../../../../examples/jsm/utils/BufferGeometryUtils';
+
+import { BufferAttribute } from '../../../../src/core/BufferAttribute';
+import { BufferGeometry } from '../../../../src/core/BufferGeometry';
 
 export default QUnit.module( 'BufferGeometryUtils', () => {
 
-  QUnit.test( 'mergeBufferAttributes - basic', ( assert ) => {
+	QUnit.test( 'mergeBufferAttributes - basic', ( assert ) => {
 
-    var array1 = new Float32Array( [ 1, 2, 3, 4 ] );
-    var attr1 = new THREE.BufferAttribute( array1, 2, false );
+		var array1 = new Float32Array( [ 1, 2, 3, 4 ] );
+		var attr1 = new BufferAttribute( array1, 2, false );
 
-    var array2 = new Float32Array( [ 5, 6, 7, 8 ] );
-    var attr2 = new THREE.BufferAttribute( array2, 2, false );
+		var array2 = new Float32Array( [ 5, 6, 7, 8 ] );
+		var attr2 = new BufferAttribute( array2, 2, false );
 
-    var mergedAttr = THREE.BufferGeometryUtils.mergeBufferAttributes( [ attr1, attr2 ] );
+		var mergedAttr = BufferGeometryUtils.mergeBufferAttributes( [ attr1, attr2 ] );
 
-    assert.smartEqual( Array.from( mergedAttr.array ), [ 1, 2, 3, 4, 5, 6, 7, 8 ], 'merges elements' );
-    assert.equal( mergedAttr.itemSize, 2, 'retains .itemSize' );
-    assert.equal( mergedAttr.normalized, false, 'retains .normalized' );
+		assert.smartEqual( Array.from( mergedAttr.array ), [ 1, 2, 3, 4, 5, 6, 7, 8 ], 'merges elements' );
+		assert.equal( mergedAttr.itemSize, 2, 'retains .itemSize' );
+		assert.equal( mergedAttr.normalized, false, 'retains .normalized' );
 
-  } );
+	} );
 
-  QUnit.test( 'mergeBufferAttributes - invalid', ( assert ) => {
+	QUnit.test( 'mergeBufferAttributes - invalid', ( assert ) => {
 
-    var array1 = new Float32Array( [ 1, 2, 3, 4 ] );
-    var attr1 = new THREE.BufferAttribute( array1, 2, false );
+		var array1 = new Float32Array( [ 1, 2, 3, 4 ] );
+		var attr1 = new BufferAttribute( array1, 2, false );
 
-    var array2 = new Float32Array( [ 5, 6, 7, 8 ] );
-    var attr2 = new THREE.BufferAttribute( array2, 4, false );
+		var array2 = new Float32Array( [ 5, 6, 7, 8 ] );
+		var attr2 = new BufferAttribute( array2, 4, false );
 
-    assert.notOk( THREE.BufferGeometryUtils.mergeBufferAttributes( [ attr1, attr2 ] ) );
+		assert.notOk( BufferGeometryUtils.mergeBufferAttributes( [ attr1, attr2 ] ) );
 
-    attr2.itemSize = 2;
-    attr2.normalized = true;
+		attr2.itemSize = 2;
+		attr2.normalized = true;
 
-    assert.notOk( THREE.BufferGeometryUtils.mergeBufferAttributes( [ attr1, attr2 ] ) );
+		assert.notOk( BufferGeometryUtils.mergeBufferAttributes( [ attr1, attr2 ] ) );
 
-    attr2.normalized = false;
+		attr2.normalized = false;
 
-    assert.ok( THREE.BufferGeometryUtils.mergeBufferAttributes( [ attr1, attr2 ] ) );
+		assert.ok( BufferGeometryUtils.mergeBufferAttributes( [ attr1, attr2 ] ) );
 
-  } );
+	} );
 
-  QUnit.test( 'mergeBufferGeometries - basic', ( assert ) => {
+	QUnit.test( 'mergeBufferGeometries - basic', ( assert ) => {
 
-    var geometry1 = new THREE.BufferGeometry();
-    geometry1.addAttribute( 'position', new THREE.BufferAttribute( new Float32Array( [ 1, 2, 3 ] ), 1, false ) );
+		var geometry1 = new BufferGeometry();
+		geometry1.addAttribute( 'position', new BufferAttribute( new Float32Array( [ 1, 2, 3 ] ), 1, false ) );
 
-    var geometry2 = new THREE.BufferGeometry();
-    geometry2.addAttribute( 'position', new THREE.BufferAttribute( new Float32Array( [ 4, 5, 6 ] ), 1, false ) );
+		var geometry2 = new BufferGeometry();
+		geometry2.addAttribute( 'position', new BufferAttribute( new Float32Array( [ 4, 5, 6 ] ), 1, false ) );
 
-    var mergedGeometry = THREE.BufferGeometryUtils.mergeBufferGeometries( [ geometry1, geometry2 ] );
+		var mergedGeometry = BufferGeometryUtils.mergeBufferGeometries( [ geometry1, geometry2 ] );
 
-    assert.ok( mergedGeometry, 'merge succeeds' );
-    assert.smartEqual( Array.from( mergedGeometry.attributes.position.array ), [ 1, 2, 3, 4, 5, 6 ], 'merges elements' );
-    assert.equal( mergedGeometry.attributes.position.itemSize, 1, 'retains .itemSize' );
+		assert.ok( mergedGeometry, 'merge succeeds' );
+		assert.smartEqual( Array.from( mergedGeometry.attributes.position.array ), [ 1, 2, 3, 4, 5, 6 ], 'merges elements' );
+		assert.equal( mergedGeometry.attributes.position.itemSize, 1, 'retains .itemSize' );
 
-  } );
+	} );
 
-  QUnit.test( 'mergeBufferGeometries - indexed', ( assert ) => {
+	QUnit.test( 'mergeBufferGeometries - indexed', ( assert ) => {
 
-    var geometry1 = new THREE.BufferGeometry();
-    geometry1.addAttribute( 'position', new THREE.BufferAttribute( new Float32Array( [ 1, 2, 3 ] ), 1, false ) );
-    geometry1.setIndex( new THREE.BufferAttribute( new Uint16Array( [ 0, 1, 2, 2, 1, 0 ] ), 1, false ) );
+		var geometry1 = new BufferGeometry();
+		geometry1.addAttribute( 'position', new BufferAttribute( new Float32Array( [ 1, 2, 3 ] ), 1, false ) );
+		geometry1.setIndex( new BufferAttribute( new Uint16Array( [ 0, 1, 2, 2, 1, 0 ] ), 1, false ) );
 
-    var geometry2 = new THREE.BufferGeometry();
-    geometry2.addAttribute( 'position', new THREE.BufferAttribute( new Float32Array( [ 4, 5, 6 ] ), 1, false ) );
-    geometry2.setIndex( new THREE.BufferAttribute( new Uint16Array( [ 0, 1, 2 ] ), 1, false ) );
+		var geometry2 = new BufferGeometry();
+		geometry2.addAttribute( 'position', new BufferAttribute( new Float32Array( [ 4, 5, 6 ] ), 1, false ) );
+		geometry2.setIndex( new BufferAttribute( new Uint16Array( [ 0, 1, 2 ] ), 1, false ) );
 
-    var mergedGeometry = THREE.BufferGeometryUtils.mergeBufferGeometries( [ geometry1, geometry2 ] );
+		var mergedGeometry = BufferGeometryUtils.mergeBufferGeometries( [ geometry1, geometry2 ] );
 
-    assert.ok( mergedGeometry, 'merge succeeds' );
-    assert.smartEqual( Array.from( mergedGeometry.attributes.position.array ), [ 1, 2, 3, 4, 5, 6 ], 'merges elements' );
-    assert.smartEqual( Array.from( mergedGeometry.index.array ), [ 0, 1, 2, 2, 1, 0, 3, 4, 5 ], 'merges indices' );
-    assert.equal( mergedGeometry.attributes.position.itemSize, 1, 'retains .itemSize' );
+		assert.ok( mergedGeometry, 'merge succeeds' );
+		assert.smartEqual( Array.from( mergedGeometry.attributes.position.array ), [ 1, 2, 3, 4, 5, 6 ], 'merges elements' );
+		assert.smartEqual( Array.from( mergedGeometry.index.array ), [ 0, 1, 2, 2, 1, 0, 3, 4, 5 ], 'merges indices' );
+		assert.equal( mergedGeometry.attributes.position.itemSize, 1, 'retains .itemSize' );
 
-  } );
+	} );
 
-  QUnit.test( 'mergeBufferGeometries - morph targets', ( assert ) => {
+	QUnit.test( 'mergeBufferGeometries - morph targets', ( assert ) => {
 
-    var geometry1 = new THREE.BufferGeometry();
-    geometry1.addAttribute( 'position', new THREE.BufferAttribute( new Float32Array( [ 1, 2, 3 ] ), 1, false ) );
-    geometry1.morphAttributes.position = [
-      new THREE.BufferAttribute( new Float32Array( [ 10, 20, 30 ] ), 1, false ),
-      new THREE.BufferAttribute( new Float32Array( [ 100, 200, 300 ] ), 1, false )
-    ];
+		var geometry1 = new BufferGeometry();
+		geometry1.addAttribute( 'position', new BufferAttribute( new Float32Array( [ 1, 2, 3 ] ), 1, false ) );
+		geometry1.morphAttributes.position = [
+			new BufferAttribute( new Float32Array( [ 10, 20, 30 ] ), 1, false ),
+			new BufferAttribute( new Float32Array( [ 100, 200, 300 ] ), 1, false )
+		];
 
-    var geometry2 = new THREE.BufferGeometry();
-    geometry2.addAttribute( 'position', new THREE.BufferAttribute( new Float32Array( [ 4, 5, 6 ] ), 1, false ) );
-    geometry2.morphAttributes.position = [
-      new THREE.BufferAttribute( new Float32Array( [ 40, 50, 60 ] ), 1, false ),
-      new THREE.BufferAttribute( new Float32Array( [ 400, 500, 600 ] ), 1, false )
-    ];
+		var geometry2 = new BufferGeometry();
+		geometry2.addAttribute( 'position', new BufferAttribute( new Float32Array( [ 4, 5, 6 ] ), 1, false ) );
+		geometry2.morphAttributes.position = [
+			new BufferAttribute( new Float32Array( [ 40, 50, 60 ] ), 1, false ),
+			new BufferAttribute( new Float32Array( [ 400, 500, 600 ] ), 1, false )
+		];
 
-    var mergedGeometry = THREE.BufferGeometryUtils.mergeBufferGeometries( [ geometry1, geometry2 ] );
+		var mergedGeometry = BufferGeometryUtils.mergeBufferGeometries( [ geometry1, geometry2 ] );
 
-    assert.ok( mergedGeometry, 'merge succeeds' );
-    assert.smartEqual( Array.from( mergedGeometry.attributes.position.array ), [ 1, 2, 3, 4, 5, 6 ], 'merges elements' );
-    assert.smartEqual( Array.from( mergedGeometry.morphAttributes.position[ 0 ].array ), [ 10, 20, 30, 40, 50, 60 ], 'merges morph targets' );
-    assert.smartEqual( Array.from( mergedGeometry.morphAttributes.position[ 1 ].array ), [ 100, 200, 300, 400, 500, 600 ], 'merges morph targets' );
-    assert.equal( mergedGeometry.attributes.position.itemSize, 1, 'retains .itemSize' );
+		assert.ok( mergedGeometry, 'merge succeeds' );
+		assert.smartEqual( Array.from( mergedGeometry.attributes.position.array ), [ 1, 2, 3, 4, 5, 6 ], 'merges elements' );
+		assert.smartEqual( Array.from( mergedGeometry.morphAttributes.position[ 0 ].array ), [ 10, 20, 30, 40, 50, 60 ], 'merges morph targets' );
+		assert.smartEqual( Array.from( mergedGeometry.morphAttributes.position[ 1 ].array ), [ 100, 200, 300, 400, 500, 600 ], 'merges morph targets' );
+		assert.equal( mergedGeometry.attributes.position.itemSize, 1, 'retains .itemSize' );
 
-  } );
+	} );
 
-  QUnit.test( 'mergeBufferGeometries - invalid', ( assert ) => {
+	QUnit.test( 'mergeBufferGeometries - invalid', ( assert ) => {
 
-    var geometry1 = new THREE.BufferGeometry();
-    geometry1.addAttribute( 'position', new THREE.BufferAttribute( new Float32Array( [ 1, 2, 3 ] ), 1, false ) );
-    geometry1.setIndex( new THREE.BufferAttribute( new Uint16Array( [ 0, 1, 2 ] ), 1, false ) );
+		var geometry1 = new BufferGeometry();
+		geometry1.addAttribute( 'position', new BufferAttribute( new Float32Array( [ 1, 2, 3 ] ), 1, false ) );
+		geometry1.setIndex( new BufferAttribute( new Uint16Array( [ 0, 1, 2 ] ), 1, false ) );
 
-    var geometry2 = new THREE.BufferGeometry();
-    geometry2.addAttribute( 'position', new THREE.BufferAttribute( new Float32Array( [ 4, 5, 6 ] ), 1, false ) );
+		var geometry2 = new BufferGeometry();
+		geometry2.addAttribute( 'position', new BufferAttribute( new Float32Array( [ 4, 5, 6 ] ), 1, false ) );
 
-    assert.notOk( THREE.BufferGeometryUtils.mergeBufferGeometries( [ geometry1, geometry2 ] ) );
+		assert.notOk( BufferGeometryUtils.mergeBufferGeometries( [ geometry1, geometry2 ] ) );
 
-    geometry2.setIndex( new THREE.BufferAttribute( new Uint16Array( [ 0, 1, 2 ] ), 1, false ) );
+		geometry2.setIndex( new BufferAttribute( new Uint16Array( [ 0, 1, 2 ] ), 1, false ) );
 
-    assert.ok( THREE.BufferGeometryUtils.mergeBufferGeometries( [ geometry1, geometry2 ] ) );
+		assert.ok( BufferGeometryUtils.mergeBufferGeometries( [ geometry1, geometry2 ] ) );
 
-    geometry2.addAttribute( 'foo', new THREE.BufferAttribute( new Float32Array( [ 1, 2, 3 ] ), 1, false ) );
+		geometry2.addAttribute( 'foo', new BufferAttribute( new Float32Array( [ 1, 2, 3 ] ), 1, false ) );
 
-    assert.notOk( THREE.BufferGeometryUtils.mergeBufferGeometries( [ geometry1, geometry2 ] ) );
+		assert.notOk( BufferGeometryUtils.mergeBufferGeometries( [ geometry1, geometry2 ] ) );
 
-  } );
+	} );
 
 } );