Add option to show bounds of the model in Editor preview

This commit is contained in:
Wojtek Figat
2021-06-01 10:45:23 +02:00
parent 1789e879bf
commit f701e35c50

View File

@@ -1,5 +1,6 @@
// Copyright (c) 2012-2021 Wojciech Figat. All rights reserved.
using FlaxEditor.GUI.ContextMenu;
using FlaxEditor.GUI.Input;
using FlaxEngine;
using Object = FlaxEngine.Object;
@@ -12,7 +13,9 @@ namespace FlaxEditor.Viewport.Previews
/// <seealso cref="AssetPreview" />
public class ModelPreview : AssetPreview
{
private ContextMenuButton _showBoundsButton;
private StaticModel _previewModel;
private bool _showBounds;
/// <summary>
/// Gets or sets the model asset to preview.
@@ -28,6 +31,22 @@ namespace FlaxEditor.Viewport.Previews
/// </summary>
public StaticModel PreviewActor => _previewModel;
/// <summary>
/// Gets or sets a value indicating whether show animated model bounding box debug view.
/// </summary>
public bool ShowBounds
{
get => _showBounds;
set
{
_showBounds = value;
if (value)
ShowDebugDraw = true;
if (_showBoundsButton != null)
_showBoundsButton.Checked = value;
}
}
/// <summary>
/// Gets or sets a value indicating whether scale the model to the normalized bounds.
/// </summary>
@@ -50,6 +69,9 @@ namespace FlaxEditor.Viewport.Previews
if (useWidgets)
{
// Show Bounds
_showBoundsButton = ViewWidgetShowMenu.AddButton("Bounds", () => ShowBounds = !ShowBounds);
// Preview LOD
{
var previewLOD = ViewWidgetButtonMenu.AddButton("Preview LOD");
@@ -85,6 +107,18 @@ namespace FlaxEditor.Viewport.Previews
}
}
/// <inheritdoc />
protected override void OnDebugDraw(GPUContext context, ref RenderContext renderContext)
{
base.OnDebugDraw(context, ref renderContext);
// Draw bounds
if (_showBounds)
{
DebugDraw.DrawWireBox(_previewModel.Box, Color.Violet.RGBMultiplied(0.8f), 0, false);
}
}
/// <inheritdoc />
public override bool OnKeyDown(KeyboardKeys key)
{