未验证 提交 06649938 编写于 作者: M Mr.doob 提交者: GitHub

Merge pull request #18460 from Mugen87/dev32

Editor: Avoid duplicated code in RemoveObjectCommand.
...@@ -144,7 +144,7 @@ Editor.prototype = { ...@@ -144,7 +144,7 @@ Editor.prototype = {
// //
addObject: function ( object ) { addObject: function ( object, parent, index ) {
var scope = this; var scope = this;
...@@ -158,7 +158,16 @@ Editor.prototype = { ...@@ -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.objectAdded.dispatch( object );
this.signals.sceneGraphChanged.dispatch(); this.signals.sceneGraphChanged.dispatch();
......
...@@ -33,41 +33,16 @@ RemoveObjectCommand.prototype = { ...@@ -33,41 +33,16 @@ RemoveObjectCommand.prototype = {
execute: function () { execute: function () {
var scope = this.editor; this.editor.removeObject( this.object );
this.object.traverse( function ( child ) { this.editor.deselect();
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();
}, },
undo: function () { undo: function () {
var scope = this.editor; this.editor.addObject( this.object, this.parent, this.index );
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.select( this.object ); this.editor.select( this.object );
this.editor.signals.objectAdded.dispatch( this.object );
this.editor.signals.sceneGraphChanged.dispatch();
}, },
toJSON: function () { toJSON: function () {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册