Explorar o código

Editor: Moving delete shortcut handling outside of Viewport. Also showing Scene on top of scene graph.

Mr.doob %!s(int64=12) %!d(string=hai) anos
pai
achega
6f21b09b82
Modificáronse 3 ficheiros con 38 adicións e 48 borrados
  1. 15 3
      editor/index.html
  2. 19 16
      editor/js/ui/Sidebar.Scene.js
  3. 4 29
      editor/js/ui/Viewport.js

+ 15 - 3
editor/index.html

@@ -540,18 +540,30 @@
 
 			//
 
+			document.addEventListener( 'keydown', function ( event ) {
+
+				switch ( event.keyCode ) {
+
+					case 46: // delete
+
+						signals.removeSelectedObject.dispatch();
+
+						break;
+
+				}
+
+			}, false );
+
 			var onWindowResize = function ( event ) {
 
 				signals.windowResize.dispatch();
 
 			};
 
-			//
+			window.addEventListener( 'resize', onWindowResize, false );
 
 			onWindowResize();
 
-			window.addEventListener( 'resize', onWindowResize, false );
-
 		</script>
 	</body>
 </html>

+ 19 - 16
editor/js/ui/Sidebar.Scene.js

@@ -1,18 +1,5 @@
 Sidebar.Scene = function ( signals ) {
 
-	var objectTypes = {
-
-		'PerspectiveCamera': THREE.PerspectiveCamera,
-		'AmbientLight': THREE.AmbientLight,
-		'DirectionalLight': THREE.DirectionalLight,
-		'HemisphereLight': THREE.HemisphereLight,
-		'PointLight': THREE.PointLight,
-		'SpotLight': THREE.SpotLight,
-		'Mesh': THREE.Mesh,
-		'Object3D': THREE.Object3D
-
-	};
-
 	var selected = null;
 
 	var container = new UI.Panel();
@@ -96,9 +83,23 @@ Sidebar.Scene = function ( signals ) {
 
 	function getObjectType( object ) {
 
-		for ( var type in objectTypes ) {
+		var objects = {
+
+			'Scene': THREE.Scene,
+			'PerspectiveCamera': THREE.PerspectiveCamera,
+			'AmbientLight': THREE.AmbientLight,
+			'DirectionalLight': THREE.DirectionalLight,
+			'HemisphereLight': THREE.HemisphereLight,
+			'PointLight': THREE.PointLight,
+			'SpotLight': THREE.SpotLight,
+			'Mesh': THREE.Mesh,
+			'Object3D': THREE.Object3D
 
-			if ( object instanceof objectTypes[ type ] ) return type;
+		};
+
+		for ( var type in objects ) {
+
+			if ( object instanceof objects[ type ] ) return type;
 
 		}
 
@@ -161,6 +162,8 @@ Sidebar.Scene = function ( signals ) {
 
 		var options = {};
 
+		options[ scene.id ] = scene.name + ' <span style="color: #aaa">- ' + getObjectType( scene ) + '</span>';
+
 		( function addObjects( objects, pad ) {
 
 			for ( var i = 0, l = objects.length; i < l; i ++ ) {
@@ -173,7 +176,7 @@ Sidebar.Scene = function ( signals ) {
 
 			}
 
-		} )( scene.children, '' );
+		} )( scene.children, '&nbsp;&nbsp;&nbsp;' );
 
 		outliner.setOptions( options );
 

+ 4 - 29
editor/js/ui/Viewport.js

@@ -196,26 +196,6 @@ var Viewport = function ( signals ) {
 
 	};
 
-	var onKeyDown = function ( event ) {
-
-		switch ( event.keyCode ) {
-
-			case 27: // esc
-
-				signals.toggleHelpers.dispatch();
-
-				break;
-
-			case 46: // delete
-
-				signals.removeSelectedObject.dispatch();
-
-				break;
-
-		}
-
-	};
-
 	container.dom.addEventListener( 'mousedown', onMouseDown, false );
 	container.dom.addEventListener( 'click', onClick, false );
 
@@ -389,12 +369,14 @@ var Viewport = function ( signals ) {
 
 	signals.removeSelectedObject.add( function () {
 
-		if ( selected === camera ) return;
+		if ( selected.parent === undefined ) return;
 
 		var name = selected.name ?  '"' + selected.name + '"': "selected object";
 
 		if ( confirm( 'Delete ' + name + '?' ) === false ) return;
 
+		var parent = selected.parent;
+
 		if ( selected instanceof THREE.Light ) {
 
 			var helper = objectsToHelpers[ selected.id ];
@@ -435,7 +417,7 @@ var Viewport = function ( signals ) {
 		}
 
 		signals.sceneChanged.dispatch( scene );
-		signals.objectSelected.dispatch( null );
+		signals.objectSelected.dispatch( parent );
 
 	} );
 
@@ -570,13 +552,6 @@ var Viewport = function ( signals ) {
 
 	animate();
 
-	// set up for hotkeys
-	// must be done here, otherwise it doesn't work
-
-	container.dom.tabIndex = 1;
-	container.dom.style.outline = 'transparent';
-	container.dom.addEventListener( 'keydown', onKeyDown, false );
-
 	// must come after listeners are registered
 
 	signals.sceneChanged.dispatch( scene );