Browse Source

Merge remote-tracking branch 'mrdoob/dev' into dev

Kyle Larson 8 years ago
parent
commit
24f5862bc3
78 changed files with 5456 additions and 1343 deletions
  1. 242 181
      build/three.js
  2. 301 300
      build/three.min.js
  3. 242 181
      build/three.module.js
  4. 2 2
      docs/api/animation/AnimationUtils.html
  5. 4 4
      docs/api/extras/SceneUtils.html
  6. 1 1
      docs/api/helpers/ArrowHelper.html
  7. 1 1
      docs/api/helpers/AxisHelper.html
  8. 1 1
      docs/api/helpers/BoxHelper.html
  9. 2 3
      docs/api/helpers/CameraHelper.html
  10. 1 1
      docs/api/helpers/DirectionalLightHelper.html
  11. 1 1
      docs/api/helpers/FaceNormalsHelper.html
  12. 1 1
      docs/api/helpers/GridHelper.html
  13. 1 1
      docs/api/helpers/HemisphereLightHelper.html
  14. 1 1
      docs/api/helpers/PointLightHelper.html
  15. 1 1
      docs/api/helpers/PolarGridHelper.html
  16. 1 1
      docs/api/helpers/RectAreaLightHelper.html
  17. 1 1
      docs/api/helpers/SkeletonHelper.html
  18. 1 1
      docs/api/helpers/SpotLightHelper.html
  19. 1 1
      docs/api/helpers/VertexNormalsHelper.html
  20. 1 1
      docs/api/lights/RectAreaLight.html
  21. 2 2
      docs/api/objects/Line.html
  22. 2 2
      docs/api/objects/LineSegments.html
  23. 17 17
      docs/list.js
  24. 22 0
      editor/js/libs/app/index.html
  25. 47 55
      examples/js/Mirror.js
  26. 134 148
      examples/js/SkyShader.js
  27. 118 123
      examples/js/WaterShader.js
  28. 1 1
      examples/js/loaders/AssimpJSONLoader.js
  29. 1 9
      examples/js/loaders/FBXLoader.js
  30. 3860 0
      examples/js/loaders/FBXLoader2.js
  31. 47 19
      examples/js/loaders/GLTFLoader.js
  32. 1 1
      examples/js/loaders/MMDLoader.js
  33. 4 1
      examples/js/loaders/PLYLoader.js
  34. 13 7
      examples/js/pmrem/PMREMCubeUVPacker.js
  35. 17 7
      examples/js/pmrem/PMREMGenerator.js
  36. 3 0
      examples/js/postprocessing/AdaptiveToneMappingPass.js
  37. 2 0
      examples/js/postprocessing/BloomPass.js
  38. 2 0
      examples/js/postprocessing/BokehPass.js
  39. 2 1
      examples/js/postprocessing/EffectComposer.js
  40. 7 0
      examples/js/postprocessing/OutlinePass.js
  41. 4 0
      examples/js/postprocessing/SMAAPass.js
  42. 20 9
      examples/js/postprocessing/SSAARenderPass.js
  43. 4 4
      examples/js/postprocessing/SavePass.js
  44. 25 13
      examples/js/postprocessing/TAARenderPass.js
  45. 3 0
      examples/js/postprocessing/UnrealBloomPass.js
  46. 5 37
      examples/webgl_loader_fbx.html
  47. 1 0
      examples/webgl_postprocessing_ssao.html
  48. 3 1
      examples/webgl_shaders_ocean.html
  49. 1 1
      package.json
  50. 1 1
      src/animation/PropertyBinding.js
  51. 1 0
      src/cameras/CubeCamera.js
  52. 1 1
      src/constants.js
  53. 12 3
      src/core/BufferGeometry.js
  54. 3 3
      src/geometries/BoxGeometry.js
  55. 2 2
      src/geometries/CircleGeometry.js
  56. 2 2
      src/geometries/CylinderGeometry.js
  57. 41 26
      src/geometries/EdgesGeometry.js
  58. 3 3
      src/geometries/LatheGeometry.js
  59. 11 14
      src/geometries/ParametricGeometry.js
  60. 2 2
      src/geometries/PlaneGeometry.js
  61. 0 3
      src/geometries/PolyhedronGeometry.js
  62. 3 3
      src/geometries/RingGeometry.js
  63. 2 2
      src/geometries/ShapeGeometry.js
  64. 2 2
      src/geometries/SphereGeometry.js
  65. 1 1
      src/geometries/TextGeometry.js
  66. 2 2
      src/geometries/TorusGeometry.js
  67. 2 2
      src/geometries/TorusKnotGeometry.js
  68. 2 2
      src/geometries/TubeGeometry.js
  69. 82 85
      src/geometries/WireframeGeometry.js
  70. 11 5
      src/helpers/ArrowHelper.js
  71. 3 0
      src/loaders/ObjectLoader.js
  72. 39 25
      src/renderers/WebGLRenderer.js
  73. 2 1
      src/renderers/webgl/WebGLIndexedBufferRenderer.js
  74. 3 4
      src/renderers/webgl/WebGLObjects.js
  75. 4 3
      src/renderers/webgl/WebGLShadowMap.js
  76. 2 0
      src/textures/Texture.js
  77. 39 0
      src/utils.js
  78. 3 3
      utils/exporters/blender/addons/io_three/constants.py

+ 242 - 181
build/three.js

@@ -181,7 +181,7 @@
 
 	};
 
-	var REVISION = '84dev';
+	var REVISION = '85dev';
 	var MOUSE = { LEFT: 0, MIDDLE: 1, RIGHT: 2 };
 	var CullFaceNone = 0;
 	var CullFaceBack = 1;
@@ -1034,6 +1034,8 @@
 
 		copy: function ( source ) {
 
+			this.name = source.name;
+
 			this.image = source.image;
 			this.mipmaps = source.mipmaps.slice( 0 );
 
@@ -9238,6 +9240,7 @@
 					var pars = { minFilter: NearestFilter, magFilter: NearestFilter, format: RGBAFormat };
 
 					shadow.map = new WebGLRenderTarget( _shadowMapSize.x, _shadowMapSize.y, pars );
+					shadow.map.texture.name = light.name + ".shadowMap";
 
 					shadowCamera.updateProjectionMatrix();
 
@@ -9250,7 +9253,7 @@
 				}
 
 				// TODO (abelnation / sam-g-steel): is this needed?
-				if (shadow && shadow.isRectAreaLightShadow ) {
+				if ( shadow && shadow.isRectAreaLightShadow ) {
 
 					shadow.update( light );
 
@@ -9355,8 +9358,8 @@
 			}
 
 			// Restore GL state.
-			var clearColor = _renderer.getClearColor(),
-			clearAlpha = _renderer.getClearAlpha();
+			var clearColor = _renderer.getClearColor();
+			var clearAlpha = _renderer.getClearAlpha();
 			_renderer.setClearColor( clearColor, clearAlpha );
 
 			scope.needsUpdate = false;
@@ -12393,6 +12396,26 @@
 
 	} );
 
