Browse Source

Editor: Added .parent() and fixed .removeObject().

Mr.doob 12 years ago
parent
commit
d97324a27f
5 changed files with 44 additions and 38 deletions
  1. 21 1
      editor/js/Editor.js
  2. 2 3
      editor/js/Loader.js
  3. 10 23
      editor/js/Sidebar.Object3D.js
  4. 2 5
      editor/js/Sidebar.Scene.js
  5. 9 6
      editor/js/Viewport.js

+ 21 - 1
editor/js/Editor.js

@@ -14,6 +14,8 @@ var Editor = function () {
 		snapChanged: new SIGNALS.Signal(),
 		rendererChanged: new SIGNALS.Signal(),
 
+		sceneGraphChanged: new SIGNALS.Signal(),
+
 		objectSelected: new SIGNALS.Signal(),
 		objectAdded: new SIGNALS.Signal(),
 		objectChanged: new SIGNALS.Signal(),
@@ -67,6 +69,7 @@ Editor.prototype = {
 		this.addHelper( object );
 
 		this.signals.objectAdded.dispatch( object );
+		this.signals.sceneGraphChanged.dispatch();
 
 	},
 
@@ -76,10 +79,11 @@ Editor.prototype = {
 
 		if ( confirm( 'Delete ' + object.name + '?' ) === false ) return;
 
-		this.scene.remove( object );
+		object.parent.remove( object );
 		this.removeHelper( object );
 
 		this.signals.objectRemoved.dispatch( object );
+		this.signals.sceneGraphChanged.dispatch();
 
 	},
 
@@ -166,6 +170,22 @@ Editor.prototype = {
 
 	//
 
+	parent: function ( object, parent ) {
+
+		if ( parent === undefined ) {
+
+			parent = this.scene;
+
+		}
+
+		parent.add( object );
+
+		this.signals.sceneGraphChanged.dispatch();
+
+	},
+
+	//
+
 	select: function ( object ) {
 
 		this.selected = object;

+ 2 - 3
editor/js/Loader.js

@@ -37,6 +37,7 @@ var Loader = function ( editor ) {
 
 	};
 
+	var exporter = new THREE.ObjectExporter();
 	var timeout;
 
 	this.saveLocalStorage = function ( scene ) {
@@ -45,10 +46,8 @@ var Loader = function ( editor ) {
 
 		timeout = setTimeout( function () {
 
-			var exporter = new THREE.ObjectExporter();
 			localStorage.threejsEditor = JSON.stringify( exporter.parse( editor.scene ) );
-
-			console.log( 'Saved state to Local Storage' );
+			console.log( '[' + /\d\d\:\d\d\:\d\d/.exec( new Date() )[ 0 ] + ']', 'Saved state to LocalStorage.' );
 
 		}, 3000 );
 

+ 10 - 23
editor/js/Sidebar.Object3D.js

@@ -281,17 +281,7 @@ Sidebar.Object3D = function ( editor ) {
 
 				if ( object.parent.id !== newParentId && object.id !== newParentId ) {
 
-					var parent = scene.getObjectById( newParentId, true );
-
-					if ( parent === undefined ) {
-
-						parent = scene;
-
-					}
-
-					parent.add( object );
-
-					signals.sceneChanged.dispatch();
+					editor.parent( object, editor.scene.getObjectById( newParentId, true ) );
 
 				}
 
@@ -450,7 +440,15 @@ Sidebar.Object3D = function ( editor ) {
 
 	}
 
-	var updateObjectParent = function () {
+	// events
+
+	signals.objectSelected.add( function ( object ) {
+
+		updateUI();
+
+	} );
+
+	signals.sceneGraphChanged.add( function () {
 
 		var scene = editor.scene;
 
@@ -474,19 +472,8 @@ Sidebar.Object3D = function ( editor ) {
 
 		objectParent.setOptions( options );
 
-	};
-
-	// events
-
-	signals.objectSelected.add( function ( object ) {
-
-		updateUI();
-
 	} );
 
-	signals.objectAdded.add( updateObjectParent );
-	signals.objectRemoved.add( updateObjectParent );
-
 	signals.objectChanged.add( function ( object ) {
 
 		if ( object !== editor.selected ) return;

+ 2 - 5
editor/js/Sidebar.Scene.js

@@ -146,7 +146,7 @@ Sidebar.Scene = function ( editor ) {
 
 	// events
 
-	var updateUI = function () {
+	signals.sceneGraphChanged.add( function () {
 
 		var scene = editor.scene;
 
@@ -196,10 +196,7 @@ Sidebar.Scene = function ( editor ) {
 
 		refreshFogUI();
 
-	};
-
-	signals.objectAdded.add( updateUI );
-	signals.objectRemoved.add( updateUI );
+	} );
 
 	signals.objectSelected.add( function ( object ) {
 

+ 9 - 6
editor/js/Viewport.js

@@ -119,11 +119,13 @@ var Viewport = function ( editor ) {
 
 				editor.select( object );
 
+				/*
 				if ( helpersToObjects[ object.id ] !== undefined ) {
 
 					editor.select( helpersToObjects[ object.id ] );
 
 				}
+				*/
 
 			} else {
 
@@ -205,6 +207,13 @@ var Viewport = function ( editor ) {
 
 	} );
 
+	signals.sceneGraphChanged.add( function () {
+
+		render();
+		updateInfo();
+
+	} );
+
 	signals.objectSelected.add( function ( object ) {
 
 		selectionBox.visible = false;
@@ -241,9 +250,6 @@ var Viewport = function ( editor ) {
 
 		}
 
-		render();
-		updateInfo();
-
 	} );
 
 	signals.objectChanged.add( function ( object ) {
@@ -274,9 +280,6 @@ var Viewport = function ( editor ) {
 
 		}
 
-		render();
-		updateInfo();
-
 	} );
 
 	signals.materialChanged.add( function ( material ) {