Refactor focusing on selection logic in Editor
This commit is contained in:
@@ -27,6 +27,11 @@ namespace FlaxEditor.Gizmo
|
||||
/// </summary>
|
||||
public virtual bool IsControllingMouse => false;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the custom world-space bounds for current gizmo mode focus for used (eg. selected object part bounds). Returns <see cref="BoundingSphere.Empty"/> if not used.
|
||||
/// </summary>
|
||||
public virtual BoundingSphere FocusBounds => BoundingSphere.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GizmoBase"/> class.
|
||||
/// </summary>
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -143,13 +143,22 @@ namespace FlaxEditor.Viewport.Cameras
|
||||
ShowSphere(ref mergesSphere, ref orientation);
|
||||
}
|
||||
|
||||
private void ShowSphere(ref BoundingSphere sphere)
|
||||
/// <summary>
|
||||
/// Moves the camera to visualize given world area defined by the sphere.
|
||||
/// </summary>
|
||||
/// <param name="sphere">The sphere.</param>
|
||||
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)
|
||||
/// <summary>
|
||||
/// Moves the camera to visualize given world area defined by the sphere.
|
||||
/// </summary>
|
||||
/// <param name="sphere">The sphere.</param>
|
||||
/// <param name="orientation">The camera orientation.</param>
|
||||
public void ShowSphere(ref BoundingSphere sphere, ref Quaternion orientation)
|
||||
{
|
||||
Vector3 position;
|
||||
if (Viewport.UseOrthographicProjection)
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Focuses the viewport on the current selection of the gizmo.
|
||||
/// </summary>
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Applies the transform to the collection of scene graph nodes.
|
||||
/// </summary>
|
||||
@@ -709,10 +725,7 @@ namespace FlaxEditor.Viewport
|
||||
/// <inheritdoc />
|
||||
protected override void OrientViewport(ref Quaternion orientation)
|
||||
{
|
||||
if (TransformGizmo.SelectedParents.Count != 0)
|
||||
{
|
||||
((FPSCamera)ViewportCamera).ShowActors(TransformGizmo.SelectedParents, ref orientation);
|
||||
}
|
||||
FocusSelection();
|
||||
|
||||
base.OrientViewport(ref orientation);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
/// </summary>
|
||||
public void ShowSelectedActors()
|
||||
{
|
||||
((FPSCamera)ViewportCamera).ShowActors(TransformGizmo.SelectedParents);
|
||||
var orient = Viewport.ViewOrientation;
|
||||
((FPSCamera)ViewportCamera).ShowActors(TransformGizmo.SelectedParents, ref orient);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -356,6 +356,9 @@ namespace FlaxEditor.Viewport
|
||||
/// <inheritdoc />
|
||||
public Undo Undo { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public EditorViewport Viewport => this;
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override bool IsControllingMouse => Gizmos.Active?.IsControllingMouse ?? false;
|
||||
|
||||
@@ -780,13 +783,26 @@ namespace FlaxEditor.Viewport
|
||||
Spawn(actor, ref hitLocation);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Focuses the viewport on the current selection of the gizmo.
|
||||
/// </summary>
|
||||
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);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void OrientViewport(ref Quaternion orientation)
|
||||
{
|
||||
if (TransformGizmo.SelectedParents.Count != 0)
|
||||
{
|
||||
((FPSCamera)ViewportCamera).ShowActors(TransformGizmo.SelectedParents, ref orientation);
|
||||
}
|
||||
FocusSelection();
|
||||
|
||||
base.OrientViewport(ref orientation);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
/// <inheritdoc />
|
||||
public override void OnLayoutDeserialize(XmlElement node)
|
||||
{
|
||||
|
||||
if (float.TryParse(node.GetAttribute("Split1"), out float value1))
|
||||
_split1.SplitterValue = value1;
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Moves the viewport to visualize selected actors.
|
||||
/// </summary>
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the camera previews.
|
||||
/// </summary>
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user