From 990b43a2ca0eb9cac272d7656bb2fbaa18694de1 Mon Sep 17 00:00:00 2001 From: "Mr.doob" Date: Sun, 7 Sep 2014 18:57:47 -0400 Subject: [PATCH] Editor: Focus object on double click in scene inspector. --- editor/js/Editor.js | 39 +++++++++++++++++++++----------------- editor/js/Sidebar.Scene.js | 5 +++++ editor/js/Viewport.js | 14 +++++++++++--- editor/js/libs/ui.js | 2 +- src/core/Object3D.js | 38 ++++++++++--------------------------- 5 files changed, 49 insertions(+), 49 deletions(-) diff --git a/editor/js/Editor.js b/editor/js/Editor.js index 4fcd6744fb..e3ebb66cae 100644 --- a/editor/js/Editor.js +++ b/editor/js/Editor.js @@ -32,6 +32,8 @@ var Editor = function () { geometryChanged: new SIGNALS.Signal(), objectSelected: new SIGNALS.Signal(), + objectFocused: new SIGNALS.Signal(), + objectAdded: new SIGNALS.Signal(), objectChanged: new SIGNALS.Signal(), objectRemoved: new SIGNALS.Signal(), @@ -283,35 +285,26 @@ Editor.prototype = { select: function ( object ) { - this.selected = object; - - if ( object !== null ) { + if ( this.selected === object ) return; - this.config.setKey( 'selected', object.uuid ); + var uuid = null; - } else { + if ( object !== null ) { - this.config.setKey( 'selected', null ); + uuid = object.uuid; } + this.selected = object; + + this.config.setKey( 'selected', uuid ); this.signals.objectSelected.dispatch( object ); }, selectById: function ( id ) { - var scope = this; - - this.scene.traverse( function ( child ) { - - if ( child.id === id ) { - - scope.select( child ); - - } - - } ); + this.select( this.scene.getObjectById( id, true ) ); }, @@ -335,6 +328,18 @@ Editor.prototype = { this.select( null ); + }, + + focus: function ( object ) { + + this.signals.objectFocused.dispatch( object ); + + }, + + focusById: function ( id ) { + + this.focus( this.scene.getObjectById( id, true ) ); + } } diff --git a/editor/js/Sidebar.Scene.js b/editor/js/Sidebar.Scene.js index 51cf3092d3..d6f600cdce 100644 --- a/editor/js/Sidebar.Scene.js +++ b/editor/js/Sidebar.Scene.js @@ -24,6 +24,11 @@ Sidebar.Scene = function ( editor ) { ignoreObjectSelectedSignal = false; + } ); + outliner.onDblClick( function () { + + editor.focusById( parseInt( outliner.getValue() ) ); + } ); container.add( outliner ); container.add( new UI.Break() ); diff --git a/editor/js/Viewport.js b/editor/js/Viewport.js index 69ec7829e2..9db1179d79 100644 --- a/editor/js/Viewport.js +++ b/editor/js/Viewport.js @@ -149,9 +149,11 @@ var Viewport = function ( editor ) { var intersects = getIntersects( event, objects ); - if ( intersects.length > 0 && intersects[ 0 ].object === editor.selected ) { + if ( intersects.length > 0 ) { - controls.focus( editor.selected ); + var intersect = intersects[ 0 ]; + + signals.objectFocused.dispatch( intersect.object ); } @@ -164,7 +166,7 @@ var Viewport = function ( editor ) { // otherwise controls.enabled doesn't work. var controls = new THREE.EditorControls( camera, container.dom ); - controls.center.fromArray( editor.config.getKey( 'camera/target' ) ) + controls.center.fromArray( editor.config.getKey( 'camera/target' ) ); controls.addEventListener( 'change', function () { transformControls.update(); @@ -283,6 +285,12 @@ var Viewport = function ( editor ) { } ); + signals.objectFocused.add( function ( object ) { + + controls.focus( object ); + + } ); + signals.geometryChanged.add( render ); signals.objectAdded.add( function ( object ) { diff --git a/editor/js/libs/ui.js b/editor/js/libs/ui.js index 61ddfe71eb..df6644aad9 100644 --- a/editor/js/libs/ui.js +++ b/editor/js/libs/ui.js @@ -69,7 +69,7 @@ properties.forEach( function ( property ) { // events -var events = [ 'KeyUp', 'KeyDown', 'MouseOver', 'MouseOut', 'Click', 'Change' ]; +var events = [ 'KeyUp', 'KeyDown', 'MouseOver', 'MouseOut', 'Click', 'DblClick', 'Change' ]; events.forEach( function ( event ) { diff --git a/src/core/Object3D.js b/src/core/Object3D.js index 196e6b5ec7..897df8eba3 100644 --- a/src/core/Object3D.js +++ b/src/core/Object3D.js @@ -404,25 +404,16 @@ THREE.Object3D.prototype = { getObjectById: function ( id, recursive ) { + if ( this.id === id ) return this; + for ( var i = 0, l = this.children.length; i < l; i ++ ) { var child = this.children[ i ]; + var object = child.getObjectById( id, recursive ); - if ( child.id === id ) { - - return child; - - } - - if ( recursive === true ) { + if ( object !== undefined ) { - child = child.getObjectById( id, recursive ); - - if ( child !== undefined ) { - - return child; - - } + return object; } @@ -434,25 +425,16 @@ THREE.Object3D.prototype = { getObjectByName: function ( name, recursive ) { + if ( this.name === name ) return this; + for ( var i = 0, l = this.children.length; i < l; i ++ ) { var child = this.children[ i ]; + var object = child.getObjectByName( name, recursive ); - if ( child.name === name ) { - - return child; - - } - - if ( recursive === true ) { + if ( object !== undefined ) { - child = child.getObjectByName( name, recursive ); - - if ( child !== undefined ) { - - return child; - - } + return object; } -- GitLab