2
0
Эх сурвалжийг харах

Merge pull request #13165 from Adam4lexander/focus-frames-target

Editor: Focus will frame target in view.
Mr.doob 7 жил өмнө
parent
commit
0a7fb46434

+ 29 - 1
examples/js/controls/EditorControls.js

@@ -37,8 +37,36 @@ THREE.EditorControls = function ( object, domElement ) {
 
 	this.focus = function ( target ) {
 
+		if ( target === undefined ) {
+			return;
+		}
+
 		var box = new THREE.Box3().setFromObject( target );
-		object.lookAt( center.copy( box.getCenter() ) );
+
+		var targetDistance;
+
+		if ( box.isEmpty() ) {
+
+			// Focusing on an empty such as a light.
+
+			target.getWorldPosition( center );
+			targetDistance = 0.5;
+
+		} else {
+
+			center.copy( box.getCenter() );
+			targetDistance = box.getBoundingSphere().radius * 6;
+
+		}
+
+		var forwards = object.getWorldDirection().normalize();
+
+		var targetDelta = forwards.multiplyScalar( -targetDistance );
+
+		var targetWorldPosition = targetDelta.add( center );
+
+		object.position.copy( targetWorldPosition );
+
 		scope.dispatchEvent( changeEvent );
 
 	};