+	// http://stackoverflow.com/questions/1669190/javascript-min-max-array-values/13440842#13440842
+
+	function arrayMax( array ) {
+
+		var length = array.length, max = - Infinity;
+
+		while ( length -- ) {
+
+			if ( array[ length ] > max ) {
+
+				max = array[ length ];
+
+			}
+
+		}
+
+		return max;
+
+	}
+
 	/**
 	 * @author mrdoob / http://mrdoob.com/
 	 * @author kile / http://kile.stravaganza.org/
@@ -13867,7 +13890,15 @@
 
 		setIndex: function ( index ) {
 
-			this.index = index;
+			if ( Array.isArray( index ) ) {
+
+				this.index = new ( arrayMax( index ) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( index, 1 );
+
+			} else {
+
+				this.index = index;
+
+			}
 
 		},
 
@@ -14323,7 +14354,7 @@
 
 			if ( geometry.indices.length > 0 ) {
 
-				var TypeArray = geometry.vertices.length > 65535 ? Uint32Array : Uint16Array;
+				var TypeArray = arrayMax( geometry.indices ) > 65535 ? Uint32Array : Uint16Array;
 				var indices = new TypeArray( geometry.indices.length * 3 );
 				this.setIndex( new BufferAttribute( indices, 1 ).copyIndicesArray( geometry.indices ) );
 
@@ -15339,14 +15370,14 @@
 
 		// build geometry
 
-		this.setIndex( new ( indices.length > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( indices, 1 ) );
+		this.setIndex( indices );
 		this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
 		this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
 		this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
 
 		function buildPlane( u, v, w, udir, vdir, width, height, depth, gridX, gridY, materialIndex ) {
 
-			var segmentWidth	= width / gridX;
+			var segmentWidth = width / gridX;
 			var segmentHeight = height / gridY;
 
 			var widthHalf = width / 2;
@@ -15562,7 +15593,7 @@
 
 		// build geometry
 
-		this.setIndex( new ( indices.length > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( indices, 1 ) );
+		this.setIndex( indices );
 		this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
 		this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
 		this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
@@ -16013,9 +16044,10 @@
 				size = 2;
 
 			} else {
-				
+
 				type = gl.UNSIGNED_BYTE;
 				size = 1;
+
 			}
 
 		}
@@ -17576,7 +17608,6 @@
 
 			var index = geometry.index;
 			var attributes = geometry.attributes;
-			var position = attributes.position;
 
 			// console.time( 'wireframe' );
 
@@ -17612,8 +17643,7 @@
 
 			// console.timeEnd( 'wireframe' );
 
-			var TypeArray = position.count > 65535 ? Uint32Array : Uint16Array;
-			var attribute = new BufferAttribute( new TypeArray( indices ), 1 );
+			var attribute = new ( arrayMax( indices ) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( indices, 1 );
 
 			updateAttribute( attribute, gl.ELEMENT_ARRAY_BUFFER );
 
@@ -20028,25 +20058,8 @@
 
 		//
 
-		var backgroundCamera = new OrthographicCamera( - 1, 1, 1, - 1, 0, 1 );
-		var backgroundCamera2 = new PerspectiveCamera();
-		var backgroundPlaneMesh = new Mesh(
-			new PlaneBufferGeometry( 2, 2 ),
-			new MeshBasicMaterial( { depthTest: false, depthWrite: false, fog: false } )
-		);
-		var backgroundBoxShader = ShaderLib[ 'cube' ];
-		var backgroundBoxMesh = new Mesh(
-			new BoxBufferGeometry( 5, 5, 5 ),
-			new ShaderMaterial( {
-				uniforms: backgroundBoxShader.uniforms,
-				vertexShader: backgroundBoxShader.vertexShader,
-				fragmentShader: backgroundBoxShader.fragmentShader,
-				side: BackSide,
-				depthTest: false,
-				depthWrite: false,
-				fog: false
-			} )
-		);
+		var backgroundPlaneCamera, backgroundPlaneMesh;
+		var backgroundBoxCamera, backgroundBoxMesh;
 
 		//
 
@@ -20917,25 +20930,56 @@
 
 			if ( background && background.isCubeTexture ) {
 
-				backgroundCamera2.projectionMatrix.copy( camera.projectionMatrix );
+				if ( backgroundBoxCamera === undefined ) {
+
+					backgroundBoxCamera = new PerspectiveCamera();
+
+					backgroundBoxMesh = new Mesh(
+						new BoxBufferGeometry( 5, 5, 5 ),
+						new ShaderMaterial( {
+							uniforms: ShaderLib.cube.uniforms,
+							vertexShader: ShaderLib.cube.vertexShader,
+							fragmentShader: ShaderLib.cube.fragmentShader,
+							side: BackSide,
+							depthTest: false,
+							depthWrite: false,
+							fog: false
+						} )
+					);
+
+				}
+
+				backgroundBoxCamera.projectionMatrix.copy( camera.projectionMatrix );
+
+				backgroundBoxCamera.matrixWorld.extractRotation( camera.matrixWorld );
+				backgroundBoxCamera.matrixWorldInverse.getInverse( backgroundBoxCamera.matrixWorld );
 
-				backgroundCamera2.matrixWorld.extractRotation( camera.matrixWorld );
-				backgroundCamera2.matrixWorldInverse.getInverse( backgroundCamera2.matrixWorld );
 
 				backgroundBoxMesh.material.uniforms[ "tCube" ].value = background;
-				backgroundBoxMesh.modelViewMatrix.multiplyMatrices( backgroundCamera2.matrixWorldInverse, backgroundBoxMesh.matrixWorld );
+				backgroundBoxMesh.modelViewMatrix.multiplyMatrices( backgroundBoxCamera.matrixWorldInverse, backgroundBoxMesh.matrixWorld );
 
 				objects.update( backgroundBoxMesh );
 
-				_this.renderBufferDirect( backgroundCamera2, null, backgroundBoxMesh.geometry, backgroundBoxMesh.material, backgroundBoxMesh, null );
+				_this.renderBufferDirect( backgroundBoxCamera, null, backgroundBoxMesh.geometry, backgroundBoxMesh.material, backgroundBoxMesh, null );
 
 			} else if ( background && background.isTexture ) {
 
+				if ( backgroundPlaneCamera === undefined ) {
+
+					backgroundPlaneCamera = new OrthographicCamera( - 1, 1, 1, - 1, 0, 1 );
+
+					backgroundPlaneMesh = new Mesh(
+						new PlaneBufferGeometry( 2, 2 ),
+						new MeshBasicMaterial( { depthTest: false, depthWrite: false, fog: false } )
+					);
+
+				}
+
 				backgroundPlaneMesh.material.map = background;
 
 				objects.update( backgroundPlaneMesh );
 
-				_this.renderBufferDirect( backgroundCamera, null, backgroundPlaneMesh.geometry, backgroundPlaneMesh.material, backgroundPlaneMesh, null );
+				_this.renderBufferDirect( backgroundPlaneCamera, null, backgroundPlaneMesh.geometry, backgroundPlaneMesh.material, backgroundPlaneMesh, null );
 
 			}
 
@@ -24049,49 +24093,49 @@
 
 	/**
 	 * @author mrdoob / http://mrdoob.com/
+	 * @author Mugen87 / https://github.com/Mugen87
 	 */
 
 	function WireframeGeometry( geometry ) {
 
 		BufferGeometry.call( this );
 
-		var edge = [ 0, 0 ], hash = {};
+		this.type = 'WireframeGeometry';
 
-		function sortFunction( a, b ) {
+		// buffer
 
-			return a - b;
+		var vertices = [];
 
-		}
+		// helper variables
+
+		var i, j, l, o, ol;
+		var edge = [ 0, 0 ], edges = {}, e;
+		var key, keys = [ 'a', 'b', 'c' ];
+		var vertex;
 
-		var keys = [ 'a', 'b', 'c' ];
+		// different logic for Geometry and BufferGeometry
 
 		if ( geometry && geometry.isGeometry ) {
 
-			var vertices = geometry.vertices;
-			var faces = geometry.faces;
-			var numEdges = 0;
+			// create a data structure that contains all edges without duplicates
 
-			// allocate maximal size
-			var edges = new Uint32Array( 6 * faces.length );
+			var faces = geometry.faces;
 
-			for ( var i = 0, l = faces.length; i < l; i ++ ) {
+			for ( i = 0, l = faces.length; i < l; i ++ ) {
 
 				var face = faces[ i ];
 
-				for ( var j = 0; j < 3; j ++ ) {
+				for ( j = 0; j < 3; j ++ ) {
 
 					edge[ 0 ] = face[ keys[ j ] ];
 					edge[ 1 ] = face[ keys[ ( j + 1 ) % 3 ] ];
-					edge.sort( sortFunction );
+					edge.sort( sortFunction ); // sorting prevents duplicates
 
-					var key = edge.toString();
+					key = edge.toString();
 
-					if ( hash[ key ] === undefined ) {
+					if ( edges[ key ] === undefined ) {
 
-						edges[ 2 * numEdges ] = edge[ 0 ];
-						edges[ 2 * numEdges + 1 ] = edge[ 1 ];
-						hash[ key ] = true;
-						numEdges ++;
+						edges[ key ] = { index1: edge[ 0 ], index2: edge[ 1 ] };
 
 					}
 
@@ -24099,68 +24143,64 @@
 
 			}
 
-			var coords = new Float32Array( numEdges * 2 * 3 );
+			// generate vertices
 
-			for ( var i = 0, l = numEdges; i < l; i ++ ) {
+			for ( key in edges ) {
 
-				for ( var j = 0; j < 2; j ++ ) {
+				e = edges[ key ];
 
-					var vertex = vertices[ edges [ 2 * i + j ] ];
-
-					var index = 6 * i + 3 * j;
-					coords[ index + 0 ] = vertex.x;
-					coords[ index + 1 ] = vertex.y;
-					coords[ index + 2 ] = vertex.z;
+				vertex = geometry.vertices[ e.index1 ];
+				vertices.push( vertex.x, vertex.y, vertex.z );
 
-				}
+				vertex = geometry.vertices[ e.index2 ];
+				vertices.push( vertex.x, vertex.y, vertex.z );
 
 			}
 
-			this.addAttribute( 'position', new BufferAttribute( coords, 3 ) );
-
 		} else if ( geometry && geometry.isBufferGeometry ) {
 
+			var position, indices, groups;
+			var group, start, count;
+			var index1, index2;
+
+			vertex = new Vector3();
+
 			if ( geometry.index !== null ) {
 
-				// Indexed BufferGeometry
+				// indexed BufferGeometry
 
-				var indices = geometry.index.array;
-				var vertices = geometry.attributes.position;
-				var groups = geometry.groups;
-				var numEdges = 0;
+				position = geometry.attributes.position;
+				indices = geometry.index;
+				groups = geometry.groups;
 
 				if ( groups.length === 0 ) {
 
-					geometry.addGroup( 0, indices.length );
+					geometry.addGroup( 0, indices.count );
 
 				}
 
-				// allocate maximal size
-				var edges = new Uint32Array( 2 * indices.length );
+				// create a data structure that contains all eges without duplicates
 
-				for ( var o = 0, ol = groups.length; o < ol; ++ o ) {
+				for ( o = 0, ol = groups.length; o < ol; ++ o ) {
 
-					var group = groups[ o ];
+					group = groups[ o ];
 
-					var start = group.start;
-					var count = group.count;
+					start = group.start;
+					count = group.count;
 
-					for ( var i = start, il = start + count; i < il; i += 3 ) {
+					for ( i = start, l = ( start + count ); i < l; i += 3 ) {
 
-						for ( var j = 0; j < 3; j ++ ) {
+						for ( j = 0; j < 3; j ++ ) {
 
-							edge[ 0 ] = indices[ i + j ];
-							edge[ 1 ] = indices[ i + ( j + 1 ) % 3 ];
-							edge.sort( sortFunction );
+							edge[ 0 ] = indices.getX( i + j );
+							edge[ 1 ] = indices.getX( i + ( j + 1 ) % 3 );
+							edge.sort( sortFunction ); // sorting prevents duplicates
 
-							var key = edge.toString();
+							key = edge.toString();
 
-							if ( hash[ key ] === undefined ) {
+							if ( edges[ key ] === undefined ) {
 
-								edges[ 2 * numEdges ] = edge[ 0 ];
-								edges[ 2 * numEdges + 1 ] = edge[ 1 ];
-								hash[ key ] = true;
-								numEdges ++;
+								edges[ key ] = { index1: edge[ 0 ], index2: edge[ 1 ] };
 
 							}
 
@@ -24170,61 +24210,61 @@
 
 				}
 
-				var coords = new Float32Array( numEdges * 2 * 3 );
-
-				for ( var i = 0, l = numEdges; i < l; i ++ ) {
+				// generate vertices
 
-					for ( var j = 0; j < 2; j ++ ) {
+				for ( key in edges ) {
 
-						var index = 6 * i + 3 * j;
-						var index2 = edges[ 2 * i + j ];
+					e = edges[ key ];
 
-						coords[ index + 0 ] = vertices.getX( index2 );
-						coords[ index + 1 ] = vertices.getY( index2 );
-						coords[ index + 2 ] = vertices.getZ( index2 );
+					vertex.fromBufferAttribute( position, e.index1 );
+					vertices.push( vertex.x, vertex.y, vertex.z );
 
-					}
+					vertex.fromBufferAttribute( position, e.index2 );
+					vertices.push( vertex.x, vertex.y, vertex.z );
 
 				}
 
-				this.addAttribute( 'position', new BufferAttribute( coords, 3 ) );
-
 			} else {
 
 				// non-indexed BufferGeometry
 
-				var vertices = geometry.attributes.position.array;
-				var numEdges = vertices.length / 3;
-				var numTris = numEdges / 3;
-
-				var coords = new Float32Array( numEdges * 2 * 3 );
+				position = geometry.attributes.position;
 
-				for ( var i = 0, l = numTris; i < l; i ++ ) {
+				for ( i = 0, l = ( position.count / 3 ); i < l; i ++ ) {
 
-					for ( var j = 0; j < 3; j ++ ) {
+					for ( j = 0; j < 3; j ++ ) {
 
-						var index = 18 * i + 6 * j;
+						// three edges per triangle, an edge is represented as (index1, index2)
+						// e.g. the first triangle has the following edges: (0,1),(1,2),(2,0)
 
-						var index1 = 9 * i + 3 * j;
-						coords[ index + 0 ] = vertices[ index1 ];
-						coords[ index + 1 ] = vertices[ index1 + 1 ];
-						coords[ index + 2 ] = vertices[ index1 + 2 ];
+						index1 = 3 * i + j;
+						vertex.fromBufferAttribute( position, index1 );
+						vertices.push( vertex.x, vertex.y, vertex.z );
 
-						var index2 = 9 * i + 3 * ( ( j + 1 ) % 3 );
-						coords[ index + 3 ] = vertices[ index2 ];
-						coords[ index + 4 ] = vertices[ index2 + 1 ];
-						coords[ index + 5 ] = vertices[ index2 + 2 ];
+						index2 = 3 * i + ( ( j + 1 ) % 3 );
+						vertex.fromBufferAttribute( position, index2 );
+						vertices.push( vertex.x, vertex.y, vertex.z );
 
 					}
 
 				}
 
-				this.addAttribute( 'position', new BufferAttribute( coords, 3 ) );
-
 			}
 
 		}
 
+		// build geometry
+
+		this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
+
+		// custom array sort function
+
+		function sortFunction( a, b ) {
+
+			return a - b;
+
+		}
+
 	}
 
 	WireframeGeometry.prototype = Object.create( BufferGeometry.prototype );
@@ -24278,11 +24318,11 @@
 
 		// buffers
 
+		var indices = [];
 		var vertices = [];
 		var uvs = [];
 
-		var i, j, p;
-		var u, v;
+		var i, j;
 
 		// generate vertices and uvs
 
@@ -24290,13 +24330,13 @@
 
 		for ( i = 0; i <= stacks; i ++ ) {
 
-			v = i / stacks;
+			var v = i / stacks;
 
 			for ( j = 0; j <= slices; j ++ ) {
 
-				u = j / slices;
+				var u = j / slices;
 
-				p = func( u, v );
+				var p = func( u, v );
 				vertices.push( p.x, p.y, p.z );
 
 				uvs.push( u, v );
@@ -24307,17 +24347,14 @@
 
 		// generate indices
 
-		var indices = [];
-		var a, b, c, d;
-
 		for ( i = 0; i < stacks; i ++ ) {
 
 			for ( j = 0; j < slices; j ++ ) {
 
-				a = i * sliceCount + j;
-				b = i * sliceCount + j + 1;
-				c = ( i + 1 ) * sliceCount + j + 1;
-				d = ( i + 1 ) * sliceCount + j;
+				var a = i * sliceCount + j;
+				var b = i * sliceCount + j + 1;
+				var c = ( i + 1 ) * sliceCount + j + 1;
+				var d = ( i + 1 ) * sliceCount + j;
 
 				// faces one and two
 
@@ -24330,7 +24367,7 @@
 
 		// build geometry
 
-		this.setIndex( new ( indices.length > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( indices, 1 ) );
+		this.setIndex( indices );
 		this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
 		this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
 
@@ -24414,8 +24451,6 @@
 		this.addAttribute( 'uv', new Float32BufferAttribute( uvBuffer, 2 ) );
 		this.normalizeNormals();
 
-		this.boundingSphere = new Sphere( new Vector3(), radius );
-
 		// helper functions
 
 		function subdivide( detail ) {
@@ -25006,7 +25041,7 @@
 
 		// build geometry
 
-		this.setIndex( new ( indices.length > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( indices, 1 ) );
+		this.setIndex( indices );
 		this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
 		this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
 		this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
@@ -25285,7 +25320,7 @@
 
 		// build geometry
 
-		this.setIndex( new ( indices.length > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( indices, 1 ) );
+		this.setIndex( indices );
 		this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
 		this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
 		this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
@@ -25434,7 +25469,7 @@
 
 		// build geometry
 
-		this.setIndex( new ( indices.length > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( indices, 1 ) );
+		this.setIndex( indices );
 		this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
 		this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
 		this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
@@ -26862,7 +26897,7 @@
 
 		var font = parameters.font;
 
-		if ( (font && font.isFont) === false ) {
+		if ( ( font && font.isFont ) === false ) {
 
 			console.error( 'THREE.TextGeometry: font parameter is not an instance of THREE.Font.' );
 			return new Geometry();
@@ -27023,7 +27058,7 @@
 
 		// build geometry
 
-		this.setIndex( new ( indices.length > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( indices, 1 ) );
+		this.setIndex( indices );
 		this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
 		this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
 		this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
@@ -27125,7 +27160,7 @@
 				normals.push( 0, 0, 1 );
 
 				// uv
-				
+
 				uv.x = ( vertex.x / outerRadius + 1 ) / 2;
 				uv.y = ( vertex.y / outerRadius + 1 ) / 2;
 
@@ -27165,7 +27200,7 @@
 
 		// build geometry
 
-		this.setIndex( new ( indices.length > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( indices, 1 ) );
+		this.setIndex( indices );
 		this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
 		this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
 		this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
@@ -27231,7 +27266,7 @@
 		phiLength = phiLength || Math.PI * 2;
 
 		// clamp phiLength so it's in range of [ 0, 2PI ]
-		
+
 		phiLength = _Math.clamp( phiLength, 0, Math.PI * 2 );
 
 
@@ -27304,7 +27339,7 @@
 
 		// build geometry
 
-		this.setIndex( new ( indices.length > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( indices, 1 ) );
+		this.setIndex( indices );
 		this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
 		this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
 
@@ -27442,7 +27477,7 @@
 
 		// build geometry
 
-		this.setIndex( new ( indices.length > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( indices, 1 ) );
+		this.setIndex( indices );
 		this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
 		this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
 		this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
@@ -27529,25 +27564,32 @@
 
 	/**
 	 * @author WestLangley / http://github.com/WestLangley
+	 * @author Mugen87 / https://github.com/Mugen87
 	 */
 
 	function EdgesGeometry( geometry, thresholdAngle ) {
 
 		BufferGeometry.call( this );
 
-		thresholdAngle = ( thresholdAngle !== undefined ) ? thresholdAngle : 1;
+		this.type = 'EdgesGeometry';
 
-		var thresholdDot = Math.cos( _Math.DEG2RAD * thresholdAngle );
+		this.parameters = {
+			thresholdAngle: thresholdAngle
+		};
+
+		thresholdAngle = ( thresholdAngle !== undefined ) ? thresholdAngle : 1;
 
-		var edge = [ 0, 0 ], hash = {};
+		// buffer
 
-		function sortFunction( a, b ) {
+		var vertices = [];
 
-			return a - b;
+		// helper variables
 
-		}
+		var thresholdDot = Math.cos( _Math.DEG2RAD * thresholdAngle );
+		var edge = [ 0, 0 ], edges = {};
+		var key, keys = [ 'a', 'b', 'c' ];
 
-		var keys = [ 'a', 'b', 'c' ];
+		// prepare source geometry
 
 		var geometry2;
 
@@ -27565,9 +27607,11 @@
 		geometry2.mergeVertices();
 		geometry2.computeFaceNormals();
 
-		var vertices = geometry2.vertices;
+		var sourceVertices = geometry2.vertices;
 		var faces = geometry2.faces;
 
+		// now create a data structure where each entry represents an edge with its adjoining faces
+
 		for ( var i = 0, l = faces.length; i < l; i ++ ) {
 
 			var face = faces[ i ];
@@ -27578,15 +27622,15 @@
 				edge[ 1 ] = face[ keys[ ( j + 1 ) % 3 ] ];
 				edge.sort( sortFunction );
 
-				var key = edge.toString();
+				key = edge.toString();
 
-				if ( hash[ key ] === undefined ) {
+				if ( edges[ key ] === undefined ) {
 
-					hash[ key ] = { vert1: edge[ 0 ], vert2: edge[ 1 ], face1: i, face2: undefined };
+					edges[ key ] = { index1: edge[ 0 ], index2: edge[ 1 ], face1: i, face2: undefined };
 
 				} else {
 
-					hash[ key ].face2 = i;
+					edges[ key ].face2 = i;
 
 				}
 
@@ -27594,31 +27638,37 @@
 
 		}
 
-		var coords = [];
+		// generate vertices
 
-		for ( var key in hash ) {
+		for ( key in edges ) {
 
-			var h = hash[ key ];
+			var e = edges[ key ];
 
-			// An edge is only rendered if the angle (in degrees) between the face normals of the adjoining faces exceeds this value. default = 1 degree.
+			// an edge is only rendered if the angle (in degrees) between the face normals of the adjoining faces exceeds this value. default = 1 degree.
 
-			if ( h.face2 === undefined || faces[ h.face1 ].normal.dot( faces[ h.face2 ].normal ) <= thresholdDot ) {
+			if ( e.face2 === undefined || faces[ e.face1 ].normal.dot( faces[ e.face2 ].normal ) <= thresholdDot ) {
 
-				var vertex = vertices[ h.vert1 ];
-				coords.push( vertex.x );
-				coords.push( vertex.y );
-				coords.push( vertex.z );
+				var vertex = sourceVertices[ e.index1 ];
+				vertices.push( vertex.x, vertex.y, vertex.z );
 
-				vertex = vertices[ h.vert2 ];
-				coords.push( vertex.x );
-				coords.push( vertex.y );
-				coords.push( vertex.z );
+				vertex = sourceVertices[ e.index2 ];
+				vertices.push( vertex.x, vertex.y, vertex.z );
 
 			}
 
 		}
 
-		this.addAttribute( 'position', new Float32BufferAttribute( coords, 3 ) );
+		// build geometry
+
+		this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
+
+		// custom array sort function
+
+		function sortFunction( a, b ) {
+
+			return a - b;
+
+		}
 
 	}
 
@@ -27716,7 +27766,7 @@
 
 		// build geometry
 
-		this.setIndex( new ( indices.length > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( indices, 1 ) );
+		this.setIndex( indices );
 		this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
 		this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
 		this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
@@ -28084,7 +28134,7 @@
 
 		// build geometry
 
-		this.setIndex( new ( indices.length > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( indices, 1 ) );
+		this.setIndex( indices );
 		this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
 		this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
 		this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
@@ -33044,7 +33094,10 @@
 
 				} catch ( error ) {
 
+					if ( onError !== undefined ) onError( error );
+
 					console.error( 'THREE:ObjectLoader: Can\'t parse ' + url + '.', error.message );
+
 					return;
 
 				}
@@ -35568,6 +35621,7 @@
 		var options = { format: RGBFormat, magFilter: LinearFilter, minFilter: LinearFilter };
 
 		this.renderTarget = new WebGLRenderTargetCube( cubeResolution, cubeResolution, options );
+		this.renderTarget.texture.name = "CubeCamera";
 
 		this.updateCubeMap = function ( renderer, scene ) {
 
@@ -36606,7 +36660,7 @@
 
 				this.resolvedProperty = nodeProperty;
 
-			} else if ( nodeProperty.length !== undefined ) {
+			} else if ( Array.isArray( nodeProperty ) ) {
 
 				bindingType = this.BindingType.EntireArray;
 
@@ -41052,11 +41106,8 @@
 	 *  headWidth - Number
 	 */
 
-	var lineGeometry = new BufferGeometry();
-	lineGeometry.addAttribute( 'position', new Float32BufferAttribute( [ 0, 0, 0, 0, 1, 0 ], 3 ) );
-
-	var coneGeometry = new CylinderBufferGeometry( 0, 0.5, 1, 5, 1 );
-	coneGeometry.translate( 0, - 0.5, 0 );
+	var lineGeometry;
+	var coneGeometry;
 
 	function ArrowHelper( dir, origin, length, color, headLength, headWidth ) {
 
@@ -41069,6 +41120,16 @@
 		if ( headLength === undefined ) headLength = 0.2 * length;
 		if ( headWidth === undefined ) headWidth = 0.2 * headLength;
 
+		if ( lineGeometry === undefined ) {
+
+			lineGeometry = new BufferGeometry();
+			lineGeometry.addAttribute( 'position', new Float32BufferAttribute( [ 0, 0, 0, 0, 1, 0 ], 3 ) );
+
+			coneGeometry = new CylinderBufferGeometry( 0, 0.5, 1, 5, 1 );
+			coneGeometry.translate( 0, - 0.5, 0 );
+
+		}
+
 		this.position.copy( origin );
 
 		this.line = new Line( lineGeometry, new LineBasicMaterial( { color: color } ) );

File diff suppressed because it is too large
+ 301 - 300
build/three.min.js


+ 242 - 181
build/three.module.js

@@ -175,7 +175,7 @@ EventDispatcher.prototype = {
 
 };
 
-var REVISION = '84dev';
+var REVISION = '85dev';
 var MOUSE = { LEFT: 0, MIDDLE: 1, RIGHT: 2 };
 var CullFaceNone = 0;
 var CullFaceBack = 1;
@@ -1028,6 +1028,8 @@ Texture.prototype = {
 
 	copy: function ( source ) {
 
+		this.name = source.name;
+
 		this.image = source.image;
 		this.mipmaps = source.mipmaps.slice( 0 );
 
@@ -9232,6 +9234,7 @@ function WebGLShadowMap( _renderer, _lights, _objects, capabilities ) {
 				var pars = { minFilter: NearestFilter, magFilter: NearestFilter, format: RGBAFormat };
 
 				shadow.map = new WebGLRenderTarget( _shadowMapSize.x, _shadowMapSize.y, pars );
+				shadow.map.texture.name = light.name + ".shadowMap";
 
 				shadowCamera.updateProjectionMatrix();
 
@@ -9244,7 +9247,7 @@ function WebGLShadowMap( _renderer, _lights, _objects, capabilities ) {
 			}
 
 			// TODO (abelnation / sam-g-steel): is this needed?
-			if (shadow && shadow.isRectAreaLightShadow ) {
+			if ( shadow && shadow.isRectAreaLightShadow ) {
 
 				shadow.update( light );
 
@@ -9349,8 +9352,8 @@ function WebGLShadowMap( _renderer, _lights, _objects, capabilities ) {
 		}
 
 		// Restore GL state.
-		var clearColor = _renderer.getClearColor(),
-		clearAlpha = _renderer.getClearAlpha();
+		var clearColor = _renderer.getClearColor();
+		var clearAlpha = _renderer.getClearAlpha();
 		_renderer.setClearColor( clearColor, clearAlpha );
 
 		scope.needsUpdate = false;
@@ -12387,6 +12390,26 @@ Object.assign( DirectGeometry.prototype, {
 
 } );
 
+// http://stackoverflow.com/questions/1669190/javascript-min-max-array-values/13440842#13440842
+
+function arrayMax( array ) {
+
+	var length = array.length, max = - Infinity;
+
+	while ( length -- ) {
+
+		if ( array[ length ] > max ) {
+
+			max = array[ length ];
+
+		}
+
+	}
+
+	return max;
+
+}
+
 /**
  * @author mrdoob / http://mrdoob.com/
  * @author kile / http://kile.stravaganza.org/
@@ -13861,7 +13884,15 @@ BufferGeometry.prototype = {
 
 	setIndex: function ( index ) {
 
-		this.index = index;
+		if ( Array.isArray( index ) ) {
+
+			this.index = new ( arrayMax( index ) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( index, 1 );
+
+		} else {
+
+			this.index = index;
+
+		}
 
 	},
 
@@ -14317,7 +14348,7 @@ BufferGeometry.prototype = {
 
 		if ( geometry.indices.length > 0 ) {
 
-			var TypeArray = geometry.vertices.length > 65535 ? Uint32Array : Uint16Array;
+			var TypeArray = arrayMax( geometry.indices ) > 65535 ? Uint32Array : Uint16Array;
 			var indices = new TypeArray( geometry.indices.length * 3 );
 			this.setIndex( new BufferAttribute( indices, 1 ).copyIndicesArray( geometry.indices ) );
 
@@ -15333,14 +15364,14 @@ function BoxBufferGeometry( width, height, depth, widthSegments, heightSegments,
 
 	// build geometry
 
-	this.setIndex( new ( indices.length > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( indices, 1 ) );
+	this.setIndex( indices );
 	this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
 	this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
 	this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
 
 	function buildPlane( u, v, w, udir, vdir, width, height, depth, gridX, gridY, materialIndex ) {
 
-		var segmentWidth	= width / gridX;
+		var segmentWidth = width / gridX;
 		var segmentHeight = height / gridY;
 
 		var widthHalf = width / 2;
@@ -15556,7 +15587,7 @@ function PlaneBufferGeometry( width, height, widthSegments, heightSegments ) {
 
 	// build geometry
 
-	this.setIndex( new ( indices.length > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( indices, 1 ) );
+	this.setIndex( indices );
 	this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
 	this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
 	this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
@@ -16007,9 +16038,10 @@ function WebGLIndexedBufferRenderer( gl, extensions, infoRender ) {
 			size = 2;
 
 		} else {
-			
+
 			type = gl.UNSIGNED_BYTE;
 			size = 1;
+
 		}
 
 	}
@@ -17570,7 +17602,6 @@ function WebGLObjects( gl, properties, info ) {
 
 		var index = geometry.index;
 		var attributes = geometry.attributes;
-		var position = attributes.position;
 
 		// console.time( 'wireframe' );
 
@@ -17606,8 +17637,7 @@ function WebGLObjects( gl, properties, info ) {
 
 		// console.timeEnd( 'wireframe' );
 
-		var TypeArray = position.count > 65535 ? Uint32Array : Uint16Array;
-		var attribute = new BufferAttribute( new TypeArray( indices ), 1 );
+		var attribute = new ( arrayMax( indices ) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( indices, 1 );
 
 		updateAttribute( attribute, gl.ELEMENT_ARRAY_BUFFER );
 
@@ -20022,25 +20052,8 @@ function WebGLRenderer( parameters ) {
 
 	//
 
-	var backgroundCamera = new OrthographicCamera( - 1, 1, 1, - 1, 0, 1 );
-	var backgroundCamera2 = new PerspectiveCamera();
-	var backgroundPlaneMesh = new Mesh(
-		new PlaneBufferGeometry( 2, 2 ),
-		new MeshBasicMaterial( { depthTest: false, depthWrite: false, fog: false } )
-	);
-	var backgroundBoxShader = ShaderLib[ 'cube' ];
-	var backgroundBoxMesh = new Mesh(
-		new BoxBufferGeometry( 5, 5, 5 ),
-		new ShaderMaterial( {
-			uniforms: backgroundBoxShader.uniforms,
-			vertexShader: backgroundBoxShader.vertexShader,
-			fragmentShader: backgroundBoxShader.fragmentShader,
-			side: BackSide,
-			depthTest: false,
-			depthWrite: false,
-			fog: false
-		} )
-	);
+	var backgroundPlaneCamera, backgroundPlaneMesh;
+	var backgroundBoxCamera, backgroundBoxMesh;
 
 	//
 
@@ -20911,25 +20924,56 @@ function WebGLRenderer( parameters ) {
 
 		if ( background && background.isCubeTexture ) {
 
-			backgroundCamera2.projectionMatrix.copy( camera.projectionMatrix );
+			if ( backgroundBoxCamera === undefined ) {
+
+				backgroundBoxCamera = new PerspectiveCamera();
+
+				backgroundBoxMesh = new Mesh(
+					new BoxBufferGeometry( 5, 5, 5 ),
+					new ShaderMaterial( {
+						uniforms: ShaderLib.cube.uniforms,
+						vertexShader: ShaderLib.cube.vertexShader,
+						fragmentShader: ShaderLib.cube.fragmentShader,
+						side: BackSide,
+						depthTest: false,
+						depthWrite: false,
+						fog: false
+					} )
+				);
+
+			}
+
+			backgroundBoxCamera.projectionMatrix.copy( camera.projectionMatrix );
+
+			backgroundBoxCamera.matrixWorld.extractRotation( camera.matrixWorld );
+			backgroundBoxCamera.matrixWorldInverse.getInverse( backgroundBoxCamera.matrixWorld );
 
-			backgroundCamera2.matrixWorld.extractRotation( camera.matrixWorld );
-			backgroundCamera2.matrixWorldInverse.getInverse( backgroundCamera2.matrixWorld );
 
 			backgroundBoxMesh.material.uniforms[ "tCube" ].value = background;
-			backgroundBoxMesh.modelViewMatrix.multiplyMatrices( backgroundCamera2.matrixWorldInverse, backgroundBoxMesh.matrixWorld );
+			backgroundBoxMesh.modelViewMatrix.multiplyMatrices( backgroundBoxCamera.matrixWorldInverse, backgroundBoxMesh.matrixWorld );
 
 			objects.update( backgroundBoxMesh );
 
-			_this.renderBufferDirect( backgroundCamera2, null, backgroundBoxMesh.geometry, backgroundBoxMesh.material, backgroundBoxMesh, null );
+			_this.renderBufferDirect( backgroundBoxCamera, null, backgroundBoxMesh.geometry, backgroundBoxMesh.material, backgroundBoxMesh, null );
 
 		} else if ( background && background.isTexture ) {
 
+			if ( backgroundPlaneCamera === undefined ) {
+
+				backgroundPlaneCamera = new OrthographicCamera( - 1, 1, 1, - 1, 0, 1 );
+
+				backgroundPlaneMesh = new Mesh(
+					new PlaneBufferGeometry( 2, 2 ),
+					new MeshBasicMaterial( { depthTest: false, depthWrite: false, fog: false } )
+				);
+
+			}
+
 			backgroundPlaneMesh.material.map = background;
 
 			objects.update( backgroundPlaneMesh );
 
-			_this.renderBufferDirect( backgroundCamera, null, backgroundPlaneMesh.geometry, backgroundPlaneMesh.material, backgroundPlaneMesh, null );
+			_this.renderBufferDirect( backgroundPlaneCamera, null, backgroundPlaneMesh.geometry, backgroundPlaneMesh.material, backgroundPlaneMesh, null );
 
 		}
 
@@ -24043,49 +24087,49 @@ DepthTexture.prototype.isDepthTexture = true;
 
 /**
  * @author mrdoob / http://mrdoob.com/
+ * @author Mugen87 / https://github.com/Mugen87
  */
 
 function WireframeGeometry( geometry ) {
 
 	BufferGeometry.call( this );
 
-	var edge = [ 0, 0 ], hash = {};
+	this.type = 'WireframeGeometry';
 
-	function sortFunction( a, b ) {
+	// buffer
 
-		return a - b;
+	var vertices = [];
 
-	}
+	// helper variables
+
+	var i, j, l, o, ol;
+	var edge = [ 0, 0 ], edges = {}, e;
+	var key, keys = [ 'a', 'b', 'c' ];
+	var vertex;
 
-	var keys = [ 'a', 'b', 'c' ];
+	// different logic for Geometry and BufferGeometry
 
 	if ( geometry && geometry.isGeometry ) {
 
-		var vertices = geometry.vertices;
-		var faces = geometry.faces;
-		var numEdges = 0;
+		// create a data structure that contains all edges without duplicates
 
-		// allocate maximal size
-		var edges = new Uint32Array( 6 * faces.length );
+		var faces = geometry.faces;
 
-		for ( var i = 0, l = faces.length; i < l; i ++ ) {
+		for ( i = 0, l = faces.length; i < l; i ++ ) {
 
 			var face = faces[ i ];
 
-			for ( var j = 0; j < 3; j ++ ) {
+			for ( j = 0; j < 3; j ++ ) {
 
 				edge[ 0 ] = face[ keys[ j ] ];
 				edge[ 1 ] = face[ keys[ ( j + 1 ) % 3 ] ];
-				edge.sort( sortFunction );
+				edge.sort( sortFunction ); // sorting prevents duplicates
 
-				var key = edge.toString();
+				key = edge.toString();
 
-				if ( hash[ key ] === undefined ) {
+				if ( edges[ key ] === undefined ) {
 
-					edges[ 2 * numEdges ] = edge[ 0 ];
-					edges[ 2 * numEdges + 1 ] = edge[ 1 ];
-					hash[ key ] = true;
-					numEdges ++;
+					edges[ key ] = { index1: edge[ 0 ], index2: edge[ 1 ] };
 
 				}
 
@@ -24093,68 +24137,64 @@ function WireframeGeometry( geometry ) {
 
 		}
 
-		var coords = new Float32Array( numEdges * 2 * 3 );
+		// generate vertices
 
-		for ( var i = 0, l = numEdges; i < l; i ++ ) {
+		for ( key in edges ) {
 
-			for ( var j = 0; j < 2; j ++ ) {
+			e = edges[ key ];
 
-				var vertex = vertices[ edges [ 2 * i + j ] ];
-
-				var index = 6 * i + 3 * j;
-				coords[ index + 0 ] = vertex.x;
-				coords[ index + 1 ] = vertex.y;
-				coords[ index + 2 ] = vertex.z;
+			vertex = geometry.vertices[ e.index1 ];
+			vertices.push( vertex.x, vertex.y, vertex.z );
 
-			}
+			vertex = geometry.vertices[ e.index2 ];
+			vertices.push( vertex.x, vertex.y, vertex.z );
 
 		}
 
-		this.addAttribute( 'position', new BufferAttribute( coords, 3 ) );
-
 	} else if ( geometry && geometry.isBufferGeometry ) {
 
+		var position, indices, groups;
+		var group, start, count;
+		var index1, index2;
+
+		vertex = new Vector3();
+
 		if ( geometry.index !== null ) {
 
-			// Indexed BufferGeometry
+			// indexed BufferGeometry
 
-			var indices = geometry.index.array;
-			var vertices = geometry.attributes.position;
-			var groups = geometry.groups;
-			var numEdges = 0;
+			position = geometry.attributes.position;
+			indices = geometry.index;
+			groups = geometry.groups;
 
 			if ( groups.length === 0 ) {
 
-				geometry.addGroup( 0, indices.length );
+				geometry.addGroup( 0, indices.count );
 
 			}
 
-			// allocate maximal size
-			var edges = new Uint32Array( 2 * indices.length );
+			// create a data structure that contains all eges without duplicates
 
-			for ( var o = 0, ol = groups.length; o < ol; ++ o ) {
+			for ( o = 0, ol = groups.length; o < ol; ++ o ) {
 
-				var group = groups[ o ];
+				group = groups[ o ];
 
-				var start = group.start;
-				var count = group.count;
+				start = group.start;
+				count = group.count;
 
-				for ( var i = start, il = start + count; i < il; i += 3 ) {
+				for ( i = start, l = ( start + count ); i < l; i += 3 ) {
 
-					for ( var j = 0; j < 3; j ++ ) {
+					for ( j = 0; j < 3; j ++ ) {
 
-						edge[ 0 ] = indices[ i + j ];
-						edge[ 1 ] = indices[ i + ( j + 1 ) % 3 ];
-						edge.sort( sortFunction );
+						edge[ 0 ] = indices.getX( i + j );
+						edge[ 1 ] = indices.getX( i + ( j + 1 ) % 3 );
+						edge.sort( sortFunction ); // sorting prevents duplicates
 
-						var key = edge.toString();
+						key = edge.toString();
 
-						if ( hash[ key ] === undefined ) {
+						if ( edges[ key ] === undefined ) {
 
-							edges[ 2 * numEdges ] = edge[ 0 ];
-							edges[ 2 * numEdges + 1 ] = edge[ 1 ];
-							hash[ key ] = true;
-							numEdges ++;
+							edges[ key ] = { index1: edge[ 0 ], index2: edge[ 1 ] };
 
 						}
 
@@ -24164,61 +24204,61 @@ function WireframeGeometry( geometry ) {
 
 			}
 
-			var coords = new Float32Array( numEdges * 2 * 3 );
-
-			for ( var i = 0, l = numEdges; i < l; i ++ ) {
+			// generate vertices
 
-				for ( var j = 0; j < 2; j ++ ) {
+			for ( key in edges ) {
 
-					var index = 6 * i + 3 * j;
-					var index2 = edges[ 2 * i + j ];
+				e = edges[ key ];
 
-					coords[ index + 0 ] = vertices.getX( index2 );
-					coords[ index + 1 ] = vertices.getY( index2 );
-					coords[ index + 2 ] = vertices.getZ( index2 );
+				vertex.fromBufferAttribute( position, e.index1 );
+				vertices.push( vertex.x, vertex.y, vertex.z );
 
-				}
+				vertex.fromBufferAttribute( position, e.index2 );
+				vertices.push( vertex.x, vertex.y, vertex.z );
 
 			}
 
-			this.addAttribute( 'position', new BufferAttribute( coords, 3 ) );
-
 		} else {
 
 			// non-indexed BufferGeometry
 
-			var vertices = geometry.attributes.position.array;
-			var numEdges = vertices.length / 3;
-			var numTris = numEdges / 3;
-
-			var coords = new Float32Array( numEdges * 2 * 3 );
+			position = geometry.attributes.position;
 
-			for ( var i = 0, l = numTris; i < l; i ++ ) {
+			for ( i = 0, l = ( position.count / 3 ); i < l; i ++ ) {
 
-				for ( var j = 0; j < 3; j ++ ) {
+				for ( j = 0; j < 3; j ++ ) {
 
-					var index = 18 * i + 6 * j;
+					// three edges per triangle, an edge is represented as (index1, index2)
+					// e.g. the first triangle has the following edges: (0,1),(1,2),(2,0)
 
-					var index1 = 9 * i + 3 * j;
-					coords[ index + 0 ] = vertices[ index1 ];
-					coords[ index + 1 ] = vertices[ index1 + 1 ];
-					coords[ index + 2 ] = vertices[ index1 + 2 ];
+					index1 = 3 * i + j;
+					vertex.fromBufferAttribute( position, index1 );
+					vertices.push( vertex.x, vertex.y, vertex.z );
 
-					var index2 = 9 * i + 3 * ( ( j + 1 ) % 3 );
-					coords[ index + 3 ] = vertices[ index2 ];
-					coords[ index + 4 ] = vertices[ index2 + 1 ];
-					coords[ index + 5 ] = vertices[ index2 + 2 ];
+					index2 = 3 * i + ( ( j + 1 ) % 3 );
+					vertex.fromBufferAttribute( position, index2 );
+					vertices.push( vertex.x, vertex.y, vertex.z );
 
 				}
 
 			}
 
-			this.addAttribute( 'position', new BufferAttribute( coords, 3 ) );
-
 		}
 
 	}
 
+	// build geometry
+
+	this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
+
+	// custom array sort function
+
+	function sortFunction( a, b ) {
+
+		return a - b;
+
+	}
+
 }
 
 WireframeGeometry.prototype = Object.create( BufferGeometry.prototype );
@@ -24272,11 +24312,11 @@ function ParametricBufferGeometry( func, slices, stacks ) {
 
 	// buffers
 
+	var indices = [];
 	var vertices = [];
 	var uvs = [];
 
-	var i, j, p;
-	var u, v;
+	var i, j;
 
 	// generate vertices and uvs
 
@@ -24284,13 +24324,13 @@ function ParametricBufferGeometry( func, slices, stacks ) {
 
 	for ( i = 0; i <= stacks; i ++ ) {
 
-		v = i / stacks;
+		var v = i / stacks;
 
 		for ( j = 0; j <= slices; j ++ ) {
 
-			u = j / slices;
+			var u = j / slices;
 
-			p = func( u, v );
+			var p = func( u, v );
 			vertices.push( p.x, p.y, p.z );
 
 			uvs.push( u, v );
@@ -24301,17 +24341,14 @@ function ParametricBufferGeometry( func, slices, stacks ) {
 
 	// generate indices
 
-	var indices = [];
-	var a, b, c, d;
-
 	for ( i = 0; i < stacks; i ++ ) {
 
 		for ( j = 0; j < slices; j ++ ) {
 
-			a = i * sliceCount + j;
-			b = i * sliceCount + j + 1;
-			c = ( i + 1 ) * sliceCount + j + 1;
-			d = ( i + 1 ) * sliceCount + j;
+			var a = i * sliceCount + j;
+			var b = i * sliceCount + j + 1;
+			var c = ( i + 1 ) * sliceCount + j + 1;
+			var d = ( i + 1 ) * sliceCount + j;
 
 			// faces one and two
 
@@ -24324,7 +24361,7 @@ function ParametricBufferGeometry( func, slices, stacks ) {
 
 	// build geometry
 
-	this.setIndex( new ( indices.length > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( indices, 1 ) );
+	this.setIndex( indices );
 	this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
 	this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
 
@@ -24408,8 +24445,6 @@ function PolyhedronBufferGeometry( vertices, indices, radius, detail ) {
 	this.addAttribute( 'uv', new Float32BufferAttribute( uvBuffer, 2 ) );
 	this.normalizeNormals();
 
-	this.boundingSphere = new Sphere( new Vector3(), radius );
-
 	// helper functions
 
 	function subdivide( detail ) {
@@ -25000,7 +25035,7 @@ function TubeBufferGeometry( path, tubularSegments, radius, radialSegments, clos
 
 	// build geometry
 
-	this.setIndex( new ( indices.length > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( indices, 1 ) );
+	this.setIndex( indices );
 	this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
 	this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
 	this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
@@ -25279,7 +25314,7 @@ function TorusKnotBufferGeometry( radius, tube, tubularSegments, radialSegments,
 
 	// build geometry
 
-	this.setIndex( new ( indices.length > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( indices, 1 ) );
+	this.setIndex( indices );
 	this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
 	this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
 	this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
@@ -25428,7 +25463,7 @@ function TorusBufferGeometry( radius, tube, radialSegments, tubularSegments, arc
 
 	// build geometry
 
-	this.setIndex( new ( indices.length > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( indices, 1 ) );
+	this.setIndex( indices );
 	this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
 	this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
 	this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
@@ -26856,7 +26891,7 @@ function TextGeometry( text, parameters ) {
 
 	var font = parameters.font;
 
-	if ( (font && font.isFont) === false ) {
+	if ( ( font && font.isFont ) === false ) {
 
 		console.error( 'THREE.TextGeometry: font parameter is not an instance of THREE.Font.' );
 		return new Geometry();
@@ -27017,7 +27052,7 @@ function SphereBufferGeometry( radius, widthSegments, heightSegments, phiStart,
 
 	// build geometry
 
-	this.setIndex( new ( indices.length > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( indices, 1 ) );
+	this.setIndex( indices );
 	this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
 	this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
 	this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
@@ -27119,7 +27154,7 @@ function RingBufferGeometry( innerRadius, outerRadius, thetaSegments, phiSegment
 			normals.push( 0, 0, 1 );
 
 			// uv
-			
+
 			uv.x = ( vertex.x / outerRadius + 1 ) / 2;
 			uv.y = ( vertex.y / outerRadius + 1 ) / 2;
 
@@ -27159,7 +27194,7 @@ function RingBufferGeometry( innerRadius, outerRadius, thetaSegments, phiSegment
 
 	// build geometry
 
-	this.setIndex( new ( indices.length > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( indices, 1 ) );
+	this.setIndex( indices );
 	this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
 	this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
 	this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
@@ -27225,7 +27260,7 @@ function LatheBufferGeometry( points, segments, phiStart, phiLength ) {
 	phiLength = phiLength || Math.PI * 2;
 
 	// clamp phiLength so it's in range of [ 0, 2PI ]
-	
+
 	phiLength = _Math.clamp( phiLength, 0, Math.PI * 2 );
 
 
@@ -27298,7 +27333,7 @@ function LatheBufferGeometry( points, segments, phiStart, phiLength ) {
 
 	// build geometry
 
-	this.setIndex( new ( indices.length > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( indices, 1 ) );
+	this.setIndex( indices );
 	this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
 	this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
 
@@ -27436,7 +27471,7 @@ function ShapeBufferGeometry( shapes, curveSegments ) {
 
 	// build geometry
 
-	this.setIndex( new ( indices.length > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( indices, 1 ) );
+	this.setIndex( indices );
 	this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
 	this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
 	this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
@@ -27523,25 +27558,32 @@ ShapeBufferGeometry.prototype.constructor = ShapeBufferGeometry;
 
 /**
  * @author WestLangley / http://github.com/WestLangley
+ * @author Mugen87 / https://github.com/Mugen87
  */
 
 function EdgesGeometry( geometry, thresholdAngle ) {
 
 	BufferGeometry.call( this );
 
-	thresholdAngle = ( thresholdAngle !== undefined ) ? thresholdAngle : 1;
+	this.type = 'EdgesGeometry';
 
-	var thresholdDot = Math.cos( _Math.DEG2RAD * thresholdAngle );
+	this.parameters = {
+		thresholdAngle: thresholdAngle
+	};
+
+	thresholdAngle = ( thresholdAngle !== undefined ) ? thresholdAngle : 1;
 
-	var edge = [ 0, 0 ], hash = {};
+	// buffer
 
-	function sortFunction( a, b ) {
+	var vertices = [];
 
-		return a - b;
+	// helper variables
 
-	}
+	var thresholdDot = Math.cos( _Math.DEG2RAD * thresholdAngle );
+	var edge = [ 0, 0 ], edges = {};
+	var key, keys = [ 'a', 'b', 'c' ];
 
-	var keys = [ 'a', 'b', 'c' ];
+	// prepare source geometry
 
 	var geometry2;
 
@@ -27559,9 +27601,11 @@ function EdgesGeometry( geometry, thresholdAngle ) {
 	geometry2.mergeVertices();
 	geometry2.computeFaceNormals();
 
-	var vertices = geometry2.vertices;
+	var sourceVertices = geometry2.vertices;
 	var faces = geometry2.faces;
 
+	// now create a data structure where each entry represents an edge with its adjoining faces
+
 	for ( var i = 0, l = faces.length; i < l; i ++ ) {
 
 		var face = faces[ i ];
@@ -27572,15 +27616,15 @@ function EdgesGeometry( geometry, thresholdAngle ) {
 			edge[ 1 ] = face[ keys[ ( j + 1 ) % 3 ] ];
 			edge.sort( sortFunction );
 
-			var key = edge.toString();
+			key = edge.toString();
 
-			if ( hash[ key ] === undefined ) {
+			if ( edges[ key ] === undefined ) {
 
-				hash[ key ] = { vert1: edge[ 0 ], vert2: edge[ 1 ], face1: i, face2: undefined };
+				edges[ key ] = { index1: edge[ 0 ], index2: edge[ 1 ], face1: i, face2: undefined };
 
 			} else {
 
-				hash[ key ].face2 = i;
+				edges[ key ].face2 = i;
 
 			}
 
@@ -27588,31 +27632,37 @@ function EdgesGeometry( geometry, thresholdAngle ) {
 
 	}
 
-	var coords = [];
+	// generate vertices
 
-	for ( var key in hash ) {
+	for ( key in edges ) {
 
-		var h = hash[ key ];
+		var e = edges[ key ];
 
-		// An edge is only rendered if the angle (in degrees) between the face normals of the adjoining faces exceeds this value. default = 1 degree.
+		// an edge is only rendered if the angle (in degrees) between the face normals of the adjoining faces exceeds this value. default = 1 degree.
 
-		if ( h.face2 === undefined || faces[ h.face1 ].normal.dot( faces[ h.face2 ].normal ) <= thresholdDot ) {
+		if ( e.face2 === undefined || faces[ e.face1 ].normal.dot( faces[ e.face2 ].normal ) <= thresholdDot ) {
 
-			var vertex = vertices[ h.vert1 ];
-			coords.push( vertex.x );
-			coords.push( vertex.y );
-			coords.push( vertex.z );
+			var vertex = sourceVertices[ e.index1 ];
+			vertices.push( vertex.x, vertex.y, vertex.z );
 
-			vertex = vertices[ h.vert2 ];
-			coords.push( vertex.x );
-			coords.push( vertex.y );
-			coords.push( vertex.z );
+			vertex = sourceVertices[ e.index2 ];
+			vertices.push( vertex.x, vertex.y, vertex.z );
 
 		}
 
 	}
 
-	this.addAttribute( 'position', new Float32BufferAttribute( coords, 3 ) );
+	// build geometry
+
+	this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
+
+	// custom array sort function
+
+	function sortFunction( a, b ) {
+
+		return a - b;
+
+	}
 
 }
 
@@ -27710,7 +27760,7 @@ function CylinderBufferGeometry( radiusTop, radiusBottom, height, radialSegments
 
 	// build geometry
 
-	this.setIndex( new ( indices.length > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( indices, 1 ) );
+	this.setIndex( indices );
 	this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
 	this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
 	this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
@@ -28078,7 +28128,7 @@ function CircleBufferGeometry( radius, segments, thetaStart, thetaLength ) {
 
 	// build geometry
 
-	this.setIndex( new ( indices.length > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( indices, 1 ) );
+	this.setIndex( indices );
 	this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
 	this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
 	this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
@@ -33038,7 +33088,10 @@ Object.assign( ObjectLoader.prototype, {
 
 			} catch ( error ) {
 
+				if ( onError !== undefined ) onError( error );
+
 				console.error( 'THREE:ObjectLoader: Can\'t parse ' + url + '.', error.message );
+
 				return;
 
 			}
@@ -35562,6 +35615,7 @@ function CubeCamera( near, far, cubeResolution ) {
 	var options = { format: RGBFormat, magFilter: LinearFilter, minFilter: LinearFilter };
 
 	this.renderTarget = new WebGLRenderTargetCube( cubeResolution, cubeResolution, options );
+	this.renderTarget.texture.name = "CubeCamera";
 
 	this.updateCubeMap = function ( renderer, scene ) {
 
@@ -36600,7 +36654,7 @@ PropertyBinding.prototype = {
 
 			this.resolvedProperty = nodeProperty;
 
-		} else if ( nodeProperty.length !== undefined ) {
+		} else if ( Array.isArray( nodeProperty ) ) {
 
 			bindingType = this.BindingType.EntireArray;
 
@@ -41046,11 +41100,8 @@ BoxHelper.prototype.update = ( function () {
  *  headWidth - Number
  */
 
-var lineGeometry = new BufferGeometry();
-lineGeometry.addAttribute( 'position', new Float32BufferAttribute( [ 0, 0, 0, 0, 1, 0 ], 3 ) );
-
-var coneGeometry = new CylinderBufferGeometry( 0, 0.5, 1, 5, 1 );
-coneGeometry.translate( 0, - 0.5, 0 );
+var lineGeometry;
+var coneGeometry;
 
 function ArrowHelper( dir, origin, length, color, headLength, headWidth ) {
 
@@ -41063,6 +41114,16 @@ function ArrowHelper( dir, origin, length, color, headLength, headWidth ) {
 	if ( headLength === undefined ) headLength = 0.2 * length;
 	if ( headWidth === undefined ) headWidth = 0.2 * headLength;
 
+	if ( lineGeometry === undefined ) {
+
+		lineGeometry = new BufferGeometry();
+		lineGeometry.addAttribute( 'position', new Float32BufferAttribute( [ 0, 0, 0, 0, 1, 0 ], 3 ) );
+
+		coneGeometry = new CylinderBufferGeometry( 0, 0.5, 1, 5, 1 );
+		coneGeometry.translate( 0, - 0.5, 0 );
+
+	}
+
 	this.position.copy( origin );
 
 	this.line = new Line( lineGeometry, new LineBasicMaterial( { color: color } ) );

+ 2 - 2
docs/api/animation/AnimationUtils.html

@@ -18,12 +18,12 @@
 
     <h3>[method:Array arraySlice]( array, from, to )</h3>
     <div>
-    Convert an array to a specific type.
+    This is the same as  Array.prototype.slice, but also works on typed arrays.
     </div>
 
     <h3>[method:Array convertArray]( array, type, forceClone )</h3>
     <div>
-    This is the same as  Array.prototype.slice, but also works on typed arrays.
+    Convert an array to a specific type.
     </div>
 
     <h3>[method:Boolean isTypedArray]( object )</h3>

+ 4 - 4
docs/api/extras/SceneUtils.html

@@ -16,14 +16,14 @@
 		<h2>Methods</h2>
 
 
-		<h3>[method:Object3D createMultiMaterialObject]( [page:Geometry geometry], [page:Array materials] )</h3>
+		<h3>[method:Group createMultiMaterialObject]( [page:Geometry geometry], [page:Array materials] )</h3>
 		<div>
-		geometry -- The geometry for the Object. <br />
+		geometry -- The geometry for the set of materials. <br />
 		materials -- The materials for the object.
 		</div>
 		<div>
-		Creates an new Object3D an new mesh for each material defined in materials. Beware that this is not the same as MultiMaterial which defines multiple material for 1 mesh.<br />
-		This is mostly useful for object that need a material and a wireframe implementation.
+		Creates a new Group that contains a new mesh for each material defined in materials. Beware that this is not the same as MultiMaterial which defines multiple material for 1 mesh.<br />
+		This is mostly useful for objects that need both a material and a wireframe implementation.
 		</div>
 
 		<h3>[method:null attach]( [page:Object3D child], [page:Object3D scene], [page:Object3D parent] )</h3>

+ 1 - 1
docs/api/extras/helpers/ArrowHelper.html → docs/api/helpers/ArrowHelper.html

@@ -2,7 +2,7 @@
 <html lang="en">
 	<head>
 		<meta charset="utf-8" />
-		<base href="../../../" />
+		<base href="../../" />
 		<script src="list.js"></script>
 		<script src="page.js"></script>
 		<link type="text/css" rel="stylesheet" href="page.css" />

+ 1 - 1
docs/api/extras/helpers/AxisHelper.html → docs/api/helpers/AxisHelper.html

@@ -2,7 +2,7 @@
 <html lang="en">
 	<head>
 		<meta charset="utf-8" />
-		<base href="../../../" />
+		<base href="../../" />
 		<script src="list.js"></script>
 		<script src="page.js"></script>
 		<link type="text/css" rel="stylesheet" href="page.css" />

+ 1 - 1
docs/api/extras/helpers/BoxHelper.html → docs/api/helpers/BoxHelper.html

@@ -2,7 +2,7 @@
 <html lang="en">
 	<head>
 		<meta charset="utf-8" />
-		<base href="../../../" />
+		<base href="../../" />
 		<script src="list.js"></script>
 		<script src="page.js"></script>
 		<link type="text/css" rel="stylesheet" href="page.css" />

+ 2 - 3
docs/api/extras/helpers/CameraHelper.html → docs/api/helpers/CameraHelper.html

@@ -2,7 +2,7 @@
 <html lang="en">
 	<head>
 		<meta charset="utf-8" />
-		<base href="../../../" />
+		<base href="../../" />
 		<script src="list.js"></script>
 		<script src="page.js"></script>
 		<link type="text/css" rel="stylesheet" href="page.css" />
@@ -24,8 +24,7 @@
 
 		<code>
 var camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 0.1, 1000 );
-
-var helper = new THREE.CameraHelper( cameraPerspective );
+var helper = new THREE.CameraHelper( camera );
 scene.add( helper );
 		</code>
 

+ 1 - 1
docs/api/extras/helpers/DirectionalLightHelper.html → docs/api/helpers/DirectionalLightHelper.html

@@ -2,7 +2,7 @@
 <html lang="en">
 	<head>
 		<meta charset="utf-8" />
-		<base href="../../../" />
+		<base href="../../" />
 		<script src="list.js"></script>
 		<script src="page.js"></script>
 		<link type="text/css" rel="stylesheet" href="page.css" />

+ 1 - 1
docs/api/extras/helpers/FaceNormalsHelper.html → docs/api/helpers/FaceNormalsHelper.html

@@ -2,7 +2,7 @@
 <html lang="en">
 	<head>
 		<meta charset="utf-8" />
-		<base href="../../../" />
+		<base href="../../" />
 		<script src="list.js"></script>
 		<script src="page.js"></script>
 		<link type="text/css" rel="stylesheet" href="page.css" />

+ 1 - 1
docs/api/extras/helpers/GridHelper.html → docs/api/helpers/GridHelper.html

@@ -2,7 +2,7 @@
 <html lang="en">
 	<head>
 		<meta charset="utf-8" />
-		<base href="../../../" />
+		<base href="../../" />
 		<script src="list.js"></script>
 		<script src="page.js"></script>
 		<link type="text/css" rel="stylesheet" href="page.css" />

+ 1 - 1
docs/api/extras/helpers/HemisphereLightHelper.html → docs/api/helpers/HemisphereLightHelper.html

@@ -2,7 +2,7 @@
 <html lang="en">
 	<head>
 		<meta charset="utf-8" />
-		<base href="../../../" />
+		<base href="../../" />
 		<script src="list.js"></script>
 		<script src="page.js"></script>
 		<link type="text/css" rel="stylesheet" href="page.css" />

+ 1 - 1
docs/api/extras/helpers/PointLightHelper.html → docs/api/helpers/PointLightHelper.html

@@ -2,7 +2,7 @@
 <html lang="en">
 	<head>
 		<meta charset="utf-8" />
-		<base href="../../../" />
+		<base href="../../" />
 		<script src="list.js"></script>
 		<script src="page.js"></script>
 		<link type="text/css" rel="stylesheet" href="page.css" />

+ 1 - 1
docs/api/extras/helpers/PolarGridHelper.html → docs/api/helpers/PolarGridHelper.html

@@ -2,7 +2,7 @@
 <html lang="en">
 	<head>
 		<meta charset="utf-8" />
-		<base href="../../../" />
+		<base href="../../" />
 		<script src="list.js"></script>
 		<script src="page.js"></script>
 		<link type="text/css" rel="stylesheet" href="page.css" />

+ 1 - 1
docs/api/extras/helpers/RectAreaLightHelper.html → docs/api/helpers/RectAreaLightHelper.html

@@ -2,7 +2,7 @@
 <html lang="en">
 	<head>
 		<meta charset="utf-8" />
-		<base href="../../../" />
+		<base href="../../" />
 		<script src="list.js"></script>
 		<script src="page.js"></script>
 		<link type="text/css" rel="stylesheet" href="page.css" />

+ 1 - 1
docs/api/extras/helpers/SkeletonHelper.html → docs/api/helpers/SkeletonHelper.html

@@ -2,7 +2,7 @@
 <html lang="en">
 	<head>
 		<meta charset="utf-8" />
-		<base href="../../../" />
+		<base href="../../" />
 		<script src="list.js"></script>
 		<script src="page.js"></script>
 		<link type="text/css" rel="stylesheet" href="page.css" />

+ 1 - 1
docs/api/extras/helpers/SpotLightHelper.html → docs/api/helpers/SpotLightHelper.html

@@ -2,7 +2,7 @@
 <html lang="en">
 	<head>
 		<meta charset="utf-8" />
-		<base href="../../../" />
+		<base href="../../" />
 		<script src="list.js"></script>
 		<script src="page.js"></script>
 		<link type="text/css" rel="stylesheet" href="page.css" />

+ 1 - 1
docs/api/extras/helpers/VertexNormalsHelper.html → docs/api/helpers/VertexNormalsHelper.html

@@ -2,7 +2,7 @@
 <html lang="en">
 	<head>
 		<meta charset="utf-8" />
-		<base href="../../../" />
+		<base href="../../" />
 		<script src="list.js"></script>
 		<script src="page.js"></script>
 		<link type="text/css" rel="stylesheet" href="page.css" />

+ 1 - 1
docs/api/lights/RectAreaLight.html

@@ -96,7 +96,7 @@ scene.add(rectLight)
 
 		<h3>[property:Boolean isRectAreaLight]</h3>
 		<div>
-			Used to check whether this or derived classes are spot lights. Default is *true*.<br /><br />
+			Used to check whether this or derived classes are RectAreaLights. Default is *true*.<br /><br />
 
 			You should not change this, as it used internally for optimisation.
 		</div>

+ 2 - 2
docs/api/objects/Line.html

@@ -17,8 +17,8 @@
 
 			This is nearly the same
 			as [page:LineSegments]; the only difference is that it is rendered using
-			[link:https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/drawElements gl.LINES]
-			instead of [link:https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/drawElements gl.LINE_STRIP]
+			[link:https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/drawElements gl.LINE_STRIP]
+			instead of [link:https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/drawElements gl.LINES]
 
 		</div>
 

+ 2 - 2
docs/api/objects/LineSegments.html

@@ -16,8 +16,8 @@
 			A series of lines drawn between pairs of vertices.<br /><br />
 
 			This is nearly the same	as [page:Line]; the only difference is that it is rendered using
-			[link:https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/drawElements gl.LINE_STRIP]
-			instead of [link:https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/drawElements gl.LINES]
+			[link:https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/drawElements gl.LINES]
+			instead of [link:https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/drawElements gl.LINE_STRIP].
 		</div>
 
 

+ 17 - 17
docs/list.js

@@ -126,23 +126,6 @@ var list = {
 			[ "SplineCurve", "api/extras/curves/SplineCurve" ]
 		],
 
-		"Extras / Helpers": [
-			[ "ArrowHelper", "api/extras/helpers/ArrowHelper" ],
-			[ "AxisHelper", "api/extras/helpers/AxisHelper" ],
-			[ "BoxHelper", "api/extras/helpers/BoxHelper" ],
-			[ "CameraHelper", "api/extras/helpers/CameraHelper" ],
-			[ "DirectionalLightHelper", "api/extras/helpers/DirectionalLightHelper" ],
-			[ "FaceNormalsHelper", "api/extras/helpers/FaceNormalsHelper" ],
-			[ "GridHelper", "api/extras/helpers/GridHelper" ],
-			[ "PolarGridHelper", "api/extras/helpers/PolarGridHelper"],
-			[ "HemisphereLightHelper", "api/extras/helpers/HemisphereLightHelper" ],
-			[ "PointLightHelper", "api/extras/helpers/PointLightHelper" ],
-			[ "RectAreaLightHelper", "api/extras/helpers/RectAreaLightHelper" ],
-			[ "SkeletonHelper", "api/extras/helpers/SkeletonHelper" ],
-			[ "SpotLightHelper", "api/extras/helpers/SpotLightHelper" ],
-			[ "VertexNormalsHelper", "api/extras/helpers/VertexNormalsHelper" ]
-		],
-
 		"Extras / Objects": [
 			[ "ImmediateRenderObject", "api/extras/objects/ImmediateRenderObject" ],
 			[ "MorphBlendMesh", "api/extras/objects/MorphBlendMesh" ]
@@ -191,6 +174,23 @@ var list = {
 			[ "WireframeGeometry", "api/geometries/WireframeGeometry" ]
 		],
 
+		"Helpers": [
+			[ "ArrowHelper", "api/helpers/ArrowHelper" ],
+			[ "AxisHelper", "api/helpers/AxisHelper" ],
+			[ "BoxHelper", "api/helpers/BoxHelper" ],
+			[ "CameraHelper", "api/helpers/CameraHelper" ],
+			[ "DirectionalLightHelper", "api/helpers/DirectionalLightHelper" ],
+			[ "FaceNormalsHelper", "api/helpers/FaceNormalsHelper" ],
+			[ "GridHelper", "api/helpers/GridHelper" ],
+			[ "PolarGridHelper", "api/helpers/PolarGridHelper" ],
+			[ "HemisphereLightHelper", "api/helpers/HemisphereLightHelper" ],
+			[ "PointLightHelper", "api/helpers/PointLightHelper" ],
+			[ "RectAreaLightHelper", "api/helpers/RectAreaLightHelper" ],
+			[ "SkeletonHelper", "api/helpers/SkeletonHelper" ],
+			[ "SpotLightHelper", "api/helpers/SpotLightHelper" ],
+			[ "VertexNormalsHelper", "api/helpers/VertexNormalsHelper" ]
+		],
+
 		"Lights": [
 			[ "AmbientLight", "api/lights/AmbientLight" ],
 			[ "DirectionalLight", "api/lights/DirectionalLight" ],

+ 22 - 0
editor/js/libs/app/index.html

@@ -13,6 +13,19 @@
 				margin: 0px;
 				overflow: hidden;
 			}
+			#edit {
+				position: absolute;
+				bottom: 20px;
+				right: 20px;
+				padding: 8px;
+				text-decoration: none;
+				background-color: #fff;
+				color: #555;
+				opacity: 0.5;
+			}
+			#edit:hover {
+				opacity: 1;
+			}
 		</style>
 	</head>
 	<body ontouchstart="">
@@ -35,6 +48,15 @@
 					player.setSize( window.innerWidth, window.innerHeight );
 				} );
 
+				if ( location.search === '?edit' ) {
+					var button = document.createElement( 'a' );
+					button.id = 'edit';
+					button.href = 'https://threejs.org/editor/#file=' + location.href.split( '/' ).slice( 0, - 1 ).join( '/' ) + '/app.json';
+					button.target = '_blank';
+					button.textContent = 'EDIT';
+					document.body.appendChild( button );
+				}
+
 			} );
 
 		</script>

+ 47 - 55
examples/js/Mirror.js

@@ -2,56 +2,6 @@
  * @author Slayvin / http://slayvin.net
  */
 
-THREE.ShaderLib[ 'mirror' ] = {
-
-	uniforms: {
-		"mirrorColor": { value: new THREE.Color( 0x7F7F7F ) },
-		"mirrorSampler": { value: null },
-		"textureMatrix" : { value: new THREE.Matrix4() }
-	},
-
-	vertexShader: [
-
-		"uniform mat4 textureMatrix;",
-
-		"varying vec4 mirrorCoord;",
-
-		"void main() {",
-
-			"vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
-			"vec4 worldPosition = modelMatrix * vec4( position, 1.0 );",
-			"mirrorCoord = textureMatrix * worldPosition;",
-
-			"gl_Position = projectionMatrix * mvPosition;",
-
-		"}"
-
-	].join( "\n" ),
-
-	fragmentShader: [
-
-		"uniform vec3 mirrorColor;",
-		"uniform sampler2D mirrorSampler;",
-
-		"varying vec4 mirrorCoord;",
-
-		"float blendOverlay(float base, float blend) {",
-			"return( base < 0.5 ? ( 2.0 * base * blend ) : (1.0 - 2.0 * ( 1.0 - base ) * ( 1.0 - blend ) ) );",
-		"}",
-
-		"void main() {",
-
-			"vec4 color = texture2DProj(mirrorSampler, mirrorCoord);",
-			"color = vec4(blendOverlay(mirrorColor.r, color.r), blendOverlay(mirrorColor.g, color.g), blendOverlay(mirrorColor.b, color.b), 1.0);",
-
-			"gl_FragColor = color;",
-
-		"}"
-
-	].join( "\n" )
-
-};
-
 THREE.Mirror = function ( renderer, camera, options ) {
 
 	THREE.Object3D.call( this );
@@ -118,7 +68,47 @@ THREE.Mirror = function ( renderer, camera, options ) {
 	this.renderTarget = new THREE.WebGLRenderTarget( width, height, parameters );
 	this.renderTarget2 = new THREE.WebGLRenderTarget( width, height, parameters );
 
-	var mirrorShader = THREE.ShaderLib[ "mirror" ];
+	var mirrorShader = {
+
+		uniforms: {
+			mirrorColor: { value: new THREE.Color( 0x7F7F7F ) },
+			mirrorSampler: { value: null },
+			textureMatrix: { value: new THREE.Matrix4() }
+		},
+
+		vertexShader: [
+			'uniform mat4 textureMatrix;',
+			'varying vec4 mirrorCoord;',
+
+			'void main() {',
+
+			'	vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );',
+			'	vec4 worldPosition = modelMatrix * vec4( position, 1.0 );',
+			'	mirrorCoord = textureMatrix * worldPosition;',
+
+			'	gl_Position = projectionMatrix * mvPosition;',
+
+			'}'
+		].join( '\n' ),
+
+		fragmentShader: [
+			'uniform vec3 mirrorColor;',
+			'uniform sampler2D mirrorSampler;',
+			'varying vec4 mirrorCoord;',
+
+			'float blendOverlay(float base, float blend) {',
+			'	return( base < 0.5 ? ( 2.0 * base * blend ) : (1.0 - 2.0 * ( 1.0 - base ) * ( 1.0 - blend ) ) );',
+			'}',
+
+			'void main() {',
+			'	vec4 color = texture2DProj(mirrorSampler, mirrorCoord);',
+			'	color = vec4(blendOverlay(mirrorColor.r, color.r), blendOverlay(mirrorColor.g, color.g), blendOverlay(mirrorColor.b, color.b), 1.0);',
+			'	gl_FragColor = color;',
+			'}'
+		].join( '\n' )
+
+	};
+
 	var mirrorUniforms = THREE.UniformsUtils.clone( mirrorShader.uniforms );
 
 	this.material = new THREE.ShaderMaterial( {
@@ -215,10 +205,12 @@ THREE.Mirror.prototype.updateTextureMatrix = function () {
 	this.mirrorCamera.matrixWorldInverse.getInverse( this.mirrorCamera.matrixWorld );
 
 	// Update the texture matrix
-	this.textureMatrix.set( 0.5, 0.0, 0.0, 0.5,
-							0.0, 0.5, 0.0, 0.5,
-							0.0, 0.0, 0.5, 0.5,
-							0.0, 0.0, 0.0, 1.0 );
+	this.textureMatrix.set(
+		0.5, 0.0, 0.0, 0.5,
+		0.0, 0.5, 0.0, 0.5,
+		0.0, 0.0, 0.5, 0.5,
+		0.0, 0.0, 0.0, 1.0
+	);
 	this.textureMatrix.multiply( this.mirrorCamera.projectionMatrix );
 	this.textureMatrix.multiply( this.mirrorCamera.matrixWorldInverse );
 

+ 134 - 148
examples/js/SkyShader.js

@@ -14,211 +14,197 @@
  * Three.js integration by zz85 http://twitter.com/blurspline
 */
 
-THREE.ShaderLib[ 'sky' ] = {
-
-	uniforms: {
+THREE.Sky = function () {
 
-		luminance: { value: 1 },
-		turbidity: { value: 2 },
-		rayleigh: { value: 1 },
-		mieCoefficient: { value: 0.005 },
-		mieDirectionalG: { value: 0.8 },
-		sunPosition: { value: new THREE.Vector3() }
+	var skyShader = {
 
-	},
+		uniforms: {
+			luminance: { value: 1 },
+			turbidity: { value: 2 },
+			rayleigh: { value: 1 },
+			mieCoefficient: { value: 0.005 },
+			mieDirectionalG: { value: 0.8 },
+			sunPosition: { value: new THREE.Vector3() }
+		},
 
-	vertexShader: [
+		vertexShader: [
+			'uniform vec3 sunPosition;',
+			'uniform float rayleigh;',
+			'uniform float turbidity;',
+			'uniform float mieCoefficient;',
 
-		"uniform vec3 sunPosition;",
-		"uniform float rayleigh;",
-		"uniform float turbidity;",
-		"uniform float mieCoefficient;",
+			'varying vec3 vWorldPosition;',
+			'varying vec3 vSunDirection;',
+			'varying float vSunfade;',
+			'varying vec3 vBetaR;',
+			'varying vec3 vBetaM;',
+			'varying float vSunE;',
 
-		"varying vec3 vWorldPosition;",
-		"varying vec3 vSunDirection;",
-		"varying float vSunfade;",
-		"varying vec3 vBetaR;",
-		"varying vec3 vBetaM;",
-		"varying float vSunE;",
+			'const vec3 up = vec3( 0.0, 1.0, 0.0 );',
 
-		"const vec3 up = vec3( 0.0, 1.0, 0.0 );",
+			// constants for atmospheric scattering
+			'const float e = 2.71828182845904523536028747135266249775724709369995957;',
+			'const float pi = 3.141592653589793238462643383279502884197169;',
 
-		// constants for atmospheric scattering
-		"const float e = 2.71828182845904523536028747135266249775724709369995957;",
-		"const float pi = 3.141592653589793238462643383279502884197169;",
+			// wavelength of used primaries, according to preetham
+			'const vec3 lambda = vec3( 680E-9, 550E-9, 450E-9 );',
+			// this pre-calcuation replaces older TotalRayleigh(vec3 lambda) function:
+			// (8.0 * pow(pi, 3.0) * pow(pow(n, 2.0) - 1.0, 2.0) * (6.0 + 3.0 * pn)) / (3.0 * N * pow(lambda, vec3(4.0)) * (6.0 - 7.0 * pn))
+			'const vec3 totalRayleigh = vec3( 5.804542996261093E-6, 1.3562911419845635E-5, 3.0265902468824876E-5 );',
 
-		// wavelength of used primaries, according to preetham
-		"const vec3 lambda = vec3( 680E-9, 550E-9, 450E-9 );",
-		// this pre-calcuation replaces older TotalRayleigh(vec3 lambda) function:
-		// (8.0 * pow(pi, 3.0) * pow(pow(n, 2.0) - 1.0, 2.0) * (6.0 + 3.0 * pn)) / (3.0 * N * pow(lambda, vec3(4.0)) * (6.0 - 7.0 * pn))
-		"const vec3 totalRayleigh = vec3( 5.804542996261093E-6, 1.3562911419845635E-5, 3.0265902468824876E-5 );",
-		
-		// mie stuff
-		// K coefficient for the primaries
-		"const float v = 4.0;",
-		"const vec3 K = vec3( 0.686, 0.678, 0.666 );",
-		// MieConst = pi * pow( ( 2.0 * pi ) / lambda, vec3( v - 2.0 ) ) * K
-		"const vec3 MieConst = vec3( 1.8399918514433978E14, 2.7798023919660528E14, 4.0790479543861094E14 );",
+			// mie stuff
+			// K coefficient for the primaries
+			'const float v = 4.0;',
+			'const vec3 K = vec3( 0.686, 0.678, 0.666 );',
+			// MieConst = pi * pow( ( 2.0 * pi ) / lambda, vec3( v - 2.0 ) ) * K
+			'const vec3 MieConst = vec3( 1.8399918514433978E14, 2.7798023919660528E14, 4.0790479543861094E14 );',
 
-		// earth shadow hack
-		// cutoffAngle = pi / 1.95;
-		"const float cutoffAngle = 1.6110731556870734;",
-		"const float steepness = 1.5;",
-		"const float EE = 1000.0;",
+			// earth shadow hack
+			// cutoffAngle = pi / 1.95;
+			'const float cutoffAngle = 1.6110731556870734;',
+			'const float steepness = 1.5;',
+			'const float EE = 1000.0;',
 
-		"float sunIntensity( float zenithAngleCos )",
-		"{",
-			"zenithAngleCos = clamp( zenithAngleCos, -1.0, 1.0 );",
-			"return EE * max( 0.0, 1.0 - pow( e, -( ( cutoffAngle - acos( zenithAngleCos ) ) / steepness ) ) );",
-		"}",
+			'float sunIntensity( float zenithAngleCos ) {',
+			'	zenithAngleCos = clamp( zenithAngleCos, -1.0, 1.0 );',
+			'	return EE * max( 0.0, 1.0 - pow( e, -( ( cutoffAngle - acos( zenithAngleCos ) ) / steepness ) ) );',
+			'}',
 
-		"vec3 totalMie( float T )",
-		"{",
-			"float c = ( 0.2 * T ) * 10E-18;",
-			"return 0.434 * c * MieConst;",
-		"}",
+			'vec3 totalMie( float T ) {',
+			'	float c = ( 0.2 * T ) * 10E-18;',
+			'	return 0.434 * c * MieConst;',
+			'}',
 
-		"void main() {",
+			'void main() {',
 
-			"vec4 worldPosition = modelMatrix * vec4( position, 1.0 );",
-			"vWorldPosition = worldPosition.xyz;",
+			'	vec4 worldPosition = modelMatrix * vec4( position, 1.0 );',
+			'	vWorldPosition = worldPosition.xyz;',
 
-			"gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
+			'	gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );',
 
-			"vSunDirection = normalize( sunPosition );",
+			'	vSunDirection = normalize( sunPosition );',
 
-			"vSunE = sunIntensity( dot( vSunDirection, up ) );",
+			'	vSunE = sunIntensity( dot( vSunDirection, up ) );',
 
-			"vSunfade = 1.0 - clamp( 1.0 - exp( ( sunPosition.y / 450000.0 ) ), 0.0, 1.0 );",
+			'	vSunfade = 1.0 - clamp( 1.0 - exp( ( sunPosition.y / 450000.0 ) ), 0.0, 1.0 );',
 
-			"float rayleighCoefficient = rayleigh - ( 1.0 * ( 1.0 - vSunfade ) );",
+			'	float rayleighCoefficient = rayleigh - ( 1.0 * ( 1.0 - vSunfade ) );',
 
 			// extinction (absorbtion + out scattering)
 			// rayleigh coefficients
-			"vBetaR = totalRayleigh * rayleighCoefficient;",
+			'	vBetaR = totalRayleigh * rayleighCoefficient;',
 
 			// mie coefficients
-			"vBetaM = totalMie( turbidity ) * mieCoefficient;",
-
-		"}"
-
-	].join( "\n" ),
+			'	vBetaM = totalMie( turbidity ) * mieCoefficient;',
 
-	fragmentShader: [
+			'}'
+		].join( '\n' ),
 
-		"varying vec3 vWorldPosition;",
-		"varying vec3 vSunDirection;",
-		"varying float vSunfade;",
-		"varying vec3 vBetaR;",
-		"varying vec3 vBetaM;",
-		"varying float vSunE;",
+		fragmentShader: [
+			'varying vec3 vWorldPosition;',
+			'varying vec3 vSunDirection;',
+			'varying float vSunfade;',
+			'varying vec3 vBetaR;',
+			'varying vec3 vBetaM;',
+			'varying float vSunE;',
 
-		"uniform float luminance;",
-		"uniform float mieDirectionalG;",
+			'uniform float luminance;',
+			'uniform float mieDirectionalG;',
 
-		"const vec3 cameraPos = vec3( 0.0, 0.0, 0.0 );",
+			'const vec3 cameraPos = vec3( 0.0, 0.0, 0.0 );',
 
-		// constants for atmospheric scattering
-		"const float pi = 3.141592653589793238462643383279502884197169;",
+			// constants for atmospheric scattering
+			'const float pi = 3.141592653589793238462643383279502884197169;',
 
-		"const float n = 1.0003;", // refractive index of air
-		"const float N = 2.545E25;", // number of molecules per unit volume for air at
-									// 288.15K and 1013mb (sea level -45 celsius)
+			'const float n = 1.0003;', // refractive index of air
+			'const float N = 2.545E25;', // number of molecules per unit volume for air at
+										// 288.15K and 1013mb (sea level -45 celsius)
 
-		// optical length at zenith for molecules
-		"const float rayleighZenithLength = 8.4E3;",
-		"const float mieZenithLength = 1.25E3;",
-		"const vec3 up = vec3( 0.0, 1.0, 0.0 );",
-		// 66 arc seconds -> degrees, and the cosine of that
-		"const float sunAngularDiameterCos = 0.999956676946448443553574619906976478926848692873900859324;",
+			// optical length at zenith for molecules
+			'const float rayleighZenithLength = 8.4E3;',
+			'const float mieZenithLength = 1.25E3;',
+			'const vec3 up = vec3( 0.0, 1.0, 0.0 );',
+			// 66 arc seconds -> degrees, and the cosine of that
+			'const float sunAngularDiameterCos = 0.999956676946448443553574619906976478926848692873900859324;',
 
-		// 3.0 / ( 16.0 * pi )
-		"const float THREE_OVER_SIXTEENPI = 0.05968310365946075;",
-		// 1.0 / ( 4.0 * pi )
-		"const float ONE_OVER_FOURPI = 0.07957747154594767;",
+			// 3.0 / ( 16.0 * pi )
+			'const float THREE_OVER_SIXTEENPI = 0.05968310365946075;',
+			// 1.0 / ( 4.0 * pi )
+			'const float ONE_OVER_FOURPI = 0.07957747154594767;',
 
-		"float rayleighPhase( float cosTheta )",
-		"{",
-			"return THREE_OVER_SIXTEENPI * ( 1.0 + pow( cosTheta, 2.0 ) );",
-		"}",
+			'float rayleighPhase( float cosTheta ) {',
+			'	return THREE_OVER_SIXTEENPI * ( 1.0 + pow( cosTheta, 2.0 ) );',
+			'}',
 
-		"float hgPhase( float cosTheta, float g )",
-		"{",
-			"float g2 = pow( g, 2.0 );",
-			"float inverse = 1.0 / pow( 1.0 - 2.0 * g * cosTheta + g2, 1.5 );",
-			"return ONE_OVER_FOURPI * ( ( 1.0 - g2 ) * inverse );",
-		"}",
+			'float hgPhase( float cosTheta, float g ) {',
+			'	float g2 = pow( g, 2.0 );',
+			'	float inverse = 1.0 / pow( 1.0 - 2.0 * g * cosTheta + g2, 1.5 );',
+			'	return ONE_OVER_FOURPI * ( ( 1.0 - g2 ) * inverse );',
+			'}',
 
-		// Filmic ToneMapping http://filmicgames.com/archives/75
-		"const float A = 0.15;",
-		"const float B = 0.50;",
-		"const float C = 0.10;",
-		"const float D = 0.20;",
-		"const float E = 0.02;",
-		"const float F = 0.30;",
+			// Filmic ToneMapping http://filmicgames.com/archives/75
+			'const float A = 0.15;',
+			'const float B = 0.50;',
+			'const float C = 0.10;',
+			'const float D = 0.20;',
+			'const float E = 0.02;',
+			'const float F = 0.30;',
 
-		"const float whiteScale = 1.0748724675633854;", // 1.0 / Uncharted2Tonemap(1000.0)
+			'const float whiteScale = 1.0748724675633854;', // 1.0 / Uncharted2Tonemap(1000.0)
 
-		"vec3 Uncharted2Tonemap( vec3 x )",
-		"{",
-			"return ( ( x * ( A * x + C * B ) + D * E ) / ( x * ( A * x + B ) + D * F ) ) - E / F;",
-		"}",
+			'vec3 Uncharted2Tonemap( vec3 x ) {',
+			'	return ( ( x * ( A * x + C * B ) + D * E ) / ( x * ( A * x + B ) + D * F ) ) - E / F;',
+			'}',
 
 
-		"void main() ",
-		"{",
+			'void main() {',
 			// optical length
 			// cutoff angle at 90 to avoid singularity in next formula.
-			"float zenithAngle = acos( max( 0.0, dot( up, normalize( vWorldPosition - cameraPos ) ) ) );",
-			"float inverse = 1.0 / ( cos( zenithAngle ) + 0.15 * pow( 93.885 - ( ( zenithAngle * 180.0 ) / pi ), -1.253 ) );",
-			"float sR = rayleighZenithLength * inverse;",
-			"float sM = mieZenithLength * inverse;",
+			'	float zenithAngle = acos( max( 0.0, dot( up, normalize( vWorldPosition - cameraPos ) ) ) );',
+			'	float inverse = 1.0 / ( cos( zenithAngle ) + 0.15 * pow( 93.885 - ( ( zenithAngle * 180.0 ) / pi ), -1.253 ) );',
+			'	float sR = rayleighZenithLength * inverse;',
+			'	float sM = mieZenithLength * inverse;',
 
 			// combined extinction factor
-			"vec3 Fex = exp( -( vBetaR * sR + vBetaM * sM ) );",
+			'	vec3 Fex = exp( -( vBetaR * sR + vBetaM * sM ) );',
 
 			// in scattering
-			"float cosTheta = dot( normalize( vWorldPosition - cameraPos ), vSunDirection );",
+			'	float cosTheta = dot( normalize( vWorldPosition - cameraPos ), vSunDirection );',
 
-			"float rPhase = rayleighPhase( cosTheta * 0.5 + 0.5 );",
-			"vec3 betaRTheta = vBetaR * rPhase;",
+			'	float rPhase = rayleighPhase( cosTheta * 0.5 + 0.5 );',
+			'	vec3 betaRTheta = vBetaR * rPhase;',
 
-			"float mPhase = hgPhase( cosTheta, mieDirectionalG );",
-			"vec3 betaMTheta = vBetaM * mPhase;",
+			'	float mPhase = hgPhase( cosTheta, mieDirectionalG );',
+			'	vec3 betaMTheta = vBetaM * mPhase;',
 
-			"vec3 Lin = pow( vSunE * ( ( betaRTheta + betaMTheta ) / ( vBetaR + vBetaM ) ) * ( 1.0 - Fex ), vec3( 1.5 ) );",
-			"Lin *= mix( vec3( 1.0 ), pow( vSunE * ( ( betaRTheta + betaMTheta ) / ( vBetaR + vBetaM ) ) * Fex, vec3( 1.0 / 2.0 ) ), clamp( pow( 1.0 - dot( up, vSunDirection ), 5.0 ), 0.0, 1.0 ) );",
+			'	vec3 Lin = pow( vSunE * ( ( betaRTheta + betaMTheta ) / ( vBetaR + vBetaM ) ) * ( 1.0 - Fex ), vec3( 1.5 ) );',
+			'	Lin *= mix( vec3( 1.0 ), pow( vSunE * ( ( betaRTheta + betaMTheta ) / ( vBetaR + vBetaM ) ) * Fex, vec3( 1.0 / 2.0 ) ), clamp( pow( 1.0 - dot( up, vSunDirection ), 5.0 ), 0.0, 1.0 ) );',
 
-			//nightsky
-			"vec3 direction = normalize( vWorldPosition - cameraPos );",
-			"float theta = acos( direction.y ); // elevation --> y-axis, [-pi/2, pi/2]",
-			"float phi = atan( direction.z, direction.x ); // azimuth --> x-axis [-pi/2, pi/2]",
-			"vec2 uv = vec2( phi, theta ) / vec2( 2.0 * pi, pi ) + vec2( 0.5, 0.0 );",
-			"vec3 L0 = vec3( 0.1 ) * Fex;",
+			// nightsky
+			'	vec3 direction = normalize( vWorldPosition - cameraPos );',
+			'	float theta = acos( direction.y ); // elevation --> y-axis, [-pi/2, pi/2]',
+			'	float phi = atan( direction.z, direction.x ); // azimuth --> x-axis [-pi/2, pi/2]',
+			'	vec2 uv = vec2( phi, theta ) / vec2( 2.0 * pi, pi ) + vec2( 0.5, 0.0 );',
+			'	vec3 L0 = vec3( 0.1 ) * Fex;',
 
 			// composition + solar disc
-			"float sundisk = smoothstep( sunAngularDiameterCos, sunAngularDiameterCos + 0.00002, cosTheta );",
-			"L0 += ( vSunE * 19000.0 * Fex ) * sundisk;",
+			'	float sundisk = smoothstep( sunAngularDiameterCos, sunAngularDiameterCos + 0.00002, cosTheta );',
+			'	L0 += ( vSunE * 19000.0 * Fex ) * sundisk;',
 
-			"vec3 texColor = ( Lin + L0 ) * 0.04 + vec3( 0.0, 0.0003, 0.00075 );",
+			'	vec3 texColor = ( Lin + L0 ) * 0.04 + vec3( 0.0, 0.0003, 0.00075 );',
 
-			"vec3 curr = Uncharted2Tonemap( ( log2( 2.0 / pow( luminance, 4.0 ) ) ) * texColor );",
-			"vec3 color = curr * whiteScale;",
+			'	vec3 curr = Uncharted2Tonemap( ( log2( 2.0 / pow( luminance, 4.0 ) ) ) * texColor );',
+			'	vec3 color = curr * whiteScale;',
 
-			"vec3 retColor = pow( color, vec3( 1.0 / ( 1.2 + ( 1.2 * vSunfade ) ) ) );",
+			'	vec3 retColor = pow( color, vec3( 1.0 / ( 1.2 + ( 1.2 * vSunfade ) ) ) );',
 
-			"gl_FragColor.rgb = retColor;",
+			'	gl_FragColor = vec4( retColor, 1.0 );',
 
-			"gl_FragColor.a = 1.0;",
-		"}"
+			'}'
+		].join( '\n' )
 
-	].join( "\n" )
-
-};
-
-THREE.Sky = function () {
+	};
 
-	var skyShader = THREE.ShaderLib[ "sky" ];
 	var skyUniforms = THREE.UniformsUtils.clone( skyShader.uniforms );
 
 	var skyMat = new THREE.ShaderMaterial( {

+ 118 - 123
examples/js/WaterShader.js

@@ -7,121 +7,12 @@
  * @author Jonas Wagner / http://29a.ch/ && http://29a.ch/slides/2012/webglwater/ : Water shader explanations in WebGL
  */
 
-THREE.ShaderLib[ 'water' ] = {
-
-	uniforms: THREE.UniformsUtils.merge( [
-		THREE.UniformsLib[ "fog" ], {
-			"normalSampler":    { value: null },
-			"mirrorSampler":    { value: null },
-			"alpha":            { value: 1.0 },
-			"time":             { value: 0.0 },
-			"distortionScale":  { value: 20.0 },
-			"noiseScale":       { value: 1.0 },
-			"textureMatrix" :   { value: new THREE.Matrix4() },
-			"sunColor":         { value: new THREE.Color( 0x7F7F7F ) },
-			"sunDirection":     { value: new THREE.Vector3( 0.70707, 0.70707, 0 ) },
-			"eye":              { value: new THREE.Vector3() },
-			"waterColor":       { value: new THREE.Color( 0x555555 ) }
-		}
-	] ),
-
-	vertexShader: [
-		'uniform mat4 textureMatrix;',
-		'uniform float time;',
-
-		'varying vec4 mirrorCoord;',
-		'varying vec3 worldPosition;',
-
-		THREE.ShaderChunk[ "fog_pars_vertex"],
-
-		'void main()',
-		'{',
-		'	mirrorCoord = modelMatrix * vec4( position, 1.0 );',
-		'	worldPosition = mirrorCoord.xyz;',
-		'	mirrorCoord = textureMatrix * mirrorCoord;',
-		'	gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );',
-
-		THREE.ShaderChunk[ "fog_vertex"],
-
-		'}'
-	].join( '\n' ),
-
-	fragmentShader: [
-		'precision highp float;',
-
-		'uniform sampler2D mirrorSampler;',
-		'uniform float alpha;',
-		'uniform float time;',
-		'uniform float distortionScale;',
-		'uniform sampler2D normalSampler;',
-		'uniform vec3 sunColor;',
-		'uniform vec3 sunDirection;',
-		'uniform vec3 eye;',
-		'uniform vec3 waterColor;',
-
-		'varying vec4 mirrorCoord;',
-		'varying vec3 worldPosition;',
-
-		'vec4 getNoise( vec2 uv )',
-		'{',
-		'	vec2 uv0 = ( uv / 103.0 ) + vec2(time / 17.0, time / 29.0);',
-		'	vec2 uv1 = uv / 107.0-vec2( time / -19.0, time / 31.0 );',
-		'	vec2 uv2 = uv / vec2( 8907.0, 9803.0 ) + vec2( time / 101.0, time / 97.0 );',
-		'	vec2 uv3 = uv / vec2( 1091.0, 1027.0 ) - vec2( time / 109.0, time / -113.0 );',
-		'	vec4 noise = texture2D( normalSampler, uv0 ) +',
-		'		texture2D( normalSampler, uv1 ) +',
-		'		texture2D( normalSampler, uv2 ) +',
-		'		texture2D( normalSampler, uv3 );',
-		'	return noise * 0.5 - 1.0;',
-		'}',
-
-		'void sunLight( const vec3 surfaceNormal, const vec3 eyeDirection, float shiny, float spec, float diffuse, inout vec3 diffuseColor, inout vec3 specularColor )',
-		'{',
-		'	vec3 reflection = normalize( reflect( -sunDirection, surfaceNormal ) );',
-		'	float direction = max( 0.0, dot( eyeDirection, reflection ) );',
-		'	specularColor += pow( direction, shiny ) * sunColor * spec;',
-		'	diffuseColor += max( dot( sunDirection, surfaceNormal ), 0.0 ) * sunColor * diffuse;',
-		'}',
-
-		THREE.ShaderChunk[ "common" ],
-		THREE.ShaderChunk[ "fog_pars_fragment" ],
-
-		'void main()',
-		'{',
-		'	vec4 noise = getNoise( worldPosition.xz );',
-		'	vec3 surfaceNormal = normalize( noise.xzy * vec3( 1.5, 1.0, 1.5 ) );',
-
-		'	vec3 diffuseLight = vec3(0.0);',
-		'	vec3 specularLight = vec3(0.0);',
-
-		'	vec3 worldToEye = eye-worldPosition;',
-		'	vec3 eyeDirection = normalize( worldToEye );',
-		'	sunLight( surfaceNormal, eyeDirection, 100.0, 2.0, 0.5, diffuseLight, specularLight );',
-
-		'	float distance = length(worldToEye);',
-
-		'	vec2 distortion = surfaceNormal.xz * ( 0.001 + 1.0 / distance ) * distortionScale;',
-		'	vec3 reflectionSample = vec3( texture2D( mirrorSampler, mirrorCoord.xy / mirrorCoord.z + distortion ) );',
-
-		'	float theta = max( dot( eyeDirection, surfaceNormal ), 0.0 );',
-		'	float rf0 = 0.3;',
-		'	float reflectance = rf0 + ( 1.0 - rf0 ) * pow( ( 1.0 - theta ), 5.0 );',
-		'	vec3 scatter = max( 0.0, dot( surfaceNormal, eyeDirection ) ) * waterColor;',
-		'	vec3 albedo = mix( sunColor * diffuseLight * 0.3 + scatter, ( vec3( 0.1 ) + reflectionSample * 0.9 + reflectionSample * specularLight ), reflectance );',
-		'	vec3 outgoingLight = albedo;',
-			THREE.ShaderChunk[ "fog_fragment" ],
-		'	gl_FragColor = vec4( outgoingLight, alpha );',
-		'}'
-	].join( '\n' )
-
-};
-
 THREE.Water = function ( renderer, camera, scene, options ) {
 
 	THREE.Object3D.call( this );
 	this.name = 'water_' + this.id;
 
-	function optionalParameter ( value, defaultValue ) {
+	function optionalParameter( value, defaultValue ) {
 
 		return value !== undefined ? value : defaultValue;
 
@@ -173,7 +64,115 @@ THREE.Water = function ( renderer, camera, scene, options ) {
 	this.renderTarget = new THREE.WebGLRenderTarget( width, height );
 	this.renderTarget2 = new THREE.WebGLRenderTarget( width, height );
 
-	var mirrorShader = THREE.ShaderLib[ "water" ];
+	var mirrorShader = {
+
+		uniforms: THREE.UniformsUtils.merge( [
+			THREE.UniformsLib[ 'fog' ],
+			{
+				normalSampler: { value: null },
+				mirrorSampler: { value: null },
+				alpha: { value: 1.0 },
+				time: { value: 0.0 },
+				distortionScale: { value: 20.0 },
+				noiseScale: { value: 1.0 },
+				textureMatrix: { value: new THREE.Matrix4() },
+				sunColor: { value: new THREE.Color( 0x7F7F7F ) },
+				sunDirection: { value: new THREE.Vector3( 0.70707, 0.70707, 0 ) },
+				eye: { value: new THREE.Vector3() },
+				waterColor: { value: new THREE.Color( 0x555555 ) }
+			}
+		] ),
+
+		vertexShader: [
+			'uniform mat4 textureMatrix;',
+			'uniform float time;',
+
+			'varying vec4 mirrorCoord;',
+			'varying vec3 worldPosition;',
+
+			THREE.ShaderChunk[ 'fog_pars_vertex' ],
+
+			'void main() {',
+			'	mirrorCoord = modelMatrix * vec4( position, 1.0 );',
+			'	worldPosition = mirrorCoord.xyz;',
+			'	mirrorCoord = textureMatrix * mirrorCoord;',
+			'	vec4 mvPosition =  modelViewMatrix * vec4( position, 1.0 );',
+			'	gl_Position = projectionMatrix * mvPosition;',
+
+			THREE.ShaderChunk[ 'fog_vertex' ],
+
+			'}'
+		].join( '\n' ),
+
+		fragmentShader: [
+			'precision highp float;',
+
+			'uniform sampler2D mirrorSampler;',
+			'uniform float alpha;',
+			'uniform float time;',
+			'uniform float distortionScale;',
+			'uniform sampler2D normalSampler;',
+			'uniform vec3 sunColor;',
+			'uniform vec3 sunDirection;',
+			'uniform vec3 eye;',
+			'uniform vec3 waterColor;',
+
+			'varying vec4 mirrorCoord;',
+			'varying vec3 worldPosition;',
+
+			'vec4 getNoise( vec2 uv ) {',
+			'	vec2 uv0 = ( uv / 103.0 ) + vec2(time / 17.0, time / 29.0);',
+			'	vec2 uv1 = uv / 107.0-vec2( time / -19.0, time / 31.0 );',
+			'	vec2 uv2 = uv / vec2( 8907.0, 9803.0 ) + vec2( time / 101.0, time / 97.0 );',
+			'	vec2 uv3 = uv / vec2( 1091.0, 1027.0 ) - vec2( time / 109.0, time / -113.0 );',
+			'	vec4 noise = texture2D( normalSampler, uv0 ) +',
+			'		texture2D( normalSampler, uv1 ) +',
+			'		texture2D( normalSampler, uv2 ) +',
+			'		texture2D( normalSampler, uv3 );',
+			'	return noise * 0.5 - 1.0;',
+			'}',
+
+			'void sunLight( const vec3 surfaceNormal, const vec3 eyeDirection, float shiny, float spec, float diffuse, inout vec3 diffuseColor, inout vec3 specularColor ) {',
+			'	vec3 reflection = normalize( reflect( -sunDirection, surfaceNormal ) );',
+			'	float direction = max( 0.0, dot( eyeDirection, reflection ) );',
+			'	specularColor += pow( direction, shiny ) * sunColor * spec;',
+			'	diffuseColor += max( dot( sunDirection, surfaceNormal ), 0.0 ) * sunColor * diffuse;',
+			'}',
+
+			THREE.ShaderChunk[ 'common' ],
+			THREE.ShaderChunk[ 'fog_pars_fragment' ],
+
+			'void main() {',
+			'	vec4 noise = getNoise( worldPosition.xz );',
+			'	vec3 surfaceNormal = normalize( noise.xzy * vec3( 1.5, 1.0, 1.5 ) );',
+
+			'	vec3 diffuseLight = vec3(0.0);',
+			'	vec3 specularLight = vec3(0.0);',
+
+			'	vec3 worldToEye = eye-worldPosition;',
+			'	vec3 eyeDirection = normalize( worldToEye );',
+			'	sunLight( surfaceNormal, eyeDirection, 100.0, 2.0, 0.5, diffuseLight, specularLight );',
+
+			'	float distance = length(worldToEye);',
+
+			'	vec2 distortion = surfaceNormal.xz * ( 0.001 + 1.0 / distance ) * distortionScale;',
+			'	vec3 reflectionSample = vec3( texture2D( mirrorSampler, mirrorCoord.xy / mirrorCoord.z + distortion ) );',
+
+			'	float theta = max( dot( eyeDirection, surfaceNormal ), 0.0 );',
+			'	float rf0 = 0.3;',
+			'	float reflectance = rf0 + ( 1.0 - rf0 ) * pow( ( 1.0 - theta ), 5.0 );',
+			'	vec3 scatter = max( 0.0, dot( surfaceNormal, eyeDirection ) ) * waterColor;',
+			'	vec3 albedo = mix( sunColor * diffuseLight * 0.3 + scatter, ( vec3( 0.1 ) + reflectionSample * 0.9 + reflectionSample * specularLight ), reflectance );',
+			'	vec3 outgoingLight = albedo;',
+			'	gl_FragColor = vec4( outgoingLight, alpha );',
+
+			THREE.ShaderChunk[ 'fog_fragment' ],
+
+			'}'
+		].join( '\n' )
+
+	};
+
 	var mirrorUniforms = THREE.UniformsUtils.clone( mirrorShader.uniforms );
 
 	this.material = new THREE.ShaderMaterial( {
@@ -217,12 +216,6 @@ THREE.Water.prototype.constructor = THREE.Water;
 
 THREE.Water.prototype.updateTextureMatrix = function () {
 
-	function sign( x ) {
-
-		return x ? x < 0 ? - 1 : 1 : 0;
-
-	}
-
 	this.updateMatrixWorld();
 	this.camera.updateMatrixWorld();
 
@@ -262,10 +255,12 @@ THREE.Water.prototype.updateTextureMatrix = function () {
 	this.mirrorCamera.matrixWorldInverse.getInverse( this.mirrorCamera.matrixWorld );
 
 	// Update the texture matrix
-	this.textureMatrix.set( 0.5, 0.0, 0.0, 0.5,
-							0.0, 0.5, 0.0, 0.5,
-							0.0, 0.0, 0.5, 0.5,
-							0.0, 0.0, 0.0, 1.0 );
+	this.textureMatrix.set(
+		0.5, 0.0, 0.0, 0.5,
+		0.0, 0.5, 0.0, 0.5,
+		0.0, 0.0, 0.5, 0.5,
+		0.0, 0.0, 0.0, 1.0
+	);
 	this.textureMatrix.multiply( this.mirrorCamera.projectionMatrix );
 	this.textureMatrix.multiply( this.mirrorCamera.matrixWorldInverse );
 
@@ -279,8 +274,8 @@ THREE.Water.prototype.updateTextureMatrix = function () {
 	var q = new THREE.Vector4();
 	var projectionMatrix = this.mirrorCamera.projectionMatrix;
 
-	q.x = ( sign( this.clipPlane.x ) + projectionMatrix.elements[ 8 ] ) / projectionMatrix.elements[ 0 ];
-	q.y = ( sign( this.clipPlane.y ) + projectionMatrix.elements[ 9 ] ) / projectionMatrix.elements[ 5 ];
+	q.x = ( Math.sign( this.clipPlane.x ) + projectionMatrix.elements[ 8 ] ) / projectionMatrix.elements[ 0 ];
+	q.y = ( Math.sign( this.clipPlane.y ) + projectionMatrix.elements[ 9 ] ) / projectionMatrix.elements[ 5 ];
 	q.z = - 1.0;
 	q.w = ( 1.0 + projectionMatrix.elements[ 10 ] ) / projectionMatrix.elements[ 14 ];
 

+ 1 - 1
examples/js/loaders/AssimpJSONLoader.js

@@ -125,7 +125,7 @@ THREE.AssimpJSONLoader.prototype = {
 
 		}
 
-		geometry.setIndex( new ( indices.length > 65535 ? THREE.Uint32BufferAttribute : THREE.Uint16BufferAttribute )( indices, 1 ) );
+		geometry.setIndex( indices );
 		geometry.addAttribute( 'position', new THREE.Float32BufferAttribute( vertices, 3 ) );
 
 		if ( normals.length > 0 ) {

+ 1 - 9
examples/js/loaders/FBXLoader.js

@@ -263,15 +263,7 @@
 
 				if ( geoNode.indices !== undefined && geoNode.indices.length > 0 ) {
 
-					if ( geoNode.indices.length > 65535 ) {
-
-						tmpGeo.setIndex( new THREE.BufferAttribute( new Uint32Array( geoNode.indices ), 1 ) );
-
-					} else {
-
-						tmpGeo.setIndex( new THREE.BufferAttribute( new Uint16Array( geoNode.indices ), 1 ) );
-
-					}
+					tmpGeo.setIndex( geoNode.indices );
 
 				}
 

+ 3860 - 0
examples/js/loaders/FBXLoader2.js

@@ -0,0 +1,3860 @@
+/**
+ * @author Kyle-Larson https://github.com/Kyle-Larson
+ *
+ * Loader loads FBX file and generates Group representing FBX scene.
+ * Requires FBX file to be >= 7.0 and in ASCII format.
+ *
+ * Supports:
+ * 	Mesh Generation (Positional Data)
+ * 	Normal Data (Per Vertex Drawing Instance)
+ *  UV Data (Per Vertex Drawing Instance)
+ *  Skinning
+ *  Animation
+ * 	- Separated Animations based on stacks.
+ * 	- Skeletal & Non-Skeletal Animations
+ *
+ * Needs Support:
+ * 	Indexed Buffers
+ * 	PreRotation support.
+ */
+
+( function () {
+
+	/**
+	 * Generates a loader for loading FBX files from URL and parsing into
+	 * a THREE.Group.
+	 * @param {THREE.LoadingManager} manager - Loading Manager for loader to use.
+	 */
+	THREE.FBXLoader = function ( manager ) {
+
+		THREE.Loader.call( this );
+		this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
+		this.fileLoader = new THREE.FileLoader( this.manager );
+		this.textureLoader = new THREE.TextureLoader( this.manager );
+
+	};
+
+	Object.assign( THREE.FBXLoader.prototype, THREE.Loader.prototype );
+
+	THREE.FBXLoader.prototype.constructor = THREE.FBXLoader;
+
+	Object.assign( THREE.FBXLoader.prototype, {
+
+		/**
+		 * Loads an ASCII FBX file from URL and parses into a THREE.Group.
+		 * THREE.Group will have an animations property of AnimationClips
+		 * of the different animations exported with the FBX.
+		 * @param {string} url - URL of the FBX file.
+		 * @param {function(THREE.Group):void} onLoad - Callback for when FBX file is loaded and parsed.
+		 * @param {function(ProgressEvent):void} onProgress - Callback fired periodically when file is being retrieved from server.
+		 * @param {function(Event):void} onError - Callback fired when error occurs (Currently only with retrieving file, not with parsing errors).
+		 */
+		load: function ( url, onLoad, onProgress, onError ) {
+
+			var self = this;
+
+			var resourceDirectory = url.split( /[\\\/]/ );
+			resourceDirectory.pop();
+			resourceDirectory = resourceDirectory.join( '/' );
+
+			this.fileLoader.load( url, function ( text ) {
+
+				if ( ! isFbxFormatASCII( text ) ) {
+
+					console.error( 'FBXLoader: FBX Binary format not supported.' );
+					self.manager.itemError( url );
+					return;
+
+				}
+				if ( getFbxVersion( text ) < 7000 ) {
+
+					console.error( 'FBXLoader: FBX version not supported for file at ' + url + ', FileVersion: ' + getFbxVersion( text ) );
+					self.manager.itemError( url );
+					return;
+
+				}
+
+				var scene = self.parse( text, resourceDirectory );
+				onLoad( scene );
+
+			}, onProgress, onError );
+
+		},
+
+		/**
+		 * Parses an ASCII FBX file and returns a THREE.Group.
+		 * THREE.Group will have an animations property of AnimationClips
+		 * of the different animations within the FBX file.
+		 * @param {string} FBXText - Contents of FBX file to parse.
+		 * @param {string} resourceDirectory - Directory to load external assets (e.g. textures ) from.
+		 * @returns {THREE.Group}
+		 */
+		parse: function ( FBXText, resourceDirectory ) {
+
+			var loader = this;
+
+			var FBXTree = new TextParser().parse( FBXText );
+
+			var connections = parseConnections( FBXTree );
+
+			var textures = parseTextures( FBXTree );
+
+			var materials = parseMaterials( FBXTree, textures, connections );
+
+			var deformerMap = parseDeformers( FBXTree, connections );
+
+			var geometryMap = parseGeometries( FBXTree, connections, deformerMap );
+
+			var sceneGraph = parseScene( FBXTree, connections, deformerMap, geometryMap, materials );
+
+			return sceneGraph;
+
+
+			/**
+			 * @typedef {{value: number}} FBXValue
+			 */
+			/**
+			 * @typedef {{value: {x: string, y: string, z: string}}} FBXVector3
+			 */
+			/**
+			 * @typedef {{properties: {a: string}}} FBXArrayNode
+			 */
+			/**
+			 * @typedef {{properties: {MappingInformationType: string, ReferenceInformationType: string }, subNodes: Object<string, FBXArrayNode>}} FBXMappedArrayNode
+			 */
+			/**
+			 * @typedef {{id: number, name: string, properties: {FileName: string}}} FBXTextureNode
+			 */
+			/**
+			 * @typedef {{id: number, attrName: string, properties: {ShadingModel: string, Diffuse: FBXVector3, Specular: FBXVector3, Shininess: FBXValue, Emissive: FBXVector3, EmissiveFactor: FBXValue, Opacity: FBXValue}}} FBXMaterialNode
+			 */
+			/**
+			 * @typedef {{subNodes: {Indexes: FBXArrayNode, Weights: FBXArrayNode, Transform: FBXArrayNode, TransformLink: FBXArrayNode}, properties: { Mode: string }}} FBXSubDeformerNode
+			 */
+			/**
+			 * @typedef {{id: number, attrName: string, attrType: string, subNodes: {Vertices: FBXArrayNode, PolygonVertexIndex: FBXArrayNode, LayerElementNormal: FBXMappedArrayNode[], LayerElementMaterial: FBXMappedArrayNode[], LayerElementUV: FBXMappedArrayNode[]}}} FBXGeometryNode
+			 */
+			/**
+			 * @typedef {{id: number, attrName: string, attrType: string, properties: {Lcl_Translation: FBXValue, Lcl_Rotation: FBXValue, Lcl_Scaling: FBXValue}}} FBXModelNode
+			 */
+
+
+
+
+
+
+
+
+			/**
+			 * Parses map of relationships between objects.
+			 * @param {{Connections: { properties: { connections: [number, number, string][]}}}} FBXTree
+			 * @returns {Map<number, {parents: {ID: number, relationship: string}[], children: {ID: number, relationship: string}[]}>}
+			 */
+			function parseConnections( FBXTree ) {
+
+				/**
+				 * @type {Map<number, { parents: {ID: number, relationship: string}[], children: {ID: number, relationship: string}[]}>}
+				 */
+				var connectionMap = new Map();
+
+				if ( 'Connections' in FBXTree ) {
+
+					/**
+					 * @type {[number, number, string][]}
+					 */
+					var connectionArray = FBXTree.Connections.properties.connections;
+					connectionArray.forEach( function ( connection ) {
+
+						if ( ! connectionMap.has( connection[ 0 ] ) ) {
+
+							connectionMap.set( connection[ 0 ], {
+								parents: [],
+								children: []
+							} );
+
+						}
+
+						var parentRelationship = { ID: connection[ 1 ], relationship: connection[ 2 ] };
+						connectionMap.get( connection[ 0 ] ).parents.push( parentRelationship );
+
+						if ( ! connectionMap.has( connection[ 1 ] ) ) {
+
+							connectionMap.set( connection[ 1 ], {
+								parents: [],
+								children: []
+							} );
+
+						}
+
+						var childRelationship = { ID: connection[ 0 ], relationship: connection[ 2 ] };
+						connectionMap.get( connection[ 1 ] ).children.push( childRelationship );
+
+					} );
+
+				}
+
+				return connectionMap;
+
+			}
+
+			/**
+			 * Parses map of textures referenced in FBXTree.
+			 * @param {{Objects: {subNodes: {Texture: Object.<string, FBXTextureNode>}}}} FBXTree
+			 * @returns {Map<number, THREE.Texture>}
+			 */
+			function parseTextures( FBXTree ) {
+
+				/**
+				 * @type {Map<number, THREE.Texture>}
+				 */
+				var textureMap = new Map();
+
+				if ( 'Texture' in FBXTree.Objects.subNodes ) {
+
+					var textureNodes = FBXTree.Objects.subNodes.Texture;
+					for ( var nodeID in textureNodes ) {
+
+						var texture = parseTexture( textureNodes[ nodeID ] );
+						textureMap.set( parseInt( nodeID ), texture );
+
+					}
+
+				}
+
+				return textureMap;
+
+				/**
+				 * @param {textureNode} textureNode - Node to get texture information from.
+				 * @returns {THREE.Texture}
+				 */
+				function parseTexture( textureNode ) {
+
+					var FBX_ID = textureNode.id;
+					var name = textureNode.name;
+					var filePath = textureNode.properties.FileName;
+					var split = filePath.split( /[\\\/]/ );
+					if ( split.length > 0 ) {
+
+						var fileName = split[ split.length - 1 ];
+
+					} else {
+
+						var fileName = filePath;
+
+					}
+					/**
+					 * @type {THREE.Texture}
+					 */
+					var texture = loader.textureLoader.load( resourceDirectory + '/' + fileName );
+					texture.name = name;
+					texture.FBX_ID = FBX_ID;
+
+					return texture;
+
+				}
+
+			}
+
+			/**
+			 * Parses map of Material information.
+			 * @param {{Objects: {subNodes: {Material: Object.<number, FBXMaterialNode>}}}} FBXTree
+			 * @param {Map<number, THREE.Texture>} textureMap
+			 * @param {Map<number, {parents: {ID: number, relationship: string}[], children: {ID: number, relationship: string}[]}>} connections
+			 * @returns {Map<number, THREE.Material>}
+			 */
+			function parseMaterials( FBXTree, textureMap, connections ) {
+
+				var materialMap = new Map();
+
+				if ( 'Material' in FBXTree.Objects.subNodes ) {
+
+					var materialNodes = FBXTree.Objects.subNodes.Material;
+					for ( var nodeID in materialNodes ) {
+
+						var material = parseMaterial( materialNodes[ nodeID ], textureMap, connections );
+						materialMap.set( parseInt( nodeID ), material );
+
+					}
+
+				}
+
+				return materialMap;
+
+				/**
+				 * Takes information from Material node and returns a generated THREE.Material
+				 * @param {FBXMaterialNode} materialNode
+				 * @param {Map<number, THREE.Texture>} textureMap
+				 * @param {Map<number, {parents: {ID: number, relationship: string}[], children: {ID: number, relationship: string}[]}>} connections
+				 * @returns {THREE.Material}
+				 */
+				function parseMaterial( materialNode, textureMap, connections ) {
+
+					var FBX_ID = materialNode.id;
+					var name = materialNode.attrName;
+					var type = materialNode.properties.ShadingModel;
+
+					var children = connections.get( FBX_ID ).children;
+
+					var parameters = parseParameters( materialNode.properties, textureMap, children );
+
+					var material;
+					switch ( type ) {
+
+						case 'phong':
+							material = new THREE.MeshPhongMaterial();
+							break;
+						case 'lambert':
+							material = new THREE.MeshLambertMaterial();
+							break;
+						default:
+							console.warn( 'No implementation given for material type ' + type + ' in FBXLoader.js.  Defaulting to basic material' );
+							material = new THREE.MeshBasicMaterial( { color: 0x3300ff } );
+							break;
+
+					}
+
+					material.setValues( parameters );
+					material.name = name;
+
+					return material;
+
+					/**
+					 * @typedef {{Diffuse: FBXVector3, Specular: FBXVector3, Shininess: FBXValue, Emissive: FBXVector3, EmissiveFactor: FBXValue, Opacity: FBXValue}} FBXMaterialProperties
+					 */
+					/**
+					 * @typedef {{color: THREE.Color=, specular: THREE.Color=, shininess: number=, emissive: THREE.Color=, emissiveIntensity: number=, opacity: number=, transparent: boolean=, map: THREE.Texture=}} THREEMaterialParameterPack
+					 */
+					/**
+					 * @param {FBXMaterialProperties} properties
+					 * @param {Map<number, THREE.Texture>} textureMap
+					 * @param {{ID: number, relationship: string}[]} childrenRelationships
+					 * @returns {THREEMaterialParameterPack}
+					 */
+					function parseParameters( properties, textureMap, childrenRelationships ) {
+
+						var parameters = {};
+
+						if ( properties.Diffuse ) {
+
+							parameters.color = parseColor( properties.Diffuse );
+
+						}
+						if ( properties.Specular ) {
+
+							parameters.specular = parseColor( properties.Specular );
+
+						}
+						if ( properties.Shininess ) {
+
+							parameters.shininess = properties.Shininess.value;
+
+						}
+						if ( properties.Emissive ) {
+
+							parameters.emissive = parseColor( properties.Emissive );
+
+						}
+						if ( properties.EmissiveFactor ) {
+
+							parameters.emissiveIntensity = properties.EmissiveFactor.value;
+
+						}
+						if ( properties.Opacity ) {
+
+							parameters.opacity = properties.Opacity.value;
+
+						}
+						if ( parameters.opacity < 1.0 ) {
+
+							parameters.transparent = true;
+
+						}
+
+						childrenRelationships.forEach( function ( relationship ) {
+
+							var type = relationship.relationship;
+							switch ( type ) {
+
+								case " \"AmbientColor":
+									//TODO: Support AmbientColor textures
+									break;
+
+								case " \"DiffuseColor":
+									parameters.map = textureMap.get( relationship.ID );
+									break;
+
+								default:
+									console.warn( 'Unknown texture application of type ' + type + ', skipping texture' );
+									break;
+
+							}
+
+						} );
+
+						return parameters;
+
+					}
+
+				}
+
+			}
+
+			/**
+			 * Generates map of Skeleton-like objects for use later when generating and binding skeletons.
+			 * @param {{Objects: {subNodes: {Deformer: Object.<number, FBXSubDeformerNode>}}}} FBXTree
+			 * @param {Map<number, {parents: {ID: number, relationship: string}[], children: {ID: number, relationship: string}[]}>} connections
+			 * @returns {Map<number, {map: Map<number, {FBX_ID: number, indices: number[], weights: number[], transform: number[], transformLink: number[], linkMode: string}>, array: {FBX_ID: number, indices: number[], weights: number[], transform: number[], transformLink: number[], linkMode: string}[], skeleton: THREE.Skeleton|null}>}
+			 */
+			function parseDeformers( FBXTree, connections ) {
+
+				var skeletonMap = new Map();
+
+				if ( 'Deformer' in FBXTree.Objects.subNodes ) {
+
+					var DeformerNodes = FBXTree.Objects.subNodes.Deformer;
+					for ( var nodeID in DeformerNodes ) {
+
+						var deformerNode = DeformerNodes[ nodeID ];
+						if ( deformerNode.attrType === 'Skin' ) {
+
+							var conns = connections.get( parseInt( nodeID ) );
+							var skeleton = parseSkeleton( conns, DeformerNodes );
+							skeleton.FBX_ID = parseInt( nodeID );
+							skeletonMap.set( parseInt( nodeID ), skeleton );
+
+						}
+
+					}
+
+				}
+
+				return skeletonMap;
+
+				/**
+				 * Generates a "Skeleton Representation" of FBX nodes based on an FBX Skin Deformer's connections and an object containing SubDeformer nodes.
+				 * @param {{parents: {ID: number, relationship: string}[], children: {ID: number, relationship: string}[]}} connections
+				 * @param {Object.<number, FBXSubDeformerNode>} DeformerNodes
+				 * @returns {{map: Map<number, {FBX_ID: number, indices: number[], weights: number[], transform: number[], transformLink: number[], linkMode: string}>, array: {FBX_ID: number, indices: number[], weights: number[], transform: number[], transformLink: number[], linkMode: string}[], skeleton: THREE.Skeleton|null}}
+				 */
+				function parseSkeleton( connections, DeformerNodes ) {
+
+					var subDeformers = new Map();
+					var subDeformerArray = [];
+					connections.children.forEach( function ( child ) {
+
+						var subDeformerNode = DeformerNodes[ child.ID ];
+						var subDeformer = {
+							FBX_ID: child.ID,
+							indices: parseIntArray( subDeformerNode.subNodes.Indexes.properties.a ),
+							weights: parseFloatArray( subDeformerNode.subNodes.Weights.properties.a ),
+							transform: parseMatrixArray( subDeformerNode.subNodes.Transform.properties.a ),
+							transformLink: parseMatrixArray( subDeformerNode.subNodes.TransformLink.properties.a ),
+							linkMode: subDeformerNode.properties.Mode
+						};
+						subDeformers.set( child.ID, subDeformer );
+						subDeformerArray.push( subDeformer );
+
+					} );
+
+					return {
+						map: subDeformers,
+						array: subDeformerArray,
+						bones: []
+					};
+
+				}
+
+			}
+
+			/**
+			 * Generates Buffer geometries from geometry information in FBXTree, and generates map of THREE.BufferGeometries
+			 * @param {{Objects: {subNodes: {Geometry: Object.<number, FBXGeometryNode}}}} FBXTree
+			 * @param {Map<number, {parents: {ID: number, relationship: string}[], children: {ID: number, relationship: string}[]}>} connections
+			 * @param {Map<number, {map: Map<number, {FBX_ID: number, indices: number[], weights: number[], transform: number[], transformLink: number[], linkMode: string}>, array: {FBX_ID: number, indices: number[], weights: number[], transform: number[], transformLink: number[], linkMode: string}[], skeleton: THREE.Skeleton|null}>} deformerMap
+			 * @returns {Map<number, THREE.BufferGeometry>}
+			 */
+			function parseGeometries( FBXTree, connections, deformerMap ) {
+
+				var geometryMap = new Map();
+
+				if ( 'Geometry' in FBXTree.Objects.subNodes ) {
+
+					var geometryNodes = FBXTree.Objects.subNodes.Geometry;
+					for ( var nodeID in geometryNodes ) {
+
+						var relationships = connections.get( parseInt( nodeID ) );
+						var geo = parseGeometry( geometryNodes[ nodeID ], relationships, deformerMap );
+						geometryMap.set( parseInt( nodeID ), geo );
+
+					}
+
+				}
+
+				return geometryMap;
+
+				/**
+				 * Generates BufferGeometry from FBXGeometryNode.
+				 * @param {FBXGeometryNode} geometryNode
+				 * @param {{parents: {ID: number, relationship: string}[], children: {ID: number, relationship: string}[]}} relationships
+				 * @param {Map<number, {map: Map<number, {FBX_ID: number, indices: number[], weights: number[], transform: number[], transformLink: number[], linkMode: string}>, array: {FBX_ID: number, indices: number[], weights: number[], transform: number[], transformLink: number[], linkMode: string}[]}>} deformerMap
+				 * @returns {THREE.BufferGeometry}
+				 */
+				function parseGeometry( geometryNode, relationships, deformerMap ) {
+
+					switch ( geometryNode.attrType ) {
+
+						case 'Mesh':
+							return parseMeshGeometry( geometryNode, relationships, deformerMap );
+							break;
+
+						case 'NurbsCurve':
+							return parseNurbsGeometry( geometryNode, relationships, deformerMap );
+							break;
+
+					}
+
+					/**
+					 * Specialty function for parsing Mesh based Geometry Nodes.
+					 * @param {FBXGeometryNode} geometryNode
+					 * @param {{parents: {ID: number, relationship: string}[], children: {ID: number, relationship: string}[]}} relationships - Object representing relationships between specific geometry node and other nodes.
+					 * @param {Map<number, {map: Map<number, {FBX_ID: number, indices: number[], weights: number[], transform: number[], transformLink: number[], linkMode: string}>, array: {FBX_ID: number, indices: number[], weights: number[], transform: number[], transformLink: number[], linkMode: string}[]}>} deformerMap - Map object of deformers and subDeformers by ID.
+					 * @returns {THREE.BufferGeometry}
+					 */
+					function parseMeshGeometry( geometryNode, relationships, deformerMap ) {
+
+						var FBX_ID = geometryNode.id;
+						var name = geometryNode.attrName;
+						for ( var i = 0; i < relationships.children.length; ++ i ) {
+
+							if ( deformerMap.has( relationships.children[ i ].ID ) ) {
+
+								var deformer = deformerMap.get( relationships.children[ i ].ID );
+								break;
+
+							}
+
+						}
+
+						var geometry = genGeometry( geometryNode, deformer );
+
+						return geometry;
+
+						/**
+						 * @param {{map: Map<number, {FBX_ID: number, indices: number[], weights: number[], transform: number[], transformLink: number[], linkMode: string}>, array: {FBX_ID: number, indices: number[], weights: number[], transform: number[], transformLink: number[], linkMode: string}[]}} deformer - Skeleton representation for geometry instance.
+						 * @returns {THREE.BufferGeometry}
+						 */
+						function genGeometry( geometryNode, deformer ) {
+
+							var geometry = new Geometry();
+
+							//First, each index is going to be its own vertex.
+							var vertexBuffer = parseFloatArray( geometryNode.subNodes.Vertices.properties.a );
+							var indexBuffer = parseIntArray( geometryNode.subNodes.PolygonVertexIndex.properties.a );
+
+							if ( 'LayerElementNormal' in geometryNode.subNodes ) {
+
+								var normalInfo = getNormals( geometryNode );
+
+							}
+
+							if ( 'LayerElementUV' in geometryNode.subNodes ) {
+
+								var uvInfo = getUVs( geometryNode );
+
+							}
+
+							if ( 'LayerElementMaterial' in geometryNode.subNodes ) {
+
+								var materialInfo = getMaterials( geometryNode );
+
+							}
+
+							var faceVertexBuffer = [];
+							var polygonIndex = 0;
+							for ( var polygonVertexIndex = 0; polygonVertexIndex < indexBuffer.length; ++ polygonVertexIndex ) {
+
+								var endOfFace;
+								var vertexIndex = indexBuffer[ polygonVertexIndex ];
+								if ( indexBuffer[ polygonVertexIndex ] < 0 ) {
+
+									vertexIndex = vertexIndex ^ - 1;
+									indexBuffer[ polygonVertexIndex ] = vertexIndex;
+									endOfFace = true;
+
+								}
+								var vertex = new Vertex();
+								var weightIndices = [];
+								var weights = [];
+								vertex.position.fromArray( vertexBuffer, vertexIndex * 3 );
+
+								// If we have a deformer for this geometry, get the skinIndex and skinWeights for this object.
+								// They are stored as vertex indices on each deformer, and we need them as deformer indices
+								// for each vertex.
+								if ( deformer ) {
+
+									for ( var j = 0; j < deformer.array.length; ++ j ) {
+
+										var index = deformer.array[ j ].indices.findIndex( function ( index ) {
+
+											return index === indexBuffer[ polygonVertexIndex ];
+
+										} );
+
+										if ( index !== - 1 ) {
+
+											weights.push( deformer.array[ j ].weights[ index ] );
+											weightIndices.push( j );
+
+										}
+
+									}
+
+									if ( weights.length > 4 ) {
+
+										console.warn( 'FBXLoader: Vertex has more than 4 skinning weights assigned to vertex.  Deleting additional weights.' );
+
+										var WIndex = [ 0, 0, 0, 0 ];
+										var Weight = [ 0, 0, 0, 0 ];
+
+										for ( var polygonVertexIndex = 0; polygonVertexIndex < weights.length; ++ polygonVertexIndex ) {
+
+											var currentWeight = weights[ polygonVertexIndex ];
+											var currentIndex = weightIndices[ polygonVertexIndex ];
+											for ( var j = 0; j < Weight.length; ++ j ) {
+
+												if ( currentWeight > Weight[ j ] ) {
+
+													var tmp = Weight[ j ];
+													Weight[ j ] = currentWeight;
+													currentWeight = tmp;
+
+													tmp = WIndex[ j ];
+													WIndex[ j ] = currentIndex;
+													currentIndex = tmp;
+
+												}
+
+											}
+
+										}
+
+										weightIndices = WIndex;
+										weights = Weight;
+
+									}
+
+									for ( var i = weights.length; i < 4; i ++ ) {
+
+										weights[ i ] = 0;
+										weightIndices[ i ] = 0;
+
+									}
+
+									vertex.skinWeights.fromArray( weights );
+									vertex.skinIndices.fromArray( weightIndices );
+
+									//vertex.skinWeights.normalize();
+
+								}
+
+								if ( normalInfo ) {
+
+									vertex.normal.fromArray( getData( polygonVertexIndex, polygonIndex, vertexIndex, normalInfo ) );
+
+								}
+
+								if ( uvInfo ) {
+
+									vertex.uv.fromArray( getData( polygonVertexIndex, polygonIndex, vertexIndex, uvInfo ) );
+
+								}
+
+
+
+								//Add vertex to face buffer.
+								faceVertexBuffer.push( vertex );
+
+								// If index was negative to start with, we have finished this individual face
+								// and can generate the face data to the geometry.
+								if ( endOfFace ) {
+
+									var face = new Face();
+									var materials = getData( polygonVertexIndex, polygonIndex, vertexIndex, materialInfo );
+									face.genTrianglesFromVertices( faceVertexBuffer );
+									face.materialIndex = materials[ 0 ];
+									geometry.faces.push( face );
+									faceVertexBuffer = [];
+									polygonIndex ++;
+									endOfFace = false;
+
+								}
+
+							}
+
+							/**
+							 * @type {{vertexBuffer: number[], normalBuffer: number[], uvBuffer: number[], skinIndexBuffer: number[], skinWeightBuffer: number[], materialIndexBuffer: number[]}}
+							 */
+							var bufferInfo = geometry.flattenToBuffers();
+
+							var geo = new THREE.BufferGeometry();
+							geo.name = geometryNode.name;
+							geo.addAttribute( 'position', new THREE.BufferAttribute( new Float32Array( bufferInfo.vertexBuffer ), 3 ) );
+
+							if ( bufferInfo.normalBuffer.length > 0 ) {
+
+								geo.addAttribute( 'normal', new THREE.BufferAttribute( new Float32Array( bufferInfo.normalBuffer ), 3 ) );
+
+							}
+							if ( bufferInfo.uvBuffer.length > 0 ) {
+
+								geo.addAttribute( 'uv', new THREE.BufferAttribute( new Float32Array( bufferInfo.uvBuffer ), 2 ) );
+
+							}
+
+							if ( deformer ) {
+
+								geo.addAttribute( 'skinIndex', new THREE.BufferAttribute( new Float32Array( bufferInfo.skinIndexBuffer ), 4 ) );
+
+								geo.addAttribute( 'skinWeight', new THREE.BufferAttribute( new Float32Array( bufferInfo.skinWeightBuffer ), 4 ) );
+
+								geo.FBX_Deformer = deformer;
+
+							}
+
+							// Convert the material indices of each vertex into rendering groups on the geometry.
+							var prevMaterialIndex = bufferInfo.materialIndexBuffer[ 0 ];
+							var startIndex = 0;
+							for ( var materialBufferIndex = 0; materialBufferIndex < bufferInfo.materialIndexBuffer.length; ++ materialBufferIndex ) {
+
+								if ( bufferInfo.materialIndexBuffer[ materialBufferIndex ] !== prevMaterialIndex ) {
+
+									geo.addGroup( startIndex, materialBufferIndex - startIndex, prevMaterialIndex );
+									startIndex = materialBufferIndex;
+									prevMaterialIndex = bufferInfo.materialIndexBuffer[ materialBufferIndex ];
+
+								}
+
+							}
+
+							return geo;
+
+							/**
+							 * Parses normal information for geometry.
+							 * @param {FBXGeometryNode} geometryNode
+							 * @returns {{dataSize: number, buffer: number[], indices: number[], mappingType: string, referenceType: string}}
+							 */
+							function getNormals( geometryNode ) {
+
+								var NormalNode = geometryNode.subNodes.LayerElementNormal[ 0 ];
+
+								var mappingType = NormalNode.properties.MappingInformationType;
+								var referenceType = NormalNode.properties.ReferenceInformationType;
+								var buffer = parseFloatArray( NormalNode.subNodes.Normals.properties.a );
+								var indexBuffer = [];
+								if ( referenceType === 'IndexToDirect' ) {
+
+									indexBuffer = parseIntArray( NormalNode.subNodes.NormalIndex.properties.a );
+
+								}
+
+								return {
+									dataSize: 3,
+									buffer: buffer,
+									indices: indexBuffer,
+									mappingType: mappingType,
+									referenceType: referenceType
+								};
+
+							}
+
+							/**
+							 * Parses UV information for geometry.
+							 * @param {FBXGeometryNode} geometryNode
+							 * @returns {{dataSize: number, buffer: number[], indices: number[], mappingType: string, referenceType: string}}
+							 */
+							function getUVs( geometryNode ) {
+
+								var UVNode = geometryNode.subNodes.LayerElementUV[ 0 ];
+
+								var mappingType = UVNode.properties.MappingInformationType;
+								var referenceType = UVNode.properties.ReferenceInformationType;
+								var buffer = parseFloatArray( UVNode.subNodes.UV.properties.a );
+								var indexBuffer = [];
+								if ( referenceType === 'IndexToDirect' ) {
+
+									indexBuffer = parseIntArray( UVNode.subNodes.UVIndex.properties.a );
+
+								}
+
+								return {
+									dataSize: 2,
+									buffer: buffer,
+									indices: indexBuffer,
+									mappingType: mappingType,
+									referenceType: referenceType
+								};
+
+							}
+
+							/**
+							 * Parses material application information for geometry.
+							 * @param {FBXGeometryNode}
+							 * @returns {{dataSize: number, buffer: number[], indices: number[], mappingType: string, referenceType: string}}
+							 */
+							function getMaterials( geometryNode ) {
+
+								var MaterialNode = geometryNode.subNodes.LayerElementMaterial[ 0 ];
+								var mappingType = MaterialNode.properties.MappingInformationType;
+								var referenceType = MaterialNode.properties.ReferenceInformationType;
+								var materialIndexBuffer = parseIntArray( MaterialNode.subNodes.Materials.properties.a );
+
+								// Since materials are stored as indices, there's a bit of a mismatch between FBX and what
+								// we expect.  So we create an intermediate buffer that points to the index in the buffer,
+								// for conforming with the other functions we've written for other data.
+								var materialIndices = [];
+								materialIndexBuffer.forEach( function ( materialIndex, index ) {
+
+									materialIndices.push( index );
+
+								} );
+
+								return {
+									dataSize: 1,
+									buffer: materialIndexBuffer,
+									indices: materialIndices,
+									mappingType: mappingType,
+									referenceType: referenceType
+								};
+
+							}
+
+							/**
+							 * Function uses the infoObject and given indices to return value array of object.
+							 * @param {number} polygonVertexIndex - Index of vertex in draw order (which index of the index buffer refers to this vertex).
+							 * @param {number} polygonIndex - Index of polygon in geometry.
+							 * @param {number} vertexIndex - Index of vertex inside vertex buffer (used because some data refers to old index buffer that we don't use anymore).
+							 * @param {{datasize: number, buffer: number[], indices: number[], mappingType: string, referenceType: string}} infoObject - Object containing data and how to access data.
+							 * @returns {number[]}
+							 */
+							function getData( polygonVertexIndex, polygonIndex, vertexIndex, infoObject ) {
+
+								var GetData = {
+
+									ByPolygonVertex: {
+
+										/**
+										 * Function uses the infoObject and given indices to return value array of object.
+										 * @param {number} polygonVertexIndex - Index of vertex in draw order (which index of the index buffer refers to this vertex).
+										 * @param {number} polygonIndex - Index of polygon in geometry.
+										 * @param {number} vertexIndex - Index of vertex inside vertex buffer (used because some data refers to old index buffer that we don't use anymore).
+										 * @param {{datasize: number, buffer: number[], indices: number[], mappingType: string, referenceType: string}} infoObject - Object containing data and how to access data.
+										 * @returns {number[]}
+										 */
+										Direct: function ( polygonVertexIndex, polygonIndex, vertexIndex, infoObject ) {
+
+											return infoObject.buffer.slice( ( polygonVertexIndex * infoObject.dataSize ), ( polygonVertexIndex * infoObject.dataSize ) + infoObject.dataSize );
+
+										},
+
+										/**
+										 * Function uses the infoObject and given indices to return value array of object.
+										 * @param {number} polygonVertexIndex - Index of vertex in draw order (which index of the index buffer refers to this vertex).
+										 * @param {number} polygonIndex - Index of polygon in geometry.
+										 * @param {number} vertexIndex - Index of vertex inside vertex buffer (used because some data refers to old index buffer that we don't use anymore).
+										 * @param {{datasize: number, buffer: number[], indices: number[], mappingType: string, referenceType: string}} infoObject - Object containing data and how to access data.
+										 * @returns {number[]}
+										 */
+										IndexToDirect: function ( polygonVertexIndex, polygonIndex, vertexIndex, infoObject ) {
+
+											var index = infoObject.indices[ polygonVertexIndex ];
+											return infoObject.buffer.slice( ( index * infoObject.dataSize ), ( index * infoObject.dataSize ) + infoObject.dataSize );
+
+										}
+
+									},
+
+									ByPolygon: {
+
+										/**
+										 * Function uses the infoObject and given indices to return value array of object.
+										 * @param {number} polygonVertexIndex - Index of vertex in draw order (which index of the index buffer refers to this vertex).
+										 * @param {number} polygonIndex - Index of polygon in geometry.
+										 * @param {number} vertexIndex - Index of vertex inside vertex buffer (used because some data refers to old index buffer that we don't use anymore).
+										 * @param {{datasize: number, buffer: number[], indices: number[], mappingType: string, referenceType: string}} infoObject - Object containing data and how to access data.
+										 * @returns {number[]}
+										 */
+										Direct: function ( polygonVertexIndex, polygonIndex, vertexIndex, infoObject ) {
+
+											return infoObject.buffer.slice( polygonIndex * infoObject.dataSize, polygonIndex * infoObject.dataSize + infoObject.dataSize );
+
+										},
+
+										/**
+										 * Function uses the infoObject and given indices to return value array of object.
+										 * @param {number} polygonVertexIndex - Index of vertex in draw order (which index of the index buffer refers to this vertex).
+										 * @param {number} polygonIndex - Index of polygon in geometry.
+										 * @param {number} vertexIndex - Index of vertex inside vertex buffer (used because some data refers to old index buffer that we don't use anymore).
+										 * @param {{datasize: number, buffer: number[], indices: number[], mappingType: string, referenceType: string}} infoObject - Object containing data and how to access data.
+										 * @returns {number[]}
+										 */
+										IndexToDirect: function ( polygonVertexIndex, polygonIndex, vertexIndex, infoObject ) {
+
+											var index = infoObject.indices[ polygonIndex ];
+											return infoObject.buffer.slice( index * infoObject.dataSize, index * infoObject.dataSize + infoObject.dataSize );
+
+										}
+
+									},
+
+									AllSame: {
+
+										/**
+										 * Function uses the infoObject and given indices to return value array of object.
+										 * @param {number} polygonVertexIndex - Index of vertex in draw order (which index of the index buffer refers to this vertex).
+										 * @param {number} polygonIndex - Index of polygon in geometry.
+										 * @param {number} vertexIndex - Index of vertex inside vertex buffer (used because some data refers to old index buffer that we don't use anymore).
+										 * @param {{datasize: number, buffer: number[], indices: number[], mappingType: string, referenceType: string}} infoObject - Object containing data and how to access data.
+										 * @returns {number[]}
+										 */
+										IndexToDirect: function ( polygonVertexIndex, polygonIndex, vertexIndex, infoObject ) {
+
+											return infoObject.buffer.slice( infoObject.indices[ 0 ] * infoObject.dataSize, infoObject.indices[ 0 ] * infoObject.dataSize + infoObject.dataSize );
+
+										}
+
+									}
+
+								};
+
+								return GetData[ infoObject.mappingType ][ infoObject.referenceType ]( polygonVertexIndex, polygonIndex, vertexIndex, infoObject );
+
+							}
+
+						}
+
+					}
+
+					/**
+					 * Specialty function for parsing NurbsCurve based Geometry Nodes.
+					 * @param {FBXGeometryNode} geometryNode
+					 * @param {{parents: {ID: number, relationship: string}[], children: {ID: number, relationship: string}[]}} relationships
+					 * @returns {THREE.BufferGeometry}
+					 */
+					function parseNurbsGeometry( geometryNode, relationships ) {
+
+						if ( THREE.NURBSCurve === undefined ) {
+
+							console.error( "THREE.FBXLoader relies on THREE.NURBSCurve for any nurbs present in the model.  Nurbs will show up as empty geometry." );
+							return new THREE.BufferGeometry();
+
+						}
+
+						var order = parseInt( geometryNode.properties.Order );
+
+						if ( isNaN( order ) ) {
+
+							console.error( "FBXLoader: Invalid Order " + geometryNode.properties.Order + " given for geometry ID: " + geometryNode.id );
+							return new THREE.BufferGeometry();
+
+						}
+
+						var knots = parseFloatArray( geometryNode.subNodes.KnotVector.properties.a );
+						var controlPoints = [];
+						var pointsValues = parseFloatArray( geometryNode.subNodes.Points.properties.a );
+
+						for ( var i = 0; i < pointsValues.length; i += 4 ) {
+
+							controlPoints.push( new THREE.Vector4( pointsValues[ i ], pointsValues[ i + 1 ], pointsValues[ i + 2 ], pointsValues[ i + 3 ] ) );
+
+						}
+
+						if ( geometryNode.properties.Form === 'Closed' ) {
+
+							controlPoints.push( controlPoints[ 0 ] );
+
+						}
+
+						var curve = new THREE.NURBSCurve( order - 1, knots, controlPoints );
+						var vertices = curve.getPoints( controlPoints.length * 1.5 );
+
+						var vertexBuffer = [];
+						vertices.forEach( function ( position ) {
+
+							var array = position.toArray();
+							vertexBuffer = vertexBuffer.concat( array );
+
+						} );
+
+						var geometry = new THREE.BufferGeometry();
+						geometry.addAttribute( 'position', new THREE.BufferAttribute( new Float32Array( vertexBuffer ), 3 ) );
+
+						return geometry;
+
+					}
+
+				}
+
+			}
+
+			/**
+			 * Finally generates Scene graph and Scene graph Objects.
+			 * @param {{Objects: {subNodes: {Model: Object.<number, FBXModelNode>}}}} FBXTree
+			 * @param {Map<number, {parents: {ID: number, relationship: string}[], children: {ID: number, relationship: string}[]}>} connections
+			 * @param {Map<number, {map: Map<number, {FBX_ID: number, indices: number[], weights: number[], transform: number[], transformLink: number[], linkMode: string}>, array: {FBX_ID: number, indices: number[], weights: number[], transform: number[], transformLink: number[], linkMode: string}[], skeleton: THREE.Skeleton|null}>} deformerMap
+			 * @param {Map<number, THREE.BufferGeometry>} geometryMap
+			 * @param {Map<number, THREE.Material>} materialMap
+			 * @returns {THREE.Group}
+			 */
+			function parseScene( FBXTree, connections, deformerMap, geometryMap, materialMap ) {
+
+				var sceneGraph = new THREE.Group();
+
+				var ModelNode = FBXTree.Objects.subNodes.Model;
+
+				/**
+				 * @type {Array.<THREE.Object3D>}
+				 */
+				var modelArray = [];
+
+				/**
+				 * @type {Map.<number, THREE.Object3D>}
+				 */
+				var modelMap = new Map();
+
+				for ( var nodeID in ModelNode ) {
+
+					var id = parseInt( nodeID );
+					var node = ModelNode[ nodeID ];
+					var conns = connections.get( id );
+					var model = null;
+					for ( var i = 0; i < conns.parents.length; ++ i ) {
+
+						deformerMap.forEach( function ( deformer ) {
+
+							if ( deformer.map.has( conns.parents[ i ].ID ) ) {
+
+								model = new THREE.Bone();
+								var index = deformer.array.findIndex( function ( subDeformer ) {
+
+									return subDeformer.FBX_ID === conns.parents[ i ].ID;
+
+								} );
+								deformer.bones[ index ] = model;
+
+							}
+
+						} );
+
+					}
+					if ( ! model ) {
+
+						switch ( node.attrType ) {
+
+							case "Mesh":
+								/**
+								 * @type {?THREE.BufferGeometry}
+								 */
+								var geometry = null;
+
+								/**
+								 * @type {THREE.MultiMaterial|THREE.Material}
+								 */
+								var material = null;
+
+								/**
+								 * @type {Array.<THREE.Material>}
+								 */
+								var materials = [];
+
+								conns.children.forEach( function ( child ) {
+
+									if ( geometryMap.has( child.ID ) ) {
+
+										geometry = geometryMap.get( child.ID );
+
+									}
+
+									if ( materialMap.has( child.ID ) ) {
+
+										materials.push( materialMap.get( child.ID ) );
+
+									}
+
+								} );
+								if ( materials.length > 1 ) {
+
+									material = new THREE.MultiMaterial( materials );
+
+								} else if ( materials.length > 0 ) {
+
+									material = materials[ 0 ];
+
+								} else {
+
+									material = new THREE.MeshBasicMaterial( { color: 0x3300ff } );
+
+								}
+								if ( geometry.FBX_Deformer ) {
+
+									materials.forEach( function ( material ) {
+
+										material.skinning = true;
+
+									} );
+									material.skinning = true;
+									model = new THREE.SkinnedMesh( geometry, material );
+
+								} else {
+
+									model = new THREE.Mesh( geometry, material );
+
+								}
+								break;
+
+							case "NurbsCurve":
+								var geometry = null;
+
+								conns.children.forEach( function ( child ) {
+
+									if ( geometryMap.has( child.ID ) ) {
+
+										geometry = geometryMap.get( child.ID );
+
+									}
+
+								} );
+
+								// FBX does not list materials for Nurbs lines, so we'll just put our own in here.
+								material = new THREE.LineBasicMaterial( { color: 0x3300ff, linewidth: 5 } );
+								model = new THREE.Line( geometry, material );
+								break;
+
+							default:
+								model = new THREE.Object3D();
+								break;
+
+						}
+
+					}
+
+					model.name = node.attrName.replace( /:/, '' ).replace( /_/, '' ).replace( /-/, '' );
+					model.FBX_ID = id;
+
+					modelArray.push( model );
+					modelMap.set( id, model );
+
+				}
+
+				modelArray.forEach( function ( model ) {
+
+					var node = ModelNode[ model.FBX_ID ];
+
+					if ( 'Lcl_Translation' in node.properties ) {
+
+						model.position.fromArray( parseFloatArray( node.properties.Lcl_Translation.value ) );
+
+					}
+
+					if ( 'Lcl_Rotation' in node.properties ) {
+
+						var rotation = parseFloatArray( node.properties.Lcl_Rotation.value ).map( function ( value ) {
+
+							return value * Math.PI / 180;
+
+						} );
+						rotation.push( 'ZYX' );
+						model.rotation.fromArray( rotation );
+
+					}
+
+					if ( 'Lcl_Scaling' in node.properties ) {
+
+						model.scale.fromArray( parseFloatArray( node.properties.Lcl_Scaling.value ) );
+
+					}
+
+					var conns = connections.get( model.FBX_ID );
+					for ( var parentIndex = 0; parentIndex < conns.parents.length; parentIndex ++ ) {
+
+						var pIndex = modelArray.findIndex( function ( mod ) {
+
+							return mod.FBX_ID === conns.parents[ parentIndex ].ID;
+
+						} );
+						if ( pIndex > - 1 ) {
+
+							modelArray[ pIndex ].add( model );
+							break;
+
+						}
+
+					}
+					if ( model.parent === null ) {
+
+						sceneGraph.add( model );
+
+					}
+
+				} );
+
+
+				// Now with the bones created, we can update the skeletons and bind them to the skinned meshes.
+				sceneGraph.updateMatrixWorld( true );
+
+				// Put skeleton into bind pose.
+				var BindPoseNode = FBXTree.Objects.subNodes.Pose;
+				for ( var nodeID in BindPoseNode ) {
+
+					if ( BindPoseNode[ nodeID ].attrType === 'BindPose' ) {
+
+						BindPoseNode = BindPoseNode[ nodeID ];
+						break;
+
+					}
+
+				}
+				if ( BindPoseNode ) {
+
+					var PoseNode = BindPoseNode.subNodes.PoseNode;
+					var worldMatrices = new Map();
+
+					PoseNode.forEach( function ( node ) {
+
+						var rawMatWrd = parseMatrixArray( node.subNodes.Matrix.properties.a );
+
+						worldMatrices.set( parseInt( node.id ), rawMatWrd );
+
+					} );
+
+				}
+
+				deformerMap.forEach( function ( deformer, FBX_ID ) {
+
+					deformer.array.forEach( function ( subDeformer, subDeformerIndex ) {
+
+						/**
+						 * @type {THREE.Bone}
+						 */
+						var bone = deformer.bones[ subDeformerIndex ];
+						if ( ! worldMatrices.has( bone.FBX_ID ) ) {
+
+							return;
+
+						}
+						var mat = worldMatrices.get( bone.FBX_ID );
+						bone.matrixWorld.copy( mat );
+
+					} );
+
+					// Now that skeleton is in bind pose, bind to model.
+					deformer.skeleton = new THREE.Skeleton( deformer.bones );
+					var conns = connections.get( FBX_ID );
+					conns.parents.forEach( function ( parent ) {
+
+						if ( geometryMap.has( parent.ID ) ) {
+
+							var geoID = parent.ID;
+							var geoConns = connections.get( geoID );
+							for ( var i = 0; i < geoConns.parents.length; ++ i ) {
+
+								if ( modelMap.has( geoConns.parents[ i ].ID ) ) {
+
+									var model = modelMap.get( geoConns.parents[ i ].ID );
+									//ASSERT model typeof SkinnedMesh
+									model.bind( deformer.skeleton, model.matrixWorld );
+									break;
+
+								}
+
+							}
+
+						}
+
+					} );
+
+				} );
+
+				// Skeleton is now bound, we are now free to set up the
+				// scene graph.
+				modelArray.forEach( function ( model ) {
+
+					var node = ModelNode[ model.FBX_ID ];
+
+					if ( 'Lcl_Translation' in node.properties ) {
+
+						model.position.fromArray( parseFloatArray( node.properties.Lcl_Translation.value ) );
+
+					}
+
+					if ( 'Lcl_Rotation' in node.properties ) {
+
+						var rotation = parseFloatArray( node.properties.Lcl_Rotation.value ).map( function ( value ) {
+
+							return value * Math.PI / 180;
+
+						} );
+						rotation.push( 'ZYX' );
+						model.rotation.fromArray( rotation );
+
+					}
+
+					if ( 'Lcl_Scaling' in node.properties ) {
+
+						model.scale.fromArray( parseFloatArray( node.properties.Lcl_Scaling.value ) );
+
+					}
+
+				} );
+
+				// Silly hack with the animation parsing.  We're gonna pretend the scene graph has a skeleton
+				// to attach animations to, since FBXs treat animations as animations for the entire scene,
+				// not just for individual objects.
+				sceneGraph.skeleton = {
+					bones: modelArray
+				};
+
+				var animations = parseAnimations( FBXTree, connections, sceneGraph );
+
+				addAnimations( sceneGraph, animations );
+
+				return sceneGraph;
+
+			}
+
+			/**
+			 * Parses animation information from FBXTree and generates an AnimationInfoObject.
+			 * @param {{Objects: {subNodes: {AnimationCurveNode: any, AnimationCurve: any, AnimationLayer: any, AnimationStack: any}}}} FBXTree
+			 * @param {Map<number, {parents: {ID: number, relationship: string}[], children: {ID: number, relationship: string}[]}>} connections
+			 */
+			function parseAnimations( FBXTree, connections, sceneGraph ) {
+
+				var rawNodes = FBXTree.Objects.subNodes.AnimationCurveNode;
+				var rawCurves = FBXTree.Objects.subNodes.AnimationCurve;
+				var rawLayers = FBXTree.Objects.subNodes.AnimationLayer;
+				var rawStacks = FBXTree.Objects.subNodes.AnimationStack;
+
+				/**
+				 * @type {{
+				     curves: Map<number, {
+						 T: {
+							id: number;
+							attr: string;
+							internalID: number;
+							attrX: boolean;
+							attrY: boolean;
+							attrZ: boolean;
+							containerBoneID: number;
+							containerID: number;
+							curves: {
+								x: {
+									version: any;
+									id: number;
+									internalID: number;
+									times: number[];
+									values: number[];
+									attrFlag: number[];
+									attrData: number[];
+								};
+								y: {
+									version: any;
+									id: number;
+									internalID: number;
+									times: number[];
+									values: number[];
+									attrFlag: number[];
+									attrData: number[];
+								};
+								z: {
+									version: any;
+									id: number;
+									internalID: number;
+									times: number[];
+									values: number[];
+									attrFlag: number[];
+									attrData: number[];
+								};
+							};
+						},
+						 R: {
+							id: number;
+							attr: string;
+							internalID: number;
+							attrX: boolean;
+							attrY: boolean;
+							attrZ: boolean;
+							containerBoneID: number;
+							containerID: number;
+							curves: {
+								x: {
+									version: any;
+									id: number;
+									internalID: number;
+									times: number[];
+									values: number[];
+									attrFlag: number[];
+									attrData: number[];
+								};
+								y: {
+									version: any;
+									id: number;
+									internalID: number;
+									times: number[];
+									values: number[];
+									attrFlag: number[];
+									attrData: number[];
+								};
+								z: {
+									version: any;
+									id: number;
+									internalID: number;
+									times: number[];
+									values: number[];
+									attrFlag: number[];
+									attrData: number[];
+								};
+							};
+						},
+						 S: {
+							id: number;
+							attr: string;
+							internalID: number;
+							attrX: boolean;
+							attrY: boolean;
+							attrZ: boolean;
+							containerBoneID: number;
+							containerID: number;
+							curves: {
+								x: {
+									version: any;
+									id: number;
+									internalID: number;
+									times: number[];
+									values: number[];
+									attrFlag: number[];
+									attrData: number[];
+								};
+								y: {
+									version: any;
+									id: number;
+									internalID: number;
+									times: number[];
+									values: number[];
+									attrFlag: number[];
+									attrData: number[];
+								};
+								z: {
+									version: any;
+									id: number;
+									internalID: number;
+									times: number[];
+									values: number[];
+									attrFlag: number[];
+									attrData: number[];
+								};
+							};
+						}
+					 }>,
+					 layers: Map<number, {
+					 	T: {
+							id: number;
+							attr: string;
+							internalID: number;
+							attrX: boolean;
+							attrY: boolean;
+							attrZ: boolean;
+							containerBoneID: number;
+							containerID: number;
+							curves: {
+								x: {
+									version: any;
+									id: number;
+									internalID: number;
+									times: number[];
+									values: number[];
+									attrFlag: number[];
+									attrData: number[];
+								};
+								y: {
+									version: any;
+									id: number;
+									internalID: number;
+									times: number[];
+									values: number[];
+									attrFlag: number[];
+									attrData: number[];
+								};
+								z: {
+									version: any;
+									id: number;
+									internalID: number;
+									times: number[];
+									values: number[];
+									attrFlag: number[];
+									attrData: number[];
+								};
+							},
+						},
+						R: {
+							id: number;
+							attr: string;
+							internalID: number;
+							attrX: boolean;
+							attrY: boolean;
+							attrZ: boolean;
+							containerBoneID: number;
+							containerID: number;
+							curves: {
+								x: {
+									version: any;
+									id: number;
+									internalID: number;
+									times: number[];
+									values: number[];
+									attrFlag: number[];
+									attrData: number[];
+								};
+								y: {
+									version: any;
+									id: number;
+									internalID: number;
+									times: number[];
+									values: number[];
+									attrFlag: number[];
+									attrData: number[];
+								};
+								z: {
+									version: any;
+									id: number;
+									internalID: number;
+									times: number[];
+									values: number[];
+									attrFlag: number[];
+									attrData: number[];
+								};
+							},
+						},
+						S: {
+							id: number;
+							attr: string;
+							internalID: number;
+							attrX: boolean;
+							attrY: boolean;
+							attrZ: boolean;
+							containerBoneID: number;
+							containerID: number;
+							curves: {
+								x: {
+									version: any;
+									id: number;
+									internalID: number;
+									times: number[];
+									values: number[];
+									attrFlag: number[];
+									attrData: number[];
+								};
+								y: {
+									version: any;
+									id: number;
+									internalID: number;
+									times: number[];
+									values: number[];
+									attrFlag: number[];
+									attrData: number[];
+								};
+								z: {
+									version: any;
+									id: number;
+									internalID: number;
+									times: number[];
+									values: number[];
+									attrFlag: number[];
+									attrData: number[];
+								};
+							},
+						}
+						}[]>,
+					 stacks: Map<number, {
+						 name: string,
+						 layers: {
+							T: {
+								id: number;
+								attr: string;
+								internalID: number;
+								attrX: boolean;
+								attrY: boolean;
+								attrZ: boolean;
+								containerBoneID: number;
+								containerID: number;
+								curves: {
+									x: {
+										version: any;
+										id: number;
+										internalID: number;
+										times: number[];
+										values: number[];
+										attrFlag: number[];
+										attrData: number[];
+									};
+									y: {
+										version: any;
+										id: number;
+										internalID: number;
+										times: number[];
+										values: number[];
+										attrFlag: number[];
+										attrData: number[];
+									};
+									z: {
+										version: any;
+										id: number;
+										internalID: number;
+										times: number[];
+										values: number[];
+										attrFlag: number[];
+										attrData: number[];
+									};
+								};
+							};
+							R: {
+								id: number;
+								attr: string;
+								internalID: number;
+								attrX: boolean;
+								attrY: boolean;
+								attrZ: boolean;
+								containerBoneID: number;
+								containerID: number;
+								curves: {
+									x: {
+										version: any;
+										id: number;
+										internalID: number;
+										times: number[];
+										values: number[];
+										attrFlag: number[];
+										attrData: number[];
+									};
+									y: {
+										version: any;
+										id: number;
+										internalID: number;
+										times: number[];
+										values: number[];
+										attrFlag: number[];
+										attrData: number[];
+									};
+									z: {
+										version: any;
+										id: number;
+										internalID: number;
+										times: number[];
+										values: number[];
+										attrFlag: number[];
+										attrData: number[];
+									};
+								};
+							};
+							S: {
+								id: number;
+								attr: string;
+								internalID: number;
+								attrX: boolean;
+								attrY: boolean;
+								attrZ: boolean;
+								containerBoneID: number;
+								containerID: number;
+								curves: {
+									x: {
+										version: any;
+										id: number;
+										internalID: number;
+										times: number[];
+										values: number[];
+										attrFlag: number[];
+										attrData: number[];
+									};
+									y: {
+										version: any;
+										id: number;
+										internalID: number;
+										times: number[];
+										values: number[];
+										attrFlag: number[];
+										attrData: number[];
+									};
+									z: {
+										version: any;
+										id: number;
+										internalID: number;
+										times: number[];
+										values: number[];
+										attrFlag: number[];
+										attrData: number[];
+									};
+								};
+							};
+						}[][],
+					 length: number,
+					 frames: number }>,
+					 length: number,
+					 fps: number,
+					 frames: number
+				 }}
+				 */
+				var returnObject = {
+					curves: new Map(),
+					layers: new Map(),
+					stacks: new Map(),
+					length: 0,
+					fps: 30,
+					frames: 0
+				};
+
+				/**
+				 * @type {Array.<{
+						id: number;
+						attr: string;
+						internalID: number;
+						attrX: boolean;
+						attrY: boolean;
+						attrZ: boolean;
+						containerBoneID: number;
+						containerID: number;
+					}>}
+				 */
+				var animationCurveNodes = [];
+				for ( var nodeID in rawNodes ) {
+
+					if ( nodeID.match( /\d+/ ) ) {
+
+						var animationNode = parseAnimationNode( FBXTree, rawNodes[ nodeID ], connections, sceneGraph );
+						animationCurveNodes.push( animationNode );
+
+					}
+
+				}
+
+				/**
+				 * @type {Map.<number, {
+						id: number,
+						attr: string,
+						internalID: number,
+						attrX: boolean,
+						attrY: boolean,
+						attrZ: boolean,
+						containerBoneID: number,
+						containerID: number,
+						curves: {
+							x: {
+								version: any,
+								id: number,
+								internalID: number,
+								times: number[],
+								values: number[],
+								attrFlag: number[],
+								attrData: number[],
+							},
+							y: {
+								version: any,
+								id: number,
+								internalID: number,
+								times: number[],
+								values: number[],
+								attrFlag: number[],
+								attrData: number[],
+							},
+							z: {
+								version: any,
+								id: number,
+								internalID: number,
+								times: number[],
+								values: number[],
+								attrFlag: number[],
+								attrData: number[],
+							}
+						}
+					}>}
+				 */
+				var tmpMap = new Map();
+				for ( var animationCurveNodeIndex = 0; animationCurveNodeIndex < animationCurveNodes.length; ++ animationCurveNodeIndex ) {
+
+					if ( animationCurveNodes[ animationCurveNodeIndex ] === null ) {
+
+						continue;
+
+					}
+					tmpMap.set( animationCurveNodes[ animationCurveNodeIndex ].id, animationCurveNodes[ animationCurveNodeIndex ] );
+
+				}
+
+
+				/**
+				 * @type {{
+						version: any,
+						id: number,
+						internalID: number,
+						times: number[],
+						values: number[],
+						attrFlag: number[],
+						attrData: number[],
+					}[]}
+				 */
+				var animationCurves = [];
+				for ( nodeID in rawCurves ) {
+
+					if ( nodeID.match( /\d+/ ) ) {
+
+						var animationCurve = parseAnimationCurve( rawCurves[ nodeID ] );
+						animationCurves.push( animationCurve );
+
+						var firstParentConn = connections.get( animationCurve.id ).parents[ 0 ];
+						var firstParentID = firstParentConn.ID;
+						var firstParentRelationship = firstParentConn.relationship;
+						var axis = '';
+
+						if ( firstParentRelationship.match( /X/ ) ) {
+
+							axis = 'x';
+
+						} else if ( firstParentRelationship.match( /Y/ ) ) {
+
+							axis = 'y';
+
+						} else if ( firstParentRelationship.match( /Z/ ) ) {
+
+							axis = 'z';
+
+						} else {
+
+							continue;
+
+						}
+
+						tmpMap.get( firstParentID ).curves[ axis ] = animationCurve;
+
+					}
+
+				}
+
+				tmpMap.forEach( function ( curveNode ) {
+
+					var id = curveNode.containerBoneID;
+					if ( ! returnObject.curves.has( id ) ) {
+
+						returnObject.curves.set( id, { T: null, R: null, S: null } );
+
+					}
+					returnObject.curves.get( id )[ curveNode.attr ] = curveNode;
+
+				} );
+
+				for ( var nodeID in rawLayers ) {
+
+					/**
+					 * @type {{
+					 	T: {
+							id: number;
+							attr: string;
+							internalID: number;
+							attrX: boolean;
+							attrY: boolean;
+							attrZ: boolean;
+							containerBoneID: number;
+							containerID: number;
+							curves: {
+								x: {
+									version: any;
+									id: number;
+									internalID: number;
+									times: number[];
+									values: number[];
+									attrFlag: number[];
+									attrData: number[];
+								};
+								y: {
+									version: any;
+									id: number;
+									internalID: number;
+									times: number[];
+									values: number[];
+									attrFlag: number[];
+									attrData: number[];
+								};
+								z: {
+									version: any;
+									id: number;
+									internalID: number;
+									times: number[];
+									values: number[];
+									attrFlag: number[];
+									attrData: number[];
+								};
+							},
+						},
+						R: {
+							id: number;
+							attr: string;
+							internalID: number;
+							attrX: boolean;
+							attrY: boolean;
+							attrZ: boolean;
+							containerBoneID: number;
+							containerID: number;
+							curves: {
+								x: {
+									version: any;
+									id: number;
+									internalID: number;
+									times: number[];
+									values: number[];
+									attrFlag: number[];
+									attrData: number[];
+								};
+								y: {
+									version: any;
+									id: number;
+									internalID: number;
+									times: number[];
+									values: number[];
+									attrFlag: number[];
+									attrData: number[];
+								};
+								z: {
+									version: any;
+									id: number;
+									internalID: number;
+									times: number[];
+									values: number[];
+									attrFlag: number[];
+									attrData: number[];
+								};
+							},
+						},
+						S: {
+							id: number;
+							attr: string;
+							internalID: number;
+							attrX: boolean;
+							attrY: boolean;
+							attrZ: boolean;
+							containerBoneID: number;
+							containerID: number;
+							curves: {
+								x: {
+									version: any;
+									id: number;
+									internalID: number;
+									times: number[];
+									values: number[];
+									attrFlag: number[];
+									attrData: number[];
+								};
+								y: {
+									version: any;
+									id: number;
+									internalID: number;
+									times: number[];
+									values: number[];
+									attrFlag: number[];
+									attrData: number[];
+								};
+								z: {
+									version: any;
+									id: number;
+									internalID: number;
+									times: number[];
+									values: number[];
+									attrFlag: number[];
+									attrData: number[];
+								};
+							},
+						}
+						}[]}
+					 */
+					var layer = [];
+					var children = connections.get( parseInt( nodeID ) ).children;
+					for ( var childIndex = 0; childIndex < children.length; childIndex ++ ) {
+
+						// Skip lockInfluenceWeights
+						if ( tmpMap.has( children[ childIndex ].ID ) ) {
+
+							var curveNode = tmpMap.get( children[ childIndex ].ID );
+							var boneID = curveNode.containerBoneID;
+							if ( layer[ boneID ] === undefined ) {
+
+								layer[ boneID ] = {
+									T: null,
+									R: null,
+									S: null
+								};
+
+							}
+
+							layer[ boneID ][ curveNode.attr ] = curveNode;
+
+						}
+
+					}
+
+					returnObject.layers.set( parseInt( nodeID ), layer );
+
+				}
+
+				for ( var nodeID in rawStacks ) {
+
+					var layers = [];
+					var children = connections.get( parseInt( nodeID ) ).children;
+					var maxTimeStamp = 0;
+					var minTimeStamp = Number.MAX_VALUE;
+					for ( var childIndex = 0; childIndex < children.length; ++ childIndex ) {
+
+						if ( returnObject.layers.has( children[ childIndex ].ID ) ) {
+
+							var currentLayer = returnObject.layers.get( children[ childIndex ].ID );
+							layers.push( currentLayer );
+
+							currentLayer.forEach( function ( layer ) {
+
+								if ( layer ) {
+
+									getCurveNodeMaxMinTimeStamps( layer );
+
+								}
+
+								/**
+								 * Sets the maxTimeStamp and minTimeStamp variables if it has timeStamps that are either larger or smaller
+								 * than the max or min respectively.
+								 * @param {{
+											T: {
+													id: number,
+													attr: string,
+													internalID: number,
+													attrX: boolean,
+													attrY: boolean,
+													attrZ: boolean,
+													containerBoneID: number,
+													containerID: number,
+													curves: {
+															x: {
+																	version: any,
+																	id: number,
+																	internalID: number,
+																	times: number[],
+																	values: number[],
+																	attrFlag: number[],
+																	attrData: number[],
+															},
+															y: {
+																	version: any,
+																	id: number,
+																	internalID: number,
+																	times: number[],
+																	values: number[],
+																	attrFlag: number[],
+																	attrData: number[],
+															},
+															z: {
+																	version: any,
+																	id: number,
+																	internalID: number,
+																	times: number[],
+																	values: number[],
+																	attrFlag: number[],
+																	attrData: number[],
+															},
+													},
+											},
+											R: {
+													id: number,
+													attr: string,
+													internalID: number,
+													attrX: boolean,
+													attrY: boolean,
+													attrZ: boolean,
+													containerBoneID: number,
+													containerID: number,
+													curves: {
+															x: {
+																	version: any,
+																	id: number,
+																	internalID: number,
+																	times: number[],
+																	values: number[],
+																	attrFlag: number[],
+																	attrData: number[],
+															},
+															y: {
+																	version: any,
+																	id: number,
+																	internalID: number,
+																	times: number[],
+																	values: number[],
+																	attrFlag: number[],
+																	attrData: number[],
+															},
+															z: {
+																	version: any,
+																	id: number,
+																	internalID: number,
+																	times: number[],
+																	values: number[],
+																	attrFlag: number[],
+																	attrData: number[],
+															},
+													},
+											},
+											S: {
+													id: number,
+													attr: string,
+													internalID: number,
+													attrX: boolean,
+													attrY: boolean,
+													attrZ: boolean,
+													containerBoneID: number,
+													containerID: number,
+													curves: {
+															x: {
+																	version: any,
+																	id: number,
+																	internalID: number,
+																	times: number[],
+																	values: number[],
+																	attrFlag: number[],
+																	attrData: number[],
+															},
+															y: {
+																	version: any,
+																	id: number,
+																	internalID: number,
+																	times: number[],
+																	values: number[],
+																	attrFlag: number[],
+																	attrData: number[],
+															},
+															z: {
+																	version: any,
+																	id: number,
+																	internalID: number,
+																	times: number[],
+																	values: number[],
+																	attrFlag: number[],
+																	attrData: number[],
+															},
+													},
+											},
+									}} layer
+								 */
+								function getCurveNodeMaxMinTimeStamps( layer ) {
+
+									/**
+									 * Sets the maxTimeStamp and minTimeStamp if one of the curve's time stamps
+									 * exceeds the maximum or minimum.
+									 * @param {{
+												x: {
+														version: any,
+														id: number,
+														internalID: number,
+														times: number[],
+														values: number[],
+														attrFlag: number[],
+														attrData: number[],
+												},
+												y: {
+														version: any,
+														id: number,
+														internalID: number,
+														times: number[],
+														values: number[],
+														attrFlag: number[],
+														attrData: number[],
+												},
+												z: {
+														version: any,
+														id: number,
+														internalID: number,
+														times: number[],
+														values: number[],
+														attrFlag: number[],
+														attrData: number[],
+												}
+										}} curve
+									 */
+									function getCurveMaxMinTimeStamp( curve ) {
+
+										/**
+										 * Sets the maxTimeStamp and minTimeStamp if one of its timestamps exceeds the maximum or minimum.
+										 * @param {{times: number[]}} axis
+										 */
+										function getCurveAxisMaxMinTimeStamps( axis ) {
+
+											maxTimeStamp = axis.times[ axis.times.length - 1 ] > maxTimeStamp ? axis.times[ axis.times.length - 1 ] : maxTimeStamp;
+											minTimeStamp = axis.times[ 0 ] < minTimeStamp ? axis.times[ 0 ] : minTimeStamp;
+
+										}
+
+										if ( curve.x ) {
+
+											getCurveAxisMaxMinTimeStamps( curve.x );
+
+										}
+										if ( curve.y ) {
+
+											getCurveAxisMaxMinTimeStamps( curve.y );
+
+										}
+										if ( curve.z ) {
+
+											getCurveAxisMaxMinTimeStamps( curve.z );
+
+										}
+
+									}
+
+									if ( layer.R ) {
+
+										getCurveMaxMinTimeStamp( layer.R.curves );
+
+									}
+									if ( layer.S ) {
+
+										getCurveMaxMinTimeStamp( layer.S.curves );
+
+									}
+									if ( layer.T ) {
+
+										getCurveMaxMinTimeStamp( layer.T.curves );
+
+									}
+
+								}
+
+							} );
+
+						}
+
+					}
+
+					// Do we have an animation clip with actual length?
+					if ( maxTimeStamp > minTimeStamp ) {
+
+						returnObject.stacks.set( parseInt( nodeID ), {
+							name: rawStacks[ nodeID ].attrName,
+							layers: layers,
+							length: maxTimeStamp - minTimeStamp,
+							frames: ( maxTimeStamp - minTimeStamp ) * 30
+						} );
+
+					}
+
+				}
+
+				return returnObject;
+
+				/**
+				 * @param {Object} FBXTree
+				 * @param {{id: number, attrName: string, properties: Object<string, any>}} animationCurveNode
+				 * @param {Map<number, {parents: {ID: number, relationship: string}[], children: {ID: number, relationship: string}[]}>} connections
+				 * @param {{skeleton: {bones: {FBX_ID: number}[]}}} sceneGraph
+				 */
+				function parseAnimationNode( FBXTree, animationCurveNode, connections, sceneGraph ) {
+
+					var returnObject = {
+						/**
+						 * @type {number}
+						 */
+						id: animationCurveNode.id,
+
+						/**
+						 * @type {string}
+						 */
+						attr: animationCurveNode.attrName,
+
+						/**
+						 * @type {number}
+						 */
+						internalID: animationCurveNode.id,
+
+						/**
+						 * @type {boolean}
+						 */
+						attrX: false,
+
+						/**
+						 * @type {boolean}
+						 */
+						attrY: false,
+
+						/**
+						 * @type {boolean}
+						 */
+						attrZ: false,
+
+						/**
+						 * @type {number}
+						 */
+						containerBoneID: - 1,
+
+						/**
+						 * @type {number}
+						 */
+						containerID: - 1,
+
+						curves: {
+							x: null,
+							y: null,
+							z: null
+						}
+					};
+
+					if ( returnObject.attr.match( /S|R|T/ ) ) {
+
+						for ( var attributeKey in animationCurveNode.properties ) {
+
+							if ( attributeKey.match( /X/ ) ) {
+
+								returnObject.attrX = true;
+
+							}
+							if ( attributeKey.match( /Y/ ) ) {
+
+								returnObject.attrY = true;
+
+							}
+							if ( attributeKey.match( /Z/ ) ) {
+
+								returnObject.attrZ = true;
+
+							}
+
+						}
+
+					} else {
+
+						return null;
+
+					}
+
+					var conns = connections.get( returnObject.id );
+					var containerIndices = conns.parents;
+
+					for ( var containerIndicesIndex = containerIndices.length - 1; containerIndicesIndex >= 0; -- containerIndicesIndex ) {
+
+						var boneID = sceneGraph.skeleton.bones.findIndex( function ( bone ) {
+
+							return bone.FBX_ID === containerIndices[ containerIndicesIndex ].ID;
+
+						} );
+						if ( boneID > - 1 ) {
+
+							returnObject.containerBoneID = boneID;
+							returnObject.containerID = containerIndices[ containerIndicesIndex ].ID;
+							break;
+
+						}
+
+					}
+
+					return returnObject;
+
+				}
+
+				/**
+				 * @param {{id: number, subNodes: {KeyTime: {properties: {a: string}}, KeyValueFloat: {properties: {a: string}}, KeyAttrFlags: {properties: {a: string}}, KeyAttrDataFloat: {properties: {a: string}}}}} animationCurve
+				 */
+				function parseAnimationCurve( animationCurve ) {
+
+					return {
+						version: null,
+						id: animationCurve.id,
+						internalID: animationCurve.id,
+						times: parseFloatArray( animationCurve.subNodes.KeyTime.properties.a ).map( function ( time ) {
+
+							return ConvertFBXTimeToSeconds( time );
+
+						} ),
+						values: parseFloatArray( animationCurve.subNodes.KeyValueFloat.properties.a ),
+
+						attrFlag: parseIntArray( animationCurve.subNodes.KeyAttrFlags.properties.a ),
+						attrData: parseFloatArray( animationCurve.subNodes.KeyAttrDataFloat.properties.a )
+					};
+
+				}
+
+			}
+
+			/**
+			 * @param {{
+				curves: Map<number, {
+					T: {
+						id: number;
+						attr: string;
+						internalID: number;
+						attrX: boolean;
+						attrY: boolean;
+						attrZ: boolean;
+						containerBoneID: number;
+						containerID: number;
+						curves: {
+							x: {
+								version: any;
+								id: number;
+								internalID: number;
+								times: number[];
+								values: number[];
+								attrFlag: number[];
+								attrData: number[];
+							};
+							y: {
+								version: any;
+								id: number;
+								internalID: number;
+								times: number[];
+								values: number[];
+								attrFlag: number[];
+								attrData: number[];
+							};
+							z: {
+								version: any;
+								id: number;
+								internalID: number;
+								times: number[];
+								values: number[];
+								attrFlag: number[];
+								attrData: number[];
+							};
+						};
+					};
+					R: {
+						id: number;
+						attr: string;
+						internalID: number;
+						attrX: boolean;
+						attrY: boolean;
+						attrZ: boolean;
+						containerBoneID: number;
+						containerID: number;
+						curves: {
+							x: {
+								version: any;
+								id: number;
+								internalID: number;
+								times: number[];
+								values: number[];
+								attrFlag: number[];
+								attrData: number[];
+							};
+							y: {
+								version: any;
+								id: number;
+								internalID: number;
+								times: number[];
+								values: number[];
+								attrFlag: number[];
+								attrData: number[];
+							};
+							z: {
+								version: any;
+								id: number;
+								internalID: number;
+								times: number[];
+								values: number[];
+								attrFlag: number[];
+								attrData: number[];
+							};
+						};
+					};
+					S: {
+						id: number;
+						attr: string;
+						internalID: number;
+						attrX: boolean;
+						attrY: boolean;
+						attrZ: boolean;
+						containerBoneID: number;
+						containerID: number;
+						curves: {
+							x: {
+								version: any;
+								id: number;
+								internalID: number;
+								times: number[];
+								values: number[];
+								attrFlag: number[];
+								attrData: number[];
+							};
+							y: {
+								version: any;
+								id: number;
+								internalID: number;
+								times: number[];
+								values: number[];
+								attrFlag: number[];
+								attrData: number[];
+							};
+							z: {
+								version: any;
+								id: number;
+								internalID: number;
+								times: number[];
+								values: number[];
+								attrFlag: number[];
+								attrData: number[];
+							};
+						};
+					};
+				}>;
+				layers: Map<number, {
+					T: {
+						id: number;
+						attr: string;
+						internalID: number;
+						attrX: boolean;
+						attrY: boolean;
+						attrZ: boolean;
+						containerBoneID: number;
+						containerID: number;
+						curves: {
+							x: {
+								version: any;
+								id: number;
+								internalID: number;
+								times: number[];
+								values: number[];
+								attrFlag: number[];
+								attrData: number[];
+							};
+							y: {
+								version: any;
+								id: number;
+								internalID: number;
+								times: number[];
+								values: number[];
+								attrFlag: number[];
+								attrData: number[];
+							};
+							z: {
+								version: any;
+								id: number;
+								internalID: number;
+								times: number[];
+								values: number[];
+								attrFlag: number[];
+								attrData: number[];
+							};
+						};
+					};
+					R: {
+						id: number;
+						attr: string;
+						internalID: number;
+						attrX: boolean;
+						attrY: boolean;
+						attrZ: boolean;
+						containerBoneID: number;
+						containerID: number;
+						curves: {
+							x: {
+								version: any;
+								id: number;
+								internalID: number;
+								times: number[];
+								values: number[];
+								attrFlag: number[];
+								attrData: number[];
+							};
+							y: {
+								version: any;
+								id: number;
+								internalID: number;
+								times: number[];
+								values: number[];
+								attrFlag: number[];
+								attrData: number[];
+							};
+							z: {
+								version: any;
+								id: number;
+								internalID: number;
+								times: number[];
+								values: number[];
+								attrFlag: number[];
+								attrData: number[];
+							};
+						};
+					};
+					S: {
+						id: number;
+						attr: string;
+						internalID: number;
+						attrX: boolean;
+						attrY: boolean;
+						attrZ: boolean;
+						containerBoneID: number;
+						containerID: number;
+						curves: {
+							x: {
+								version: any;
+								id: number;
+								internalID: number;
+								times: number[];
+								values: number[];
+								attrFlag: number[];
+								attrData: number[];
+							};
+							y: {
+								version: any;
+								id: number;
+								internalID: number;
+								times: number[];
+								values: number[];
+								attrFlag: number[];
+								attrData: number[];
+							};
+							z: {
+								version: any;
+								id: number;
+								internalID: number;
+								times: number[];
+								values: number[];
+								attrFlag: number[];
+								attrData: number[];
+							};
+						};
+					};
+				}[]>;
+				stacks: Map<number, {
+					name: string;
+					layers: {
+						T: {
+							id: number;
+							attr: string;
+							internalID: number;
+							attrX: boolean;
+							attrY: boolean;
+							attrZ: boolean;
+							containerBoneID: number;
+							containerID: number;
+							curves: {
+								x: {
+									version: any;
+									id: number;
+									internalID: number;
+									times: number[];
+									values: number[];
+									attrFlag: number[];
+									attrData: number[];
+								};
+								y: {
+									version: any;
+									id: number;
+									internalID: number;
+									times: number[];
+									values: number[];
+									attrFlag: number[];
+									attrData: number[];
+								};
+								z: {
+									version: any;
+									id: number;
+									internalID: number;
+									times: number[];
+									values: number[];
+									attrFlag: number[];
+									attrData: number[];
+								};
+							};
+						};
+						R: {
+							id: number;
+							attr: string;
+							internalID: number;
+							attrX: boolean;
+							attrY: boolean;
+							attrZ: boolean;
+							containerBoneID: number;
+							containerID: number;
+							curves: {
+								x: {
+									version: any;
+									id: number;
+									internalID: number;
+									times: number[];
+									values: number[];
+									attrFlag: number[];
+									attrData: number[];
+								};
+								y: {
+									version: any;
+									id: number;
+									internalID: number;
+									times: number[];
+									values: number[];
+									attrFlag: number[];
+									attrData: number[];
+								};
+								z: {
+									version: any;
+									id: number;
+									internalID: number;
+									times: number[];
+									values: number[];
+									attrFlag: number[];
+									attrData: number[];
+								};
+							};
+						};
+						S: {
+							id: number;
+							attr: string;
+							internalID: number;
+							attrX: boolean;
+							attrY: boolean;
+							attrZ: boolean;
+							containerBoneID: number;
+							containerID: number;
+							curves: {
+								x: {
+									version: any;
+									id: number;
+									internalID: number;
+									times: number[];
+									values: number[];
+									attrFlag: number[];
+									attrData: number[];
+								};
+								y: {
+									version: any;
+									id: number;
+									internalID: number;
+									times: number[];
+									values: number[];
+									attrFlag: number[];
+									attrData: number[];
+								};
+								z: {
+									version: any;
+									id: number;
+									internalID: number;
+									times: number[];
+									values: number[];
+									attrFlag: number[];
+									attrData: number[];
+								};
+							};
+						};
+					}[][];
+					length: number;
+					frames: number;
+				}>;
+				length: number;
+				fps: number;
+				frames: number;
+			}} animations,
+			 * @param {{skeleton: { bones: THREE.Bone[]}}} group
+			 */
+			function addAnimations( group, animations ) {
+
+				if ( group.animations === undefined ) {
+
+					group.animations = [];
+
+				}
+
+				animations.stacks.forEach( function ( stack ) {
+
+					var animationData = {
+						name: stack.name,
+						fps: 30,
+						length: stack.length,
+						hierarchy: []
+					};
+
+					var bones = group.skeleton.bones;
+
+					bones.forEach( function ( bone ) {
+
+						var name = bone.name.replace( /.*:/, '' );
+						var parentIndex = bones.findIndex( function ( parentBone ) {
+
+							return bone.parent === parentBone;
+
+						} );
+						animationData.hierarchy.push( { parent: parentIndex, name: name, keys: [] } );
+
+					} );
+
+					for ( var frame = 0; frame < stack.frames; frame ++ ) {
+
+						bones.forEach( function ( bone, boneIndex ) {
+
+							var animationNode = stack.layers[ 0 ][ boneIndex ];
+
+							animationData.hierarchy.forEach( function ( node ) {
+
+								if ( node.name === bone.name ) {
+
+									node.keys.push( generateKey( animationNode, bone, frame ) );
+
+								}
+
+							} );
+
+						} );
+
+					}
+
+					group.animations.push( THREE.AnimationClip.parseAnimation( animationData, bones ) );
+
+
+					/**
+					 * @param {THREE.Bone} bone
+					 */
+					function generateKey( animationNode, bone, frame ) {
+
+						var key = {
+							time: frame / animations.fps,
+							pos: bone.position.toArray(),
+							rot: bone.quaternion.toArray(),
+							scl: bone.scale.toArray()
+						};
+
+						if ( animationNode === undefined ) {
+
+							return key;
+
+						}
+
+						try {
+
+							if ( hasCurve( animationNode, 'T' ) && hasKeyOnFrame( animationNode.T, frame ) ) {
+
+								key.pos = [ animationNode.T.curves.x.values[ frame ], animationNode.T.curves.y.values[ frame ], animationNode.T.curves.z.values[ frame ] ];
+
+							}
+
+							if ( hasCurve( animationNode, 'R' ) && hasKeyOnFrame( animationNode.R, frame ) ) {
+
+								var rotationX = degreeToRadian( animationNode.R.curves.x.values[ frame ] );
+								var rotationY = degreeToRadian( animationNode.R.curves.y.values[ frame ] );
+								var rotationZ = degreeToRadian( animationNode.R.curves.z.values[ frame ] );
+								var euler = new THREE.Euler( rotationX, rotationY, rotationZ, 'ZYX' );
+								key.rot = new THREE.Quaternion().setFromEuler( euler ).toArray();
+
+							}
+
+							if ( hasCurve( animationNode, 'S' ) && hasKeyOnFrame( animationNode.S, frame ) ) {
+
+								key.scl = [ animationNode.S.curves.x.values[ frame ], animationNode.S.curves.y.values[ frame ], animationNode.S.curves.z.values[ frame ] ];
+
+							}
+
+						} catch ( error ) {
+
+							// Curve is not fully plotted.
+							console.log( bone );
+							console.log( error );
+
+						}
+
+						return key;
+
+						function hasCurve( animationNode, attribute ) {
+
+							if ( animationNode === undefined ) {
+
+								return false;
+
+							}
+
+							var attributeNode = animationNode[ attribute ];
+							if ( ! attributeNode ) {
+
+								return false;
+
+							}
+
+							return [ 'x', 'y', 'z' ].every( function ( key ) {
+
+								return attributeNode.curves[ key ] !== undefined;
+
+							} );
+
+						}
+
+						function hasKeyOnFrame( attributeNode, frame ) {
+
+							return [ 'x', 'y', 'z' ].every( function ( key ) {
+
+								return isKeyExistOnFrame( attributeNode.curves[ key ], frame );
+
+								function isKeyExistOnFrame( curve, frame ) {
+
+									return curve.values[ frame ] !== undefined;
+
+								}
+
+							} );
+
+						}
+
+					}
+
+				} );
+
+			}
+
+
+
+			// UTILS
+			/**
+			 * Parses Vector3 property from FBXTree.  Property is given as .value.x, .value.y, etc.
+			 * @param {FBXVector3} property - Property to parse as Vector3.
+			 * @returns {THREE.Vector3}
+			 */
+			function parseVector3( property ) {
+
+				return new THREE.Vector3( parseFloat( property.value.x ), parseFloat( property.value.y ), parseFloat( property.value.z ) );
+
+			}
+
+			/**
+			 * Parses Color property from FBXTree.  Property is given as .value.x, .value.y, etc.
+			 * @param {FBXVector3} property - Property to parse as Color.
+			 * @returns {THREE.Color}
+			 */
+			function parseColor( property ) {
+
+				return new THREE.Color().fromArray( parseVector3( property ).toArray() );
+
+			}
+
+		}
+
+	} );
+
+	/**
+	 * An instance of a Vertex with data for drawing vertices to the screen.
+	 * @constructor
+	 */
+	function Vertex() {
+
+		/**
+		 * Position of the vertex.
+		 * @type {THREE.Vector3}
+		 */
+		this.position = new THREE.Vector3( );
+
+		/**
+		 * Normal of the vertex
+		 * @type {THREE.Vector3}
+		 */
+		this.normal = new THREE.Vector3( );
+
+		/**
+		 * UV coordinates of the vertex.
+		 * @type {THREE.Vector2}
+		 */
+		this.uv = new THREE.Vector2( );
+
+		/**
+		 * Indices of the bones vertex is influenced by.
+		 * @type {THREE.Vector4}
+		 */
+		this.skinIndices = new THREE.Vector4( 0, 0, 0, 0 );
+
+		/**
+		 * Weights that each bone influences the vertex.
+		 * @type {THREE.Vector4}
+		 */
+		this.skinWeights = new THREE.Vector4( 0, 0, 0, 0 );
+
+	}
+
+	Object.assign( Vertex.prototype, {
+
+		copy: function ( target ) {
+
+			var returnVar = target || new Vertex();
+
+			returnVar.position.copy( this.position );
+			returnVar.normal.copy( this.normal );
+			returnVar.uv.copy( this.uv );
+			returnVar.skinIndices.copy( this.skinIndices );
+			returnVar.skinWeights.copy( this.skinWeights );
+
+			return returnVar;
+
+		},
+
+		flattenToBuffers: function () {
+
+			var vertexBuffer = this.position.toArray();
+			var normalBuffer = this.normal.toArray();
+			var uvBuffer = this.uv.toArray();
+			var skinIndexBuffer = this.skinIndices.toArray();
+			var skinWeightBuffer = this.skinWeights.toArray();
+
+			return {
+				vertexBuffer: vertexBuffer,
+				normalBuffer: normalBuffer,
+				uvBuffer: uvBuffer,
+				skinIndexBuffer: skinIndexBuffer,
+				skinWeightBuffer: skinWeightBuffer,
+			};
+
+		}
+
+	} );
+
+	/**
+	 * @constructor
+	 */
+	function Triangle() {
+
+		/**
+		 * @type {{position: THREE.Vector3, normal: THREE.Vector3, uv: THREE.Vector2, skinIndices: THREE.Vector4, skinWeights: THREE.Vector4}[]}
+		 */
+		this.vertices = [ ];
+
+	}
+
+	Object.assign( Triangle.prototype, {
+
+		copy: function ( target ) {
+
+			var returnVar = target || new Triangle();
+
+			for ( var i = 0; i < this.vertices.length; ++ i ) {
+
+				 this.vertices[ i ].copy( returnVar.vertices[ i ] );
+
+			}
+
+			return returnVar;
+
+		},
+
+		flattenToBuffers: function () {
+
+			var vertexBuffer = [];
+			var normalBuffer = [];
+			var uvBuffer = [];
+			var skinIndexBuffer = [];
+			var skinWeightBuffer = [];
+
+			this.vertices.forEach( function ( vertex ) {
+
+				var flatVertex = vertex.flattenToBuffers();
+				vertexBuffer = vertexBuffer.concat( flatVertex.vertexBuffer );
+				normalBuffer = normalBuffer.concat( flatVertex.normalBuffer );
+				uvBuffer = uvBuffer.concat( flatVertex.uvBuffer );
+				skinIndexBuffer = skinIndexBuffer.concat( flatVertex.skinIndexBuffer );
+				skinWeightBuffer = skinWeightBuffer.concat( flatVertex.skinWeightBuffer );
+
+			} );
+
+			return {
+				vertexBuffer: vertexBuffer,
+				normalBuffer: normalBuffer,
+				uvBuffer: uvBuffer,
+				skinIndexBuffer: skinIndexBuffer,
+				skinWeightBuffer: skinWeightBuffer,
+			};
+
+		}
+
+	} );
+
+	/**
+	 * @constructor
+	 */
+	function Face() {
+
+		/**
+		 * @type {{vertices: {position: THREE.Vector3, normal: THREE.Vector3, uv: THREE.Vector2, skinIndices: THREE.Vector4, skinWeights: THREE.Vector4}[]}[]}
+		 */
+		this.triangles = [ ];
+		this.materialIndex = 0;
+
+	}
+
+	Object.assign( Face.prototype, {
+
+		copy: function ( target ) {
+
+			var returnVar = target || new Face();
+
+			for ( var i = 0; i < this.triangles.length; ++ i ) {
+
+				this.triangles[ i ].copy( returnVar.triangles[ i ] );
+
+			}
+
+			returnVar.materialIndex = this.materialIndex;
+
+			return returnVar;
+
+		},
+
+		genTrianglesFromVertices: function ( vertexArray ) {
+
+			for ( var i = 2; i < vertexArray.length; ++ i ) {
+
+				var triangle = new Triangle();
+				triangle.vertices[ 0 ] = vertexArray[ 0 ];
+				triangle.vertices[ 1 ] = vertexArray[ i - 1 ];
+				triangle.vertices[ 2 ] = vertexArray[ i ];
+				this.triangles.push( triangle );
+
+			}
+
+		},
+
+		flattenToBuffers: function () {
+
+			var vertexBuffer = [];
+			var normalBuffer = [];
+			var uvBuffer = [];
+			var skinIndexBuffer = [];
+			var skinWeightBuffer = [];
+
+			var materialIndexBuffer = [];
+
+			var materialIndex = this.materialIndex;
+
+			this.triangles.forEach( function ( triangle ) {
+
+				var flatTriangle = triangle.flattenToBuffers();
+				vertexBuffer = vertexBuffer.concat( flatTriangle.vertexBuffer );
+				normalBuffer = normalBuffer.concat( flatTriangle.normalBuffer );
+				uvBuffer = uvBuffer.concat( flatTriangle.uvBuffer );
+				skinIndexBuffer = skinIndexBuffer.concat( flatTriangle.skinIndexBuffer );
+				skinWeightBuffer = skinWeightBuffer.concat( flatTriangle.skinWeightBuffer );
+				materialIndexBuffer = materialIndexBuffer.concat( [ materialIndex, materialIndex, materialIndex ] );
+
+			} );
+
+			return {
+				vertexBuffer: vertexBuffer,
+				normalBuffer: normalBuffer,
+				uvBuffer: uvBuffer,
+				skinIndexBuffer: skinIndexBuffer,
+				skinWeightBuffer: skinWeightBuffer,
+				materialIndexBuffer: materialIndexBuffer
+			};
+
+		}
+
+	} );
+
+	/**
+	 * @constructor
+	 */
+	function Geometry() {
+
+		/**
+		 * @type {{triangles: {vertices: {position: THREE.Vector3, normal: THREE.Vector3, uv: THREE.Vector2, skinIndices: THREE.Vector4, skinWeights: THREE.Vector4}[]}[], materialIndex: number}[]}
+		 */
+		this.faces = [ ];
+
+		/**
+		 * @type {{}|THREE.Skeleton}
+		 */
+		this.skeleton = null;
+
+	}
+
+	Object.assign( Geometry.prototype, {
+
+		/**
+		 * @returns	{{vertexBuffer: number[], normalBuffer: number[], uvBuffer: number[], skinIndexBuffer: number[], skinWeightBuffer: number[], materialIndexBuffer: number[]}}
+		 */
+		flattenToBuffers: function () {
+
+			var vertexBuffer = [];
+			var normalBuffer = [];
+			var uvBuffer = [];
+			var skinIndexBuffer = [];
+			var skinWeightBuffer = [];
+
+			var materialIndexBuffer = [];
+
+			this.faces.forEach( function ( face ) {
+
+				var flatFace = face.flattenToBuffers();
+				vertexBuffer = vertexBuffer.concat( flatFace.vertexBuffer );
+				normalBuffer = normalBuffer.concat( flatFace.normalBuffer );
+				uvBuffer = uvBuffer.concat( flatFace.uvBuffer );
+				skinIndexBuffer = skinIndexBuffer.concat( flatFace.skinIndexBuffer );
+				skinWeightBuffer = skinWeightBuffer.concat( flatFace.skinWeightBuffer );
+				materialIndexBuffer = materialIndexBuffer.concat( flatFace.materialIndexBuffer );
+
+			} );
+
+			return {
+				vertexBuffer: vertexBuffer,
+				normalBuffer: normalBuffer,
+				uvBuffer: uvBuffer,
+				skinIndexBuffer: skinIndexBuffer,
+				skinWeightBuffer: skinWeightBuffer,
+				materialIndexBuffer: materialIndexBuffer
+			};
+
+		}
+
+	} );
+
+	function TextParser() {}
+
+	Object.assign( TextParser.prototype, {
+
+		getPrevNode: function () {
+
+			return this.nodeStack[ this.currentIndent - 2 ];
+
+		},
+
+		getCurrentNode: function () {
+
+			return this.nodeStack[ this.currentIndent - 1 ];
+
+		},
+
+		getCurrentProp: function () {
+
+			return this.currentProp;
+
+		},
+
+		pushStack: function ( node ) {
+
+			this.nodeStack.push( node );
+			this.currentIndent += 1;
+
+		},
+
+		popStack: function () {
+
+			this.nodeStack.pop();
+			this.currentIndent -= 1;
+
+		},
+
+		setCurrentProp: function ( val, name ) {
+
+			this.currentProp = val;
+			this.currentPropName = name;
+
+		},
+
+		// ----------parse ---------------------------------------------------
+		parse: function ( text ) {
+
+			this.currentIndent = 0;
+			this.allNodes = new FBXTree();
+			this.nodeStack = [];
+			this.currentProp = [];
+			this.currentPropName = '';
+
+			var split = text.split( "\n" );
+			for ( var line in split ) {
+
+				var l = split[ line ];
+
+				// short cut
+				if ( l.match( /^[\s\t]*;/ ) ) {
+
+					continue;
+
+				} // skip comment line
+				if ( l.match( /^[\s\t]*$/ ) ) {
+
+					continue;
+
+				} // skip empty line
+
+				// beginning of node
+				var beginningOfNodeExp = new RegExp( "^\\t{" + this.currentIndent + "}(\\w+):(.*){", '' );
+				var match = l.match( beginningOfNodeExp );
+				if ( match ) {
+
+					var nodeName = match[ 1 ].trim().replace( /^"/, '' ).replace( /"$/, "" );
+					var nodeAttrs = match[ 2 ].split( ',' ).map( function ( element ) {
+
+						return element.trim().replace( /^"/, '' ).replace( /"$/, '' );
+
+					} );
+
+					this.parseNodeBegin( l, nodeName, nodeAttrs || null );
+					continue;
+
+				}
+
+				// node's property
+				var propExp = new RegExp( "^\\t{" + ( this.currentIndent ) + "}(\\w+):[\\s\\t\\r\\n](.*)" );
+				var match = l.match( propExp );
+				if ( match ) {
+
+					var propName = match[ 1 ].replace( /^"/, '' ).replace( /"$/, "" ).trim();
+					var propValue = match[ 2 ].replace( /^"/, '' ).replace( /"$/, "" ).trim();
+
+					this.parseNodeProperty( l, propName, propValue );
+					continue;
+
+				}
+
+				// end of node
+				var endOfNodeExp = new RegExp( "^\\t{" + ( this.currentIndent - 1 ) + "}}" );
+				if ( l.match( endOfNodeExp ) ) {
+
+					this.nodeEnd();
+					continue;
+
+				}
+
+				// for special case,
+				//
+				//	  Vertices: *8670 {
+				//		  a: 0.0356229953467846,13.9599733352661,-0.399196773.....(snip)
+				// -0.0612030513584614,13.960485458374,-0.409748703241348,-0.10.....
+				// 0.12490539252758,13.7450733184814,-0.454119384288788,0.09272.....
+				// 0.0836158767342567,13.5432004928589,-0.435397416353226,0.028.....
+				//
+				// these case the lines must contiue with previous line
+				if ( l.match( /^[^\s\t}]/ ) ) {
+
+					this.parseNodePropertyContinued( l );
+
+				}
+
+			}
+
+			return this.allNodes;
+
+		},
+
+		parseNodeBegin: function ( line, nodeName, nodeAttrs ) {
+
+			// var nodeName = match[1];
+			var node = { 'name': nodeName, properties: {}, 'subNodes': {} };
+			var attrs = this.parseNodeAttr( nodeAttrs );
+			var currentNode = this.getCurrentNode();
+
+			// a top node
+			if ( this.currentIndent === 0 ) {
+
+				this.allNodes.add( nodeName, node );
+
+			} else {
+
+				// a subnode
+
+				// already exists subnode, then append it
+				if ( nodeName in currentNode.subNodes ) {
+
+					var tmp = currentNode.subNodes[ nodeName ];
+
+					// console.log( "duped entry found\nkey: " + nodeName + "\nvalue: " + propValue );
+					if ( this.isFlattenNode( currentNode.subNodes[ nodeName ] ) ) {
+
+
+						if ( attrs.id === '' ) {
+
+							currentNode.subNodes[ nodeName ] = [];
+							currentNode.subNodes[ nodeName ].push( tmp );
+
+						} else {
+
+							currentNode.subNodes[ nodeName ] = {};
+							currentNode.subNodes[ nodeName ][ tmp.id ] = tmp;
+
+						}
+
+					}
+
+					if ( attrs.id === '' ) {
+
+						currentNode.subNodes[ nodeName ].push( node );
+
+					} else {
+
+						currentNode.subNodes[ nodeName ][ attrs.id ] = node;
+
+					}
+
+				} else if ( typeof attrs.id === 'number' || attrs.id.match( /^\d+$/ ) ) {
+
+					currentNode.subNodes[ nodeName ] = {};
+					currentNode.subNodes[ nodeName ][ attrs.id ] = node;
+
+				} else {
+
+					currentNode.subNodes[ nodeName ] = node;
+
+				}
+
+			}
+
+			// for this		  ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
+			// NodeAttribute: 1001463072, "NodeAttribute::", "LimbNode" {
+			if ( nodeAttrs ) {
+
+				node.id = attrs.id;
+				node.attrName = attrs.name;
+				node.attrType = attrs.type;
+
+			}
+
+			this.pushStack( node );
+
+		},
+
+		parseNodeAttr: function ( attrs ) {
+
+			var id = attrs[ 0 ];
+
+			if ( attrs[ 0 ] !== "" ) {
+
+				id = parseInt( attrs[ 0 ] );
+
+				if ( isNaN( id ) ) {
+
+					// PolygonVertexIndex: *16380 {
+					id = attrs[ 0 ];
+
+				}
+
+			}
+
+			var name;
+			var type;
+			if ( attrs.length > 1 ) {
+
+				name = attrs[ 1 ].replace( /^(\w+)::/, '' );
+				type = attrs[ 2 ];
+
+			}
+
+			return { id: id, name: name || '', type: type || '' };
+
+		},
+
+		parseNodeProperty: function ( line, propName, propValue ) {
+
+			var currentNode = this.getCurrentNode();
+			var parentName = currentNode.name;
+
+			// special case parent node's is like "Properties70"
+			// these chilren nodes must treat with careful
+			if ( parentName !== undefined ) {
+
+				var propMatch = parentName.match( /Properties(\d)+/ );
+				if ( propMatch ) {
+
+					this.parseNodeSpecialProperty( line, propName, propValue );
+					return;
+
+				}
+
+			}
+
+			// special case Connections
+			if ( propName == 'C' ) {
+
+				var connProps = propValue.split( ',' ).slice( 1 );
+				var from = parseInt( connProps[ 0 ] );
+				var to = parseInt( connProps[ 1 ] );
+
+				var rest = propValue.split( ',' ).slice( 3 );
+
+				propName = 'connections';
+				propValue = [ from, to ];
+				propValue = propValue.concat( rest );
+
+				if ( currentNode.properties[ propName ] === undefined ) {
+
+					currentNode.properties[ propName ] = [];
+
+				}
+
+			}
+
+			// special case Connections
+			if ( propName == 'Node' ) {
+
+				var id = parseInt( propValue );
+				currentNode.properties.id = id;
+				currentNode.id = id;
+
+			}
+
+			// already exists in properties, then append this
+			if ( propName in currentNode.properties ) {
+
+				// console.log( "duped entry found\nkey: " + propName + "\nvalue: " + propValue );
+				if ( Array.isArray( currentNode.properties[ propName ] ) ) {
+
+					currentNode.properties[ propName ].push( propValue );
+
+				} else {
+
+					currentNode.properties[ propName ] += propValue;
+
+				}
+
+			} else {
+
+				// console.log( propName + ":  " + propValue );
+				if ( Array.isArray( currentNode.properties[ propName ] ) ) {
+
+					currentNode.properties[ propName ].push( propValue );
+
+				} else {
+
+					currentNode.properties[ propName ] = propValue;
+
+				}
+
+			}
+
+			this.setCurrentProp( currentNode.properties, propName );
+
+		},
+
+		// TODO:
+		parseNodePropertyContinued: function ( line ) {
+
+			this.currentProp[ this.currentPropName ] += line;
+
+		},
+
+		parseNodeSpecialProperty: function ( line, propName, propValue ) {
+
+			// split this
+			// P: "Lcl Scaling", "Lcl Scaling", "", "A",1,1,1
+			// into array like below
+			// ["Lcl Scaling", "Lcl Scaling", "", "A", "1,1,1" ]
+			var props = propValue.split( '",' ).map( function ( element ) {
+
+				return element.trim().replace( /^\"/, '' ).replace( /\s/, '_' );
+
+			} );
+
+			var innerPropName = props[ 0 ];
+			var innerPropType1 = props[ 1 ];
+			var innerPropType2 = props[ 2 ];
+			var innerPropFlag = props[ 3 ];
+			var innerPropValue = props[ 4 ];
+
+			/*
+			if ( innerPropValue === undefined ) {
+				innerPropValue = props[3];
+			}
+			*/
+
+			// cast value in its type
+			switch ( innerPropType1 ) {
+
+				case "int":
+					innerPropValue = parseInt( innerPropValue );
+					break;
+
+				case "double":
+					innerPropValue = parseFloat( innerPropValue );
+					break;
+
+				case "ColorRGB":
+				case "Vector3D":
+					var tmp = innerPropValue.split( ',' );
+					innerPropValue = new THREE.Vector3( tmp[ 0 ], tmp[ 1 ], tmp[ 2 ] );
+					break;
+
+			}
+
+			// CAUTION: these props must append to parent's parent
+			this.getPrevNode().properties[ innerPropName ] = {
+
+				'type': innerPropType1,
+				'type2': innerPropType2,
+				'flag': innerPropFlag,
+				'value': innerPropValue
+
+			};
+
+			this.setCurrentProp( this.getPrevNode().properties, innerPropName );
+
+		},
+
+		nodeEnd: function () {
+
+			this.popStack();
+
+		},
+
+		/* ---------------------------------------------------------------- */
+		/*		util													  */
+		isFlattenNode: function ( node ) {
+
+			return ( 'subNodes' in node && 'properties' in node ) ? true : false;
+
+		}
+
+	} );
+
+	function FBXTree() {}
+
+	Object.assign( FBXTree.prototype, {
+
+		add: function ( key, val ) {
+
+			this[ key ] = val;
+
+		},
+
+		searchConnectionParent: function ( id ) {
+
+			if ( this.__cache_search_connection_parent === undefined ) {
+
+				this.__cache_search_connection_parent = [];
+
+			}
+
+			if ( this.__cache_search_connection_parent[ id ] !== undefined ) {
+
+				return this.__cache_search_connection_parent[ id ];
+
+			} else {
+
+				this.__cache_search_connection_parent[ id ] = [];
+
+			}
+
+			var conns = this.Connections.properties.connections;
+
+			var results = [];
+			for ( var i = 0; i < conns.length; ++ i ) {
+
+				if ( conns[ i ][ 0 ] == id ) {
+
+					// 0 means scene root
+					var res = conns[ i ][ 1 ] === 0 ? - 1 : conns[ i ][ 1 ];
+					results.push( res );
+
+				}
+
+			}
+
+			if ( results.length > 0 ) {
+
+				this.__cache_search_connection_parent[ id ] = this.__cache_search_connection_parent[ id ].concat( results );
+				return results;
+
+			} else {
+
+				this.__cache_search_connection_parent[ id ] = [ - 1 ];
+				return [ - 1 ];
+
+			}
+
+		},
+
+		searchConnectionChildren: function ( id ) {
+
+			if ( this.__cache_search_connection_children === undefined ) {
+
+				this.__cache_search_connection_children = [];
+
+			}
+
+			if ( this.__cache_search_connection_children[ id ] !== undefined ) {
+
+				return this.__cache_search_connection_children[ id ];
+
+			} else {
+
+				this.__cache_search_connection_children[ id ] = [];
+
+			}
+
+			var conns = this.Connections.properties.connections;
+
+			var res = [];
+			for ( var i = 0; i < conns.length; ++ i ) {
+
+				if ( conns[ i ][ 1 ] == id ) {
+
+					// 0 means scene root
+					res.push( conns[ i ][ 0 ] === 0 ? - 1 : conns[ i ][ 0 ] );
+					// there may more than one kid, then search to the end
+
+				}
+
+			}
+
+			if ( res.length > 0 ) {
+
+				this.__cache_search_connection_children[ id ] = this.__cache_search_connection_children[ id ].concat( res );
+				return res;
+
+			} else {
+
+				this.__cache_search_connection_children[ id ] = [ ];
+				return [ ];
+
+			}
+
+		},
+
+		searchConnectionType: function ( id, to ) {
+
+			var key = id + ',' + to; // TODO: to hash
+			if ( this.__cache_search_connection_type === undefined ) {
+
+				this.__cache_search_connection_type = {};
+
+			}
+
+			if ( this.__cache_search_connection_type[ key ] !== undefined ) {
+
+				return this.__cache_search_connection_type[ key ];
+
+			} else {
+
+				this.__cache_search_connection_type[ key ] = '';
+
+			}
+
+			var conns = this.Connections.properties.connections;
+
+			for ( var i = 0; i < conns.length; ++ i ) {
+
+				if ( conns[ i ][ 0 ] == id && conns[ i ][ 1 ] == to ) {
+
+					// 0 means scene root
+					this.__cache_search_connection_type[ key ] = conns[ i ][ 2 ];
+					return conns[ i ][ 2 ];
+
+				}
+
+			}
+
+			this.__cache_search_connection_type[ id ] = null;
+			return null;
+
+		}
+
+	} );
+
+	/**
+	 * @returns {boolean}
+	 */
+	function isFbxFormatASCII( text ) {
+
+		var CORRECT = [ 'K', 'a', 'y', 'd', 'a', 'r', 'a', '\\', 'F', 'B', 'X', '\\', 'B', 'i', 'n', 'a', 'r', 'y', '\\', '\\' ];
+
+		var cursor = 0;
+		var read = function ( offset ) {
+
+			var result = text[ offset - 1 ];
+			text = text.slice( cursor + offset );
+			cursor ++;
+			return result;
+
+		};
+
+		for ( var i = 0; i < CORRECT.length; ++ i ) {
+
+			var num = read( 1 );
+			if ( num == CORRECT[ i ] ) {
+
+				return false;
+
+			}
+
+		}
+
+		return true;
+
+	}
+
+	/**
+	 * @returns {number}
+	 */
+	function getFbxVersion( text ) {
+
+		var versionRegExp = /FBXVersion: (\d+)/;
+		var match = text.match( versionRegExp );
+		if ( match ) {
+
+			var version = parseInt( match[ 1 ] );
+			return version;
+
+		}
+		throw new Error( 'FBXLoader: Cannot find the version number for the file given.' );
+
+	}
+
+	/**
+	 * Converts FBX ticks into real time seconds.
+	 * @param {number} time - FBX tick timestamp to convert.
+	 * @returns {number} - FBX tick in real world time.
+	 */
+	function ConvertFBXTimeToSeconds( time ) {
+
+		// Constant is FBX ticks per second.
+		return time / 46186158000;
+
+	}
+
+	/**
+	 * Parses comma separated list of float numbers and returns them in an array.
+	 * @example
+	 * // Returns [ 5.6, 9.4, 2.5, 1.4 ]
+	 * parseFloatArray( "5.6,9.4,2.5,1.4" )
+	 * @returns {number[]}
+	 */
+	function parseFloatArray( floatString ) {
+
+		return floatString.split( ',' ).map( function ( stringValue ) {
+
+			return parseFloat( stringValue );
+
+		} );
+
+	}
+
+	/**
+	 * Parses comma separated list of int numbers and returns them in an array.
+	 * @example
+	 * // Returns [ 5, 8, 2, 3 ]
+	 * parseFloatArray( "5,8,2,3" )
+	 * @returns {number[]}
+	 */
+	function parseIntArray( intString ) {
+
+		return intString.split( ',' ).map( function ( stringValue ) {
+
+			return parseInt( stringValue );
+
+		} );
+
+	}
+
+	function parseMatrixArray( floatString ) {
+
+		return new THREE.Matrix4().fromArray( parseFloatArray( floatString ) );
+
+	}
+
+	/**
+	 * Converts number from degrees into radians.
+	 * @param {number} value
+	 * @returns {number}
+	 */
+	function degreeToRadian( value ) {
+
+		return value * Math.PI / 180;
+
+	}
+
+} )();

+ 47 - 19
examples/js/loaders/GLTFLoader.js

@@ -463,6 +463,21 @@ THREE.GLTFLoader = ( function () {
 		10497: THREE.RepeatWrapping
 	};
 
+	var WEBGL_TEXTURE_FORMATS = {
+		6406: THREE.AlphaFormat,
+		6407: THREE.RGBFormat,
+		6408: THREE.RGBAFormat,
+		6409: THREE.LuminanceFormat,
+		6410: THREE.LuminanceAlphaFormat
+	};
+
+	var WEBGL_TEXTURE_DATATYPES = {
+		5121: THREE.UnsignedByteType,
+		32819: THREE.UnsignedShort4444Type,
+		32820: THREE.UnsignedShort5551Type,
+		33635: THREE.UnsignedShort565Type
+	};
+
 	var WEBGL_SIDES = {
 		1028: THREE.BackSide,  // Culling front
 		1029: THREE.FrontSide  // Culling back
@@ -961,7 +976,9 @@ THREE.GLTFLoader = ( function () {
 
 				var arraybuffer = dependencies.buffers[ bufferView.buffer ];
 
-				return arraybuffer.slice( bufferView.byteOffset, bufferView.byteOffset + bufferView.byteLength );
+				var byteLength = bufferView.byteLength !== undefined ? bufferView.byteLength : 0;
+
+				return arraybuffer.slice( bufferView.byteOffset, bufferView.byteOffset + byteLength );
 
 			} );
 
@@ -1055,6 +1072,19 @@ THREE.GLTFLoader = ( function () {
 
 							_texture.flipY = false;
 
+							if ( texture.name !== undefined ) _texture.name = texture.name;
+
+							_texture.format = texture.format !== undefined ? WEBGL_TEXTURE_FORMATS[ texture.format ] : THREE.RGBAFormat;
+
+							if ( texture.internalFormat !== undefined && _texture.format !== WEBGL_TEXTURE_FORMATS[ texture.internalFormat ] ) {
+
+								console.warn( 'THREE.GLTFLoader: Three.js doesn\'t support texture internalFormat which is different from texture format. ' +
+								              'internalFormat will be forced to be the same value as format.' );
+
+							}
+
+							_texture.type = texture.type !== undefined ? WEBGL_TEXTURE_DATATYPES[ texture.type ] : THREE.UnsignedByteType;
+
 							if ( texture.sampler ) {
 
 								var sampler = json.samplers[ texture.sampler ];
@@ -1107,10 +1137,6 @@ THREE.GLTFLoader = ( function () {
 
 					khr_material = material.extensions[ EXTENSIONS.KHR_MATERIALS_COMMON ];
 
-				} else if ( json.extensions && json.extensions[ EXTENSIONS.KHR_MATERIALS_COMMON ] ) {
-
-					khr_material = json.extensions[ EXTENSIONS.KHR_MATERIALS_COMMON ];
-
 				}
 
 				if ( khr_material ) {
@@ -1525,7 +1551,7 @@ THREE.GLTFLoader = ( function () {
 
 				if ( mesh.extras ) group.userData = mesh.extras;
 
-				var primitives = mesh.primitives;
+				var primitives = mesh.primitives || [];
 
 				for ( var name in primitives ) {
 
@@ -1673,18 +1699,13 @@ THREE.GLTFLoader = ( function () {
 			if ( camera.type == "perspective" && camera.perspective ) {
 
 				var yfov = camera.perspective.yfov;
-				var xfov = camera.perspective.xfov;
-				var aspect_ratio = camera.perspective.aspect_ratio || 1;
+				var aspectRatio = camera.perspective.aspectRatio !== undefined ? camera.perspective.aspectRatio : 1;
 
 				// According to COLLADA spec...
-				// aspect_ratio = xfov / yfov
-				xfov = ( xfov === undefined && yfov ) ? yfov * aspect_ratio : xfov;
+				// aspectRatio = xfov / yfov
+				var xfov = yfov * aspectRatio;
 
-				// According to COLLADA spec...
-				// aspect_ratio = xfov / yfov
-				// yfov = ( yfov === undefined && xfov ) ? xfov / aspect_ratio : yfov;
-
-				var _camera = new THREE.PerspectiveCamera( THREE.Math.radToDeg( xfov ), aspect_ratio, camera.perspective.znear || 1, camera.perspective.zfar || 2e6 );
+				var _camera = new THREE.PerspectiveCamera( THREE.Math.radToDeg( xfov ), aspectRatio, camera.perspective.znear || 1, camera.perspective.zfar || 2e6 );
 				if ( camera.name !== undefined ) _camera.name = camera.name;
 
 				if ( camera.extras ) _camera.userData = camera.extras;
@@ -1718,8 +1739,12 @@ THREE.GLTFLoader = ( function () {
 
 			return _each( json.skins, function ( skin ) {
 
+				var bindShapeMatrix = new THREE.Matrix4();
+
+				if ( skin.bindShapeMatrix !== undefined ) bindShapeMatrix.fromArray( skin.bindShapeMatrix );
+
 				var _skin = {
-					bindShapeMatrix: new THREE.Matrix4().fromArray( skin.bindShapeMatrix ),
+					bindShapeMatrix: bindShapeMatrix,
 					jointNames: skin.jointNames,
 					inverseBindMatrices: dependencies.accessors[ skin.inverseBindMatrices ]
 				};
@@ -1774,6 +1799,7 @@ THREE.GLTFLoader = ( function () {
 								: THREE.VectorKeyframeTrack;
 
 							var targetName = node.name ? node.name : node.uuid;
+							var interpolation = sampler.interpolation !== undefined ? INTERPOLATION[ sampler.interpolation ] : THREE.InterpolateLinear;
 
 							// KeyframeTrack.optimize() will modify given 'times' and 'values'
 							// buffers before creating a truncated copy to keep. Because buffers may
@@ -1782,7 +1808,7 @@ THREE.GLTFLoader = ( function () {
 								targetName + '.' + PATH_PROPERTIES[ target.path ],
 								THREE.AnimationUtils.arraySlice( inputAccessor.array, 0 ),
 								THREE.AnimationUtils.arraySlice( outputAccessor.array, 0 ),
-								INTERPOLATION[ sampler.interpolation ]
+								interpolation
 							) );
 
 						}
@@ -1791,7 +1817,9 @@ THREE.GLTFLoader = ( function () {
 
 				}
 
-				return new THREE.AnimationClip( "animation_" + animationId, undefined, tracks );
+				var name = animation.name !== undefined ? animation.name : "animation_" + animationId;
+
+				return new THREE.AnimationClip( name, undefined, tracks );
 
 			} );
 
@@ -2092,7 +2120,7 @@ THREE.GLTFLoader = ( function () {
 
 				if ( scene.extras ) _scene.userData = scene.extras;
 
-				var nodes = scene.nodes;
+				var nodes = scene.nodes || [];
 
 				for ( var i = 0, l = nodes.length; i < l; i ++ ) {
 

+ 1 - 1
examples/js/loaders/MMDLoader.js

@@ -1477,7 +1477,7 @@ THREE.MMDLoader.prototype.createMesh = function ( model, texturePath, onProgress
 
 	var initGeometry = function () {
 
-		geometry.setIndex( new ( buffer.indices.length > 65535 ? THREE.Uint32BufferAttribute : THREE.Uint16BufferAttribute )( buffer.indices, 1 ) );
+		geometry.setIndex( buffer.indices );
 		geometry.addAttribute( 'position', new THREE.Float32BufferAttribute( buffer.vertices, 3 ) );
 		geometry.addAttribute( 'normal', new THREE.Float32BufferAttribute( buffer.normals, 3 ) );
 		geometry.addAttribute( 'uv', new THREE.Float32BufferAttribute( buffer.uvs, 2 ) );

+ 4 - 1
examples/js/loaders/PLYLoader.js

@@ -313,8 +313,11 @@ THREE.PLYLoader.prototype = {
 			// mandatory buffer data
 
 			if ( buffer.indices.length > 0 ) {
-				geometry.setIndex( new ( buffer.indices.length > 65535 ? THREE.Uint32BufferAttribute : THREE.Uint16BufferAttribute )( buffer.indices, 1 ) );
+
+				geometry.setIndex( buffer.indices );
+
 			}
+
 			geometry.addAttribute( 'position', new THREE.Float32BufferAttribute( buffer.vertices, 3 ) );
 
 			// optional buffer data

+ 13 - 7
examples/js/pmrem/PMREMCubeUVPacker.js

@@ -31,7 +31,13 @@ THREE.PMREMCubeUVPacker = function( cubeTextureLods, numLods ) {
 		encoding: sourceTexture.encoding
 	};
 
+	if( sourceTexture.encoding === THREE.RGBM16Encoding ) {
+		params.magFilter = THREE.LinearFilter;
+		params.minFilter = THREE.LinearFilter;
+	}
+
 	this.CubeUVRenderTarget = new THREE.WebGLRenderTarget( size, size, params );
+	this.CubeUVRenderTarget.texture.name = "PMREMCubeUVPacker.cubeUv";
 	this.CubeUVRenderTarget.texture.mapping = THREE.CubeUVReflectionMapping;
 	this.camera = new THREE.OrthographicCamera( - size * 0.5, size * 0.5, - size * 0.5, size * 0.5, 0.0, 1000 );
 
@@ -53,7 +59,7 @@ THREE.PMREMCubeUVPacker = function( cubeTextureLods, numLods ) {
 
 	var offset2 = 0;
 	var c = 4.0;
-	this.numLods = Math.log2( cubeTextureLods[ 0 ].width ) - 2;
+	this.numLods = Math.log( cubeTextureLods[ 0 ].width ) / Math.log( 2 ) - 2; // IE11 doesn't support Math.log2
 	for ( var i = 0; i < this.numLods; i ++ ) {
 
 		var offset1 = ( textureResolution - textureResolution / c ) * 0.5;
@@ -156,17 +162,17 @@ THREE.PMREMCubeUVPacker.prototype = {
 					uv = uv * 2.0 - 1.0;\
 					uv.y *= -1.0;\
 					if(faceIndex == 0) {\
-						sampleDirection = normalize(vec3(-1.0, uv.y, -uv.x));\
+						sampleDirection = normalize(vec3(1.0, uv.y, -uv.x));\
 					} else if(faceIndex == 1) {\
-						sampleDirection = normalize(vec3(-uv.x, 1.0, uv.y));\
+						sampleDirection = normalize(vec3(uv.x, 1.0, uv.y));\
 					} else if(faceIndex == 2) {\
-						sampleDirection = normalize(vec3(-uv.x, uv.y, 1.0));\
+						sampleDirection = normalize(vec3(uv.x, uv.y, 1.0));\
 					} else if(faceIndex == 3) {\
-						sampleDirection = normalize(vec3(1.0, uv.y, uv.x));\
+						sampleDirection = normalize(vec3(-1.0, uv.y, uv.x));\
 					} else if(faceIndex == 4) {\
-						sampleDirection = normalize(vec3(-uv.x, -1.0, -uv.y));\
+						sampleDirection = normalize(vec3(uv.x, -1.0, -uv.y));\
 					} else {\
-						sampleDirection = normalize(vec3(uv.x, uv.y, -1.0));\
+						sampleDirection = normalize(vec3(-uv.x, uv.y, -1.0));\
 					}\
 					vec4 color = envMapTexelToLinear( textureCube( envMap, sampleDirection ) );\
 					gl_FragColor = linearToOutputTexel( color );\

+ 17 - 7
examples/js/pmrem/PMREMGenerator.js

@@ -11,10 +11,11 @@
  *	by this class.
  */
 
-THREE.PMREMGenerator = function( sourceTexture ) {
+THREE.PMREMGenerator = function( sourceTexture, samplesPerLevel, resolution ) {
 
 	this.sourceTexture = sourceTexture;
-	this.resolution = 256; // NODE: 256 is currently hard coded in the glsl code for performance reasons
+	this.resolution = ( resolution !== undefined ) ? resolution : 256; // NODE: 256 is currently hard coded in the glsl code for performance reasons
+	this.samplesPerLevel = ( samplesPerLevel !== undefined ) ? samplesPerLevel : 16;
 
 	var monotonicEncoding = ( sourceTexture.encoding === THREE.LinearEncoding ) ||
 		( sourceTexture.encoding === THREE.GammaEncoding ) || ( sourceTexture.encoding === THREE.sRGBEncoding );
@@ -37,11 +38,12 @@ THREE.PMREMGenerator = function( sourceTexture ) {
 	 };
 
 	// how many LODs fit in the given CubeUV Texture.
-	this.numLods = Math.log2( size ) - 2;
+	this.numLods = Math.log( size ) / Math.log( 2 ) - 2;  // IE11 doesn't support Math.log2
 
 	for ( var i = 0; i < this.numLods; i ++ ) {
 
 		var renderTarget = new THREE.WebGLRenderTargetCube( size, size, params );
+		renderTarget.texture.name = "PMREMGenerator.cube" + i;
 		this.cubeLods.push( renderTarget );
 		size = Math.max( 16, size / 2 );
 
@@ -50,6 +52,7 @@ THREE.PMREMGenerator = function( sourceTexture ) {
 	this.camera = new THREE.OrthographicCamera( - 1, 1, 1, - 1, 0.0, 1000 );
 
 	this.shader = this.getShader();
+	this.shader.defines['SAMPLES_PER_LEVEL'] = this.samplesPerLevel;
 	this.planeMesh = new THREE.Mesh( new THREE.PlaneGeometry( 2, 2, 0 ), this.shader );
 	this.planeMesh.material.side = THREE.DoubleSide;
 	this.scene = new THREE.Scene();
@@ -97,6 +100,7 @@ THREE.PMREMGenerator.prototype = {
 
 			var r = i / ( this.numLods - 1 );
 			this.shader.uniforms[ 'roughness' ].value = r * 0.9; // see comment above, pragmatic choice
+			this.shader.uniforms[ 'queryScale' ].value.x = ( i == 0 ) ? -1 : 1;
 			var size = this.cubeLods[ i ].width;
 			this.shader.uniforms[ 'mapSize' ].value = size;
 			this.renderToCubeMapTarget( renderer, this.cubeLods[ i ] );
@@ -134,12 +138,17 @@ THREE.PMREMGenerator.prototype = {
 
 		return new THREE.ShaderMaterial( {
 
+			defines: {
+				"SAMPLES_PER_LEVEL": 20,
+			},
+
 			uniforms: {
 				"faceIndex": { value: 0 },
 				"roughness": { value: 0.5 },
 				"mapSize": { value: 0.5 },
 				"envMap": { value: null },
-				"testColor": { value: new THREE.Vector3( 1, 1, 1 ) }
+				"queryScale": { value: new THREE.Vector3( 1, 1, 1 ) },
+				"testColor": { value: new THREE.Vector3( 1, 1, 1 ) },
 			},
 
 			vertexShader:
@@ -157,6 +166,7 @@ THREE.PMREMGenerator.prototype = {
 				uniform samplerCube envMap;\n\
 				uniform float mapSize;\n\
 				uniform vec3 testColor;\n\
+				uniform vec3 queryScale;\n\
 				\n\
 				float GGXRoughnessToBlinnExponent( const in float ggxRoughness ) {\n\
 					float a = ggxRoughness + 0.0001;\n\
@@ -227,12 +237,12 @@ THREE.PMREMGenerator.prototype = {
 					} else {\n\
 						sampleDirection = vec3(-uv.x, -uv.y, -1.0);\n\
 					}\n\
-					mat3 vecSpace = matrixFromVector(normalize(sampleDirection));\n\
+					mat3 vecSpace = matrixFromVector(normalize(sampleDirection * queryScale));\n\
 					vec3 rgbColor = vec3(0.0);\n\
-					const int NumSamples = 1024;\n\
+					const int NumSamples = SAMPLES_PER_LEVEL;\n\
 					vec3 vect;\n\
 					float weight = 0.0;\n\
-					for(int i=0; i<NumSamples; i++) {\n\
+					for( int i = 0; i < NumSamples; i ++ ) {\n\
 						float sini = sin(float(i));\n\
 						float cosi = cos(float(i));\n\
 						float r = rand(vec2(sini, cosi));\n\

+ 3 - 0
examples/js/postprocessing/AdaptiveToneMappingPass.js

@@ -191,14 +191,17 @@ THREE.AdaptiveToneMappingPass.prototype = Object.assign( Object.create( THREE.Pa
 		var pars = { minFilter: THREE.LinearFilter, magFilter: THREE.LinearFilter, format: THREE.RGBAFormat }; // was RGB format. changed to RGBA format. see discussion in #8415 / #8450
 
 		this.luminanceRT = new THREE.WebGLRenderTarget( this.resolution, this.resolution, pars );
+		this.luminanceRT.texture.name = "AdaptiveToneMappingPass.l";
 		this.luminanceRT.texture.generateMipmaps = false;
 
 		this.previousLuminanceRT = new THREE.WebGLRenderTarget( this.resolution, this.resolution, pars );
+		this.previousLuminanceRT.texture.name = "AdaptiveToneMappingPass.pl";
 		this.previousLuminanceRT.texture.generateMipmaps = false;
 
 		// We only need mipmapping for the current luminosity because we want a down-sampled version to sample in our adaptive shader
 		pars.minFilter = THREE.LinearMipMapLinearFilter;
 		this.currentLuminanceRT = new THREE.WebGLRenderTarget( this.resolution, this.resolution, pars );
+		this.currentLuminanceRT.texture.name = "AdaptiveToneMappingPass.cl";
 
 		if ( this.adaptive ) {
 

+ 2 - 0
examples/js/postprocessing/BloomPass.js

@@ -16,7 +16,9 @@ THREE.BloomPass = function ( strength, kernelSize, sigma, resolution ) {
 	var pars = { minFilter: THREE.LinearFilter, magFilter: THREE.LinearFilter, format: THREE.RGBAFormat };
 
 	this.renderTargetX = new THREE.WebGLRenderTarget( resolution, resolution, pars );
+	this.renderTargetX.texture.name = "BloomPass.x";
 	this.renderTargetY = new THREE.WebGLRenderTarget( resolution, resolution, pars );
+	this.renderTargetY.texture.name = "BloomPass.y";
 
 	// copy material
 

+ 2 - 0
examples/js/postprocessing/BokehPass.js

@@ -25,8 +25,10 @@ THREE.BokehPass = function ( scene, camera, params ) {
 		magFilter: THREE.LinearFilter,
 		format: THREE.RGBFormat
 	} );
+	this.renderTargetColor.texture.name = "BokehPass.color";
 
 	this.renderTargetDepth = this.renderTargetColor.clone();
+	this.renderTargetDepth.texture.name = "BokehPass.depth";
 
 	// depth material
 

+ 2 - 1
examples/js/postprocessing/EffectComposer.js

@@ -16,11 +16,12 @@ THREE.EffectComposer = function ( renderer, renderTarget ) {
 		};
 		var size = renderer.getSize();
 		renderTarget = new THREE.WebGLRenderTarget( size.width, size.height, parameters );
-
+		renderTarget.texture.name = "EffectComposer.rt1";
 	}
 
 	this.renderTarget1 = renderTarget;
 	this.renderTarget2 = renderTarget.clone();
+	this.renderTarget2.texture.name = "EffectComposer.rt2";
 
 	this.writeBuffer = this.renderTarget1;
 	this.readBuffer = this.renderTarget2;

+ 7 - 0
examples/js/postprocessing/OutlinePass.js

@@ -28,6 +28,7 @@ THREE.OutlinePass = function ( resolution, scene, camera, selectedObjects ) {
 	this.maskBufferMaterial = new THREE.MeshBasicMaterial( { color: 0xffffff } );
 	this.maskBufferMaterial.side = THREE.DoubleSide;
 	this.renderTargetMaskBuffer = new THREE.WebGLRenderTarget( this.resolution.x, this.resolution.y, pars );
+	this.renderTargetMaskBuffer.texture.name = "OutlinePass.mask";
 	this.renderTargetMaskBuffer.texture.generateMipmaps = false;
 
 	this.depthMaterial = new THREE.MeshDepthMaterial();
@@ -39,20 +40,26 @@ THREE.OutlinePass = function ( resolution, scene, camera, selectedObjects ) {
 	this.prepareMaskMaterial.side = THREE.DoubleSide;
 
 	this.renderTargetDepthBuffer = new THREE.WebGLRenderTarget( this.resolution.x, this.resolution.y, pars );
+	this.renderTargetDepthBuffer.texture.name = "OutlinePass.depth";
 	this.renderTargetDepthBuffer.texture.generateMipmaps = false;
 
 	this.renderTargetMaskDownSampleBuffer = new THREE.WebGLRenderTarget( resx, resy, pars );
+	this.renderTargetMaskDownSampleBuffer.texture.name = "OutlinePass.depthDownSample";
 	this.renderTargetMaskDownSampleBuffer.texture.generateMipmaps = false;
 
 	this.renderTargetBlurBuffer1 = new THREE.WebGLRenderTarget( resx, resy, pars );
+	this.renderTargetBlurBuffer1.texture.name = "OutlinePass.blur1";
 	this.renderTargetBlurBuffer1.texture.generateMipmaps = false;
 	this.renderTargetBlurBuffer2 = new THREE.WebGLRenderTarget( Math.round( resx / 2 ), Math.round( resy / 2 ), pars );
+	this.renderTargetBlurBuffer2.texture.name = "OutlinePass.blur2";
 	this.renderTargetBlurBuffer2.texture.generateMipmaps = false;
 
 	this.edgeDetectionMaterial = this.getEdgeDetectionMaterial();
 	this.renderTargetEdgeBuffer1 = new THREE.WebGLRenderTarget( resx, resy, pars );
+	this.renderTargetEdgeBuffer1.texture.name = "OutlinePass.edge1";
 	this.renderTargetEdgeBuffer1.texture.generateMipmaps = false;
 	this.renderTargetEdgeBuffer2 = new THREE.WebGLRenderTarget( Math.round( resx / 2 ), Math.round( resy / 2 ), pars );
+	this.renderTargetEdgeBuffer2.texture.name = "OutlinePass.edge2";
 	this.renderTargetEdgeBuffer2.texture.generateMipmaps = false;
 
 	var MAX_EDGE_THICKNESS = 4;

+ 4 - 0
examples/js/postprocessing/SMAAPass.js

@@ -15,6 +15,7 @@ THREE.SMAAPass = function ( width, height ) {
 		minFilter: THREE.LinearFilter,
 		format: THREE.RGBFormat
 	} );
+	this.edgesRT.texture.name = "SMAAPass.edges";
 
 	this.weightsRT = new THREE.WebGLRenderTarget( width, height, {
 		depthBuffer: false,
@@ -23,6 +24,7 @@ THREE.SMAAPass = function ( width, height ) {
 		minFilter: THREE.LinearFilter,
 		format: THREE.RGBAFormat
 	} );
+	this.weightsRT.texture.name = "SMAAPass.weights";
 
 	// textures
 
@@ -30,6 +32,7 @@ THREE.SMAAPass = function ( width, height ) {
 	areaTextureImage.src = this.getAreaTexture();
 
 	this.areaTexture = new THREE.Texture();
+	this.areaTexture.name = "SMAAPass.area";
 	this.areaTexture.image = areaTextureImage;
 	this.areaTexture.format = THREE.RGBFormat;
 	this.areaTexture.minFilter = THREE.LinearFilter;
@@ -41,6 +44,7 @@ THREE.SMAAPass = function ( width, height ) {
 	searchTextureImage.src = this.getSearchTexture();
 
 	this.searchTexture = new THREE.Texture();
+	this.searchTexture.name = "SMAAPass.search";
 	this.searchTexture.image = searchTextureImage;
 	this.searchTexture.magFilter = THREE.NearestFilter;
 	this.searchTexture.minFilter = THREE.NearestFilter;

+ 20 - 9
examples/js/postprocessing/SSAARenderPass.js

@@ -52,7 +52,7 @@ THREE.SSAARenderPass.prototype = Object.assign( Object.create( THREE.Pass.protot
 
 	constructor: THREE.SSAARenderPass,
 
-	dispose: function() {
+	dispose: function () {
 
 		if ( this.sampleRenderTarget ) {
 
@@ -69,12 +69,12 @@ THREE.SSAARenderPass.prototype = Object.assign( Object.create( THREE.Pass.protot
 
 	},
 
-	render: function ( renderer, writeBuffer, readBuffer, delta, maskActive ) {
+	render: function ( renderer, writeBuffer, readBuffer ) {
 
 		if ( ! this.sampleRenderTarget ) {
 
-			this.sampleRenderTarget = new THREE.WebGLRenderTarget( readBuffer.width, readBuffer.height,
-				{ minFilter: THREE.LinearFilter, magFilter: THREE.LinearFilter, format: THREE.RGBAFormat } );
+			this.sampleRenderTarget = new THREE.WebGLRenderTarget( readBuffer.width, readBuffer.height, { minFilter: THREE.LinearFilter, magFilter: THREE.LinearFilter, format: THREE.RGBAFormat } );
+			this.sampleRenderTarget.texture.name = "SSAARenderPass.sample";
 
 		}
 
@@ -95,29 +95,40 @@ THREE.SSAARenderPass.prototype = Object.assign( Object.create( THREE.Pass.protot
 		// render the scene multiple times, each slightly jitter offset from the last and accumulate the results.
 		for ( var i = 0; i < jitterOffsets.length; i ++ ) {
 
-			var jitterOffset = jitterOffsets[i];
+			var jitterOffset = jitterOffsets[ i ];
+
 			if ( this.camera.setViewOffset ) {
+
 				this.camera.setViewOffset( width, height,
 					jitterOffset[ 0 ] * 0.0625, jitterOffset[ 1 ] * 0.0625,   // 0.0625 = 1 / 16
 					width, height );
+
 			}
 
 			var sampleWeight = baseSampleWeight;
-			if( this.unbiased ) {
+
+			if ( this.unbiased ) {
+
 				// the theory is that equal weights for each sample lead to an accumulation of rounding errors.
 				// The following equation varies the sampleWeight per sample so that it is uniformly distributed
 				// across a range of values whose rounding errors cancel each other out.
-				var uniformCenteredDistribution = ( -0.5 + ( i + 0.5 ) / jitterOffsets.length );
+
+				var uniformCenteredDistribution = ( - 0.5 + ( i + 0.5 ) / jitterOffsets.length );
 				sampleWeight += roundingRange * uniformCenteredDistribution;
+
 			}
 
 			this.copyUniforms[ "opacity" ].value = sampleWeight;
 			renderer.setClearColor( this.clearColor, this.clearAlpha );
 			renderer.render( this.scene, this.camera, this.sampleRenderTarget, true );
-			if (i === 0) {
+
+			if ( i === 0 ) {
+
 				renderer.setClearColor( 0x000000, 0.0 );
+
 			}
-			renderer.render( this.scene2, this.camera2, this.renderToScreen ? null : writeBuffer, (i === 0) );
+
+			renderer.render( this.scene2, this.camera2, this.renderToScreen ? null : writeBuffer, ( i === 0 ) );
 
 		}
 

+ 4 - 4
examples/js/postprocessing/SavePass.js

@@ -27,15 +27,15 @@ THREE.SavePass = function ( renderTarget ) {
 
 	if ( this.renderTarget === undefined ) {
 
-		this.renderTargetParameters = { minFilter: THREE.LinearFilter, magFilter: THREE.LinearFilter, format: THREE.RGBFormat, stencilBuffer: false };
-		this.renderTarget = new THREE.WebGLRenderTarget( window.innerWidth, window.innerHeight, this.renderTargetParameters );
+		this.renderTarget = new THREE.WebGLRenderTarget( window.innerWidth, window.innerHeight, { minFilter: THREE.LinearFilter, magFilter: THREE.LinearFilter, format: THREE.RGBFormat, stencilBuffer: false } );
+		this.renderTarget.texture.name = "SavePass.rt";
 
 	}
 
 	this.needsSwap = false;
 
 	this.camera = new THREE.OrthographicCamera( - 1, 1, 1, - 1, 0, 1 );
-	this.scene  = new THREE.Scene();
+	this.scene = new THREE.Scene();
 
 	this.quad = new THREE.Mesh( new THREE.PlaneBufferGeometry( 2, 2 ), null );
 	this.quad.frustumCulled = false; // Avoid getting clipped
@@ -47,7 +47,7 @@ THREE.SavePass.prototype = Object.assign( Object.create( THREE.Pass.prototype ),
 
 	constructor: THREE.SavePass,
 
-	render: function ( renderer, writeBuffer, readBuffer, delta, maskActive ) {
+	render: function ( renderer, writeBuffer, readBuffer ) {
 
 		if ( this.uniforms[ this.textureID ] ) {
 

+ 25 - 13
examples/js/postprocessing/TAARenderPass.js

@@ -35,12 +35,12 @@ THREE.TAARenderPass.prototype = Object.assign( Object.create( THREE.SSAARenderPa
 
 	render: function ( renderer, writeBuffer, readBuffer, delta ) {
 
-		if( ! this.accumulate ) {
+		if ( ! this.accumulate ) {
 
-				THREE.SSAARenderPass.prototype.render.call( this, renderer, writeBuffer, readBuffer, delta );
+			THREE.SSAARenderPass.prototype.render.call( this, renderer, writeBuffer, readBuffer, delta );
 
-				this.accumulateIndex = -1;
-				return;
+			this.accumulateIndex = - 1;
+			return;
 
 		}
 
@@ -49,20 +49,22 @@ THREE.TAARenderPass.prototype = Object.assign( Object.create( THREE.SSAARenderPa
 		if ( ! this.sampleRenderTarget ) {
 
 			this.sampleRenderTarget = new THREE.WebGLRenderTarget( readBuffer.width, readBuffer.height, this.params );
+			this.sampleRenderTarget.texture.name = "TAARenderPass.sample";
 
 		}
 
 		if ( ! this.holdRenderTarget ) {
 
 			this.holdRenderTarget = new THREE.WebGLRenderTarget( readBuffer.width, readBuffer.height, this.params );
+			this.holdRenderTarget.texture.name = "TAARenderPass.hold";
 
 		}
 
-		if( this.accumulate && this.accumulateIndex === -1 ) {
+		if ( this.accumulate && this.accumulateIndex === - 1 ) {
 
-				THREE.SSAARenderPass.prototype.render.call( this, renderer, this.holdRenderTarget, readBuffer, delta );
+			THREE.SSAARenderPass.prototype.render.call( this, renderer, this.holdRenderTarget, readBuffer, delta );
 
-				this.accumulateIndex = 0;
+			this.accumulateIndex = 0;
 
 		}
 
@@ -71,7 +73,7 @@ THREE.TAARenderPass.prototype = Object.assign( Object.create( THREE.SSAARenderPa
 
 		var sampleWeight = 1.0 / ( jitterOffsets.length );
 
-		if( this.accumulateIndex >= 0 && this.accumulateIndex < jitterOffsets.length ) {
+		if ( this.accumulateIndex >= 0 && this.accumulateIndex < jitterOffsets.length ) {
 
 			this.copyUniforms[ "opacity" ].value = sampleWeight;
 			this.copyUniforms[ "tDiffuse" ].value = writeBuffer.texture;
@@ -81,18 +83,23 @@ THREE.TAARenderPass.prototype = Object.assign( Object.create( THREE.SSAARenderPa
 			for ( var i = 0; i < numSamplesPerFrame; i ++ ) {
 
 				var j = this.accumulateIndex;
-				var jitterOffset = jitterOffsets[j];
+				var jitterOffset = jitterOffsets[ j ];
+
 				if ( this.camera.setViewOffset ) {
+
 					this.camera.setViewOffset( readBuffer.width, readBuffer.height,
 						jitterOffset[ 0 ] * 0.0625, jitterOffset[ 1 ] * 0.0625,   // 0.0625 = 1 / 16
 						readBuffer.width, readBuffer.height );
+
 				}
 
 				renderer.render( this.scene, this.camera, writeBuffer, true );
 				renderer.render( this.scene2, this.camera2, this.sampleRenderTarget, ( this.accumulateIndex === 0 ) );
 
 				this.accumulateIndex ++;
-				if( this.accumulateIndex >= jitterOffsets.length ) break;
+
+				if ( this.accumulateIndex >= jitterOffsets.length ) break;
+
 			}
 
 			if ( this.camera.clearViewOffset ) this.camera.clearViewOffset();
@@ -101,19 +108,24 @@ THREE.TAARenderPass.prototype = Object.assign( Object.create( THREE.SSAARenderPa
 
 		var accumulationWeight = this.accumulateIndex * sampleWeight;
 
-		if( accumulationWeight > 0 ) {
+		if ( accumulationWeight > 0 ) {
+
 			this.copyUniforms[ "opacity" ].value = 1.0;
 			this.copyUniforms[ "tDiffuse" ].value = this.sampleRenderTarget.texture;
 			renderer.render( this.scene2, this.camera2, writeBuffer, true );
+
 		}
-		if( accumulationWeight < 1.0 ) {
+
+		if ( accumulationWeight < 1.0 ) {
+
 			this.copyUniforms[ "opacity" ].value = 1.0 - accumulationWeight;
 			this.copyUniforms[ "tDiffuse" ].value = this.holdRenderTarget.texture;
 			renderer.render( this.scene2, this.camera2, writeBuffer, ( accumulationWeight === 0 ) );
+
 		}
 
 		renderer.autoClear = autoClear;
 
 	}
 
-});
+} );

+ 3 - 0
examples/js/postprocessing/UnrealBloomPass.js

@@ -22,18 +22,21 @@ THREE.UnrealBloomPass = function ( resolution, strength, radius, threshold ) {
 	var resy = Math.round(this.resolution.y/2);
 
 	this.renderTargetBright = new THREE.WebGLRenderTarget( resx, resy, pars );
+	this.renderTargetBright.texture.name = "UnrealBloomPass.bright";
 	this.renderTargetBright.texture.generateMipmaps = false;
 
 	for( var i=0; i<this.nMips; i++) {
 
 		var renderTarget = new THREE.WebGLRenderTarget( resx, resy, pars );
 
+		renderTarget.texture.name = "UnrealBloomPass.h" + i;
 		renderTarget.texture.generateMipmaps = false;
 
 		this.renderTargetsHorizontal.push(renderTarget);
 
 		var renderTarget = new THREE.WebGLRenderTarget( resx, resy, pars );
 
+		renderTarget.texture.name = "UnrealBloomPass.v" + i;
 		renderTarget.texture.generateMipmaps = false;
 
 		this.renderTargetsVertical.push(renderTarget);

+ 5 - 37
examples/webgl_loader_fbx.html

@@ -36,7 +36,7 @@
 
 		<script src="js/curves/NURBSCurve.js"></script>
 		<script src="js/curves/NURBSUtils.js"></script>
-		<script src="js/loaders/FBXLoader.js"></script>
+		<script src="js/loaders/FBXLoader2.js"></script>
 
 		<script src="js/Detector.js"></script>
 		<script src="js/libs/stats.min.js"></script>
@@ -97,29 +97,11 @@
 				var loader = new THREE.FBXLoader( manager );
 				loader.load( 'models/fbx/xsi_man_skinning.fbx', function( object ) {
 
-					object.traverse( function( child ) {
+					object.mixer = new THREE.AnimationMixer( object );
+					mixers.push( object.mixer );
 
-						if ( child instanceof THREE.Mesh ) {
-
-							// pass
-
-						}
-
-						if ( child instanceof THREE.SkinnedMesh ) {
-
-							if ( child.geometry.animations !== undefined || child.geometry.morphAnimations !== undefined ) {
-
-								child.mixer = new THREE.AnimationMixer( child );
-								mixers.push( child.mixer );
-
-								var action = child.mixer.clipAction( child.geometry.animations[ 0 ] );
-								action.play();
-
-							}
-
-						}
-
-					} );
+					var action = object.mixer.clipAction( object.animations[ 0 ] );
+					action.play();
 
 					scene.add( object );
 
@@ -128,20 +110,6 @@
 
 				loader.load( 'models/fbx/nurbs.fbx', function( object ) {
 
-					object.traverse( function( child ) {
-
-						if ( child instanceof THREE.Line ) {
-
-							child.material = new THREE.LineBasicMaterial( { color: 0xffffff, linewidth: 5 } );
-							// Generate a more detailed geometry
-							var nurbsGeometry = new THREE.Geometry();
-							nurbsGeometry.vertices = child.userData.curve.getPoints( 100 );
-							child.geometry = nurbsGeometry;
-
-						}
-
-					} );
-
 					scene.add( object );
 
 				}, onProgress, onError );

+ 1 - 0
examples/webgl_postprocessing_ssao.html

@@ -180,6 +180,7 @@ Spiral sampling http://web.archive.org/web/20120421191837/http://www.cgafaq.info
 
 				var pars = { minFilter: THREE.LinearFilter, magFilter: THREE.LinearFilter };
 				depthRenderTarget = new THREE.WebGLRenderTarget( window.innerWidth, window.innerHeight, pars );
+				depthRenderTarget.texture.name = "SSAOShader.rt";
 
 				// Setup SSAO pass
 				ssaoPass = new THREE.ShaderPass( THREE.SSAOShader );

+ 3 - 1
examples/webgl_shaders_ocean.html

@@ -79,6 +79,7 @@
 				container.appendChild( renderer.domElement );
 
 				scene = new THREE.Scene();
+				scene.fog = new THREE.FogExp2(0xaabbbb, 0.0001);
 
 				camera = new THREE.PerspectiveCamera( 55, window.innerWidth / window.innerHeight, 0.5, 3000000 );
 				camera.position.set( 2000, 750, 2000 );
@@ -108,7 +109,8 @@
 					sunDirection: light.position.clone().normalize(),
 					sunColor: 0xffffff,
 					waterColor: 0x001e0f,
-					distortionScale: 50.0
+					distortionScale: 50.0,
+					fog: scene.fog != undefined
 				} );
 
 

+ 1 - 1
package.json

@@ -1,6 +1,6 @@
 {
   "name": "three",
-  "version": "0.83.0",
+  "version": "0.84.0",
   "description": "JavaScript 3D library",
   "main": "build/three.js",
   "repository": "mrdoob/three.js",

+ 1 - 1
src/animation/PropertyBinding.js

@@ -237,7 +237,7 @@ PropertyBinding.prototype = {
 
 			this.resolvedProperty = nodeProperty;
 
-		} else if ( nodeProperty.length !== undefined ) {
+		} else if ( Array.isArray( nodeProperty ) ) {
 
 			bindingType = this.BindingType.EntireArray;
 

+ 1 - 0
src/cameras/CubeCamera.js

@@ -52,6 +52,7 @@ function CubeCamera( near, far, cubeResolution ) {
 	var options = { format: RGBFormat, magFilter: LinearFilter, minFilter: LinearFilter };
 
 	this.renderTarget = new WebGLRenderTargetCube( cubeResolution, cubeResolution, options );
+	this.renderTarget.texture.name = "CubeCamera";
 
 	this.updateCubeMap = function ( renderer, scene ) {
 

+ 1 - 1
src/constants.js

@@ -1,4 +1,4 @@
-export var REVISION = '84dev';
+export var REVISION = '85dev';
 export var MOUSE = { LEFT: 0, MIDDLE: 1, RIGHT: 2 };
 export var CullFaceNone = 0;
 export var CullFaceBack = 1;

+ 12 - 3
src/core/BufferGeometry.js

@@ -1,13 +1,14 @@
 import { Vector3 } from '../math/Vector3';
 import { Box3 } from '../math/Box3';
 import { EventDispatcher } from './EventDispatcher';
-import { BufferAttribute, Float32BufferAttribute } from './BufferAttribute';
+import { BufferAttribute, Float32BufferAttribute, Uint16BufferAttribute, Uint32BufferAttribute } from './BufferAttribute';
 import { Sphere } from '../math/Sphere';
 import { DirectGeometry } from './DirectGeometry';
 import { Object3D } from './Object3D';
 import { Matrix4 } from '../math/Matrix4';
 import { Matrix3 } from '../math/Matrix3';
 import { _Math } from '../math/Math';
+import { arrayMax } from '../utils';
 import { GeometryIdCount } from './Geometry';
 
 /**
@@ -52,7 +53,15 @@ BufferGeometry.prototype = {
 
 	setIndex: function ( index ) {
 
-		this.index = index;
+		if ( Array.isArray( index ) ) {
+
+			this.index = new ( arrayMax( index ) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( index, 1 );
+
+		} else {
+
+			this.index = index;
+
+		}
 
 	},
 
@@ -508,7 +517,7 @@ BufferGeometry.prototype = {
 
 		if ( geometry.indices.length > 0 ) {
 
-			var TypeArray = geometry.vertices.length > 65535 ? Uint32Array : Uint16Array;
+			var TypeArray = arrayMax( geometry.indices ) > 65535 ? Uint32Array : Uint16Array;
 			var indices = new TypeArray( geometry.indices.length * 3 );
 			this.setIndex( new BufferAttribute( indices, 1 ).copyIndicesArray( geometry.indices ) );
 

+ 3 - 3
src/geometries/BoxGeometry.js

@@ -32,7 +32,7 @@ BoxGeometry.prototype.constructor = BoxGeometry;
  * @author Mugen87 / https://github.com/Mugen87
  */
 
-import { Float32BufferAttribute, Uint16BufferAttribute, Uint32BufferAttribute } from '../core/BufferAttribute';
+import { Float32BufferAttribute } from '../core/BufferAttribute';
 import { BufferGeometry } from '../core/BufferGeometry';
 import { Vector3 } from '../math/Vector3';
 
@@ -82,14 +82,14 @@ function BoxBufferGeometry( width, height, depth, widthSegments, heightSegments,
 
 	// build geometry
 
-	this.setIndex( new ( indices.length > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( indices, 1 ) );
+	this.setIndex( indices );
 	this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
 	this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
 	this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
 
 	function buildPlane( u, v, w, udir, vdir, width, height, depth, gridX, gridY, materialIndex ) {
 
-		var segmentWidth	= width / gridX;
+		var segmentWidth = width / gridX;
 		var segmentHeight = height / gridY;
 
 		var widthHalf = width / 2;

+ 2 - 2
src/geometries/CircleGeometry.js

@@ -29,7 +29,7 @@ CircleGeometry.prototype.constructor = CircleGeometry;
  * @author Mugen87 / https://github.com/Mugen87
  */
 
-import { Float32BufferAttribute, Uint16BufferAttribute, Uint32BufferAttribute } from '../core/BufferAttribute';
+import { Float32BufferAttribute } from '../core/BufferAttribute';
 import { BufferGeometry } from '../core/BufferGeometry';
 import { Vector3 } from '../math/Vector3';
 import { Vector2 } from '../math/Vector2';
@@ -106,7 +106,7 @@ function CircleBufferGeometry( radius, segments, thetaStart, thetaLength ) {
 
 	// build geometry
 
-	this.setIndex( new ( indices.length > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( indices, 1 ) );
+	this.setIndex( indices );
 	this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
 	this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
 	this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );

+ 2 - 2
src/geometries/CylinderGeometry.js

@@ -33,7 +33,7 @@ CylinderGeometry.prototype.constructor = CylinderGeometry;
  * @author Mugen87 / https://github.com/Mugen87
  */
 
-import { Float32BufferAttribute, Uint16BufferAttribute, Uint32BufferAttribute } from '../core/BufferAttribute';
+import { Float32BufferAttribute } from '../core/BufferAttribute';
 import { BufferGeometry } from '../core/BufferGeometry';
 import { Vector3 } from '../math/Vector3';
 import { Vector2 } from '../math/Vector2';
@@ -96,7 +96,7 @@ function CylinderBufferGeometry( radiusTop, radiusBottom, height, radialSegments
 
 	// build geometry
 
-	this.setIndex( new ( indices.length > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( indices, 1 ) );
+	this.setIndex( indices );
 	this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
 	this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
 	this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );

+ 41 - 26
src/geometries/EdgesGeometry.js

@@ -5,25 +5,32 @@ import { _Math } from '../math/Math';
 
 /**
  * @author WestLangley / http://github.com/WestLangley
+ * @author Mugen87 / https://github.com/Mugen87
  */
 
 function EdgesGeometry( geometry, thresholdAngle ) {
 
 	BufferGeometry.call( this );
 
-	thresholdAngle = ( thresholdAngle !== undefined ) ? thresholdAngle : 1;
+	this.type = 'EdgesGeometry';
 
-	var thresholdDot = Math.cos( _Math.DEG2RAD * thresholdAngle );
+	this.parameters = {
+		thresholdAngle: thresholdAngle
+	};
 
-	var edge = [ 0, 0 ], hash = {};
+	thresholdAngle = ( thresholdAngle !== undefined ) ? thresholdAngle : 1;
 
-	function sortFunction( a, b ) {
+	// buffer
 
-		return a - b;
+	var vertices = [];
 
-	}
+	// helper variables
+
+	var thresholdDot = Math.cos( _Math.DEG2RAD * thresholdAngle );
+	var edge = [ 0, 0 ], edges = {};
+	var key, keys = [ 'a', 'b', 'c' ];
 
-	var keys = [ 'a', 'b', 'c' ];
+	// prepare source geometry
 
 	var geometry2;
 
@@ -41,9 +48,11 @@ function EdgesGeometry( geometry, thresholdAngle ) {
 	geometry2.mergeVertices();
 	geometry2.computeFaceNormals();
 
-	var vertices = geometry2.vertices;
+	var sourceVertices = geometry2.vertices;
 	var faces = geometry2.faces;
 
+	// now create a data structure where each entry represents an edge with its adjoining faces
+
 	for ( var i = 0, l = faces.length; i < l; i ++ ) {
 
 		var face = faces[ i ];
@@ -54,15 +63,15 @@ function EdgesGeometry( geometry, thresholdAngle ) {
 			edge[ 1 ] = face[ keys[ ( j + 1 ) % 3 ] ];
 			edge.sort( sortFunction );
 
-			var key = edge.toString();
+			key = edge.toString();
 
-			if ( hash[ key ] === undefined ) {
+			if ( edges[ key ] === undefined ) {
 
-				hash[ key ] = { vert1: edge[ 0 ], vert2: edge[ 1 ], face1: i, face2: undefined };
+				edges[ key ] = { index1: edge[ 0 ], index2: edge[ 1 ], face1: i, face2: undefined };
 
 			} else {
 
-				hash[ key ].face2 = i;
+				edges[ key ].face2 = i;
 
 			}
 
@@ -70,31 +79,37 @@ function EdgesGeometry( geometry, thresholdAngle ) {
 
 	}
 
-	var coords = [];
+	// generate vertices
 
-	for ( var key in hash ) {
+	for ( key in edges ) {
 
-		var h = hash[ key ];
+		var e = edges[ key ];
 
-		// An edge is only rendered if the angle (in degrees) between the face normals of the adjoining faces exceeds this value. default = 1 degree.
+		// an edge is only rendered if the angle (in degrees) between the face normals of the adjoining faces exceeds this value. default = 1 degree.
 
-		if ( h.face2 === undefined || faces[ h.face1 ].normal.dot( faces[ h.face2 ].normal ) <= thresholdDot ) {
+		if ( e.face2 === undefined || faces[ e.face1 ].normal.dot( faces[ e.face2 ].normal ) <= thresholdDot ) {
 
-			var vertex = vertices[ h.vert1 ];
-			coords.push( vertex.x );
-			coords.push( vertex.y );
-			coords.push( vertex.z );
+			var vertex = sourceVertices[ e.index1 ];
+			vertices.push( vertex.x, vertex.y, vertex.z );
 
-			vertex = vertices[ h.vert2 ];
-			coords.push( vertex.x );
-			coords.push( vertex.y );
-			coords.push( vertex.z );
+			vertex = sourceVertices[ e.index2 ];
+			vertices.push( vertex.x, vertex.y, vertex.z );
 
 		}
 
 	}
 
-	this.addAttribute( 'position', new Float32BufferAttribute( coords, 3 ) );
+	// build geometry
+
+	this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
+
+	// custom array sort function
+
+	function sortFunction( a, b ) {
+
+		return a - b;
+
+	}
 
 }
 

+ 3 - 3
src/geometries/LatheGeometry.js

@@ -34,7 +34,7 @@ function LatheGeometry( points, segments, phiStart, phiLength ) {
 LatheGeometry.prototype = Object.create( Geometry.prototype );
 LatheGeometry.prototype.constructor = LatheGeometry;
 
-import { Float32BufferAttribute, Uint16BufferAttribute, Uint32BufferAttribute } from '../core/BufferAttribute';
+import { Float32BufferAttribute } from '../core/BufferAttribute';
 import { BufferGeometry } from '../core/BufferGeometry';
 import { Vector3 } from '../math/Vector3';
 import { Vector2 } from '../math/Vector2';
@@ -62,7 +62,7 @@ function LatheBufferGeometry( points, segments, phiStart, phiLength ) {
 	phiLength = phiLength || Math.PI * 2;
 
 	// clamp phiLength so it's in range of [ 0, 2PI ]
-	
+
 	phiLength = _Math.clamp( phiLength, 0, Math.PI * 2 );
 
 
@@ -135,7 +135,7 @@ function LatheBufferGeometry( points, segments, phiStart, phiLength ) {
 
 	// build geometry
 
-	this.setIndex( new ( indices.length > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( indices, 1 ) );
+	this.setIndex( indices );
 	this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
 	this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
 

+ 11 - 14
src/geometries/ParametricGeometry.js

@@ -35,7 +35,7 @@ ParametricGeometry.prototype.constructor = ParametricGeometry;
  */
 
 import { BufferGeometry } from '../core/BufferGeometry';
-import { Float32BufferAttribute, Uint16BufferAttribute, Uint32BufferAttribute } from '../core/BufferAttribute';
+import { Float32BufferAttribute } from '../core/BufferAttribute';
 
 function ParametricBufferGeometry( func, slices, stacks ) {
 
@@ -51,11 +51,11 @@ function ParametricBufferGeometry( func, slices, stacks ) {
 
 	// buffers
 
+	var indices = [];
 	var vertices = [];
 	var uvs = [];
 
-	var i, j, p;
-	var u, v;
+	var i, j;
 
 	// generate vertices and uvs
 
@@ -63,13 +63,13 @@ function ParametricBufferGeometry( func, slices, stacks ) {
 
 	for ( i = 0; i <= stacks; i ++ ) {
 
-		v = i / stacks;
+		var v = i / stacks;
 
 		for ( j = 0; j <= slices; j ++ ) {
 
-			u = j / slices;
+			var u = j / slices;
 
-			p = func( u, v );
+			var p = func( u, v );
 			vertices.push( p.x, p.y, p.z );
 
 			uvs.push( u, v );
@@ -80,17 +80,14 @@ function ParametricBufferGeometry( func, slices, stacks ) {
 
 	// generate indices
 
-	var indices = [];
-	var a, b, c, d;
-
 	for ( i = 0; i < stacks; i ++ ) {
 
 		for ( j = 0; j < slices; j ++ ) {
 
-			a = i * sliceCount + j;
-			b = i * sliceCount + j + 1;
-			c = ( i + 1 ) * sliceCount + j + 1;
-			d = ( i + 1 ) * sliceCount + j;
+			var a = i * sliceCount + j;
+			var b = i * sliceCount + j + 1;
+			var c = ( i + 1 ) * sliceCount + j + 1;
+			var d = ( i + 1 ) * sliceCount + j;
 
 			// faces one and two
 
@@ -103,7 +100,7 @@ function ParametricBufferGeometry( func, slices, stacks ) {
 
 	// build geometry
 
-	this.setIndex( new ( indices.length > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( indices, 1 ) );
+	this.setIndex( indices );
 	this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
 	this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
 

+ 2 - 2
src/geometries/PlaneGeometry.js

@@ -32,7 +32,7 @@ PlaneGeometry.prototype.constructor = PlaneGeometry;
  * based on http://papervision3d.googlecode.com/svn/trunk/as3/trunk/src/org/papervision3d/objects/primitives/Plane.as
  */
 
-import { Float32BufferAttribute, Uint16BufferAttribute, Uint32BufferAttribute } from '../core/BufferAttribute';
+import { Float32BufferAttribute } from '../core/BufferAttribute';
 import { BufferGeometry } from '../core/BufferGeometry';
 
 function PlaneBufferGeometry( width, height, widthSegments, heightSegments ) {
@@ -112,7 +112,7 @@ function PlaneBufferGeometry( width, height, widthSegments, heightSegments ) {
 
 	// build geometry
 
-	this.setIndex( new ( indices.length > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( indices, 1 ) );
+	this.setIndex( indices );
 	this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
 	this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
 	this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );

+ 0 - 3
src/geometries/PolyhedronGeometry.js

@@ -35,7 +35,6 @@ import { Float32BufferAttribute } from '../core/BufferAttribute';
 import { BufferGeometry } from '../core/BufferGeometry';
 import { Vector3 } from '../math/Vector3';
 import { Vector2 } from '../math/Vector2';
-import { Sphere } from '../math/Sphere';
 
 function PolyhedronBufferGeometry( vertices, indices, radius, detail ) {
 
@@ -77,8 +76,6 @@ function PolyhedronBufferGeometry( vertices, indices, radius, detail ) {
 	this.addAttribute( 'uv', new Float32BufferAttribute( uvBuffer, 2 ) );
 	this.normalizeNormals();
 
-	this.boundingSphere = new Sphere( new Vector3(), radius );
-
 	// helper functions
 
 	function subdivide( detail ) {

+ 3 - 3
src/geometries/RingGeometry.js

@@ -30,7 +30,7 @@ RingGeometry.prototype.constructor = RingGeometry;
  * @author Mugen87 / https://github.com/Mugen87
  */
 
-import { Float32BufferAttribute, Uint16BufferAttribute, Uint32BufferAttribute } from '../core/BufferAttribute';
+import { Float32BufferAttribute } from '../core/BufferAttribute';
 import { BufferGeometry } from '../core/BufferGeometry';
 import { Vector2 } from '../math/Vector2';
 import { Vector3 } from '../math/Vector3';
@@ -97,7 +97,7 @@ function RingBufferGeometry( innerRadius, outerRadius, thetaSegments, phiSegment
 			normals.push( 0, 0, 1 );
 
 			// uv
-			
+
 			uv.x = ( vertex.x / outerRadius + 1 ) / 2;
 			uv.y = ( vertex.y / outerRadius + 1 ) / 2;
 
@@ -137,7 +137,7 @@ function RingBufferGeometry( innerRadius, outerRadius, thetaSegments, phiSegment
 
 	// build geometry
 
-	this.setIndex( new ( indices.length > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( indices, 1 ) );
+	this.setIndex( indices );
 	this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
 	this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
 	this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );

+ 2 - 2
src/geometries/ShapeGeometry.js

@@ -35,7 +35,7 @@ ShapeGeometry.prototype.constructor = ShapeGeometry;
  * @author Mugen87 / https://github.com/Mugen87
  */
 
-import { Float32BufferAttribute, Uint16BufferAttribute, Uint32BufferAttribute } from '../core/BufferAttribute';
+import { Float32BufferAttribute } from '../core/BufferAttribute';
 import { BufferGeometry } from '../core/BufferGeometry';
 import { ShapeUtils } from '../extras/ShapeUtils';
 
@@ -87,7 +87,7 @@ function ShapeBufferGeometry( shapes, curveSegments ) {
 
 	// build geometry
 
-	this.setIndex( new ( indices.length > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( indices, 1 ) );
+	this.setIndex( indices );
 	this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
 	this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
 	this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );

+ 2 - 2
src/geometries/SphereGeometry.js

@@ -32,7 +32,7 @@ SphereGeometry.prototype.constructor = SphereGeometry;
  * @author Mugen87 / https://github.com/Mugen87
  */
 
-import { Float32BufferAttribute, Uint16BufferAttribute, Uint32BufferAttribute } from '../core/BufferAttribute';
+import { Float32BufferAttribute } from '../core/BufferAttribute';
 import { BufferGeometry } from '../core/BufferGeometry';
 import { Vector3 } from '../math/Vector3';
 
@@ -137,7 +137,7 @@ function SphereBufferGeometry( radius, widthSegments, heightSegments, phiStart,
 
 	// build geometry
 
-	this.setIndex( new ( indices.length > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( indices, 1 ) );
+	this.setIndex( indices );
 	this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
 	this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
 	this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );

+ 1 - 1
src/geometries/TextGeometry.js

@@ -26,7 +26,7 @@ function TextGeometry( text, parameters ) {
 
 	var font = parameters.font;
 
-	if ( (font && font.isFont) === false ) {
+	if ( ( font && font.isFont ) === false ) {
 
 		console.error( 'THREE.TextGeometry: font parameter is not an instance of THREE.Font.' );
 		return new Geometry();

+ 2 - 2
src/geometries/TorusGeometry.js

@@ -31,7 +31,7 @@ TorusGeometry.prototype.constructor = TorusGeometry;
  * @author Mugen87 / https://github.com/Mugen87
  */
 
-import { Float32BufferAttribute, Uint16BufferAttribute, Uint32BufferAttribute } from '../core/BufferAttribute';
+import { Float32BufferAttribute } from '../core/BufferAttribute';
 import { BufferGeometry } from '../core/BufferGeometry';
 import { Vector3 } from '../math/Vector3';
 
@@ -128,7 +128,7 @@ function TorusBufferGeometry( radius, tube, radialSegments, tubularSegments, arc
 
 	// build geometry
 
-	this.setIndex( new ( indices.length > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( indices, 1 ) );
+	this.setIndex( indices );
 	this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
 	this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
 	this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );

+ 2 - 2
src/geometries/TorusKnotGeometry.js

@@ -34,7 +34,7 @@ TorusKnotGeometry.prototype.constructor = TorusKnotGeometry;
  * see: http://www.blackpawn.com/texts/pqtorus/
  */
 
-import { Float32BufferAttribute, Uint16BufferAttribute, Uint32BufferAttribute } from '../core/BufferAttribute';
+import { Float32BufferAttribute } from '../core/BufferAttribute';
 import { BufferGeometry } from '../core/BufferGeometry';
 import { Vector3 } from '../math/Vector3';
 import { Vector2 } from '../math/Vector2';
@@ -166,7 +166,7 @@ function TorusKnotBufferGeometry( radius, tube, tubularSegments, radialSegments,
 
 	// build geometry
 
-	this.setIndex( new ( indices.length > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( indices, 1 ) );
+	this.setIndex( indices );
 	this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
 	this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
 	this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );

+ 2 - 2
src/geometries/TubeGeometry.js

@@ -48,7 +48,7 @@ TubeGeometry.prototype.constructor = TubeGeometry;
  * @author Mugen87 / https://github.com/Mugen87
  */
 
-import { Float32BufferAttribute, Uint16BufferAttribute, Uint32BufferAttribute } from '../core/BufferAttribute';
+import { Float32BufferAttribute } from '../core/BufferAttribute';
 import { BufferGeometry } from '../core/BufferGeometry';
 import { Vector2 } from '../math/Vector2';
 import { Vector3 } from '../math/Vector3';
@@ -101,7 +101,7 @@ function TubeBufferGeometry( path, tubularSegments, radius, radialSegments, clos
 
 	// build geometry
 
-	this.setIndex( new ( indices.length > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( indices, 1 ) );
+	this.setIndex( indices );
 	this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
 	this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
 	this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );

+ 82 - 85
src/geometries/WireframeGeometry.js

@@ -1,51 +1,52 @@
 import { BufferGeometry } from '../core/BufferGeometry';
-import { BufferAttribute } from '../core/BufferAttribute';
+import { Float32BufferAttribute } from '../core/BufferAttribute';
+import { Vector3 } from '../math/Vector3';
 
 /**
  * @author mrdoob / http://mrdoob.com/
+ * @author Mugen87 / https://github.com/Mugen87
  */
 
 function WireframeGeometry( geometry ) {
 
 	BufferGeometry.call( this );
 
-	var edge = [ 0, 0 ], hash = {};
+	this.type = 'WireframeGeometry';
 
-	function sortFunction( a, b ) {
+	// buffer
 
-		return a - b;
+	var vertices = [];
 
-	}
+	// helper variables
+
+	var i, j, l, o, ol;
+	var edge = [ 0, 0 ], edges = {}, e;
+	var key, keys = [ 'a', 'b', 'c' ];
+	var vertex;
 
-	var keys = [ 'a', 'b', 'c' ];
+	// different logic for Geometry and BufferGeometry
 
 	if ( geometry && geometry.isGeometry ) {
 
-		var vertices = geometry.vertices;
-		var faces = geometry.faces;
-		var numEdges = 0;
+		// create a data structure that contains all edges without duplicates
 
-		// allocate maximal size
-		var edges = new Uint32Array( 6 * faces.length );
+		var faces = geometry.faces;
 
-		for ( var i = 0, l = faces.length; i < l; i ++ ) {
+		for ( i = 0, l = faces.length; i < l; i ++ ) {
 
 			var face = faces[ i ];
 
-			for ( var j = 0; j < 3; j ++ ) {
+			for ( j = 0; j < 3; j ++ ) {
 
 				edge[ 0 ] = face[ keys[ j ] ];
 				edge[ 1 ] = face[ keys[ ( j + 1 ) % 3 ] ];
-				edge.sort( sortFunction );
+				edge.sort( sortFunction ); // sorting prevents duplicates
 
-				var key = edge.toString();
+				key = edge.toString();
 
-				if ( hash[ key ] === undefined ) {
+				if ( edges[ key ] === undefined ) {
 
-					edges[ 2 * numEdges ] = edge[ 0 ];
-					edges[ 2 * numEdges + 1 ] = edge[ 1 ];
-					hash[ key ] = true;
-					numEdges ++;
+					edges[ key ] = { index1: edge[ 0 ], index2: edge[ 1 ] };
 
 				}
 
@@ -53,68 +54,64 @@ function WireframeGeometry( geometry ) {
 
 		}
 
-		var coords = new Float32Array( numEdges * 2 * 3 );
+		// generate vertices
 
-		for ( var i = 0, l = numEdges; i < l; i ++ ) {
+		for ( key in edges ) {
 
-			for ( var j = 0; j < 2; j ++ ) {
+			e = edges[ key ];
 
-				var vertex = vertices[ edges [ 2 * i + j ] ];
+			vertex = geometry.vertices[ e.index1 ];
+			vertices.push( vertex.x, vertex.y, vertex.z );
 
-				var index = 6 * i + 3 * j;
-				coords[ index + 0 ] = vertex.x;
-				coords[ index + 1 ] = vertex.y;
-				coords[ index + 2 ] = vertex.z;
-
-			}
+			vertex = geometry.vertices[ e.index2 ];
+			vertices.push( vertex.x, vertex.y, vertex.z );
 
 		}
 
-		this.addAttribute( 'position', new BufferAttribute( coords, 3 ) );
-
 	} else if ( geometry && geometry.isBufferGeometry ) {
 
+		var position, indices, groups;
+		var group, start, count;
+		var index1, index2;
+
+		vertex = new Vector3();
+
 		if ( geometry.index !== null ) {
 
-			// Indexed BufferGeometry
+			// indexed BufferGeometry
 
-			var indices = geometry.index.array;
-			var vertices = geometry.attributes.position;
-			var groups = geometry.groups;
-			var numEdges = 0;
+			position = geometry.attributes.position;
+			indices = geometry.index;
+			groups = geometry.groups;
 
 			if ( groups.length === 0 ) {
 
-				geometry.addGroup( 0, indices.length );
+				geometry.addGroup( 0, indices.count );
 
 			}
 
-			// allocate maximal size
-			var edges = new Uint32Array( 2 * indices.length );
+			// create a data structure that contains all eges without duplicates
 
-			for ( var o = 0, ol = groups.length; o < ol; ++ o ) {
+			for ( o = 0, ol = groups.length; o < ol; ++ o ) {
 
-				var group = groups[ o ];
+				group = groups[ o ];
 
-				var start = group.start;
-				var count = group.count;
+				start = group.start;
+				count = group.count;
 
-				for ( var i = start, il = start + count; i < il; i += 3 ) {
+				for ( i = start, l = ( start + count ); i < l; i += 3 ) {
 
-					for ( var j = 0; j < 3; j ++ ) {
+					for ( j = 0; j < 3; j ++ ) {
 
-						edge[ 0 ] = indices[ i + j ];
-						edge[ 1 ] = indices[ i + ( j + 1 ) % 3 ];
-						edge.sort( sortFunction );
+						edge[ 0 ] = indices.getX( i + j );
+						edge[ 1 ] = indices.getX( i + ( j + 1 ) % 3 );
+						edge.sort( sortFunction ); // sorting prevents duplicates
 
-						var key = edge.toString();
+						key = edge.toString();
 
-						if ( hash[ key ] === undefined ) {
+						if ( edges[ key ] === undefined ) {
 
-							edges[ 2 * numEdges ] = edge[ 0 ];
-							edges[ 2 * numEdges + 1 ] = edge[ 1 ];
-							hash[ key ] = true;
-							numEdges ++;
+							edges[ key ] = { index1: edge[ 0 ], index2: edge[ 1 ] };
 
 						}
 
@@ -124,61 +121,61 @@ function WireframeGeometry( geometry ) {
 
 			}
 
-			var coords = new Float32Array( numEdges * 2 * 3 );
-
-			for ( var i = 0, l = numEdges; i < l; i ++ ) {
+			// generate vertices
 
-				for ( var j = 0; j < 2; j ++ ) {
+			for ( key in edges ) {
 
-					var index = 6 * i + 3 * j;
-					var index2 = edges[ 2 * i + j ];
+				e = edges[ key ];
 
-					coords[ index + 0 ] = vertices.getX( index2 );
-					coords[ index + 1 ] = vertices.getY( index2 );
-					coords[ index + 2 ] = vertices.getZ( index2 );
+				vertex.fromBufferAttribute( position, e.index1 );
+				vertices.push( vertex.x, vertex.y, vertex.z );
 
-				}
+				vertex.fromBufferAttribute( position, e.index2 );
+				vertices.push( vertex.x, vertex.y, vertex.z );
 
 			}
 
-			this.addAttribute( 'position', new BufferAttribute( coords, 3 ) );
-
 		} else {
 
 			// non-indexed BufferGeometry
 
-			var vertices = geometry.attributes.position.array;
-			var numEdges = vertices.length / 3;
-			var numTris = numEdges / 3;
-
-			var coords = new Float32Array( numEdges * 2 * 3 );
+			position = geometry.attributes.position;
 
-			for ( var i = 0, l = numTris; i < l; i ++ ) {
+			for ( i = 0, l = ( position.count / 3 ); i < l; i ++ ) {
 
-				for ( var j = 0; j < 3; j ++ ) {
+				for ( j = 0; j < 3; j ++ ) {
 
-					var index = 18 * i + 6 * j;
+					// three edges per triangle, an edge is represented as (index1, index2)
+					// e.g. the first triangle has the following edges: (0,1),(1,2),(2,0)
 
-					var index1 = 9 * i + 3 * j;
-					coords[ index + 0 ] = vertices[ index1 ];
-					coords[ index + 1 ] = vertices[ index1 + 1 ];
-					coords[ index + 2 ] = vertices[ index1 + 2 ];
+					index1 = 3 * i + j;
+					vertex.fromBufferAttribute( position, index1 );
+					vertices.push( vertex.x, vertex.y, vertex.z );
 
-					var index2 = 9 * i + 3 * ( ( j + 1 ) % 3 );
-					coords[ index + 3 ] = vertices[ index2 ];
-					coords[ index + 4 ] = vertices[ index2 + 1 ];
-					coords[ index + 5 ] = vertices[ index2 + 2 ];
+					index2 = 3 * i + ( ( j + 1 ) % 3 );
+					vertex.fromBufferAttribute( position, index2 );
+					vertices.push( vertex.x, vertex.y, vertex.z );
 
 				}
 
 			}
 
-			this.addAttribute( 'position', new BufferAttribute( coords, 3 ) );
-
 		}
 
 	}
 
+	// build geometry
+
+	this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
+
+	// custom array sort function
+
+	function sortFunction( a, b ) {
+
+		return a - b;
+
+	}
+
 }
 
 WireframeGeometry.prototype = Object.create( BufferGeometry.prototype );

+ 11 - 5
src/helpers/ArrowHelper.js

@@ -24,11 +24,7 @@ import { Mesh } from '../objects/Mesh';
 import { Line } from '../objects/Line';
 import { Vector3 } from '../math/Vector3';
 
-var lineGeometry = new BufferGeometry();
-lineGeometry.addAttribute( 'position', new Float32BufferAttribute( [ 0, 0, 0, 0, 1, 0 ], 3 ) );
-
-var coneGeometry = new CylinderBufferGeometry( 0, 0.5, 1, 5, 1 );
-coneGeometry.translate( 0, - 0.5, 0 );
+var lineGeometry, coneGeometry;
 
 function ArrowHelper( dir, origin, length, color, headLength, headWidth ) {
 
@@ -41,6 +37,16 @@ function ArrowHelper( dir, origin, length, color, headLength, headWidth ) {
 	if ( headLength === undefined ) headLength = 0.2 * length;
 	if ( headWidth === undefined ) headWidth = 0.2 * headLength;
 
+	if ( lineGeometry === undefined ) {
+
+		lineGeometry = new BufferGeometry();
+		lineGeometry.addAttribute( 'position', new Float32BufferAttribute( [ 0, 0, 0, 0, 1, 0 ], 3 ) );
+
+		coneGeometry = new CylinderBufferGeometry( 0, 0.5, 1, 5, 1 );
+		coneGeometry.translate( 0, - 0.5, 0 );
+
+	}
+
 	this.position.copy( origin );
 
 	this.line = new Line( lineGeometry, new LineBasicMaterial( { color: color } ) );

+ 3 - 0
src/loaders/ObjectLoader.js

@@ -84,7 +84,10 @@ Object.assign( ObjectLoader.prototype, {
 
 			} catch ( error ) {
 
+				if ( onError !== undefined ) onError( error );
+
 				console.error( 'THREE:ObjectLoader: Can\'t parse ' + url + '.', error.message );
+
 				return;
 
 			}

+ 39 - 25
src/renderers/WebGLRenderer.js

@@ -297,25 +297,8 @@ function WebGLRenderer( parameters ) {
 
 	//
 
-	var backgroundCamera = new OrthographicCamera( - 1, 1, 1, - 1, 0, 1 );
-	var backgroundCamera2 = new PerspectiveCamera();
-	var backgroundPlaneMesh = new Mesh(
-		new PlaneBufferGeometry( 2, 2 ),
-		new MeshBasicMaterial( { depthTest: false, depthWrite: false, fog: false } )
-	);
-	var backgroundBoxShader = ShaderLib[ 'cube' ];
-	var backgroundBoxMesh = new Mesh(
-		new BoxBufferGeometry( 5, 5, 5 ),
-		new ShaderMaterial( {
-			uniforms: backgroundBoxShader.uniforms,
-			vertexShader: backgroundBoxShader.vertexShader,
-			fragmentShader: backgroundBoxShader.fragmentShader,
-			side: BackSide,
-			depthTest: false,
-			depthWrite: false,
-			fog: false
-		} )
-	);
+	var backgroundPlaneCamera, backgroundPlaneMesh;
+	var backgroundBoxCamera, backgroundBoxMesh;
 
 	//
 
@@ -1186,25 +1169,56 @@ function WebGLRenderer( parameters ) {
 
 		if ( background && background.isCubeTexture ) {
 
-			backgroundCamera2.projectionMatrix.copy( camera.projectionMatrix );
+			if ( backgroundBoxCamera === undefined ) {
+
+				backgroundBoxCamera = new PerspectiveCamera();
+
+				backgroundBoxMesh = new Mesh(
+					new BoxBufferGeometry( 5, 5, 5 ),
+					new ShaderMaterial( {
+						uniforms: ShaderLib.cube.uniforms,
+						vertexShader: ShaderLib.cube.vertexShader,
+						fragmentShader: ShaderLib.cube.fragmentShader,
+						side: BackSide,
+						depthTest: false,
+						depthWrite: false,
+						fog: false
+					} )
+				);
+
+			}
+
+			backgroundBoxCamera.projectionMatrix.copy( camera.projectionMatrix );
+
+			backgroundBoxCamera.matrixWorld.extractRotation( camera.matrixWorld );
+			backgroundBoxCamera.matrixWorldInverse.getInverse( backgroundBoxCamera.matrixWorld );
 
-			backgroundCamera2.matrixWorld.extractRotation( camera.matrixWorld );
-			backgroundCamera2.matrixWorldInverse.getInverse( backgroundCamera2.matrixWorld );
 
 			backgroundBoxMesh.material.uniforms[ "tCube" ].value = background;
-			backgroundBoxMesh.modelViewMatrix.multiplyMatrices( backgroundCamera2.matrixWorldInverse, backgroundBoxMesh.matrixWorld );
+			backgroundBoxMesh.modelViewMatrix.multiplyMatrices( backgroundBoxCamera.matrixWorldInverse, backgroundBoxMesh.matrixWorld );
 
 			objects.update( backgroundBoxMesh );
 
-			_this.renderBufferDirect( backgroundCamera2, null, backgroundBoxMesh.geometry, backgroundBoxMesh.material, backgroundBoxMesh, null );
+			_this.renderBufferDirect( backgroundBoxCamera, null, backgroundBoxMesh.geometry, backgroundBoxMesh.material, backgroundBoxMesh, null );
 
 		} else if ( background && background.isTexture ) {
 
+			if ( backgroundPlaneCamera === undefined ) {
+
+				backgroundPlaneCamera = new OrthographicCamera( - 1, 1, 1, - 1, 0, 1 );
+
+				backgroundPlaneMesh = new Mesh(
+					new PlaneBufferGeometry( 2, 2 ),
+					new MeshBasicMaterial( { depthTest: false, depthWrite: false, fog: false } )
+				);
+
+			}
+
 			backgroundPlaneMesh.material.map = background;
 
 			objects.update( backgroundPlaneMesh );
 
-			_this.renderBufferDirect( backgroundCamera, null, backgroundPlaneMesh.geometry, backgroundPlaneMesh.material, backgroundPlaneMesh, null );
+			_this.renderBufferDirect( backgroundPlaneCamera, null, backgroundPlaneMesh.geometry, backgroundPlaneMesh.material, backgroundPlaneMesh, null );
 
 		}
 

+ 2 - 1
src/renderers/webgl/WebGLIndexedBufferRenderer.js

@@ -27,9 +27,10 @@ function WebGLIndexedBufferRenderer( gl, extensions, infoRender ) {
 			size = 2;
 
 		} else {
-			
+
 			type = gl.UNSIGNED_BYTE;
 			size = 1;
+
 		}
 
 	}

+ 3 - 4
src/renderers/webgl/WebGLObjects.js

@@ -2,7 +2,8 @@
  * @author mrdoob / http://mrdoob.com/
  */
 
-import { BufferAttribute } from '../../core/BufferAttribute';
+import { Uint16BufferAttribute, Uint32BufferAttribute } from '../../core/BufferAttribute';
+import { arrayMax } from '../../utils';
 import { WebGLGeometries } from './WebGLGeometries';
 
 function WebGLObjects( gl, properties, info ) {
@@ -199,7 +200,6 @@ function WebGLObjects( gl, properties, info ) {
 
 		var index = geometry.index;
 		var attributes = geometry.attributes;
-		var position = attributes.position;
 
 		// console.time( 'wireframe' );
 
@@ -235,8 +235,7 @@ function WebGLObjects( gl, properties, info ) {
 
 		// console.timeEnd( 'wireframe' );
 
-		var TypeArray = position.count > 65535 ? Uint32Array : Uint16Array;
-		var attribute = new BufferAttribute( new TypeArray( indices ), 1 );
+		var attribute = new ( arrayMax( indices ) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( indices, 1 );
 
 		updateAttribute( attribute, gl.ELEMENT_ARRAY_BUFFER );
 

+ 4 - 3
src/renderers/webgl/WebGLShadowMap.js

@@ -190,6 +190,7 @@ function WebGLShadowMap( _renderer, _lights, _objects, capabilities ) {
 				var pars = { minFilter: NearestFilter, magFilter: NearestFilter, format: RGBAFormat };
 
 				shadow.map = new WebGLRenderTarget( _shadowMapSize.x, _shadowMapSize.y, pars );
+				shadow.map.texture.name = light.name + ".shadowMap";
 
 				shadowCamera.updateProjectionMatrix();
 
@@ -202,7 +203,7 @@ function WebGLShadowMap( _renderer, _lights, _objects, capabilities ) {
 			}
 
 			// TODO (abelnation / sam-g-steel): is this needed?
-			if (shadow && shadow.isRectAreaLightShadow ) {
+			if ( shadow && shadow.isRectAreaLightShadow ) {
 
 				shadow.update( light );
 
@@ -307,8 +308,8 @@ function WebGLShadowMap( _renderer, _lights, _objects, capabilities ) {
 		}
 
 		// Restore GL state.
-		var clearColor = _renderer.getClearColor(),
-		clearAlpha = _renderer.getClearAlpha();
+		var clearColor = _renderer.getClearColor();
+		var clearAlpha = _renderer.getClearAlpha();
 		_renderer.setClearColor( clearColor, clearAlpha );
 
 		scope.needsUpdate = false;

+ 2 - 0
src/textures/Texture.js

@@ -79,6 +79,8 @@ Texture.prototype = {
 
 	copy: function ( source ) {
 
+		this.name = source.name;
+
 		this.image = source.image;
 		this.mipmaps = source.mipmaps.slice( 0 );
 

+ 39 - 0
src/utils.js

@@ -0,0 +1,39 @@
+// http://stackoverflow.com/questions/1669190/javascript-min-max-array-values/13440842#13440842
+
+function arrayMin( array ) {
+
+	var length = array.length, min = Infinity;
+
+	while ( length -- ) {
+
+		if ( array[ length ] < min ) {
+
+			min = array[ length ];
+
+		}
+
+	}
+
+	return min;
+
+}
+
+function arrayMax( array ) {
+
+	var length = array.length, max = - Infinity;
+
+	while ( length -- ) {
+
+		if ( array[ length ] > max ) {
+
+			max = array[ length ];
+
+		}
+
+	}
+
+	return max;
+
+}
+
+export { arrayMin, arrayMax };

+ 3 - 3
utils/exporters/blender/addons/io_three/constants.py

@@ -257,9 +257,9 @@ URL = 'url'
 WRAP = 'wrap'
 REPEAT = 'repeat'
 WRAPPING = type('Wrapping', (), {
-    'REPEAT': 'RepeatWrapping',
-    'CLAMP': 'ClampToEdgeWrapping',
-    'MIRROR': 'MirroredRepeatWrapping'
+    'REPEAT': 'repeat',
+    'CLAMP': 'clamp',
+    'MIRROR': 'mirror'
 })
 ANISOTROPY = 'anisotropy'
 MAG_FILTER = 'magFilter'

Some files were not shown because too many files changed in this diff