FitAll

by MS_DOS_86

HTML

<header>
		<title> three.js test </title>
		
		<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r71/three.min.js"></script>
		<script src="https://dl.dropboxusercontent.com/u/3587259/Code/Threejs/OrbitControls.js"></script>	
		<!--<script src="js/detector.js"></script>-->
	</header>
<script>
    //Detector for WebGLRenderer
    //if ( ! Detector.webgl ) Detector.addGetWebGLMessage();
			
			//Global Variables
			var camera, controls, scene, renderer;
			var aspectRatio = innerWidth / innerHeight;
			
			init();
			render();
			
			function animate() {
				requestAnimationFrame( animate );
				controls.update();
			}		
			
			function fitAll() {   
				var helper = new THREE.BoundingBoxHelper( scene );
					
				helper.update();
				//scene.add( helper );
				
				/*var height = helper.box.max.y;
				var width = helper.box.max.x - helper.box.min.x;
				var vertical_FOV = camera.fov * (Math.PI/ 180);
				var max_z = helper.box.max.z;
				var horizontal_FOV = 2 * Math.atan (Math.tan (vertical_FOV/2) * aspectRatio);
				var distance_vertical = height / (2 * Math.tan(vertical_FOV/2));
				var distance_horizontal = width / (2 * Math.tan(horizontal_FOV/2));
				var z_distance = distance_vertical >= distance_horizontal? distance_vertical : distance_horizontal;

				camera.position.z = z_distance + max_z;
				camera.position.y = 0 ;
				camera.position.x = 0;
				
				var fov = 2 * Math.atan( ( realHeight / (window.innerWidth / window.innerHeight) ) / ( 2 * distance )) * ( 180 / Math.PI );

				camera.fov = fov;
				camera.updateProjectionMatrix();*/
				
				//Scene Objects
				var obj, i;
				
				for ( i = scene.children.length - 1; i >= 0 ; i -- ) {
					obj = scene.children[ i ];
					console.log(obj);
					/*if ( obj !== plane && obj !== camera) {
						scene.remove(obj);
					}*/
				}
				
				// get the bounding sphere
				var boundingSphere = helper.box.getBoundingSphere();
				
				// calculate the distance from the center of the sphere
				// and...