diff --git a/Source/Editor/Viewport/Cameras/FPSCamera.cs b/Source/Editor/Viewport/Cameras/FPSCamera.cs index 83fc49cd6..45770b007 100644 --- a/Source/Editor/Viewport/Cameras/FPSCamera.cs +++ b/Source/Editor/Viewport/Cameras/FPSCamera.cs @@ -6,9 +6,7 @@ using Real = System.Double; using Real = System.Single; #endif -using System.Collections.Generic; using FlaxEditor.Gizmo; -using FlaxEditor.SceneGraph; using FlaxEngine; namespace FlaxEditor.Viewport.Cameras @@ -85,86 +83,8 @@ namespace FlaxEditor.Viewport.Cameras _moveStartTime = Time.UnscaledGameTime; } - /// - /// Moves the viewport to visualize the actor. - /// - /// The actor to preview. - public void ShowActor(Actor actor) - { - Editor.GetActorEditorSphere(actor, out BoundingSphere sphere); - ShowSphere(ref sphere); - } - - /// - /// Moves the viewport to visualize selected actors. - /// - /// The actors to show. - /// The used orientation. - public void ShowActor(Actor actor, ref Quaternion orientation) - { - Editor.GetActorEditorSphere(actor, out BoundingSphere sphere); - ShowSphere(ref sphere, ref orientation); - } - - /// - /// Moves the viewport to visualize selected actors. - /// - /// The actors to show. - public void ShowActors(List selection) - { - if (selection.Count == 0) - return; - - BoundingSphere mergesSphere = BoundingSphere.Empty; - for (int i = 0; i < selection.Count; i++) - { - selection[i].GetEditorSphere(out var sphere); - BoundingSphere.Merge(ref mergesSphere, ref sphere, out mergesSphere); - } - - if (mergesSphere == BoundingSphere.Empty) - return; - ShowSphere(ref mergesSphere); - } - - /// - /// Moves the viewport to visualize selected actors. - /// - /// The actors to show. - /// The used orientation. - public void ShowActors(List selection, ref Quaternion orientation) - { - if (selection.Count == 0) - return; - - BoundingSphere mergesSphere = BoundingSphere.Empty; - for (int i = 0; i < selection.Count; i++) - { - selection[i].GetEditorSphere(out var sphere); - BoundingSphere.Merge(ref mergesSphere, ref sphere, out mergesSphere); - } - - if (mergesSphere == BoundingSphere.Empty) - return; - ShowSphere(ref mergesSphere, ref orientation); - } - - /// - /// 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); - } - - /// - /// 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) + /// + public override void ShowSphere(ref BoundingSphere sphere, ref Quaternion orientation) { Vector3 position; if (Viewport.UseOrthographicProjection) diff --git a/Source/Editor/Viewport/Cameras/ViewportCamera.cs b/Source/Editor/Viewport/Cameras/ViewportCamera.cs index 5e25a29bb..f8019a481 100644 --- a/Source/Editor/Viewport/Cameras/ViewportCamera.cs +++ b/Source/Editor/Viewport/Cameras/ViewportCamera.cs @@ -6,6 +6,9 @@ using Real = System.Double; using Real = System.Single; #endif +using System.Collections.Generic; +using FlaxEditor.Gizmo; +using FlaxEditor.SceneGraph; using FlaxEngine; namespace FlaxEditor.Viewport.Cameras @@ -33,6 +36,90 @@ namespace FlaxEditor.Viewport.Cameras /// public virtual bool UseMovementSpeed => true; + /// + /// Focuses the viewport on the current selection of the gizmo. + /// + /// The gizmo collection (from viewport). + /// The target view orientation. + public virtual void FocusSelection(GizmosCollection gizmos, ref Quaternion orientation) + { + var transformGizmo = gizmos.Get(); + if (transformGizmo == null || transformGizmo.SelectedParents.Count == 0) + return; + if (gizmos.Active != null) + { + var gizmoBounds = gizmos.Active.FocusBounds; + if (gizmoBounds != BoundingSphere.Empty) + { + ShowSphere(ref gizmoBounds, ref orientation); + return; + } + } + ShowActors(transformGizmo.SelectedParents, ref orientation); + } + + /// + /// Moves the viewport to visualize the actor. + /// + /// The actor to preview. + public virtual void ShowActor(Actor actor) + { + Editor.GetActorEditorSphere(actor, out BoundingSphere sphere); + ShowSphere(ref sphere); + } + + /// + /// Moves the viewport to visualize selected actors. + /// + /// The actors to show. + public void ShowActors(List selection) + { + var q = new Quaternion(0.424461186f, -0.0940724313f, 0.0443938486f, 0.899451137f); + ShowActors(selection, ref q); + } + + /// + /// Moves the viewport to visualize selected actors. + /// + /// The actors to show. + /// The used orientation. + public virtual void ShowActors(List selection, ref Quaternion orientation) + { + if (selection.Count == 0) + return; + + BoundingSphere mergesSphere = BoundingSphere.Empty; + for (int i = 0; i < selection.Count; i++) + { + selection[i].GetEditorSphere(out var sphere); + BoundingSphere.Merge(ref mergesSphere, ref sphere, out mergesSphere); + } + + if (mergesSphere == BoundingSphere.Empty) + return; + ShowSphere(ref mergesSphere, ref orientation); + } + + /// + /// 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); + } + + /// + /// Moves the camera to visualize given world area defined by the sphere. + /// + /// The sphere. + /// The camera orientation. + public virtual void ShowSphere(ref BoundingSphere sphere, ref Quaternion orientation) + { + SetArcBallView(orientation, sphere.Center, sphere.Radius); + } + /// /// Sets view orientation and position to match the arc ball camera style view for the given target object bounds. /// diff --git a/Source/Editor/Viewport/MainEditorGizmoViewport.cs b/Source/Editor/Viewport/MainEditorGizmoViewport.cs index 1e63888bf..6d8b572a4 100644 --- a/Source/Editor/Viewport/MainEditorGizmoViewport.cs +++ b/Source/Editor/Viewport/MainEditorGizmoViewport.cs @@ -770,14 +770,7 @@ namespace FlaxEditor.Viewport /// The target view orientation. public void FocusSelection(ref Quaternion orientation) { - if (TransformGizmo.SelectedParents.Count == 0) - return; - - var gizmoBounds = Gizmos.Active.FocusBounds; - if (gizmoBounds != BoundingSphere.Empty) - ((FPSCamera)ViewportCamera).ShowSphere(ref gizmoBounds, ref orientation); - else - ((FPSCamera)ViewportCamera).ShowActors(TransformGizmo.SelectedParents, ref orientation); + ViewportCamera.FocusSelection(Gizmos, ref orientation); } /// diff --git a/Source/Editor/Viewport/PrefabWindowViewport.cs b/Source/Editor/Viewport/PrefabWindowViewport.cs index f66d4e861..4166d6163 100644 --- a/Source/Editor/Viewport/PrefabWindowViewport.cs +++ b/Source/Editor/Viewport/PrefabWindowViewport.cs @@ -309,7 +309,7 @@ namespace FlaxEditor.Viewport public void ShowSelectedActors() { var orient = ViewOrientation; - ((FPSCamera)ViewportCamera).ShowActors(TransformGizmo.SelectedParents, ref orient); + ViewportCamera.ShowActors(TransformGizmo.SelectedParents, ref orient); } /// @@ -721,14 +721,7 @@ namespace FlaxEditor.Viewport /// The target view orientation. public void FocusSelection(ref Quaternion orientation) { - if (TransformGizmo.SelectedParents.Count == 0) - return; - - var gizmoBounds = Gizmos.Active.FocusBounds; - if (gizmoBounds != BoundingSphere.Empty) - ((FPSCamera)ViewportCamera).ShowSphere(ref gizmoBounds, ref orientation); - else - ((FPSCamera)ViewportCamera).ShowActors(TransformGizmo.SelectedParents, ref orientation); + ViewportCamera.FocusSelection(Gizmos, ref orientation); } ///