diff --git a/Source/Editor/Viewport/Previews/ModelPreview.cs b/Source/Editor/Viewport/Previews/ModelPreview.cs index 3f285ddcd..81c0c350f 100644 --- a/Source/Editor/Viewport/Previews/ModelPreview.cs +++ b/Source/Editor/Viewport/Previews/ModelPreview.cs @@ -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 /// public class ModelPreview : AssetPreview { + private ContextMenuButton _showBoundsButton; private StaticModel _previewModel; + private bool _showBounds; /// /// Gets or sets the model asset to preview. @@ -28,6 +31,22 @@ namespace FlaxEditor.Viewport.Previews /// public StaticModel PreviewActor => _previewModel; + /// + /// Gets or sets a value indicating whether show animated model bounding box debug view. + /// + public bool ShowBounds + { + get => _showBounds; + set + { + _showBounds = value; + if (value) + ShowDebugDraw = true; + if (_showBoundsButton != null) + _showBoundsButton.Checked = value; + } + } + /// /// Gets or sets a value indicating whether scale the model to the normalized bounds. /// @@ -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 } } + /// + 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); + } + } + /// public override bool OnKeyDown(KeyboardKeys key) {