Browse Source

Editor improvements and fixes.

Mr.doob 12 years ago
parent
commit
2c6fa8742d

+ 1 - 3
editor/index.html

@@ -151,8 +151,6 @@
 
 			var editor = new Editor();
 
-			var loader = new Loader( editor );
-
 			var viewport = new Viewport( editor );
 			viewport.setTop( '32px' );
 			viewport.setLeft( '0px' );
@@ -216,7 +214,7 @@
 				
 			} else {
 
-				loader.loadLocalStorage();
+				editor.loader.loadLocalStorage();
 
 			}
 

+ 2 - 0
editor/js/Editor.js

@@ -33,6 +33,8 @@ var Editor = function () {
 
 	};
 
+	this.loader = new Loader( this );
+
 	this.scene = new THREE.Scene();
 	this.sceneHelpers = new THREE.Scene();
 

+ 11 - 9
editor/js/Loader.js

@@ -13,14 +13,7 @@ var Loader = function ( editor ) {
 	document.addEventListener( 'drop', function ( event ) {
 
 		event.preventDefault();
-
-		var file = event.dataTransfer.files[ 0 ];
-
-		var chunks = file.name.split( '.' );
-		var extension = chunks.pop().toLowerCase();
-		var filename = chunks.join( '.' );
-
-		scope.parseFile( file, filename, extension );
+		scope.loadFile( event.dataTransfer.files[ 0 ] );
 
 	}, false );
 
@@ -57,7 +50,10 @@ var Loader = function ( editor ) {
 	signals.objectChanged.add( this.saveLocalStorage );
 	signals.objectRemoved.add( this.saveLocalStorage );
 
-	this.parseFile = function ( file, filename, extension ) {
+	this.loadFile = function ( file ) {
+
+		var filename = file.name;
+		var extension = filename.split( '.' ).pop().toLowerCase();
 
 		switch ( extension ) {
 
@@ -306,6 +302,12 @@ var Loader = function ( editor ) {
 
 				break;
 
+			default:
+
+				alert( 'Unsupported file format.' );
+
+				break;
+
 		}
 
 	}

+ 31 - 17
editor/js/Menubar.File.js

@@ -19,21 +19,11 @@ Menubar.File = function ( editor ) {
 	options.setDisplay( 'none' );
 	container.add( options );
 
-	/*
-	// open
+	// new
 
 	var option = new UI.Panel();
 	option.setClass( 'option' );
-	option.setTextContent( 'Open' );
-	option.onClick( function () { alert( 'Open' ) } );
-	options.add( option );
-	*/
-
-	// reset
-
-	var option = new UI.Panel();
-	option.setClass( 'option' );
-	option.setTextContent( 'Reset' );
+	option.setTextContent( 'New' );
 	option.onClick( function () {
 
 		if ( confirm( 'Are you sure?' ) ) {
@@ -54,16 +44,22 @@ Menubar.File = function ( editor ) {
 	options.add( new UI.HorizontalRule() );
 
 
-	// share
+	// import
+
+	var input = document.createElement( 'input' );
+	input.type = 'file';
+	input.addEventListener( 'change', function ( event ) {
+
+		editor.loader.loadFile( input.files[ 0 ] );
+
+	} );
 
 	var option = new UI.Panel();
 	option.setClass( 'option' );
-	option.setTextContent( 'Share' );
+	option.setTextContent( 'Import' );
 	option.onClick( function () {
 
-		var exporter = new THREE.ObjectExporter();
-		var string = JSON.stringify( exporter.parse( editor.scene ) );
-		window.location.hash = 'A/' + window.btoa( RawDeflate.deflate( string ) );
+		input.click();
 
 	} );
 	options.add( option );
@@ -201,6 +197,24 @@ Menubar.File = function ( editor ) {
 
 	};
 
+	options.add( new UI.HorizontalRule() );
+
+
+	// share
+
+	var option = new UI.Panel();
+	option.setClass( 'option' );
+	option.setTextContent( 'Share' );
+	option.onClick( function () {
+
+		var exporter = new THREE.ObjectExporter();
+		var string = JSON.stringify( exporter.parse( editor.scene ) );
+		window.location.hash = 'A/' + window.btoa( RawDeflate.deflate( string ) );
+
+	} );
+	options.add( option );
+
+
 	return container;
 
 }

+ 2 - 1
editor/js/Viewport.js

@@ -119,7 +119,8 @@ var Viewport = function ( editor ) {
 
 				if ( object.userData.object !== undefined ) {
 
-				
+					// helper
+
 					editor.select( object.userData.object );
 
 				} else {

+ 1 - 0
examples/js/controls/TransformControls.js

@@ -364,6 +364,7 @@ THREE.TransformControls = function ( camera, domElement, doc ) {
 	this.detach = function ( object ) {
 
 		this.object = undefined;
+		this.hovered = false;
 
 	 	this.hide();