浏览代码

Editor: Fixed sortable outliner.

Mr.doob 10 年之前
父节点
当前提交
98cea60a59
共有 2 个文件被更改,包括 17 次插入4 次删除
  1. 9 1
      editor/js/Editor.js
  2. 8 3
      editor/js/libs/ui.three.js

+ 9 - 1
editor/js/Editor.js

@@ -319,7 +319,7 @@ Editor.prototype = {
 
 
 	//
 	//
 
 
-	parent: function ( object, parent ) {
+	parent: function ( object, parent, after ) {
 
 
 		if ( parent === undefined ) {
 		if ( parent === undefined ) {
 
 
@@ -329,6 +329,14 @@ Editor.prototype = {
 
 
 		parent.add( object );
 		parent.add( object );
 
 
+		if ( after !== undefined ) {
+
+			var index = parent.children.indexOf( after );
+			parent.children.splice( index + 1, 0, object );
+			parent.children.pop();
+
+		}
+
 		this.signals.sceneGraphChanged.dispatch();
 		this.signals.sceneGraphChanged.dispatch();
 
 
 	},
 	},

+ 8 - 3
editor/js/libs/ui.three.js

@@ -151,9 +151,14 @@ UI.Outliner = function ( editor ) {
 	var sortable = Sortable.create( dom, {
 	var sortable = Sortable.create( dom, {
 		draggable: '.draggable',
 		draggable: '.draggable',
 		onUpdate: function ( event ) {
 		onUpdate: function ( event ) {
-			var object = scene.getObjectById( scope.options[ event.oldIndex ].value );
-			var preObject = scene.getObjectById( scope.options[ event.newIndex ].value );
-			editor.parent( object, preObject.parent );
+
+			var item = event.item;
+
+			var object = scene.getObjectById( item.value );
+			var prevObject = scene.getObjectById( item.previousSibling.value );
+
+			editor.parent( object, prevObject.parent, prevObject );
+
 		}
 		}
 	} );
 	} );