浏览代码

Make focusing only move the camera the first time (#194)

Focusing a second time without changing the selection will change the
scale too.
Note that this currently applies to all ways of focusing on an element (keyboard
shortcut "F", double click in the scene tree and double click on the
element in the scene view)
Leonardo Jeanteur 4 年之前
父节点
当前提交
0dd47c8725
共有 1 个文件被更改,包括 17 次插入2 次删除
  1. 17 2
      hide/comp/SceneEditor.hx

+ 17 - 2
hide/comp/SceneEditor.hx

@@ -169,6 +169,8 @@ class SceneEditor {
 	var sceneData : PrefabElement;
 	var sceneData : PrefabElement;
 	var lastRenderProps : hrt.prefab.RenderProps;
 	var lastRenderProps : hrt.prefab.RenderProps;
 
 
+	var focusedSinceSelect = false;
+
 	public function new(view, data) {
 	public function new(view, data) {
 		ide = hide.Ide.inst;
 		ide = hide.Ide.inst;
 		this.view = view;
 		this.view = view;
@@ -325,7 +327,8 @@ class SceneEditor {
 			}
 			}
 			if(!bnds.isEmpty()) {
 			if(!bnds.isEmpty()) {
 				var s = bnds.toSphere();
 				var s = bnds.toSphere();
-				cameraController.set(s.r * 4.0, null, null, s.getCenter());
+				var r = focusedSinceSelect ? s.r * 4.0 : null;
+				cameraController.set(r, null, null, s.getCenter());
 			}
 			}
 			else {
 			else {
 				centroid.scale3(1.0 / curEdit.rootObjects.length);
 				centroid.scale3(1.0 / curEdit.rootObjects.length);
@@ -334,6 +337,7 @@ class SceneEditor {
 		}
 		}
 		for(obj in curEdit.rootElements)
 		for(obj in curEdit.rootElements)
 			tree.revealNode(obj);
 			tree.revealNode(obj);
+		focusedSinceSelect = true;
 	}
 	}
 
 
 	function getAvailableTags(p: PrefabElement) : Array<{id: String, color: String}>{
 	function getAvailableTags(p: PrefabElement) : Array<{id: String, color: String}>{
@@ -1539,8 +1543,9 @@ class SceneEditor {
 			setupGizmo();
 			setupGizmo();
 		}
 		}
 
 
+		var prev : Array<PrefabElement> = null;
 		if( curEdit != null && mode.match(Default|NoTree) ) {
 		if( curEdit != null && mode.match(Default|NoTree) ) {
-			var prev = curEdit.rootElements.copy();
+			prev = curEdit.rootElements.copy();
 			undo.change(Custom(function(u) {
 			undo.change(Custom(function(u) {
 				if(u) impl(prev,NoHistory);
 				if(u) impl(prev,NoHistory);
 				else impl(elts,NoHistory);
 				else impl(elts,NoHistory);
@@ -1548,6 +1553,16 @@ class SceneEditor {
 		}
 		}
 
 
 		impl(elts,mode);
 		impl(elts,mode);
+		if( prev == null || curEdit.rootElements.length != prev.length ) {
+			focusedSinceSelect = false;
+			return;
+		}
+		for( i in 0...curEdit.rootElements.length ) {
+			if( curEdit.rootElements[i] != prev[i] ) {
+				focusedSinceSelect = false;
+				return;
+			}
+		}
 	}
 	}
 
 
 	function hasBeenRemoved( e : hrt.prefab.Prefab ) {
 	function hasBeenRemoved( e : hrt.prefab.Prefab ) {