Преглед изворни кода

Merging with @bhouston/euler3.

Mr.doob пре 12 година
родитељ
комит
f7e1e26b74
3 измењених фајлова са 755 додато и 691 уклоњено
  1. 657 655
      src/loaders/SceneLoader.js
  2. 1 36
      src/math/Math.js
  3. 97 0
      utils/build/includes/common2.json

+ 657 - 655
src/loaders/SceneLoader.js

@@ -11,1220 +11,1222 @@ THREE.SceneLoader = function () {
 	this.callbackSync = function () {};
 	this.callbackSync = function () {};
 	this.callbackProgress = function () {};
 	this.callbackProgress = function () {};
 
 
-	this.geometryHandlers = {};
-	this.hierarchyHandlers = {};
+	this.geometryHandlerMap = {};
+	this.hierarchyHandlerMap = {};
 
 
 	this.addGeometryHandler( "ascii", THREE.JSONLoader );
 	this.addGeometryHandler( "ascii", THREE.JSONLoader );
 
 
 };
 };
 
 
-THREE.SceneLoader.prototype = {
+THREE.SceneLoader.prototype.constructor = THREE.SceneLoader;
 
 
-	constructor: THREE.SceneLoader,
+THREE.SceneLoader.prototype.load = function ( url, callbackFinished ) {
 
 
-	load: function ( url, onLoad, onProgress, onError ) {
+	var scope = this;
 
 
-		var scope = this;
+	var xhr = new XMLHttpRequest();
 
 
-		var loader = new THREE.XHRLoader( scope.manager );
-		loader.setCrossOrigin( this.crossOrigin );
-		loader.load( url, function ( text ) {
+	xhr.onreadystatechange = function () {
 
 
-			scope.parse( JSON.parse( text ), onLoad, url );
+		if ( xhr.readyState === 4 ) {
 
 
-		} );
+			if ( xhr.status === 200 || xhr.status === 0 ) {
 
 
-	},
+				var json = JSON.parse( xhr.responseText );
+				scope.parse( json, callbackFinished, url );
 
 
-	setCrossOrigin: function ( value ) {
+			} else {
 
 
-		this.crossOrigin = value;
+				console.error( "THREE.SceneLoader: Couldn't load [" + url + "] [" + xhr.status + "]" );
 
 
-	},
+			}
 
 
-	addGeometryHandler: function ( typeID, loaderClass ) {
+		}
 
 
-		this.geometryHandlers[ typeID ] = { "loaderClass": loaderClass };
+	};
 
 
-	},
+	xhr.open( "GET", url, true );
+	xhr.send( null );
 
 
-	addHierarchyHandler: function ( typeID, loaderClass ) {
+};
 
 
-		this.hierarchyHandlers[ typeID ] = { "loaderClass": loaderClass };
+THREE.SceneLoader.prototype.addGeometryHandler = function ( typeID, loaderClass ) {
 
 
-	},
+	this.geometryHandlerMap[ typeID ] = { "loaderClass": loaderClass };
 
 
-	parse: function ( json, callbackFinished, url ) {
+};
 
 
-		var scope = this;
+THREE.SceneLoader.prototype.addHierarchyHandler = function ( typeID, loaderClass ) {
 
 
-		var urlBase = THREE.Loader.prototype.extractUrlBase( url );
+	this.hierarchyHandlerMap[ typeID ] = { "loaderClass": loaderClass };
 
 
-		var geometry, material, camera, fog,
-			texture, images, color,
-			light, hex, intensity,
-			counter_models, counter_textures,
-			total_models, total_textures,
-			result;
+};
 
 
-		var target_array = [];
+THREE.SceneLoader.prototype.parse = function ( json, callbackFinished, url ) {
 
 
-		var data = json;
+	var scope = this;
 
 
-		// async geometry loaders
+	var urlBase = THREE.Loader.prototype.extractUrlBase( url );
 
 
-		for ( var typeID in this.geometryHandlers ) {
+	var geometry, material, camera, fog,
+		texture, images, color,
+		light, hex, intensity,
+		counter_models, counter_textures,
+		total_models, total_textures,
+		result;
 
 
-			var loaderClass = this.geometryHandlers[ typeID ][ "loaderClass" ];
-			this.geometryHandlers[ typeID ][ "loaderObject" ] = new loaderClass();
+	var target_array = [];
 
 
-		}
+	var data = json;
 
 
-		// async hierachy loaders
+	// async geometry loaders
 
 
-		for ( var typeID in this.hierarchyHandlers ) {
+	for ( var typeID in this.geometryHandlerMap ) {
 
 
-			var loaderClass = this.hierarchyHandlers[ typeID ][ "loaderClass" ];
-			this.hierarchyHandlers[ typeID ][ "loaderObject" ] = new loaderClass();
+		var loaderClass = this.geometryHandlerMap[ typeID ][ "loaderClass" ];
+		this.geometryHandlerMap[ typeID ][ "loaderObject" ] = new loaderClass();
 
 
-		}
+	}
 
 
-		counter_models = 0;
-		counter_textures = 0;
+	// async hierachy loaders
 
 
-		result = {
+	for ( var typeID in this.hierarchyHandlerMap ) {
 
 
-			scene: new THREE.Scene(),
-			geometries: {},
-			face_materials: {},
-			materials: {},
-			textures: {},
-			objects: {},
-			cameras: {},
-			lights: {},
-			fogs: {},
-			empties: {},
-			groups: {}
+		var loaderClass = this.hierarchyHandlerMap[ typeID ][ "loaderClass" ];
+		this.hierarchyHandlerMap[ typeID ][ "loaderObject" ] = new loaderClass();
 
 
-		};
+	}
 
 
-		if ( data.transform ) {
+	counter_models = 0;
+	counter_textures = 0;
 
 
-			var position = data.transform.position,
-				rotation = data.transform.rotation,
-				scale = data.transform.scale;
+	result = {
 
 
-			if ( position ) {
+		scene: new THREE.Scene(),
+		geometries: {},
+		face_materials: {},
+		materials: {},
+		textures: {},
+		objects: {},
+		cameras: {},
+		lights: {},
+		fogs: {},
+		empties: {},
+		groups: {}
 
 
-				result.scene.position.fromArray( position );
+	};
 
 
-			}
+	if ( data.transform ) {
 
 
-			if ( rotation ) {
+		var position = data.transform.position,
+			rotation = data.transform.rotation,
+			scale = data.transform.scale;
 
 
-				result.scene.rotation.fromArray( rotation );
+		if ( position ) {
 
 
-			}
+			result.scene.position.fromArray( position );
 
 
-			if ( scale ) {
+		}
 
 
-				result.scene.scale.fromArray( scale );
+		if ( rotation ) {
 
 
-			}
+			result.scene.rotation.fromArray( rotation );
 
 
-			if ( position || rotation || scale ) {
+		}
 
 
-				result.scene.updateMatrix();
-				result.scene.updateMatrixWorld();
+		if ( scale ) {
 
 
-			}
+			result.scene.scale.fromArray( scale );
 
 
 		}
 		}
 
 
-		function get_url( source_url, url_type ) {
+		if ( position || rotation || scale ) {
 
 
-			if ( url_type == "relativeToHTML" ) {
+			result.scene.updateMatrix();
+			result.scene.updateMatrixWorld();
 
 
-				return source_url;
+		}
 
 
-			} else {
+	}
 
 
-				return urlBase + "/" + source_url;
+	function get_url( source_url, url_type ) {
 
 
-			}
+		if ( url_type == "relativeToHTML" ) {
 
 
-		};
+			return source_url;
 
 
-		// toplevel loader function, delegates to handle_children
+		} else {
 
 
-		function handle_objects() {
-
-			handle_children( result.scene, data.objects );
+			return urlBase + "/" + source_url;
 
 
 		}
 		}
 
 
-		// handle all the children from the loaded json and attach them to given parent
-
-		function handle_children( parent, children ) {
+	};
 
 
-			var mat, dst, pos, rot, scl, quat;
+	// toplevel loader function, delegates to handle_children
 
 
-			for ( var objID in children ) {
+	function handle_objects() {
 
 
-				// check by id if child has already been handled,
-				// if not, create new object
+		handle_children( result.scene, data.objects );
 
 
-				var object = result.objects[ objID ];
-				var objJSON = children[ objID ];
+	}
 
 
-				if ( object === undefined ) {
+	// handle all the children from the loaded json and attach them to given parent
 
 
-					// meshes
+	function handle_children( parent, children ) {
 
 
-					if ( objJSON.type && ( objJSON.type in scope.hierarchyHandlers ) ) {
+		var mat, dst, pos, rot, scl, quat;
 
 
-						if ( objJSON.loading === undefined ) {
+		for ( var objID in children ) {
 
 
-							var reservedTypes = {
-								"type": 1, "url": 1, "material": 1,
-								"position": 1, "rotation": 1, "scale" : 1,
-								"visible": 1, "children": 1, "userData": 1,
-								"skin": 1, "morph": 1, "mirroredLoop": 1, "duration": 1
-							};
+			// check by id if child has already been handled,
+			// if not, create new object
 
 
-							var loaderParameters = {};
+			var object = result.objects[ objID ];
+			var objJSON = children[ objID ];
 
 
-							for ( var parType in objJSON ) {
+			if ( object === undefined ) {
 
 
-								if ( ! ( parType in reservedTypes ) ) {
+				// meshes
 
 
-									loaderParameters[ parType ] = objJSON[ parType ];
+				if ( objJSON.type && ( objJSON.type in scope.hierarchyHandlerMap ) ) {
 
 
-								}
+					if ( objJSON.loading === undefined ) {
 
 
-							}
+						var reservedTypes = {
+							"type": 1, "url": 1, "material": 1,
+							"position": 1, "rotation": 1, "scale" : 1,
+							"visible": 1, "children": 1, "userData": 1,
+							"skin": 1, "morph": 1, "mirroredLoop": 1, "duration": 1
+						};
 
 
-							material = result.materials[ objJSON.material ];
+						var loaderParameters = {};
 
 
-							objJSON.loading = true;
+						for ( var parType in objJSON ) {
 
 
-							var loader = scope.hierarchyHandlers[ objJSON.type ][ "loaderObject" ];
+							if ( ! ( parType in reservedTypes ) ) {
 
 
-							// ColladaLoader
+								loaderParameters[ parType ] = objJSON[ parType ];
 
 
-							if ( loader.options ) {
+							}
 
 
-								loader.load( get_url( objJSON.url, data.urlBaseType ), create_callback_hierachy( objID, parent, material, objJSON ) );
+						}
 
 
-							// UTF8Loader
-							// OBJLoader
+						material = result.materials[ objJSON.material ];
 
 
-							} else {
+						objJSON.loading = true;
 
 
-								loader.load( get_url( objJSON.url, data.urlBaseType ), create_callback_hierachy( objID, parent, material, objJSON ), loaderParameters );
+						var loader = scope.hierarchyHandlerMap[ objJSON.type ][ "loaderObject" ];
 
 
-							}
+						// ColladaLoader
 
 
-						}
+						if ( loader.options ) {
 
 
-					} else if ( objJSON.geometry !== undefined ) {
+							loader.load( get_url( objJSON.url, data.urlBaseType ), create_callback_hierachy( objID, parent, material, objJSON ) );
 
 
-						geometry = result.geometries[ objJSON.geometry ];
+						// UTF8Loader
+						// OBJLoader
 
 
-						// geometry already loaded
+						} else {
 
 
-						if ( geometry ) {
+							loader.load( get_url( objJSON.url, data.urlBaseType ), create_callback_hierachy( objID, parent, material, objJSON ), loaderParameters );
 
 
-							var needsTangents = false;
+						}
 
 
-							material = result.materials[ objJSON.material ];
-							needsTangents = material instanceof THREE.ShaderMaterial;
+					}
 
 
-							pos = objJSON.position;
-							rot = objJSON.rotation;
-							scl = objJSON.scale;
-							mat = objJSON.matrix;
-							quat = objJSON.quaternion;
+				} else if ( objJSON.geometry !== undefined ) {
 
 
-							// use materials from the model file
-							// if there is no material specified in the object
+					geometry = result.geometries[ objJSON.geometry ];
 
 
-							if ( ! objJSON.material ) {
+					// geometry already loaded
 
 
-								material = new THREE.MeshFaceMaterial( result.face_materials[ objJSON.geometry ] );
+					if ( geometry ) {
 
 
-							}
+						var needsTangents = false;
 
 
-							// use materials from the model file
-							// if there is just empty face material
-							// (must create new material as each model has its own face material)
+						material = result.materials[ objJSON.material ];
+						needsTangents = material instanceof THREE.ShaderMaterial;
 
 
-							if ( ( material instanceof THREE.MeshFaceMaterial ) && material.materials.length === 0 ) {
+						pos = objJSON.position;
+						rot = objJSON.rotation;
+						scl = objJSON.scale;
+						mat = objJSON.matrix;
+						quat = objJSON.quaternion;
 
 
-								material = new THREE.MeshFaceMaterial( result.face_materials[ objJSON.geometry ] );
+						// use materials from the model file
+						// if there is no material specified in the object
 
 
-							}
+						if ( ! objJSON.material ) {
 
 
-							if ( material instanceof THREE.MeshFaceMaterial ) {
+							material = new THREE.MeshFaceMaterial( result.face_materials[ objJSON.geometry ] );
 
 
-								for ( var i = 0; i < material.materials.length; i ++ ) {
+						}
 
 
-									needsTangents = needsTangents || ( material.materials[ i ] instanceof THREE.ShaderMaterial );
+						// use materials from the model file
+						// if there is just empty face material
+						// (must create new material as each model has its own face material)
 
 
-								}
+						if ( ( material instanceof THREE.MeshFaceMaterial ) && material.materials.length === 0 ) {
 
 
-							}
+							material = new THREE.MeshFaceMaterial( result.face_materials[ objJSON.geometry ] );
 
 
-							if ( needsTangents ) {
+						}
 
 
-								geometry.computeTangents();
+						if ( material instanceof THREE.MeshFaceMaterial ) {
 
 
-							}
+							for ( var i = 0; i < material.materials.length; i ++ ) {
 
 
-							if ( objJSON.skin ) {
+								needsTangents = needsTangents || ( material.materials[ i ] instanceof THREE.ShaderMaterial );
 
 
-								object = new THREE.SkinnedMesh( geometry, material );
+							}
 
 
-							} else if ( objJSON.morph ) {
+						}
 
 
-								object = new THREE.MorphAnimMesh( geometry, material );
+						if ( needsTangents ) {
 
 
-								if ( objJSON.duration !== undefined ) {
+							geometry.computeTangents();
 
 
-									object.duration = objJSON.duration;
+						}
 
 
-								}
+						if ( objJSON.skin ) {
 
 
-								if ( objJSON.time !== undefined ) {
+							object = new THREE.SkinnedMesh( geometry, material );
 
 
-									object.time = objJSON.time;
+						} else if ( objJSON.morph ) {
 
 
-								}
+							object = new THREE.MorphAnimMesh( geometry, material );
 
 
-								if ( objJSON.mirroredLoop !== undefined ) {
+							if ( objJSON.duration !== undefined ) {
 
 
-									object.mirroredLoop = objJSON.mirroredLoop;
+								object.duration = objJSON.duration;
 
 
-								}
+							}
 
 
-								if ( material.morphNormals ) {
+							if ( objJSON.time !== undefined ) {
 
 
-									geometry.computeMorphNormals();
+								object.time = objJSON.time;
 
 
-								}
+							}
 
 
-							} else {
+							if ( objJSON.mirroredLoop !== undefined ) {
 
 
-								object = new THREE.Mesh( geometry, material );
+								object.mirroredLoop = objJSON.mirroredLoop;
 
 
 							}
 							}
 
 
-							object.name = objID;
+							if ( material.morphNormals ) {
 
 
-							if ( mat ) {
+								geometry.computeMorphNormals();
 
 
-								object.matrixAutoUpdate = false;
-								object.matrix.set(
-									mat[0],  mat[1],  mat[2],  mat[3],
-									mat[4],  mat[5],  mat[6],  mat[7],
-									mat[8],  mat[9],  mat[10], mat[11],
-									mat[12], mat[13], mat[14], mat[15]
-								);
+							}
 
 
-							} else {
+						} else {
 
 
-								object.position.fromArray( pos );
+							object = new THREE.Mesh( geometry, material );
 
 
-								if ( quat ) {
+						}
 
 
-									object.quaternion.fromArray( quat );
-									object.useQuaternion = true;
+						object.name = objID;
 
 
-								} else {
+						if ( mat ) {
 
 
-									object.rotation.fromArray( rot );
+							object.matrixAutoUpdate = false;
+							object.matrix.set(
+								mat[0],  mat[1],  mat[2],  mat[3],
+								mat[4],  mat[5],  mat[6],  mat[7],
+								mat[8],  mat[9],  mat[10], mat[11],
+								mat[12], mat[13], mat[14], mat[15]
+							);
 
 
-								}
+						} else {
 
 
-								object.scale.fromArray( scl );
+							object.position.fromArray( pos );
 
 
-							}
+							if ( quat ) {
 
 
-							object.visible = objJSON.visible;
-							object.castShadow = objJSON.castShadow;
-							object.receiveShadow = objJSON.receiveShadow;
+								object.quaternion.fromArray( quat );
 
 
-							parent.add( object );
+							} else {
 
 
-							result.objects[ objID ] = object;
+								object.rotation.fromArray( rot );
 
 
-						}
+							}
 
 
-					// lights
+							object.scale.fromArray( scl );
 
 
-					} else if ( objJSON.type === "DirectionalLight" || objJSON.type === "PointLight" || objJSON.type === "AmbientLight" ) {
+						}
 
 
-						hex = ( objJSON.color !== undefined ) ? objJSON.color : 0xffffff;
-						intensity = ( objJSON.intensity !== undefined ) ? objJSON.intensity : 1;
+						object.visible = objJSON.visible;
+						object.castShadow = objJSON.castShadow;
+						object.receiveShadow = objJSON.receiveShadow;
 
 
-						if ( objJSON.type === "DirectionalLight" ) {
+						parent.add( object );
 
 
-							pos = objJSON.direction;
+						result.objects[ objID ] = object;
 
 
-							light = new THREE.DirectionalLight( hex, intensity );
-							light.position.fromArray( pos );
+					}
 
 
-							if ( objJSON.target ) {
+				// lights
 
 
-								target_array.push( { "object": light, "targetName" : objJSON.target } );
+				} else if ( objJSON.type === "DirectionalLight" || objJSON.type === "PointLight" || objJSON.type === "AmbientLight" ) {
 
 
-								// kill existing default target
-								// otherwise it gets added to scene when parent gets added
+					hex = ( objJSON.color !== undefined ) ? objJSON.color : 0xffffff;
+					intensity = ( objJSON.intensity !== undefined ) ? objJSON.intensity : 1;
 
 
-								light.target = null;
+					if ( objJSON.type === "DirectionalLight" ) {
 
 
-							}
+						pos = objJSON.direction;
 
 
-						} else if ( objJSON.type === "PointLight" ) {
+						light = new THREE.DirectionalLight( hex, intensity );
+						light.position.fromArray( pos );
 
 
-							pos = objJSON.position;
-							dst = objJSON.distance;
+						if ( objJSON.target ) {
 
 
-							light = new THREE.PointLight( hex, intensity, dst );
-							light.position.fromArray( pos );
+							target_array.push( { "object": light, "targetName" : objJSON.target } );
 
 
-						} else if ( objJSON.type === "AmbientLight" ) {
+							// kill existing default target
+							// otherwise it gets added to scene when parent gets added
 
 
-							light = new THREE.AmbientLight( hex );
+							light.target = null;
 
 
 						}
 						}
 
 
-						parent.add( light );
+					} else if ( objJSON.type === "PointLight" ) {
 
 
-						light.name = objID;
-						result.lights[ objID ] = light;
-						result.objects[ objID ] = light;
+						pos = objJSON.position;
+						dst = objJSON.distance;
 
 
-					// cameras
+						light = new THREE.PointLight( hex, intensity, dst );
+						light.position.fromArray( pos );
 
 
-					} else if ( objJSON.type === "PerspectiveCamera" || objJSON.type === "OrthographicCamera" ) {
+					} else if ( objJSON.type === "AmbientLight" ) {
 
 
-						pos = objJSON.position;
-						rot = objJSON.rotation;
-						quat = objJSON.quaternion;
+						light = new THREE.AmbientLight( hex );
 
 
-						if ( objJSON.type === "PerspectiveCamera" ) {
+					}
 
 
-							camera = new THREE.PerspectiveCamera( objJSON.fov, objJSON.aspect, objJSON.near, objJSON.far );
+					parent.add( light );
 
 
-						} else if ( objJSON.type === "OrthographicCamera" ) {
+					light.name = objID;
+					result.lights[ objID ] = light;
+					result.objects[ objID ] = light;
 
 
-							camera = new THREE.OrthographicCamera( objJSON.left, objJSON.right, objJSON.top, objJSON.bottom, objJSON.near, objJSON.far );
+				// cameras
 
 
-						}
+				} else if ( objJSON.type === "PerspectiveCamera" || objJSON.type === "OrthographicCamera" ) {
 
 
-						camera.name = objID;
-						camera.position.fromArray( pos );
+					pos = objJSON.position;
+					rot = objJSON.rotation;
+					quat = objJSON.quaternion;
 
 
-						if ( quat !== undefined ) {
+					if ( objJSON.type === "PerspectiveCamera" ) {
 
 
-							camera.quaternion.fromArray( quat );
-							camera.useQuaternion = true;
+						camera = new THREE.PerspectiveCamera( objJSON.fov, objJSON.aspect, objJSON.near, objJSON.far );
 
 
-						} else if ( rot !== undefined ) {
+					} else if ( objJSON.type === "OrthographicCamera" ) {
 
 
-							camera.rotation.fromArray( rot );
+						camera = new THREE.OrthographicCamera( objJSON.left, objJSON.right, objJSON.top, objJSON.bottom, objJSON.near, objJSON.far );
 
 
-						}
+					}
 
 
-						parent.add( camera );
+					camera.name = objID;
+					camera.position.fromArray( pos );
 
 
-						result.cameras[ objID ] = camera;
-						result.objects[ objID ] = camera;
+					if ( quat !== undefined ) {
 
 
-					// pure Object3D
+						camera.quaternion.fromArray( quat );
+				
+					} else if ( rot !== undefined ) {
 
 
-					} else {
+						camera.rotation.fromArray( rot );
 
 
-						pos = objJSON.position;
-						rot = objJSON.rotation;
-						scl = objJSON.scale;
-						quat = objJSON.quaternion;
+					}
 
 
-						object = new THREE.Object3D();
-						object.name = objID;
-						object.position.fromArray( pos );
+					parent.add( camera );
 
 
-						if ( quat ) {
+					result.cameras[ objID ] = camera;
+					result.objects[ objID ] = camera;
 
 
-							object.quaternion.fromArray( quat );
-							object.useQuaternion = true;
+				// pure Object3D
 
 
-						} else {
+				} else {
 
 
-							object.rotation.fromArray( rot );
+					pos = objJSON.position;
+					rot = objJSON.rotation;
+					scl = objJSON.scale;
+					quat = objJSON.quaternion;
 
 
-						}
+					object = new THREE.Object3D();
+					object.name = objID;
+					object.position.fromArray( pos );
 
 
-						object.scale.fromArray( scl );
-						object.visible = ( objJSON.visible !== undefined ) ? objJSON.visible : false;
+					if ( quat ) {
 
 
-						parent.add( object );
+						object.quaternion.fromArray( quat );
+				
+					} else {
 
 
-						result.objects[ objID ] = object;
-						result.empties[ objID ] = object;
+						object.rotation.fromArray( rot );
 
 
 					}
 					}
 
 
-					if ( object ) {
+					object.scale.fromArray( scl );
+					object.visible = ( objJSON.visible !== undefined ) ? objJSON.visible : false;
 
 
-						if ( objJSON.userData !== undefined ) {
+					parent.add( object );
 
 
-							for ( var key in objJSON.userData ) {
+					result.objects[ objID ] = object;
+					result.empties[ objID ] = object;
 
 
-								var value = objJSON.userData[ key ];
-								object.userData[ key ] = value;
+				}
 
 
-							}
+				if ( object ) {
 
 
-						}
+					if ( objJSON.userData !== undefined ) {
 
 
-						if ( objJSON.groups !== undefined ) {
+						for ( var key in objJSON.userData ) {
 
 
-							for ( var i = 0; i < objJSON.groups.length; i ++ ) {
+							var value = objJSON.userData[ key ];
+							object.userData[ key ] = value;
 
 
-								var groupID = objJSON.groups[ i ];
+						}
+
+					}
+
+					if ( objJSON.groups !== undefined ) {
 
 
-								if ( result.groups[ groupID ] === undefined ) {
+						for ( var i = 0; i < objJSON.groups.length; i ++ ) {
 
 
-									result.groups[ groupID ] = [];
+							var groupID = objJSON.groups[ i ];
 
 
-								}
+							if ( result.groups[ groupID ] === undefined ) {
 
 
-								result.groups[ groupID ].push( objID );
+								result.groups[ groupID ] = [];
 
 
 							}
 							}
 
 
+							result.groups[ groupID ].push( objID );
+
 						}
 						}
 
 
 					}
 					}
 
 
 				}
 				}
 
 
-				if ( object !== undefined && objJSON.children !== undefined ) {
+			}
 
 
-					handle_children( object, objJSON.children );
+			if ( object !== undefined && objJSON.children !== undefined ) {
 
 
-				}
+				handle_children( object, objJSON.children );
 
 
 			}
 			}
 
 
-		};
-
-		function handle_mesh( geo, mat, id ) {
-
-			result.geometries[ id ] = geo;
-			result.face_materials[ id ] = mat;
-			handle_objects();
+		}
 
 
-		};
+	};
 
 
-		function handle_hierarchy( node, id, parent, material, obj ) {
+	function handle_mesh( geo, mat, id ) {
 
 
-			var p = obj.position;
-			var r = obj.rotation;
-			var q = obj.quaternion;
-			var s = obj.scale;
+		result.geometries[ id ] = geo;
+		result.face_materials[ id ] = mat;
+		handle_objects();
 
 
-			node.position.fromArray( p );
+	};
 
 
-			if ( q ) {
+	function handle_hierarchy( node, id, parent, material, obj ) {
 
 
-				node.quaternion.fromArray( q );
-				node.useQuaternion = true;
+		var p = obj.position;
+		var r = obj.rotation;
+		var q = obj.quaternion;
+		var s = obj.scale;
 
 
-			} else {
+		node.position.fromArray( p );
 
 
-				node.rotation.fromArray( r );
+		if ( q ) {
 
 
-			}
+			node.quaternion.fromArray( q );
+	
+		} else {
 
 
-			node.scale.fromArray( s );
+			node.rotation.fromArray( r );
 
 
-			// override children materials
-			// if object material was specified in JSON explicitly
+		}
 
 
-			if ( material ) {
+		node.scale.fromArray( s );
 
 
-				node.traverse( function ( child ) {
+		// override children materials
+		// if object material was specified in JSON explicitly
 
 
-					child.material = material;
+		if ( material ) {
 
 
-				} );
+			node.traverse( function ( child ) {
 
 
-			}
+				child.material = material;
 
 
-			// override children visibility
-			// with root node visibility as specified in JSON
+			} );
 
 
-			var visible = ( obj.visible !== undefined ) ? obj.visible : true;
+		}
 
 
-			node.traverse( function ( child ) {
+		// override children visibility
+		// with root node visibility as specified in JSON
 
 
-				child.visible = visible;
+		var visible = ( obj.visible !== undefined ) ? obj.visible : true;
 
 
-			} );
+		node.traverse( function ( child ) {
 
 
-			parent.add( node );
+			child.visible = visible;
 
 
-			node.name = id;
+		} );
 
 
-			result.objects[ id ] = node;
-			handle_objects();
+		parent.add( node );
 
 
-		};
+		node.name = id;
 
 
-		function create_callback_geometry( id ) {
+		result.objects[ id ] = node;
+		handle_objects();
 
 
-			return function ( geo, mat ) {
+	};
 
 
-				geo.name = id;
+	function create_callback_geometry( id ) {
 
 
-				handle_mesh( geo, mat, id );
+		return function ( geo, mat ) {
 
 
-				counter_models -= 1;
+			geo.name = id;
 
 
-				scope.onLoadComplete();
+			handle_mesh( geo, mat, id );
 
 
-				async_callback_gate();
+			counter_models -= 1;
 
 
-			}
+			scope.onLoadComplete();
 
 
-		};
+			async_callback_gate();
 
 
-		function create_callback_hierachy( id, parent, material, obj ) {
+		}
 
 
-			return function ( event ) {
+	};
 
 
-				var result;
+	function create_callback_hierachy( id, parent, material, obj ) {
 
 
-				// loaders which use EventDispatcher
+		return function ( event ) {
 
 
-				if ( event.content ) {
+			var result;
 
 
-					result = event.content;
+			// loaders which use EventDispatcher
 
 
-				// ColladaLoader
+			if ( event.content ) {
 
 
-				} else if ( event.dae ) {
+				result = event.content;
 
 
-					result = event.scene;
+			// ColladaLoader
 
 
+			} else if ( event.dae ) {
 
 
-				// UTF8Loader
+				result = event.scene;
 
 
-				} else {
 
 
-					result = event;
+			// UTF8Loader
 
 
-				}
+			} else {
 
 
-				handle_hierarchy( result, id, parent, material, obj );
+				result = event;
 
 
-				counter_models -= 1;
+			}
 
 
-				scope.onLoadComplete();
+			handle_hierarchy( result, id, parent, material, obj );
 
 
-				async_callback_gate();
+			counter_models -= 1;
 
 
-			}
+			scope.onLoadComplete();
 
 
-		};
+			async_callback_gate();
 
 
-		function create_callback_embed( id ) {
+		}
 
 
-			return function ( geo, mat ) {
+	};
 
 
-				geo.name = id;
+	function create_callback_embed( id ) {
 
 
-				result.geometries[ id ] = geo;
-				result.face_materials[ id ] = mat;
+		return function ( geo, mat ) {
 
 
-			}
+			geo.name = id;
 
 
-		};
+			result.geometries[ id ] = geo;
+			result.face_materials[ id ] = mat;
 
 
-		function async_callback_gate() {
+		}
 
 
-			var progress = {
+	};
 
 
-				totalModels : total_models,
-				totalTextures : total_textures,
-				loadedModels : total_models - counter_models,
-				loadedTextures : total_textures - counter_textures
+	function async_callback_gate() {
 
 
-			};
+		var progress = {
 
 
-			scope.callbackProgress( progress, result );
+			totalModels : total_models,
+			totalTextures : total_textures,
+			loadedModels : total_models - counter_models,
+			loadedTextures : total_textures - counter_textures
 
 
-			scope.onLoadProgress();
+		};
 
 
-			if ( counter_models === 0 && counter_textures === 0 ) {
+		scope.callbackProgress( progress, result );
 
 
-				finalize();
-				callbackFinished( result );
+		scope.onLoadProgress();
 
 
-			}
+		if ( counter_models === 0 && counter_textures === 0 ) {
 
 
-		};
+			finalize();
+			callbackFinished( result );
 
 
-		function finalize() {
+		}
 
 
-			// take care of targets which could be asynchronously loaded objects
+	};
 
 
-			for ( var i = 0; i < target_array.length; i ++ ) {
+	function finalize() {
 
 
-				var ta = target_array[ i ];
+		// take care of targets which could be asynchronously loaded objects
 
 
-				var target = result.objects[ ta.targetName ];
+		for ( var i = 0; i < target_array.length; i ++ ) {
 
 
-				if ( target ) {
+			var ta = target_array[ i ];
 
 
-					ta.object.target = target;
+			var target = result.objects[ ta.targetName ];
 
 
-				} else {
+			if ( target ) {
 
 
-					// if there was error and target of specified name doesn't exist in the scene file
-					// create instead dummy target
-					// (target must be added to scene explicitly as parent is already added)
+				ta.object.target = target;
 
 
-					ta.object.target = new THREE.Object3D();
-					result.scene.add( ta.object.target );
+			} else {
 
 
-				}
+				// if there was error and target of specified name doesn't exist in the scene file
+				// create instead dummy target
+				// (target must be added to scene explicitly as parent is already added)
 
 
-				ta.object.target.userData.targetInverse = ta.object;
+				ta.object.target = new THREE.Object3D();
+				result.scene.add( ta.object.target );
 
 
 			}
 			}
 
 
-		};
+			ta.object.target.userData.targetInverse = ta.object;
 
 
-		var callbackTexture = function ( count ) {
+		}
 
 
-			counter_textures -= count;
-			async_callback_gate();
+	};
 
 
-			scope.onLoadComplete();
+	var callbackTexture = function ( count ) {
 
 
-		};
+		counter_textures -= count;
+		async_callback_gate();
+
+		scope.onLoadComplete();
 
 
-		// must use this instead of just directly calling callbackTexture
-		// because of closure in the calling context loop
+	};
 
 
-		var generateTextureCallback = function ( count ) {
+	// must use this instead of just directly calling callbackTexture
+	// because of closure in the calling context loop
 
 
-			return function () {
+	var generateTextureCallback = function ( count ) {
 
 
-				callbackTexture( count );
+		return function () {
 
 
-			};
+			callbackTexture( count );
 
 
 		};
 		};
 
 
-		function traverse_json_hierarchy( objJSON, callback ) {
+	};
 
 
-			callback( objJSON );
+	function traverse_json_hierarchy( objJSON, callback ) {
 
 
-			if ( objJSON.children !== undefined ) {
+		callback( objJSON );
 
 
-				for ( var objChildID in objJSON.children ) {
+		if ( objJSON.children !== undefined ) {
 
 
-					traverse_json_hierarchy( objJSON.children[ objChildID ], callback );
+			for ( var objChildID in objJSON.children ) {
 
 
-				}
+				traverse_json_hierarchy( objJSON.children[ objChildID ], callback );
 
 
 			}
 			}
 
 
-		};
+		}
 
 
-		// first go synchronous elements
+	};
 
 
-		// fogs
+	// first go synchronous elements
 
 
-		var fogID, fogJSON;
+	// fogs
 
 
-		for ( fogID in data.fogs ) {
+	var fogID, fogJSON;
 
 
-			fogJSON = data.fogs[ fogID ];
+	for ( fogID in data.fogs ) {
 
 
-			if ( fogJSON.type === "linear" ) {
+		fogJSON = data.fogs[ fogID ];
 
 
-				fog = new THREE.Fog( 0x000000, fogJSON.near, fogJSON.far );
+		if ( fogJSON.type === "linear" ) {
 
 
-			} else if ( fogJSON.type === "exp2" ) {
+			fog = new THREE.Fog( 0x000000, fogJSON.near, fogJSON.far );
 
 
-				fog = new THREE.FogExp2( 0x000000, fogJSON.density );
+		} else if ( fogJSON.type === "exp2" ) {
 
 
-			}
+			fog = new THREE.FogExp2( 0x000000, fogJSON.density );
 
 
-			color = fogJSON.color;
-			fog.color.setRGB( color[0], color[1], color[2] );
+		}
 
 
-			result.fogs[ fogID ] = fog;
+		color = fogJSON.color;
+		fog.color.setRGB( color[0], color[1], color[2] );
 
 
-		}
+		result.fogs[ fogID ] = fog;
 
 
-		// now come potentially asynchronous elements
+	}
 
 
-		// geometries
+	// now come potentially asynchronous elements
 
 
-		// count how many geometries will be loaded asynchronously
+	// geometries
 
 
-		var geoID, geoJSON;
+	// count how many geometries will be loaded asynchronously
 
 
-		for ( geoID in data.geometries ) {
+	var geoID, geoJSON;
 
 
-			geoJSON = data.geometries[ geoID ];
+	for ( geoID in data.geometries ) {
 
 
-			if ( geoJSON.type in this.geometryHandlers ) {
+		geoJSON = data.geometries[ geoID ];
 
 
-				counter_models += 1;
+		if ( geoJSON.type in this.geometryHandlerMap ) {
 
 
-				scope.onLoadStart();
+			counter_models += 1;
 
 
-			}
+			scope.onLoadStart();
 
 
 		}
 		}
 
 
-		// count how many hierarchies will be loaded asynchronously
+	}
 
 
-		for ( var objID in data.objects ) {
+	// count how many hierarchies will be loaded asynchronously
 
 
-			traverse_json_hierarchy( data.objects[ objID ], function ( objJSON ) {
+	for ( var objID in data.objects ) {
 
 
-				if ( objJSON.type && ( objJSON.type in scope.hierarchyHandlers ) ) {
+		traverse_json_hierarchy( data.objects[ objID ], function ( objJSON ) {
 
 
-					counter_models += 1;
+			if ( objJSON.type && ( objJSON.type in scope.hierarchyHandlerMap ) ) {
 
 
-					scope.onLoadStart();
+				counter_models += 1;
 
 
-				}
+				scope.onLoadStart();
 
 
-			});
+			}
 
 
-		}
+		});
 
 
-		total_models = counter_models;
+	}
 
 
-		for ( geoID in data.geometries ) {
+	total_models = counter_models;
 
 
-			geoJSON = data.geometries[ geoID ];
+	for ( geoID in data.geometries ) {
 
 
-			if ( geoJSON.type === "cube" ) {
+		geoJSON = data.geometries[ geoID ];
 
 
-				geometry = new THREE.CubeGeometry( geoJSON.width, geoJSON.height, geoJSON.depth, geoJSON.widthSegments, geoJSON.heightSegments, geoJSON.depthSegments );
-				geometry.name = geoID;
-				result.geometries[ geoID ] = geometry;
+		if ( geoJSON.type === "cube" ) {
 
 
-			} else if ( geoJSON.type === "plane" ) {
+			geometry = new THREE.CubeGeometry( geoJSON.width, geoJSON.height, geoJSON.depth, geoJSON.widthSegments, geoJSON.heightSegments, geoJSON.depthSegments );
+			geometry.name = geoID;
+			result.geometries[ geoID ] = geometry;
 
 
-				geometry = new THREE.PlaneGeometry( geoJSON.width, geoJSON.height, geoJSON.widthSegments, geoJSON.heightSegments );
-				geometry.name = geoID;
-				result.geometries[ geoID ] = geometry;
+		} else if ( geoJSON.type === "plane" ) {
 
 
-			} else if ( geoJSON.type === "sphere" ) {
+			geometry = new THREE.PlaneGeometry( geoJSON.width, geoJSON.height, geoJSON.widthSegments, geoJSON.heightSegments );
+			geometry.name = geoID;
+			result.geometries[ geoID ] = geometry;
 
 
-				geometry = new THREE.SphereGeometry( geoJSON.radius, geoJSON.widthSegments, geoJSON.heightSegments );
-				geometry.name = geoID;
-				result.geometries[ geoID ] = geometry;
+		} else if ( geoJSON.type === "sphere" ) {
 
 
-			} else if ( geoJSON.type === "cylinder" ) {
+			geometry = new THREE.SphereGeometry( geoJSON.radius, geoJSON.widthSegments, geoJSON.heightSegments );
+			geometry.name = geoID;
+			result.geometries[ geoID ] = geometry;
 
 
-				geometry = new THREE.CylinderGeometry( geoJSON.topRad, geoJSON.botRad, geoJSON.height, geoJSON.radSegs, geoJSON.heightSegs );
-				geometry.name = geoID;
-				result.geometries[ geoID ] = geometry;
+		} else if ( geoJSON.type === "cylinder" ) {
 
 
-			} else if ( geoJSON.type === "torus" ) {
+			geometry = new THREE.CylinderGeometry( geoJSON.topRad, geoJSON.botRad, geoJSON.height, geoJSON.radSegs, geoJSON.heightSegs );
+			geometry.name = geoID;
+			result.geometries[ geoID ] = geometry;
 
 
-				geometry = new THREE.TorusGeometry( geoJSON.radius, geoJSON.tube, geoJSON.segmentsR, geoJSON.segmentsT );
-				geometry.name = geoID;
-				result.geometries[ geoID ] = geometry;
+		} else if ( geoJSON.type === "torus" ) {
 
 
-			} else if ( geoJSON.type === "icosahedron" ) {
+			geometry = new THREE.TorusGeometry( geoJSON.radius, geoJSON.tube, geoJSON.segmentsR, geoJSON.segmentsT );
+			geometry.name = geoID;
+			result.geometries[ geoID ] = geometry;
 
 
-				geometry = new THREE.IcosahedronGeometry( geoJSON.radius, geoJSON.subdivisions );
-				geometry.name = geoID;
-				result.geometries[ geoID ] = geometry;
+		} else if ( geoJSON.type === "icosahedron" ) {
 
 
-			} else if ( geoJSON.type in this.geometryHandlers ) {
+			geometry = new THREE.IcosahedronGeometry( geoJSON.radius, geoJSON.subdivisions );
+			geometry.name = geoID;
+			result.geometries[ geoID ] = geometry;
 
 
-				var loaderParameters = {};
+		} else if ( geoJSON.type in this.geometryHandlerMap ) {
 
 
-				for ( var parType in geoJSON ) {
+			var loaderParameters = {};
 
 
-					if ( parType !== "type" && parType !== "url" ) {
+			for ( var parType in geoJSON ) {
 
 
-						loaderParameters[ parType ] = geoJSON[ parType ];
+				if ( parType !== "type" && parType !== "url" ) {
 
 
-					}
+					loaderParameters[ parType ] = geoJSON[ parType ];
 
 
 				}
 				}
 
 
-				var loader = this.geometryHandlers[ geoJSON.type ][ "loaderObject" ];
-				loader.load( get_url( geoJSON.url, data.urlBaseType ), create_callback_geometry( geoID ), loaderParameters );
+			}
 
 
-			} else if ( geoJSON.type === "embedded" ) {
+			var loader = this.geometryHandlerMap[ geoJSON.type ][ "loaderObject" ];
+			loader.load( get_url( geoJSON.url, data.urlBaseType ), create_callback_geometry( geoID ), loaderParameters );
 
 
-				var modelJson = data.embeds[ geoJSON.id ],
-					texture_path = "";
+		} else if ( geoJSON.type === "embedded" ) {
 
 
-				// pass metadata along to jsonLoader so it knows the format version
+			var modelJson = data.embeds[ geoJSON.id ],
+				texture_path = "";
 
 
-				modelJson.metadata = data.metadata;
+			// pass metadata along to jsonLoader so it knows the format version
 
 
-				if ( modelJson ) {
+			modelJson.metadata = data.metadata;
 
 
-					var jsonLoader = this.geometryHandlers[ "ascii" ][ "loaderObject" ];
-					var model = jsonLoader.parse( modelJson, texture_path );
-					create_callback_embed( geoID )( model.geometry, model.materials );
+			if ( modelJson ) {
 
 
-				}
+				var jsonLoader = this.geometryHandlerMap[ "ascii" ][ "loaderObject" ];
+				var model = jsonLoader.parse( modelJson, texture_path );
+				create_callback_embed( geoID )( model.geometry, model.materials );
 
 
 			}
 			}
 
 
 		}
 		}
 
 
-		// textures
-
-		// count how many textures will be loaded asynchronously
-
-		var textureID, textureJSON;
-
-		for ( textureID in data.textures ) {
+	}
 
 
-			textureJSON = data.textures[ textureID ];
+	// textures
 
 
-			if ( textureJSON.url instanceof Array ) {
+	// count how many textures will be loaded asynchronously
 
 
-				counter_textures += textureJSON.url.length;
+	var textureID, textureJSON;
 
 
-				for( var n = 0; n < textureJSON.url.length; n ++ ) {
+	for ( textureID in data.textures ) {
 
 
-					scope.onLoadStart();
+		textureJSON = data.textures[ textureID ];
 
 
-				}
+		if ( textureJSON.url instanceof Array ) {
 
 
-			} else {
+			counter_textures += textureJSON.url.length;
 
 
-				counter_textures += 1;
+			for( var n = 0; n < textureJSON.url.length; n ++ ) {
 
 
 				scope.onLoadStart();
 				scope.onLoadStart();
 
 
 			}
 			}
 
 
-		}
+		} else {
 
 
-		total_textures = counter_textures;
+			counter_textures += 1;
 
 
-		for ( textureID in data.textures ) {
+			scope.onLoadStart();
 
 
-			textureJSON = data.textures[ textureID ];
+		}
 
 
-			if ( textureJSON.mapping !== undefined && THREE[ textureJSON.mapping ] !== undefined ) {
+	}
 
 
-				textureJSON.mapping = new THREE[ textureJSON.mapping ]();
+	total_textures = counter_textures;
 
 
-			}
+	for ( textureID in data.textures ) {
 
 
-			if ( textureJSON.url instanceof Array ) {
+		textureJSON = data.textures[ textureID ];
 
 
-				var count = textureJSON.url.length;
-				var url_array = [];
+		if ( textureJSON.mapping !== undefined && THREE[ textureJSON.mapping ] !== undefined ) {
 
 
-				for( var i = 0; i < count; i ++ ) {
+			textureJSON.mapping = new THREE[ textureJSON.mapping ]();
 
 
-					url_array[ i ] = get_url( textureJSON.url[ i ], data.urlBaseType );
+		}
 
 
-				}
+		if ( textureJSON.url instanceof Array ) {
 
 
-				var isCompressed = /\.dds$/i.test( url_array[ 0 ] );
+			var count = textureJSON.url.length;
+			var url_array = [];
 
 
-				if ( isCompressed ) {
+			for( var i = 0; i < count; i ++ ) {
 
 
-					texture = THREE.ImageUtils.loadCompressedTextureCube( url_array, textureJSON.mapping, generateTextureCallback( count ) );
+				url_array[ i ] = get_url( textureJSON.url[ i ], data.urlBaseType );
 
 
-				} else {
+			}
 
 
-					texture = THREE.ImageUtils.loadTextureCube( url_array, textureJSON.mapping, generateTextureCallback( count ) );
+			var isCompressed = /\.dds$/i.test( url_array[ 0 ] );
 
 
-				}
+			if ( isCompressed ) {
+
+				texture = THREE.ImageUtils.loadCompressedTextureCube( url_array, textureJSON.mapping, generateTextureCallback( count ) );
 
 
 			} else {
 			} else {
 
 
-				var isCompressed = /\.dds$/i.test( textureJSON.url );
-				var fullUrl = get_url( textureJSON.url, data.urlBaseType );
-				var textureCallback = generateTextureCallback( 1 );
+				texture = THREE.ImageUtils.loadTextureCube( url_array, textureJSON.mapping, generateTextureCallback( count ) );
 
 
-				if ( isCompressed ) {
+			}
 
 
-					texture = THREE.ImageUtils.loadCompressedTexture( fullUrl, textureJSON.mapping, textureCallback );
+		} else {
 
 
-				} else {
+			var isCompressed = /\.dds$/i.test( textureJSON.url );
+			var fullUrl = get_url( textureJSON.url, data.urlBaseType );
+			var textureCallback = generateTextureCallback( 1 );
 
 
-					texture = THREE.ImageUtils.loadTexture( fullUrl, textureJSON.mapping, textureCallback );
+			if ( isCompressed ) {
 
 
-				}
+				texture = THREE.ImageUtils.loadCompressedTexture( fullUrl, textureJSON.mapping, textureCallback );
 
 
-				if ( THREE[ textureJSON.minFilter ] !== undefined )
-					texture.minFilter = THREE[ textureJSON.minFilter ];
+			} else {
 
 
-				if ( THREE[ textureJSON.magFilter ] !== undefined )
-					texture.magFilter = THREE[ textureJSON.magFilter ];
+				texture = THREE.ImageUtils.loadTexture( fullUrl, textureJSON.mapping, textureCallback );
 
 
-				if ( textureJSON.anisotropy ) texture.anisotropy = textureJSON.anisotropy;
+			}
 
 
-				if ( textureJSON.repeat ) {
+			if ( THREE[ textureJSON.minFilter ] !== undefined )
+				texture.minFilter = THREE[ textureJSON.minFilter ];
 
 
-					texture.repeat.set( textureJSON.repeat[ 0 ], textureJSON.repeat[ 1 ] );
+			if ( THREE[ textureJSON.magFilter ] !== undefined )
+				texture.magFilter = THREE[ textureJSON.magFilter ];
 
 
-					if ( textureJSON.repeat[ 0 ] !== 1 ) texture.wrapS = THREE.RepeatWrapping;
-					if ( textureJSON.repeat[ 1 ] !== 1 ) texture.wrapT = THREE.RepeatWrapping;
+			if ( textureJSON.anisotropy ) texture.anisotropy = textureJSON.anisotropy;
 
 
-				}
+			if ( textureJSON.repeat ) {
 
 
-				if ( textureJSON.offset ) {
+				texture.repeat.set( textureJSON.repeat[ 0 ], textureJSON.repeat[ 1 ] );
 
 
-					texture.offset.set( textureJSON.offset[ 0 ], textureJSON.offset[ 1 ] );
+				if ( textureJSON.repeat[ 0 ] !== 1 ) texture.wrapS = THREE.RepeatWrapping;
+				if ( textureJSON.repeat[ 1 ] !== 1 ) texture.wrapT = THREE.RepeatWrapping;
 
 
-				}
+			}
 
 
-				// handle wrap after repeat so that default repeat can be overriden
+			if ( textureJSON.offset ) {
 
 
-				if ( textureJSON.wrap ) {
+				texture.offset.set( textureJSON.offset[ 0 ], textureJSON.offset[ 1 ] );
 
 
-					var wrapMap = {
-						"repeat": THREE.RepeatWrapping,
-						"mirror": THREE.MirroredRepeatWrapping
-					}
+			}
+
+			// handle wrap after repeat so that default repeat can be overriden
 
 
-					if ( wrapMap[ textureJSON.wrap[ 0 ] ] !== undefined ) texture.wrapS = wrapMap[ textureJSON.wrap[ 0 ] ];
-					if ( wrapMap[ textureJSON.wrap[ 1 ] ] !== undefined ) texture.wrapT = wrapMap[ textureJSON.wrap[ 1 ] ];
+			if ( textureJSON.wrap ) {
 
 
+				var wrapMap = {
+					"repeat": THREE.RepeatWrapping,
+					"mirror": THREE.MirroredRepeatWrapping
 				}
 				}
 
 
-			}
+				if ( wrapMap[ textureJSON.wrap[ 0 ] ] !== undefined ) texture.wrapS = wrapMap[ textureJSON.wrap[ 0 ] ];
+				if ( wrapMap[ textureJSON.wrap[ 1 ] ] !== undefined ) texture.wrapT = wrapMap[ textureJSON.wrap[ 1 ] ];
 
 
-			result.textures[ textureID ] = texture;
+			}
 
 
 		}
 		}
 
 
-		// materials
+		result.textures[ textureID ] = texture;
 
 
-		var matID, matJSON;
-		var parID;
-
-		for ( matID in data.materials ) {
+	}
 
 
-			matJSON = data.materials[ matID ];
+	// materials
 
 
-			for ( parID in matJSON.parameters ) {
+	var matID, matJSON;
+	var parID;
 
 
-				if ( parID === "envMap" || parID === "map" || parID === "lightMap" || parID === "bumpMap" ) {
+	for ( matID in data.materials ) {
 
 
-					matJSON.parameters[ parID ] = result.textures[ matJSON.parameters[ parID ] ];
+		matJSON = data.materials[ matID ];
 
 
-				} else if ( parID === "shading" ) {
+		for ( parID in matJSON.parameters ) {
 
 
-					matJSON.parameters[ parID ] = ( matJSON.parameters[ parID ] === "flat" ) ? THREE.FlatShading : THREE.SmoothShading;
+			if ( parID === "envMap" || parID === "map" || parID === "lightMap" || parID === "bumpMap" ) {
 
 
-				} else if ( parID === "side" ) {
+				matJSON.parameters[ parID ] = result.textures[ matJSON.parameters[ parID ] ];
 
 
-					if ( matJSON.parameters[ parID ] == "double" ) {
+			} else if ( parID === "shading" ) {
 
 
-						matJSON.parameters[ parID ] = THREE.DoubleSide;
+				matJSON.parameters[ parID ] = ( matJSON.parameters[ parID ] === "flat" ) ? THREE.FlatShading : THREE.SmoothShading;
 
 
-					} else if ( matJSON.parameters[ parID ] == "back" ) {
+			} else if ( parID === "side" ) {
 
 
-						matJSON.parameters[ parID ] = THREE.BackSide;
+				if ( matJSON.parameters[ parID ] == "double" ) {
 
 
-					} else {
+					matJSON.parameters[ parID ] = THREE.DoubleSide;
 
 
-						matJSON.parameters[ parID ] = THREE.FrontSide;
+				} else if ( matJSON.parameters[ parID ] == "back" ) {
 
 
-					}
+					matJSON.parameters[ parID ] = THREE.BackSide;
 
 
-				} else if ( parID === "blending" ) {
+				} else {
 
 
-					matJSON.parameters[ parID ] = matJSON.parameters[ parID ] in THREE ? THREE[ matJSON.parameters[ parID ] ] : THREE.NormalBlending;
+					matJSON.parameters[ parID ] = THREE.FrontSide;
 
 
-				} else if ( parID === "combine" ) {
+				}
 
 
-					matJSON.parameters[ parID ] = matJSON.parameters[ parID ] in THREE ? THREE[ matJSON.parameters[ parID ] ] : THREE.MultiplyOperation;
+			} else if ( parID === "blending" ) {
 
 
-				} else if ( parID === "vertexColors" ) {
+				matJSON.parameters[ parID ] = matJSON.parameters[ parID ] in THREE ? THREE[ matJSON.parameters[ parID ] ] : THREE.NormalBlending;
 
 
-					if ( matJSON.parameters[ parID ] == "face" ) {
+			} else if ( parID === "combine" ) {
 
 
-						matJSON.parameters[ parID ] = THREE.FaceColors;
+				matJSON.parameters[ parID ] = matJSON.parameters[ parID ] in THREE ? THREE[ matJSON.parameters[ parID ] ] : THREE.MultiplyOperation;
 
 
-					// default to vertex colors if "vertexColors" is anything else face colors or 0 / null / false
+			} else if ( parID === "vertexColors" ) {
 
 
-					} else if ( matJSON.parameters[ parID ] ) {
+				if ( matJSON.parameters[ parID ] == "face" ) {
 
 
-						matJSON.parameters[ parID ] = THREE.VertexColors;
+					matJSON.parameters[ parID ] = THREE.FaceColors;
 
 
-					}
+				// default to vertex colors if "vertexColors" is anything else face colors or 0 / null / false
 
 
-				} else if ( parID === "wrapRGB" ) {
+				} else if ( matJSON.parameters[ parID ] ) {
 
 
-					var v3 = matJSON.parameters[ parID ];
-					matJSON.parameters[ parID ] = new THREE.Vector3( v3[ 0 ], v3[ 1 ], v3[ 2 ] );
+					matJSON.parameters[ parID ] = THREE.VertexColors;
 
 
 				}
 				}
 
 
-			}
+			} else if ( parID === "wrapRGB" ) {
 
 
-			if ( matJSON.parameters.opacity !== undefined && matJSON.parameters.opacity < 1.0 ) {
-
-				matJSON.parameters.transparent = true;
+				var v3 = matJSON.parameters[ parID ];
+				matJSON.parameters[ parID ] = new THREE.Vector3( v3[ 0 ], v3[ 1 ], v3[ 2 ] );
 
 
 			}
 			}
 
 
-			if ( matJSON.parameters.normalMap ) {
-
-				var shader = THREE.ShaderLib[ "normalmap" ];
-				var uniforms = THREE.UniformsUtils.clone( shader.uniforms );
+		}
 
 
-				var diffuse = matJSON.parameters.color;
-				var specular = matJSON.parameters.specular;
-				var ambient = matJSON.parameters.ambient;
-				var shininess = matJSON.parameters.shininess;
+		if ( matJSON.parameters.opacity !== undefined && matJSON.parameters.opacity < 1.0 ) {
 
 
-				uniforms[ "tNormal" ].value = result.textures[ matJSON.parameters.normalMap ];
+			matJSON.parameters.transparent = true;
 
 
-				if ( matJSON.parameters.normalScale ) {
+		}
 
 
-					uniforms[ "uNormalScale" ].value.set( matJSON.parameters.normalScale[ 0 ], matJSON.parameters.normalScale[ 1 ] );
+		if ( matJSON.parameters.normalMap ) {
 
 
-				}
+			var shader = THREE.ShaderLib[ "normalmap" ];
+			var uniforms = THREE.UniformsUtils.clone( shader.uniforms );
 
 
-				if ( matJSON.parameters.map ) {
+			var diffuse = matJSON.parameters.color;
+			var specular = matJSON.parameters.specular;
+			var ambient = matJSON.parameters.ambient;
+			var shininess = matJSON.parameters.shininess;
 
 
-					uniforms[ "tDiffuse" ].value = matJSON.parameters.map;
-					uniforms[ "enableDiffuse" ].value = true;
+			uniforms[ "tNormal" ].value = result.textures[ matJSON.parameters.normalMap ];
 
 
-				}
+			if ( matJSON.parameters.normalScale ) {
 
 
-				if ( matJSON.parameters.envMap ) {
+				uniforms[ "uNormalScale" ].value.set( matJSON.parameters.normalScale[ 0 ], matJSON.parameters.normalScale[ 1 ] );
 
 
-					uniforms[ "tCube" ].value = matJSON.parameters.envMap;
-					uniforms[ "enableReflection" ].value = true;
-					uniforms[ "uReflectivity" ].value = matJSON.parameters.reflectivity;
+			}
 
 
-				}
+			if ( matJSON.parameters.map ) {
 
 
-				if ( matJSON.parameters.lightMap ) {
+				uniforms[ "tDiffuse" ].value = matJSON.parameters.map;
+				uniforms[ "enableDiffuse" ].value = true;
 
 
-					uniforms[ "tAO" ].value = matJSON.parameters.lightMap;
-					uniforms[ "enableAO" ].value = true;
+			}
 
 
-				}
+			if ( matJSON.parameters.envMap ) {
 
 
-				if ( matJSON.parameters.specularMap ) {
+				uniforms[ "tCube" ].value = matJSON.parameters.envMap;
+				uniforms[ "enableReflection" ].value = true;
+				uniforms[ "uReflectivity" ].value = matJSON.parameters.reflectivity;
 
 
-					uniforms[ "tSpecular" ].value = result.textures[ matJSON.parameters.specularMap ];
-					uniforms[ "enableSpecular" ].value = true;
+			}
 
 
-				}
+			if ( matJSON.parameters.lightMap ) {
 
 
-				if ( matJSON.parameters.displacementMap ) {
+				uniforms[ "tAO" ].value = matJSON.parameters.lightMap;
+				uniforms[ "enableAO" ].value = true;
 
 
-					uniforms[ "tDisplacement" ].value = result.textures[ matJSON.parameters.displacementMap ];
-					uniforms[ "enableDisplacement" ].value = true;
+			}
 
 
-					uniforms[ "uDisplacementBias" ].value = matJSON.parameters.displacementBias;
-					uniforms[ "uDisplacementScale" ].value = matJSON.parameters.displacementScale;
+			if ( matJSON.parameters.specularMap ) {
 
 
-				}
+				uniforms[ "tSpecular" ].value = result.textures[ matJSON.parameters.specularMap ];
+				uniforms[ "enableSpecular" ].value = true;
 
 
-				uniforms[ "uDiffuseColor" ].value.setHex( diffuse );
-				uniforms[ "uSpecularColor" ].value.setHex( specular );
-				uniforms[ "uAmbientColor" ].value.setHex( ambient );
+			}
 
 
-				uniforms[ "uShininess" ].value = shininess;
+			if ( matJSON.parameters.displacementMap ) {
 
 
-				if ( matJSON.parameters.opacity ) {
+				uniforms[ "tDisplacement" ].value = result.textures[ matJSON.parameters.displacementMap ];
+				uniforms[ "enableDisplacement" ].value = true;
 
 
-					uniforms[ "uOpacity" ].value = matJSON.parameters.opacity;
+				uniforms[ "uDisplacementBias" ].value = matJSON.parameters.displacementBias;
+				uniforms[ "uDisplacementScale" ].value = matJSON.parameters.displacementScale;
 
 
-				}
+			}
 
 
-				var parameters = { fragmentShader: shader.fragmentShader, vertexShader: shader.vertexShader, uniforms: uniforms, lights: true, fog: true };
+			uniforms[ "uDiffuseColor" ].value.setHex( diffuse );
+			uniforms[ "uSpecularColor" ].value.setHex( specular );
+			uniforms[ "uAmbientColor" ].value.setHex( ambient );
 
 
-				material = new THREE.ShaderMaterial( parameters );
+			uniforms[ "uShininess" ].value = shininess;
 
 
-			} else {
+			if ( matJSON.parameters.opacity ) {
 
 
-				material = new THREE[ matJSON.type ]( matJSON.parameters );
+				uniforms[ "uOpacity" ].value = matJSON.parameters.opacity;
 
 
 			}
 			}
 
 
-			material.name = matID;
+			var parameters = { fragmentShader: shader.fragmentShader, vertexShader: shader.vertexShader, uniforms: uniforms, lights: true, fog: true };
 
 
-			result.materials[ matID ] = material;
+			material = new THREE.ShaderMaterial( parameters );
+
+		} else {
+
+			material = new THREE[ matJSON.type ]( matJSON.parameters );
 
 
 		}
 		}
 
 
-		// second pass through all materials to initialize MeshFaceMaterials
-		// that could be referring to other materials out of order
+		material.name = matID;
 
 
-		for ( matID in data.materials ) {
+		result.materials[ matID ] = material;
 
 
-			matJSON = data.materials[ matID ];
+	}
 
 
-			if ( matJSON.parameters.materials ) {
+	// second pass through all materials to initialize MeshFaceMaterials
+	// that could be referring to other materials out of order
 
 
-				var materialArray = [];
+	for ( matID in data.materials ) {
 
 
-				for ( var i = 0; i < matJSON.parameters.materials.length; i ++ ) {
+		matJSON = data.materials[ matID ];
 
 
-					var label = matJSON.parameters.materials[ i ];
-					materialArray.push( result.materials[ label ] );
+		if ( matJSON.parameters.materials ) {
 
 
-				}
+			var materialArray = [];
 
 
-				result.materials[ matID ].materials = materialArray;
+			for ( var i = 0; i < matJSON.parameters.materials.length; i ++ ) {
+
+				var label = matJSON.parameters.materials[ i ];
+				materialArray.push( result.materials[ label ] );
 
 
 			}
 			}
 
 
+			result.materials[ matID ].materials = materialArray;
+
 		}
 		}
 
 
-		// objects ( synchronous init of procedural primitives )
+	}
 
 
-		handle_objects();
+	// objects ( synchronous init of procedural primitives )
 
 
-		// defaults
+	handle_objects();
 
 
-		if ( result.cameras && data.defaults.camera ) {
+	// defaults
 
 
-			result.currentCamera = result.cameras[ data.defaults.camera ];
+	if ( result.cameras && data.defaults.camera ) {
 
 
-		}
+		result.currentCamera = result.cameras[ data.defaults.camera ];
 
 
-		if ( result.fogs && data.defaults.fog ) {
+	}
 
 
-			result.scene.fog = result.fogs[ data.defaults.fog ];
+	if ( result.fogs && data.defaults.fog ) {
 
 
-		}
+		result.scene.fog = result.fogs[ data.defaults.fog ];
 
 
-		// synchronous callback
+	}
 
 
-		scope.callbackSync( result );
+	// synchronous callback
 
 
-		// just in case there are no async elements
+	scope.callbackSync( result );
 
 
-		async_callback_gate();
+	// just in case there are no async elements
 
 
-	}
+	async_callback_gate();
 
 
-}
+};

