Jelajahi Sumber

EditorControls: Clean up.

Mr.doob 7 tahun lalu
induk
melakukan
689306f470
1 mengubah file dengan 12 tambahan dan 18 penghapusan
  1. 12 18
      examples/js/controls/EditorControls.js

+ 12 - 18
examples/js/controls/EditorControls.js

@@ -37,35 +37,29 @@ THREE.EditorControls = function ( object, domElement ) {
 
 	this.focus = function ( target ) {
 
-		if ( target === undefined ) {
-			return;
-		}
-
 		var box = new THREE.Box3().setFromObject( target );
 
-		var targetDistance;
+		var distance;
 
-		if ( box.isEmpty() ) {
+		if ( box.isEmpty() === false ) {
 
-			// Focusing on an empty such as a light.
-
-			target.getWorldPosition( center );
-			targetDistance = 0.5;
+			center.copy( box.getCenter() );
+			distance = box.getBoundingSphere().radius;
 
 		} else {
 
-			center.copy( box.getCenter() );
-			targetDistance = box.getBoundingSphere().radius * 6;
-
-		}
+			// Focusing on an Group, AmbientLight, etc
 
-		var forwards = object.getWorldDirection().normalize();
+			center.setFromMatrixPosition( target.matrixWorld );
+			distance = 0.1;
 
-		var targetDelta = forwards.multiplyScalar( -targetDistance );
+		}
 
-		var targetWorldPosition = targetDelta.add( center );
+		var delta = new THREE.Vector3( 0, 0, 1 );
+		delta.applyQuaternion( object.quaternion );
+		delta.multiplyScalar( distance * 4 );
 
-		object.position.copy( targetWorldPosition );
+		object.position.copy( center ).add( delta );
 
 		scope.dispatchEvent( changeEvent );