Add option to show bounds of the model in Editor preview
This commit is contained in:
@@ -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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user