Browse Source

Editor: Improved outliner.
Dragging a parent as a child of a child breaks things though :(

Mr.doob 10 years ago
parent
commit
6551bbaca7
2 changed files with 16 additions and 6 deletions
  1. 6 4
      editor/js/Editor.js
  2. 10 2
      editor/js/libs/ui.three.js

+ 6 - 4
editor/js/Editor.js

@@ -319,7 +319,7 @@ Editor.prototype = {
 
 	//
 
-	parent: function ( object, parent, after ) {
+	parent: function ( object, parent, before ) {
 
 		if ( parent === undefined ) {
 
@@ -329,10 +329,12 @@ Editor.prototype = {
 
 		parent.add( object );
 
-		if ( after !== undefined ) {
+		// sort children array
 
-			var index = parent.children.indexOf( after );
-			parent.children.splice( index + 1, 0, object );
+		if ( before !== undefined ) {
+
+			var index = parent.children.indexOf( before );
+			parent.children.splice( index, 0, object );
 			parent.children.pop();
 
 		}

+ 10 - 2
editor/js/libs/ui.three.js

@@ -155,9 +155,17 @@ UI.Outliner = function ( editor ) {
 			var item = event.item;
 
 			var object = scene.getObjectById( item.value );
-			var prevObject = scene.getObjectById( item.previousSibling.value );
 
-			editor.parent( object, prevObject.parent, prevObject );
+			if ( item.nextSibling === null ) {
+
+				editor.parent( object, editor.scene );
+
+			} else {
+
+				var nextObject = scene.getObjectById( item.nextSibling.value );
+				editor.parent( object, nextObject.parent, nextObject );
+
+			}
 
 		}
 	} );