Ver código fonte

EditorControls: Improved and simplified focus.

Mr.doob 8 anos atrás
pai
commit
7d0fe11d67
1 arquivos alterados com 3 adições e 16 exclusões
  1. 3 16
      examples/js/controls/EditorControls.js

+ 3 - 16
examples/js/controls/EditorControls.js

@@ -35,23 +35,10 @@ THREE.EditorControls = function ( object, domElement ) {
 
 	var changeEvent = { type: 'change' };
 
-	this.focus = function ( target, frame ) {
-
-		var scale = new THREE.Vector3();
-		target.matrixWorld.decompose( center, new THREE.Quaternion(), scale );
-
-		if ( frame && target.geometry ) {
-
-			scale = ( scale.x + scale.y + scale.z ) / 3;
-			center.add( target.geometry.boundingSphere.center.clone().multiplyScalar( scale ) );
-			var radius = target.geometry.boundingSphere.radius * ( scale );
-			var pos = object.position.clone().sub( center ).normalize().multiplyScalar( radius * 2 );
-			object.position.copy( center ).add( pos );
-
-		}
-
-		object.lookAt( center );
+	this.focus = function ( target ) {
 
+		var box = new THREE.Box3().setFromObject( target );
+		object.lookAt( center.copy( box.getCenter() ) );
 		scope.dispatchEvent( changeEvent );
 
 	};