+ 1 - 36
src/math/Math.js

@@ -1,45 +1,10 @@
 /**
 /**
  * @author alteredq / http://alteredqualia.com/
  * @author alteredq / http://alteredqualia.com/
- * @author mrdoob / http://mrdoob.com/
  */
  */
 
 
 THREE.Math = {
 THREE.Math = {
 
 
-	generateUUID: function () {
-
-		// http://www.broofa.com/Tools/Math.uuid.htm
-		
-		var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('');
-		var uuid = new Array(36);
-		var rnd = 0, r;
-
-		return function () {
-
-			for ( var i = 0; i < 36; i ++ ) {
-
-				if ( i == 8 || i == 13 || i == 18 || i == 23 ) {
-			
-					uuid[ i ] = '-';
-			
-				} else if ( i == 14 ) {
-			
-					uuid[ i ] = '4';
-			
-				} else {
-			
-					if (rnd <= 0x02) rnd = 0x2000000 + (Math.random()*0x1000000)|0;
-					r = rnd & 0xf;
-					rnd = rnd >> 4;
-					uuid[i] = chars[(i == 19) ? (r & 0x3) | 0x8 : r];
-
-				}
-			}
-			
-			return uuid.join('');
-
-		};
-
-	}(),
+	PI2: Math.PI * 2,
 
 
 	// Clamp value to range <a, b>
 	// Clamp value to range <a, b>
 
 

+ 97 - 0
utils/build/includes/common2.json

@@ -0,0 +1,97 @@
+[
+	"src/Three.js",
+	"src/math/Color.js",
+	"src/math/Quaternion.js",
+	"src/math/Vector2.js",
+	"src/math/Vector3.js",
+	"src/math/Vector4.js",
+	"src/math/Euler.js",
+	"src/math/Rotation.js",
+	"src/math/Box2.js",
+	"src/math/Box3.js",
+	"src/math/Matrix3.js",
+	"src/math/Matrix4.js",
+	"src/math/Ray.js",
+	"src/math/Sphere.js",
+	"src/math/Frustum.js",
+	"src/math/Plane.js",
+	"src/math/Math.js",
+	"src/math/Spline.js",
+	"src/math/Triangle.js",
+	"src/math/Vertex.js",
+	"src/math/UV.js",
+	"src/core/Clock.js",
+	"src/core/EventDispatcher.js",
+	"src/core/Raycaster.js",
+	"src/core/Object3D.js",
+	"src/core/Projector.js",
+	"src/core/Face3.js",
+	"src/core/Face4.js",
+	"src/core/Geometry.js",
+	"src/core/BufferGeometry.js",
+	"src/cameras/Camera.js",
+	"src/cameras/OrthographicCamera.js",
+	"src/cameras/PerspectiveCamera.js",
+	"src/lights/Light.js",
+	"src/lights/AmbientLight.js",
+	"src/lights/AreaLight.js",
+	"src/lights/DirectionalLight.js",
+	"src/lights/HemisphereLight.js",
+	"src/lights/PointLight.js",
+	"src/lights/SpotLight.js",
+	"src/loaders/Loader.js",
+	"src/loaders/ImageLoader.js",
+	"src/loaders/JSONLoader.js",
+	"src/loaders/LoadingMonitor.js",
+	"src/loaders/GeometryLoader.js",
+	"src/loaders/MaterialLoader.js",
+	"src/loaders/SceneLoader.js",
+	"src/loaders/TextureLoader.js",
+	"src/materials/Material.js",
+	"src/materials/LineBasicMaterial.js",
+	"src/materials/LineDashedMaterial.js",
+	"src/materials/MeshBasicMaterial.js",
+	"src/materials/MeshLambertMaterial.js",
+	"src/materials/MeshPhongMaterial.js",
+	"src/materials/MeshDepthMaterial.js",
+	"src/materials/MeshNormalMaterial.js",
+	"src/materials/MeshFaceMaterial.js",
+	"src/materials/ParticleBasicMaterial.js",
+	"src/materials/ParticleCanvasMaterial.js",
+	"src/materials/ShaderMaterial.js",
+	"src/materials/SpriteMaterial.js",
+	"src/textures/Texture.js",
+	"src/textures/CompressedTexture.js",
+	"src/textures/DataTexture.js",
+	"src/objects/Particle.js",
+	"src/objects/ParticleSystem.js",
+	"src/objects/Line.js",
+	"src/objects/Mesh.js",
+	"src/objects/Bone.js",
+	"src/objects/SkinnedMesh.js",
+	"src/objects/MorphAnimMesh.js",
+	"src/objects/Ribbon.js",
+	"src/objects/LOD.js",
+	"src/objects/Sprite.js",
+	"src/scenes/Scene.js",
+	"src/scenes/Fog.js",
+	"src/scenes/FogExp2.js",
+	"src/renderers/CanvasRenderer.js",
+	"src/renderers/WebGLShaders.js",
+	"src/renderers/WebGLRenderer2.js",
+	"src/renderers/webgl/LowLevelRenderer.js",
+	"src/renderers/webgl/ShaderBuilder.js",
+	"src/renderers/webgl/objects/Object3DRenderer.js",
+	"src/renderers/webgl/objects/MeshRenderer.js",
+	"src/renderers/webgl/objects/ParticleRenderer.js",
+	"src/renderers/webgl/objects/LineRenderer.js",
+	"src/renderers/webgl/objects/RibbonRenderer.js",
+	"src/renderers/WebGLRenderTarget.js",
+	"src/renderers/WebGLRenderTargetCube.js",
+	"src/renderers/renderables/RenderableVertex.js",
+	"src/renderers/renderables/RenderableFace3.js",
+	"src/renderers/renderables/RenderableFace4.js",
+	"src/renderers/renderables/RenderableObject.js",
+	"src/renderers/renderables/RenderableParticle.js",
+	"src/renderers/renderables/RenderableLine.js"
+]