提交 990b43a2 编写于 作者: M Mr.doob

Editor: Focus object on double click in scene inspector.

上级 19213aba
...@@ -32,6 +32,8 @@ var Editor = function () { ...@@ -32,6 +32,8 @@ var Editor = function () {
geometryChanged: new SIGNALS.Signal(), geometryChanged: new SIGNALS.Signal(),
objectSelected: new SIGNALS.Signal(), objectSelected: new SIGNALS.Signal(),
objectFocused: new SIGNALS.Signal(),
objectAdded: new SIGNALS.Signal(), objectAdded: new SIGNALS.Signal(),
objectChanged: new SIGNALS.Signal(), objectChanged: new SIGNALS.Signal(),
objectRemoved: new SIGNALS.Signal(), objectRemoved: new SIGNALS.Signal(),
...@@ -283,35 +285,26 @@ Editor.prototype = { ...@@ -283,35 +285,26 @@ Editor.prototype = {
select: function ( object ) { select: function ( object ) {
this.selected = object; if ( this.selected === object ) return;
if ( object !== null ) {
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 ); this.signals.objectSelected.dispatch( object );
}, },
selectById: function ( id ) { selectById: function ( id ) {
var scope = this; this.select( this.scene.getObjectById( id, true ) );
this.scene.traverse( function ( child ) {
if ( child.id === id ) {
scope.select( child );
}
} );
}, },
...@@ -335,6 +328,18 @@ Editor.prototype = { ...@@ -335,6 +328,18 @@ Editor.prototype = {
this.select( null ); this.select( null );
},
focus: function ( object ) {
this.signals.objectFocused.dispatch( object );
},
focusById: function ( id ) {
this.focus( this.scene.getObjectById( id, true ) );
} }
} }
...@@ -24,6 +24,11 @@ Sidebar.Scene = function ( editor ) { ...@@ -24,6 +24,11 @@ Sidebar.Scene = function ( editor ) {
ignoreObjectSelectedSignal = false; ignoreObjectSelectedSignal = false;
} );
outliner.onDblClick( function () {
editor.focusById( parseInt( outliner.getValue() ) );
} ); } );
container.add( outliner ); container.add( outliner );
container.add( new UI.Break() ); container.add( new UI.Break() );
......
...@@ -149,9 +149,11 @@ var Viewport = function ( editor ) { ...@@ -149,9 +149,11 @@ var Viewport = function ( editor ) {
var intersects = getIntersects( event, objects ); 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 ) { ...@@ -164,7 +166,7 @@ var Viewport = function ( editor ) {
// otherwise controls.enabled doesn't work. // otherwise controls.enabled doesn't work.
var controls = new THREE.EditorControls( camera, container.dom ); 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 () { controls.addEventListener( 'change', function () {
transformControls.update(); transformControls.update();
...@@ -283,6 +285,12 @@ var Viewport = function ( editor ) { ...@@ -283,6 +285,12 @@ var Viewport = function ( editor ) {
} ); } );
signals.objectFocused.add( function ( object ) {
controls.focus( object );
} );
signals.geometryChanged.add( render ); signals.geometryChanged.add( render );
signals.objectAdded.add( function ( object ) { signals.objectAdded.add( function ( object ) {
......
...@@ -69,7 +69,7 @@ properties.forEach( function ( property ) { ...@@ -69,7 +69,7 @@ properties.forEach( function ( property ) {
// events // events
var events = [ 'KeyUp', 'KeyDown', 'MouseOver', 'MouseOut', 'Click', 'Change' ]; var events = [ 'KeyUp', 'KeyDown', 'MouseOver', 'MouseOut', 'Click', 'DblClick', 'Change' ];
events.forEach( function ( event ) { events.forEach( function ( event ) {
......
...@@ -404,25 +404,16 @@ THREE.Object3D.prototype = { ...@@ -404,25 +404,16 @@ THREE.Object3D.prototype = {
getObjectById: function ( id, recursive ) { getObjectById: function ( id, recursive ) {
if ( this.id === id ) return this;
for ( var i = 0, l = this.children.length; i < l; i ++ ) { for ( var i = 0, l = this.children.length; i < l; i ++ ) {
var child = this.children[ i ]; var child = this.children[ i ];
var object = child.getObjectById( id, recursive );
if ( child.id === id ) { if ( object !== undefined ) {
return child;
}
if ( recursive === true ) {
child = child.getObjectById( id, recursive ); return object;
if ( child !== undefined ) {
return child;
}
} }
...@@ -434,25 +425,16 @@ THREE.Object3D.prototype = { ...@@ -434,25 +425,16 @@ THREE.Object3D.prototype = {
getObjectByName: function ( name, recursive ) { getObjectByName: function ( name, recursive ) {
if ( this.name === name ) return this;
for ( var i = 0, l = this.children.length; i < l; i ++ ) { for ( var i = 0, l = this.children.length; i < l; i ++ ) {
var child = this.children[ i ]; var child = this.children[ i ];
var object = child.getObjectByName( name, recursive );
if ( child.name === name ) { if ( object !== undefined ) {
return child;
}
if ( recursive === true ) {
child = child.getObjectByName( name, recursive ); return object;
if ( child !== undefined ) {
return child;
}
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册