diff --git a/Source/Editor/Gizmo/GizmoBase.cs b/Source/Editor/Gizmo/GizmoBase.cs index 1d8ccd233..a44c677dd 100644 --- a/Source/Editor/Gizmo/GizmoBase.cs +++ b/Source/Editor/Gizmo/GizmoBase.cs @@ -27,6 +27,11 @@ namespace FlaxEditor.Gizmo /// public virtual bool IsControllingMouse => false; + /// + /// Gets the custom world-space bounds for current gizmo mode focus for used (eg. selected object part bounds). Returns if not used. + /// + public virtual BoundingSphere FocusBounds => BoundingSphere.Empty; + /// /// Initializes a new instance of the class. /// diff --git a/Source/Editor/Modules/ContentFindingModule.cs b/Source/Editor/Modules/ContentFindingModule.cs index 45748f7f4..b8f7f74a0 100644 --- a/Source/Editor/Modules/ContentFindingModule.cs +++ b/Source/Editor/Modules/ContentFindingModule.cs @@ -287,11 +287,11 @@ namespace FlaxEditor.Modules break; case ActorNode actorNode: Editor.Instance.SceneEditing.Select(actorNode.Actor); - Editor.Instance.Windows.EditWin.ShowSelectedActors(); + Editor.Instance.Windows.EditWin.Viewport.FocusSelection(); break; case Actor actor: Editor.Instance.SceneEditing.Select(actor); - Editor.Instance.Windows.EditWin.ShowSelectedActors(); + Editor.Instance.Windows.EditWin.Viewport.FocusSelection(); break; } } diff --git a/Source/Editor/Viewport/Cameras/FPSCamera.cs b/Source/Editor/Viewport/Cameras/FPSCamera.cs index 22abccf69..b6cd14273 100644 --- a/Source/Editor/Viewport/Cameras/FPSCamera.cs +++ b/Source/Editor/Viewport/Cameras/FPSCamera.cs @@ -143,13 +143,22 @@ namespace FlaxEditor.Viewport.Cameras ShowSphere(ref mergesSphere, ref orientation); } - private void ShowSphere(ref BoundingSphere sphere) + /// + /// Moves the camera to visualize given world area defined by the sphere. + /// + /// The sphere. + public void ShowSphere(ref BoundingSphere sphere) { var q = new Quaternion(0.424461186f, -0.0940724313f, 0.0443938486f, 0.899451137f); ShowSphere(ref sphere, ref q); } - private void ShowSphere(ref BoundingSphere sphere, ref Quaternion orientation) + /// + /// Moves the camera to visualize given world area defined by the sphere. + /// + /// The sphere. + /// The camera orientation. + public void ShowSphere(ref BoundingSphere sphere, ref Quaternion orientation) { Vector3 position; if (Viewport.UseOrthographicProjection) diff --git a/Source/Editor/Viewport/MainEditorGizmoViewport.cs b/Source/Editor/Viewport/MainEditorGizmoViewport.cs index ea63a598b..8bc6b4c02 100644 --- a/Source/Editor/Viewport/MainEditorGizmoViewport.cs +++ b/Source/Editor/Viewport/MainEditorGizmoViewport.cs @@ -361,7 +361,7 @@ namespace FlaxEditor.Viewport InputActions.Add(options => options.TranslateMode, () => TransformGizmo.ActiveMode = TransformGizmoBase.Mode.Translate); InputActions.Add(options => options.RotateMode, () => TransformGizmo.ActiveMode = TransformGizmoBase.Mode.Rotate); InputActions.Add(options => options.ScaleMode, () => TransformGizmo.ActiveMode = TransformGizmoBase.Mode.Scale); - InputActions.Add(options => options.FocusSelection, () => _editor.Windows.EditWin.ShowSelectedActors()); + InputActions.Add(options => options.FocusSelection, FocusSelection); InputActions.Add(options => options.Delete, _editor.SceneEditing.Delete); } @@ -652,6 +652,22 @@ namespace FlaxEditor.Viewport Gizmos.ForEach(x => x.OnSelectionChanged(selection)); } + /// + /// Focuses the viewport on the current selection of the gizmo. + /// + public void FocusSelection() + { + if (TransformGizmo.SelectedParents.Count == 0) + return; + + var orientation = ViewOrientation; + var gizmoBounds = Gizmos.Active.FocusBounds; + if (gizmoBounds != BoundingSphere.Empty) + ((FPSCamera)ViewportCamera).ShowSphere(ref gizmoBounds, ref orientation); + else + ((FPSCamera)ViewportCamera).ShowActors(TransformGizmo.SelectedParents, ref orientation); + } + /// /// Applies the transform to the collection of scene graph nodes. /// @@ -709,10 +725,7 @@ namespace FlaxEditor.Viewport /// protected override void OrientViewport(ref Quaternion orientation) { - if (TransformGizmo.SelectedParents.Count != 0) - { - ((FPSCamera)ViewportCamera).ShowActors(TransformGizmo.SelectedParents, ref orientation); - } + FocusSelection(); base.OrientViewport(ref orientation); } diff --git a/Source/Editor/Viewport/PrefabWindowViewport.cs b/Source/Editor/Viewport/PrefabWindowViewport.cs index 3cdd6ae0e..1c337cc25 100644 --- a/Source/Editor/Viewport/PrefabWindowViewport.cs +++ b/Source/Editor/Viewport/PrefabWindowViewport.cs @@ -2,7 +2,6 @@ using System; using System.Collections.Generic; -using System.Security.Policy; using FlaxEditor.Content; using FlaxEditor.Gizmo; using FlaxEditor.GUI.ContextMenu; @@ -317,7 +316,8 @@ namespace FlaxEditor.Viewport /// public void ShowSelectedActors() { - ((FPSCamera)ViewportCamera).ShowActors(TransformGizmo.SelectedParents); + var orient = Viewport.ViewOrientation; + ((FPSCamera)ViewportCamera).ShowActors(TransformGizmo.SelectedParents, ref orient); } /// @@ -356,6 +356,9 @@ namespace FlaxEditor.Viewport /// public Undo Undo { get; } + /// + public EditorViewport Viewport => this; + /// protected override bool IsControllingMouse => Gizmos.Active?.IsControllingMouse ?? false; @@ -780,13 +783,26 @@ namespace FlaxEditor.Viewport Spawn(actor, ref hitLocation); } + /// + /// Focuses the viewport on the current selection of the gizmo. + /// + public void FocusSelection() + { + if (TransformGizmo.SelectedParents.Count == 0) + return; + + var orientation = ViewOrientation; + var gizmoBounds = Gizmos.Active.FocusBounds; + if (gizmoBounds != BoundingSphere.Empty) + ((FPSCamera)ViewportCamera).ShowSphere(ref gizmoBounds, ref orientation); + else + ((FPSCamera)ViewportCamera).ShowActors(TransformGizmo.SelectedParents, ref orientation); + } + /// protected override void OrientViewport(ref Quaternion orientation) { - if (TransformGizmo.SelectedParents.Count != 0) - { - ((FPSCamera)ViewportCamera).ShowActors(TransformGizmo.SelectedParents, ref orientation); - } + FocusSelection(); base.OrientViewport(ref orientation); } diff --git a/Source/Editor/Windows/Assets/PrefabWindow.Selection.cs b/Source/Editor/Windows/Assets/PrefabWindow.Selection.cs index be4bf3070..5b501d8cc 100644 --- a/Source/Editor/Windows/Assets/PrefabWindow.Selection.cs +++ b/Source/Editor/Windows/Assets/PrefabWindow.Selection.cs @@ -3,9 +3,11 @@ using System; using System.Collections.Generic; using System.Linq; +using FlaxEditor.Gizmo; using FlaxEditor.GUI.Tree; using FlaxEditor.SceneGraph; using FlaxEditor.SceneGraph.GUI; +using FlaxEditor.Viewport.Cameras; using FlaxEngine; namespace FlaxEditor.Windows.Assets diff --git a/Source/Editor/Windows/Assets/PrefabWindow.cs b/Source/Editor/Windows/Assets/PrefabWindow.cs index bec9bf7fe..85a9a2cb9 100644 --- a/Source/Editor/Windows/Assets/PrefabWindow.cs +++ b/Source/Editor/Windows/Assets/PrefabWindow.cs @@ -10,7 +10,6 @@ using FlaxEditor.SceneGraph; using FlaxEditor.Viewport; using FlaxEngine; using FlaxEngine.GUI; -using Object = FlaxEngine.Object; namespace FlaxEditor.Windows.Assets { @@ -185,6 +184,7 @@ namespace FlaxEditor.Windows.Assets InputActions.Add(options => options.Paste, Paste); InputActions.Add(options => options.Duplicate, Duplicate); InputActions.Add(options => options.Delete, Delete); + InputActions.Add(options => options.FocusSelection, _viewport.FocusSelection); } private void OnSearchBoxTextChanged() @@ -428,7 +428,6 @@ namespace FlaxEditor.Windows.Assets /// public override void OnLayoutDeserialize(XmlElement node) { - if (float.TryParse(node.GetAttribute("Split1"), out float value1)) _split1.SplitterValue = value1; diff --git a/Source/Editor/Windows/EditGameWindow.cs b/Source/Editor/Windows/EditGameWindow.cs index 4025f68ab..eb9dd8034 100644 --- a/Source/Editor/Windows/EditGameWindow.cs +++ b/Source/Editor/Windows/EditGameWindow.cs @@ -6,9 +6,7 @@ using System.Linq; using System.Xml; using FlaxEditor.SceneGraph; using FlaxEditor.SceneGraph.Actors; -using FlaxEditor.States; using FlaxEditor.Viewport; -using FlaxEditor.Viewport.Cameras; using FlaxEditor.Viewport.Widgets; using FlaxEngine; using FlaxEngine.GUI; @@ -238,20 +236,6 @@ namespace FlaxEditor.Windows } } - /// - /// Moves the viewport to visualize selected actors. - /// - public void ShowSelectedActors() - { - if (Viewport.UseOrthographicProjection) - { - var orient = Viewport.ViewOrientation; - ((FPSCamera)Viewport.ViewportCamera).ShowActors(Viewport.TransformGizmo.SelectedParents, ref orient); - } - else - ((FPSCamera)Viewport.ViewportCamera).ShowActors(Viewport.TransformGizmo.SelectedParents); - } - /// /// Updates the camera previews. /// diff --git a/Source/Editor/Windows/SceneTreeWindow.cs b/Source/Editor/Windows/SceneTreeWindow.cs index e33d658e6..afe6d977e 100644 --- a/Source/Editor/Windows/SceneTreeWindow.cs +++ b/Source/Editor/Windows/SceneTreeWindow.cs @@ -68,7 +68,7 @@ namespace FlaxEditor.Windows InputActions.Add(options => options.TranslateMode, () => Editor.MainTransformGizmo.ActiveMode = TransformGizmoBase.Mode.Translate); InputActions.Add(options => options.RotateMode, () => Editor.MainTransformGizmo.ActiveMode = TransformGizmoBase.Mode.Rotate); InputActions.Add(options => options.ScaleMode, () => Editor.MainTransformGizmo.ActiveMode = TransformGizmoBase.Mode.Scale); - InputActions.Add(options => options.FocusSelection, () => Editor.Windows.EditWin.ShowSelectedActors()); + InputActions.Add(options => options.FocusSelection, () => Editor.Windows.EditWin.Viewport.FocusSelection()); } private void OnSearchBoxTextChanged()