Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Editor: Focus will frame target in view. #13165

Merged
merged 4 commits into from
Feb 27, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion examples/js/controls/EditorControls.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

};
Expand Down