This commit is contained in:
Jean-Baptiste Perrier
2021-03-01 16:19:00 +01:00
parent ce45070d63
commit 111eaf1cf9
2 changed files with 59 additions and 22 deletions

View File

@@ -88,6 +88,12 @@ namespace FlaxEditor.Viewport.Cameras
Editor.GetActorEditorSphere(actor, out BoundingSphere sphere);
ShowSphere(ref sphere);
}
public void ShowActor(Actor actor, ref Quaternion orientation)
{
Editor.GetActorEditorSphere(actor, out BoundingSphere sphere);
ShowSphere(ref sphere, ref orientation);
}
/// <summary>
/// Moves the viewport to visualize selected actors.
@@ -111,28 +117,47 @@ namespace FlaxEditor.Viewport.Cameras
ShowSphere(ref mergesSphere);
}
public void ShowActors(List<SceneGraphNode> actors, ref Quaternion orientation)
{
if (actors.Count == 0)
return;
BoundingSphere mergesSphere = BoundingSphere.Empty;
for (int i = 0; i < actors.Count; i++)
{
if (actors[i] is ActorNode actor)
{
Editor.GetActorEditorSphere(actor.Actor, out BoundingSphere sphere);
BoundingSphere.Merge(ref mergesSphere, ref sphere, out mergesSphere);
}
}
ShowSphere(ref mergesSphere, ref orientation);
}
private void ShowSphere(ref BoundingSphere sphere)
{
Quaternion orientation;
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)
{
Vector3 position;
if (Viewport.UseOrthographicProjection)
{
orientation = Quaternion.LookRotation(Viewport.ViewDirection);
var invdir = Viewport.ViewDirection;
invdir.Negate();
position = sphere.Center + sphere.Radius * 5.0f * invdir;
Vector3 offset = Vector3.Forward * orientation;
offset.Negate();
position = sphere.Center + offset * (sphere.Radius * 5.0f);
Viewport.OrthographicScale = Vector3.Distance(position, sphere.Center) / 1000;
}
else
{
orientation = new Quaternion(0.424461186f, -0.0940724313f, 0.0443938486f, 0.899451137f);
position = sphere.Center - Vector3.Forward * orientation * (sphere.Radius * 2.5f);
}
TargetPoint = position;
MoveViewport(position, orientation);
}
/// <inheritdoc />
public override void Update(float deltaTime)
{

View File

@@ -559,14 +559,26 @@ namespace FlaxEditor.Viewport
// Camera Orientation
{
var cameraView = ViewWidgetButtonMenu.AddChildMenu("Orientation").ContextMenu;
for (int i = 0; i < EditorViewportCameraOrientationValues.Length; i++)
var cameraView = ViewWidgetButtonMenu.AddChildMenu("Viewpoint").ContextMenu;
for (int i = 0; i < EditorViewportCameraViewpointValues.Length; i++)
{
var co = EditorViewportCameraOrientationValues[i];
var co = EditorViewportCameraViewpointValues[i];
var button = cameraView.AddButton(co.Name);
button.Tag = co.Orientation;
}
cameraView.ButtonClicked += button => ViewOrientation = Quaternion.Euler((Vector3)button.Tag);
cameraView.ButtonClicked += button =>
{
var orient = Quaternion.Euler((Vector3)button.Tag);
if (Editor.Instance.SceneEditing.HasSthSelected)
((FPSCamera)ViewportCamera).ShowActors(Editor.Instance.Windows.EditWin.Viewport.TransformGizmo.SelectedParents, ref orient);
else
{
var invdir = (Vector3)button.Tag;
invdir.Negate();
ViewPosition = new Vector3(0.0f) + Vector3.Forward * orient * 1000.0f;
((FPSCamera)ViewportCamera).MoveViewport(ViewPosition, ViewOrientation);
}
};
}
// Field of View
@@ -1284,26 +1296,26 @@ namespace FlaxEditor.Viewport
base.OnDestroy();
}
private struct CameraOrientation
private struct CameraViewpoint
{
public readonly string Name;
public readonly Vector3 Orientation;
public CameraOrientation(string name, Vector3 orientation)
public CameraViewpoint(string name, Vector3 orientation)
{
Name = name;
Orientation = orientation;
}
}
private readonly CameraOrientation[] EditorViewportCameraOrientationValues =
private readonly CameraViewpoint[] EditorViewportCameraViewpointValues =
{
new CameraOrientation("Front", new Vector3(0, 0, 0)),
new CameraOrientation("Back", new Vector3(0, 180, 0)),
new CameraOrientation("Left", new Vector3(0, 90, 0)),
new CameraOrientation("Right", new Vector3(0, -90, 0)),
new CameraOrientation("Top", new Vector3(-90, 0, 0)),
new CameraOrientation("Bottom", new Vector3(90, 0, 0))
new CameraViewpoint("Front", new Vector3(0, 0, 0)),
new CameraViewpoint("Back", new Vector3(0, 180, 0)),
new CameraViewpoint("Left", new Vector3(0, 90, 0)),
new CameraViewpoint("Right", new Vector3(0, -90, 0)),
new CameraViewpoint("Top", new Vector3(90, 0, 0)),
new CameraViewpoint("Bottom", new Vector3(-90, 0, 0))
};
private readonly float[] EditorViewportCameraSpeedValues =