Browse Source

Locate scene node in editor by doubleclicking in the hierarchy window.

Lasse Öörni 11 years ago
parent
commit
97ec02619f

+ 13 - 0
Bin/Data/Scripts/Editor/EditorHierarchyWindow.as

@@ -72,6 +72,7 @@ void CreateHierarchyWindow()
     SubscribeToEvent(hierarchyWindow.GetChild("ExpandButton", true), "Released", "ExpandCollapseHierarchy");
     SubscribeToEvent(hierarchyWindow.GetChild("ExpandButton", true), "Released", "ExpandCollapseHierarchy");
     SubscribeToEvent(hierarchyWindow.GetChild("CollapseButton", true), "Released", "ExpandCollapseHierarchy");
     SubscribeToEvent(hierarchyWindow.GetChild("CollapseButton", true), "Released", "ExpandCollapseHierarchy");
     SubscribeToEvent(hierarchyList, "SelectionChanged", "HandleHierarchyListSelectionChange");
     SubscribeToEvent(hierarchyList, "SelectionChanged", "HandleHierarchyListSelectionChange");
+    SubscribeToEvent(hierarchyList, "ItemDoubleClicked", "HandleHierarchyListDoubleClick");
     SubscribeToEvent("DragDropTest", "HandleDragDropTest");
     SubscribeToEvent("DragDropTest", "HandleDragDropTest");
     SubscribeToEvent("DragDropFinish", "HandleDragDropFinish");
     SubscribeToEvent("DragDropFinish", "HandleDragDropFinish");
     SubscribeToEvent(editorScene, "NodeAdded", "HandleNodeAdded");
     SubscribeToEvent(editorScene, "NodeAdded", "HandleNodeAdded");
@@ -721,6 +722,18 @@ void HandleHierarchyListSelectionChange()
     UpdateCameraPreview();
     UpdateCameraPreview();
 }
 }
 
 
+void HandleHierarchyListDoubleClick(StringHash eventType, VariantMap& eventData)
+{
+    UIElement@ item = eventData["Item"].GetPtr();
+    int type = item.vars[TYPE_VAR].GetInt();
+    // Locate nodes from the scene by double-clicking
+    if (type == ITEM_NODE)
+    {
+        Node@ node = editorScene.GetNode(item.vars[NODE_ID_VAR].GetUInt());
+        LocateNode(node);
+    }
+}
+
 void HandleDragDropTest(StringHash eventType, VariantMap& eventData)
 void HandleDragDropTest(StringHash eventType, VariantMap& eventData)
 {
 {
     UIElement@ source = eventData["Source"].GetPtr();
     UIElement@ source = eventData["Source"].GetPtr();

+ 28 - 1
Bin/Data/Scripts/Editor/EditorView.as

@@ -1304,7 +1304,6 @@ void SteppedObjectManipulation(int key)
         UpdateNodeAttributes();
         UpdateNodeAttributes();
 }
 }
 
 
-
 void HandlePostRenderUpdate()
 void HandlePostRenderUpdate()
 {
 {
     DebugRenderer@ debug = editorScene.debugRenderer;
     DebugRenderer@ debug = editorScene.debugRenderer;
@@ -1554,6 +1553,34 @@ bool StopTestAnimation()
     return true;
     return true;
 }
 }
 
 
+void LocateNode(Node@ node)
+{
+    if (node is null || node is editorScene)
+        return;
+
+    Vector3 center = node.worldPosition;
+    float distance = newNodeDistance;
+
+    for (uint i = 0; i < node.numComponents; ++i)
+    {
+        // Determine view distance from drawable component's bounding box. Skip skybox, as its box is very large, as well as lights
+        Drawable@ drawable = cast<Drawable>(node.components[i]);
+        if (drawable !is null && cast<Skybox>(drawable) is null && cast<Light>(drawable) is null)
+        {
+            BoundingBox box = drawable.worldBoundingBox;
+            center = box.center;
+            // Ensure the object fits on the screen
+            distance = Max(distance, newNodeDistance + box.size.length);
+            break;
+        }
+    }
+
+    if (distance > viewFarClip)
+        distance = viewFarClip;
+
+    cameraNode.worldPosition = center - cameraNode.worldDirection * distance;
+}
+
 Vector3 SelectedNodesCenterPoint()
 Vector3 SelectedNodesCenterPoint()
 {
 {
     Vector3 centerPoint;
     Vector3 centerPoint;

+ 2 - 0
Docs/GettingStarted.dox

@@ -571,6 +571,8 @@ As an alternative to using the transform gizmo, scene nodes can be moved/rotated
 
 
 To reparent scene nodes, drag and drop them onto the new parent scene node in the scene hierarchy window. Reparenting should retain the effective world transform, so check afterwards from the component window that the local transform is what you expect it to be. Components can not be dragged between nodes, but can be duplicated with cut/copy/paste operations.
 To reparent scene nodes, drag and drop them onto the new parent scene node in the scene hierarchy window. Reparenting should retain the effective world transform, so check afterwards from the component window that the local transform is what you expect it to be. Components can not be dragged between nodes, but can be duplicated with cut/copy/paste operations.
 
 
+To locate a scene node from the scene, double-click it in the hierarchy window.
+
 To create a user variable into the current node, or delete it, type the variable name into the edit field below the node attributes, and press New or Del buttons next to it. The New button will prompt to choose the variable type.
 To create a user variable into the current node, or delete it, type the variable name into the edit field below the node attributes, and press New or Del buttons next to it. The New button will prompt to choose the variable type.
 
 
 While editing, you can execute script files using the "Run script" item in the %File menu. These are AngelScript files that are executed in immediate mode ie. you do not need to define a function. The editor's scene will be accessible to the script as the global property "scene."
 While editing, you can execute script files using the "Run script" item in the %File menu. These are AngelScript files that are executed in immediate mode ie. you do not need to define a function. The editor's scene will be accessible to the script as the global property "scene."