Browse Source

Fix sceneeditor (#169)

* Fix Copy Paste multiple objects
* Fix reorder children when Delete then Ctrl+Z
* Consistent param name for addElements and deleteElements
Jed974 4 years ago
parent
commit
33a5e0ae89
3 changed files with 9 additions and 12 deletions
  1. 4 4
      hide/comp/SceneEditor.hx
  2. 3 4
      hide/prefab/SplineEditor.hx
  3. 2 4
      hrt/prefab/l3d/MeshSpray.hx

+ 4 - 4
hide/comp/SceneEditor.hx

@@ -1339,7 +1339,7 @@ class SceneEditor {
 			lastRenderProps.applyProps(scene.s3d.renderer);
 	}
 
-	public function addElements(elts : Array<PrefabElement>, selectObj : Bool = true, doRefresh : Bool = true, isTemporary = false) {
+	public function addElements(elts : Array<PrefabElement>, selectObj : Bool = true, doRefresh : Bool = true, enableUndo = true) {
 		for (e in elts) {
 			makeInstance(e);
 		}
@@ -1347,7 +1347,7 @@ class SceneEditor {
 			refresh(Partial, if (selectObj) () -> selectElements(elts, NoHistory) else null);
 			refreshParents(elts);
 		}
-		if( isTemporary )
+		if( !enableUndo )
 			return;
 
 		undo.change(Custom(function(undo) {
@@ -1767,7 +1767,7 @@ class SceneEditor {
 				var lib = hrt.prefab.Prefab.loadPrefab(obj);
 				for(c in lib.children) {
 					autoName(c);
-					c.parent = parent;
+					parent.children.push(c);
 				}
 				addElements(lib.children);
 			}
@@ -1991,7 +1991,7 @@ class SceneEditor {
 				fullRefresh = true;
 			var index = elt.parent.children.indexOf(elt);
 			elt.parent.children.remove(elt);
-			undoes.push(function(undo) {
+			undoes.unshift(function(undo) {
 				if(undo) elt.parent.children.insert(index, elt);
 				else elt.parent.children.remove(elt);
 			});

+ 3 - 4
hide/prefab/SplineEditor.hx

@@ -262,12 +262,11 @@ class SplineEditor {
 			sp.rotationX = h3d.Matrix.lookAtX(dir).getFloats()[0];
 			sp.rotationY = h3d.Matrix.lookAtX(dir).getFloats()[1];
 			sp.rotationZ = h3d.Matrix.lookAtX(dir).getFloats()[2];
-			
 		}
 		sp.scaleX = scale;
 		sp.scaleY = scale;
 		sp.scaleZ = scale;
-		editContext.scene.editor.addElements([sp], false, true, true);
+		editContext.scene.editor.addElements([sp], false, true, false);
 
 		prefab.updateInstance(ctx);
 		showViewers();
@@ -456,7 +455,7 @@ class SplineEditor {
 						for (sp in prefab.points)
 							sp.computeName(editContext.getContext(sp));
 						@:privateAccess editContext.scene.editor.refresh(Partial);
-						
+
 						prefab.updateInstance(ctx);
 						showViewers();
 						createGizmos(ctx);
@@ -464,7 +463,7 @@ class SplineEditor {
 						undo.change(Custom(function(undo) {
 							if( undo ) {
 								prefab.children.insert(index, sp);
-								editContext.scene.editor.addElements([sp], false, true, true);
+								editContext.scene.editor.addElements([sp], false, true, false);
 								prefab.updateInstance(ctx);
 								showViewers();
 								createGizmos(ctx);

+ 2 - 4
hrt/prefab/l3d/MeshSpray.hx

@@ -694,12 +694,11 @@ class MeshSpray extends Object3D {
 						sceneEditor.deleteElements(addedModels, () -> removeInteractiveBrush(), true, false);
 					}
 					else {
-						sceneEditor.addElements(addedModels, false, true, true);
+						sceneEditor.addElements(addedModels, false, true, false);
 					}
 				}));
 				sprayedModels = [];
 			}
-			
 
 			if (previewModels.length > 0) {
 				sceneEditor.deleteElements(previewModels, () -> { }, false);
@@ -916,7 +915,7 @@ class MeshSpray extends Object3D {
 			}
 
 			if (previewModels.length > 0) {
-				sceneEditor.addElements(previewModels, false, false, true);
+				sceneEditor.addElements(previewModels, false, false, false);
 			}
 		}
 	}
@@ -945,7 +944,6 @@ class MeshSpray extends Object3D {
 					childToRemove.push(child);
 				}
 			}
-			
 		}
 		if (childToRemove.length > 0) {
 			wasEdited = true;