Browse Source

Editor: Avoid duplicate code in RemoveObjectCommand.

Mugen87 5 years ago
parent
commit
9ad12de1c7
2 changed files with 14 additions and 30 deletions
  1. 11 2
      editor/js/Editor.js
  2. 3 28
      editor/js/commands/RemoveObjectCommand.js

+ 11 - 2
editor/js/Editor.js

@@ -144,7 +144,7 @@ Editor.prototype = {
 
 	//
 
-	addObject: function ( object ) {
+	addObject: function ( object, parent, index ) {
 
 		var scope = this;
 
@@ -158,7 +158,16 @@ Editor.prototype = {
 
 		} );
 
-		this.scene.add( object );
+		if ( parent === undefined ) {
+
+			this.scene.add( object );
+
+		} else {
+
+			parent.children.splice( index, 0, object );
+			object.parent = parent;
+
+		}
 
 		this.signals.objectAdded.dispatch( object );
 		this.signals.sceneGraphChanged.dispatch();

+ 3 - 28
editor/js/commands/RemoveObjectCommand.js

@@ -33,41 +33,16 @@ RemoveObjectCommand.prototype = {
 
 	execute: function () {
 
-		var scope = this.editor;
-		this.object.traverse( function ( child ) {
-
-			scope.removeHelper( child );
-
-		} );
-
-		this.parent.remove( this.object );
-		this.editor.select( this.parent );
-
-		this.editor.signals.objectRemoved.dispatch( this.object );
-		this.editor.signals.sceneGraphChanged.dispatch();
+		this.editor.removeObject( this.object );
+		this.editor.deselect();
 
 	},
 
 	undo: function () {
 
-		var scope = this.editor;
-
-		this.object.traverse( function ( child ) {
-
-			if ( child.geometry !== undefined ) scope.addGeometry( child.geometry );
-			if ( child.material !== undefined ) scope.addMaterial( child.material );
-
-			scope.addHelper( child );
-
-		} );
-
-		this.parent.children.splice( this.index, 0, this.object );
-		this.object.parent = this.parent;
+		this.editor.addObject( this.object, this.parent, this.index );
 		this.editor.select( this.object );
 
-		this.editor.signals.objectAdded.dispatch( this.object );
-		this.editor.signals.sceneGraphChanged.dispatch();
-
 	},
 
 	toJSON: function () {