Browse Source

Editor: Implemented localStorage. Thanks to @sole for the suggestion!

Mr.doob 12 years ago
parent
commit
33deb3be7e
3 changed files with 55 additions and 1 deletions
  1. 31 0
      editor/index.html
  2. 22 0
      editor/js/ui/Menubar.File.js
  3. 2 1
      editor/js/ui/Viewport.js

+ 31 - 0
editor/index.html

@@ -448,6 +448,37 @@
 
 
 			}
 			}
 
 
+			// localStorage
+
+			if ( localStorage.threejsEditor !== undefined ) {
+
+				var loader = new THREE.SceneLoader2();
+
+				var scene = loader.parse( JSON.parse( localStorage.threejsEditor ) );
+
+				while ( scene.children.length > 0 ) {
+
+					signals.objectAdded.dispatch( scene.children[ 0 ] );
+
+				}
+
+			}
+
+			var timeout;
+			var sceneExporter = new THREE.SceneExporter2();
+
+			signals.sceneChanged.add( function ( scene ) {
+
+				clearTimeout( timeout );
+
+				timeout = setTimeout( function () {
+
+					localStorage.threejsEditor = JSON.stringify( sceneExporter.parse( scene ) );
+
+				}, 5000 );
+
+			} );
+
 			//
 			//
 
 
 			var onWindowResize = function ( event ) {
 			var onWindowResize = function ( event ) {

+ 22 - 0
editor/js/ui/Menubar.File.js

@@ -25,6 +25,28 @@ Menubar.File = function ( signals ) {
 	options.add( option );
 	options.add( option );
 	*/
 	*/
 
 
+	// reset
+
+	var option = new UI.Panel();
+	option.setClass( 'option' );
+	option.setTextContent( 'Reset' );
+	option.onClick( function () {
+
+		if ( confirm( 'Are you sure?' ) ) {
+
+			if ( localStorage.threejsEditor !== undefined ) {
+
+				delete localStorage.threejsEditor;
+
+			}
+
+			location.reload();
+
+		}
+
+	} );
+	options.add( option );
+
 	// export geometry
 	// export geometry
 
 
 	var option = new UI.Panel();
 	var option = new UI.Panel();

+ 2 - 1
editor/js/ui/Viewport.js

@@ -338,6 +338,8 @@ var Viewport = function ( signals ) {
 
 
 		}
 		}
 
 
+		signals.sceneChanged.dispatch( scene );
+
 		render();
 		render();
 
 
 	} );
 	} );
@@ -349,7 +351,6 @@ var Viewport = function ( signals ) {
 		var object = selected.clone();
 		var object = selected.clone();
 
 
 		signals.objectAdded.dispatch( object );
 		signals.objectAdded.dispatch( object );
-		signals.objectSelected.dispatch( object );
 
 
 	} );
 	} );