Browse Source

Editor: Focus object on double click in scene inspector.

Mr.doob 11 years ago
parent
commit
990b43a2ca
5 changed files with 49 additions and 49 deletions
  1. 22 17
      editor/js/Editor.js
  2. 5 0
      editor/js/Sidebar.Scene.js
  3. 11 3
      editor/js/Viewport.js
  4. 1 1
      editor/js/libs/ui.js
  5. 10 28
      src/core/Object3D.js

+ 22 - 17
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 ) );
+
 	}
 
 }

+ 5 - 0
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() );

+ 11 - 3
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 ) {

+ 1 - 1
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 ) {
 

+ 10 - 28
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;
 
 			}