Add option to show bounds of the animated model in Editor preview

This commit is contained in:
Wojtek Figat
2021-06-01 10:36:13 +02:00
parent a730c3b1af
commit 1789e879bf
3 changed files with 34 additions and 5 deletions

View File

@@ -1,5 +1,6 @@
// Copyright (c) 2012-2021 Wojciech Figat. All rights reserved.
using FlaxEditor.GUI.ContextMenu;
using FlaxEngine;
using FlaxEditor.GUI.Input;
using Object = FlaxEngine.Object;
@@ -12,8 +13,9 @@ namespace FlaxEditor.Viewport.Previews
/// <seealso cref="AssetPreview" />
public class AnimatedModelPreview : AssetPreview
{
private ContextMenuButton _showBoundsButton;
private AnimatedModel _previewModel;
private bool _showNodes;
private bool _showNodes, _showBounds;
/// <summary>
/// Gets or sets the skinned model asset to preview.
@@ -44,10 +46,23 @@ namespace FlaxEditor.Viewport.Previews
{
_showNodes = value;
if (value)
{
ShowDebugDraw = true;
ShowEditorPrimitives = true;
}
}
}
/// <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;
}
}
@@ -84,6 +99,9 @@ namespace FlaxEditor.Viewport.Previews
if (useWidgets)
{
// Show Bounds
_showBoundsButton = ViewWidgetShowMenu.AddButton("Bounds", () => ShowBounds = !ShowBounds);
// Preview LOD
{
var previewLOD = ViewWidgetButtonMenu.AddButton("Preview LOD");
@@ -160,6 +178,12 @@ namespace FlaxEditor.Viewport.Previews
}
}
}
// Draw bounds
if (_showBounds)
{
DebugDraw.DrawWireBox(_previewModel.Box, Color.Violet.RGBMultiplied(0.8f), 0, false);
}
}
/// <inheritdoc />

View File

@@ -85,6 +85,11 @@ namespace FlaxEditor.Viewport.Previews
view.Flags |= ViewFlags.DebugDraw;
Task.View = view;
}
if (value)
{
// Need to show editor primitives to show debug shapes
ShowEditorPrimitives = true;
}
}
}

View File

@@ -617,7 +617,7 @@ void AnimatedModel::DrawGeneric(RenderContext& renderContext)
void AnimatedModel::OnDebugDrawSelected()
{
DEBUG_DRAW_WIRE_BOX(_box, Color::Violet * 0.8f, 0, true);
DEBUG_DRAW_WIRE_BOX(_box, Color::Violet.RGBMultiplied(0.8f), 0, true);
// Base
ModelInstanceActor::OnDebugDrawSelected();