Cleanup code from #1213
This commit is contained in:
@@ -3,8 +3,6 @@
|
||||
using System;
|
||||
using FlaxEditor.GUI.ContextMenu;
|
||||
using FlaxEngine;
|
||||
using FlaxEditor.GUI.Input;
|
||||
using FlaxEngine.GUI;
|
||||
using Object = FlaxEngine.Object;
|
||||
|
||||
namespace FlaxEditor.Viewport.Previews
|
||||
@@ -15,13 +13,10 @@ namespace FlaxEditor.Viewport.Previews
|
||||
/// <seealso cref="AssetPreview" />
|
||||
public class AnimatedModelPreview : AssetPreview
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public AnimatedModel _previewModel;
|
||||
|
||||
private ContextMenuButton _showNodesButton, _showBoundsButton, _showFloorButton, _showNodesNamesButton;
|
||||
private bool _showNodes, _showBounds, _showFloor, _showNodesNames;
|
||||
private StaticModel _floorModel;
|
||||
|
||||
private bool _playAnimation, _playAnimationOnce;
|
||||
private float _playSpeed = 1.0f;
|
||||
|
||||
@@ -404,9 +399,9 @@ namespace FlaxEditor.Viewport.Previews
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calls SetArcBallView from ViewportCamera
|
||||
/// Resets the camera to focus on a object.
|
||||
/// </summary>
|
||||
public void CallSetArcBallView()
|
||||
public void ResetCamera()
|
||||
{
|
||||
ViewportCamera.SetArcBallView(_previewModel.Box);
|
||||
}
|
||||
@@ -417,8 +412,7 @@ namespace FlaxEditor.Viewport.Previews
|
||||
switch (key)
|
||||
{
|
||||
case KeyboardKeys.F:
|
||||
// Pay respect..
|
||||
CallSetArcBallView();
|
||||
ResetCamera();
|
||||
return true;
|
||||
case KeyboardKeys.Spacebar:
|
||||
PlayAnimation = !PlayAnimation;
|
||||
|
||||
@@ -48,6 +48,7 @@ namespace FlaxEditor.Viewport.Previews
|
||||
private int _selectedModelIndex;
|
||||
private Image _guiMaterialControl;
|
||||
private readonly MaterialBase[] _postFxMaterialsCache = new MaterialBase[1];
|
||||
private ContextMenu _modelWidgetButtonMenu;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the material asset to preview. It can be <see cref="FlaxEngine.Material"/> or <see cref="FlaxEngine.MaterialInstance"/>.
|
||||
@@ -65,11 +66,6 @@ namespace FlaxEditor.Viewport.Previews
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The "Model" widget button context menu.
|
||||
/// </summary>
|
||||
private ContextMenu modelWidgetButtonMenu;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the selected preview model index.
|
||||
/// </summary>
|
||||
@@ -87,27 +83,6 @@ namespace FlaxEditor.Viewport.Previews
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fill out all models
|
||||
/// </summary>
|
||||
/// <param name="control"></param>
|
||||
private void ModelWidgetMenuOnVisibleChanged(Control control)
|
||||
{
|
||||
if (!control.Visible) return;
|
||||
|
||||
modelWidgetButtonMenu.ItemsContainer.DisposeChildren();
|
||||
|
||||
// Fill out all models
|
||||
for (int i = 0; i < Models.Length; i++)
|
||||
{
|
||||
var index = i;
|
||||
var button = modelWidgetButtonMenu.AddButton(Models[index]);
|
||||
button.ButtonClicked += (button) => SelectedModelIndex = index;
|
||||
button.Checked = SelectedModelIndex == index;
|
||||
button.Tag = index;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="MaterialPreview"/> class.
|
||||
/// </summary>
|
||||
@@ -127,9 +102,24 @@ namespace FlaxEditor.Viewport.Previews
|
||||
{
|
||||
// Model mode widget
|
||||
var modelMode = new ViewportWidgetsContainer(ViewportWidgetLocation.UpperRight);
|
||||
modelWidgetButtonMenu = new ContextMenu();
|
||||
modelWidgetButtonMenu.VisibleChanged += ModelWidgetMenuOnVisibleChanged;
|
||||
var previewLODSModeButton = new ViewportWidgetButton("Model", SpriteHandle.Invalid, modelWidgetButtonMenu)
|
||||
_modelWidgetButtonMenu = new ContextMenu();
|
||||
_modelWidgetButtonMenu.VisibleChanged += control =>
|
||||
{
|
||||
if (!control.Visible)
|
||||
return;
|
||||
_modelWidgetButtonMenu.ItemsContainer.DisposeChildren();
|
||||
|
||||
// Fill out all models
|
||||
for (int i = 0; i < Models.Length; i++)
|
||||
{
|
||||
var index = i;
|
||||
var button = _modelWidgetButtonMenu.AddButton(Models[index]);
|
||||
button.ButtonClicked += _ => SelectedModelIndex = index;
|
||||
button.Checked = SelectedModelIndex == index;
|
||||
button.Tag = index;
|
||||
}
|
||||
};
|
||||
new ViewportWidgetButton("Model", SpriteHandle.Invalid, _modelWidgetButtonMenu)
|
||||
{
|
||||
TooltipText = "Change material model",
|
||||
Parent = modelMode,
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved.
|
||||
|
||||
using FlaxEditor.GUI.Input;
|
||||
using FlaxEngine;
|
||||
using Object = FlaxEngine.Object;
|
||||
|
||||
@@ -59,9 +58,9 @@ namespace FlaxEditor.Viewport.Previews
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calls SetArcBallView from ViewportCamera
|
||||
/// Resets the camera to focus on a object.
|
||||
/// </summary>
|
||||
public void CallSetArcBallView()
|
||||
public void ResetCamera()
|
||||
{
|
||||
ViewportCamera.SetArcBallView(StaticModel.Model != null ? StaticModel.Box : AnimatedModel.Box);
|
||||
}
|
||||
@@ -92,8 +91,7 @@ namespace FlaxEditor.Viewport.Previews
|
||||
switch (key)
|
||||
{
|
||||
case KeyboardKeys.F:
|
||||
// Pay respect..
|
||||
CallSetArcBallView();
|
||||
ResetCamera();
|
||||
break;
|
||||
}
|
||||
return base.OnKeyDown(key);
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved.
|
||||
|
||||
using FlaxEditor.GUI.ContextMenu;
|
||||
using FlaxEditor.GUI.Input;
|
||||
using FlaxEngine;
|
||||
using FlaxEngine.GUI;
|
||||
using FlaxEngine.Utilities;
|
||||
@@ -17,15 +16,11 @@ namespace FlaxEditor.Viewport.Previews
|
||||
public class ModelPreview : AssetPreview
|
||||
{
|
||||
private ContextMenuButton _showBoundsButton, _showCurrentLODButton, _showNormalsButton, _showTangentsButton, _showBitangentsButton, _showFloorButton;
|
||||
private ContextMenu _previewLODsWidgetButtonMenu;
|
||||
private StaticModel _previewModel, _floorModel;
|
||||
private bool _showBounds, _showCurrentLOD, _showNormals, _showTangents, _showBitangents, _showFloor;
|
||||
private MeshDataCache _meshDatas;
|
||||
|
||||
/// <summary>
|
||||
/// The "PreviewLODS" widget button context menu.
|
||||
/// </summary>
|
||||
private ContextMenu previewLODSWidgetButtonMenu;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value that shows LOD statistics
|
||||
/// </summary>
|
||||
@@ -37,8 +32,6 @@ namespace FlaxEditor.Viewport.Previews
|
||||
if (_showCurrentLOD == value)
|
||||
return;
|
||||
_showCurrentLOD = value;
|
||||
if (value)
|
||||
ShowDebugDraw = true;
|
||||
if (_showCurrentLODButton != null)
|
||||
_showCurrentLODButton.Checked = value;
|
||||
}
|
||||
@@ -222,42 +215,36 @@ namespace FlaxEditor.Viewport.Previews
|
||||
});
|
||||
_showCurrentLODButton.IndexInParent = 2;
|
||||
|
||||
// PreviewLODS mode widget
|
||||
var PreviewLODSMode = new ViewportWidgetsContainer(ViewportWidgetLocation.UpperRight);
|
||||
previewLODSWidgetButtonMenu = new ContextMenu();
|
||||
previewLODSWidgetButtonMenu.VisibleChanged += PreviewLODSWidgetMenuOnVisibleChanged;
|
||||
var previewLODSModeButton = new ViewportWidgetButton("Preview LOD", SpriteHandle.Invalid, previewLODSWidgetButtonMenu)
|
||||
// Preview LODs mode widget
|
||||
var PreviewLODsMode = new ViewportWidgetsContainer(ViewportWidgetLocation.UpperRight);
|
||||
_previewLODsWidgetButtonMenu = new ContextMenu();
|
||||
_previewLODsWidgetButtonMenu.VisibleChanged += control =>
|
||||
{
|
||||
if (!control.Visible)
|
||||
return;
|
||||
var model = _previewModel.Model;
|
||||
if (model && !model.WaitForLoaded())
|
||||
{
|
||||
_previewLODsWidgetButtonMenu.ItemsContainer.DisposeChildren();
|
||||
var lods = model.LODs.Length;
|
||||
for (int i = -1; i < lods; i++)
|
||||
{
|
||||
var index = i;
|
||||
var button = _previewLODsWidgetButtonMenu.AddButton("LOD " + (index == -1 ? "Auto" : index));
|
||||
button.ButtonClicked += _ => _previewModel.ForcedLOD = index;
|
||||
button.Checked = _previewModel.ForcedLOD == index;
|
||||
button.Tag = index;
|
||||
if (lods <= 1)
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
new ViewportWidgetButton("Preview LOD", SpriteHandle.Invalid, _previewLODsWidgetButtonMenu)
|
||||
{
|
||||
TooltipText = "Preview LOD properties",
|
||||
Parent = PreviewLODSMode,
|
||||
Parent = PreviewLODsMode,
|
||||
};
|
||||
PreviewLODSMode.Parent = this;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fill out all Model LODS
|
||||
/// </summary>
|
||||
/// <param name="control"></param>
|
||||
private void PreviewLODSWidgetMenuOnVisibleChanged(Control control)
|
||||
{
|
||||
if (!control.Visible)
|
||||
return;
|
||||
|
||||
var model = _previewModel.Model;
|
||||
if (model && !model.WaitForLoaded() && model.IsLoaded)
|
||||
{
|
||||
previewLODSWidgetButtonMenu.ItemsContainer.DisposeChildren();
|
||||
var lods = model.LODs.Length;
|
||||
for (int i = -1; i < lods; i++)
|
||||
{
|
||||
var index = i;
|
||||
var button = previewLODSWidgetButtonMenu.AddButton("LOD " + (index == -1 ? "Auto" : index));
|
||||
button.ButtonClicked += (button) => _previewModel.ForcedLOD = index;
|
||||
button.Checked = _previewModel.ForcedLOD == index;
|
||||
button.Tag = index;
|
||||
if (lods <= 1) return;
|
||||
}
|
||||
PreviewLODsMode.Parent = this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -361,7 +348,7 @@ namespace FlaxEditor.Viewport.Previews
|
||||
var distSqr = Vector3.DistanceSquared(ref sphere.Center, ref viewOrigin);
|
||||
var screenRadiusSquared = Mathf.Square(screenMultiple * sphere.Radius) / Mathf.Max(1.0f, distSqr);
|
||||
screenSize = Mathf.Sqrt((float)screenRadiusSquared) * 2.0f;
|
||||
|
||||
|
||||
// Check if model is being culled
|
||||
if (Mathf.Square(model.MinScreenSize * 0.5f) > screenRadiusSquared)
|
||||
return -1;
|
||||
@@ -422,9 +409,9 @@ namespace FlaxEditor.Viewport.Previews
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calls SetArcBallView from ViewportCamera
|
||||
/// Resets the camera to focus on a object.
|
||||
/// </summary>
|
||||
public void CallSetArcBallView()
|
||||
public void ResetCamera()
|
||||
{
|
||||
ViewportCamera.SetArcBallView(_previewModel.Box);
|
||||
}
|
||||
@@ -435,8 +422,7 @@ namespace FlaxEditor.Viewport.Previews
|
||||
switch (key)
|
||||
{
|
||||
case KeyboardKeys.F:
|
||||
// Pay respect..
|
||||
CallSetArcBallView();
|
||||
ResetCamera();
|
||||
break;
|
||||
}
|
||||
return base.OnKeyDown(key);
|
||||
@@ -449,6 +435,7 @@ namespace FlaxEditor.Viewport.Previews
|
||||
Object.Destroy(ref _previewModel);
|
||||
_showBoundsButton = null;
|
||||
_showCurrentLODButton = null;
|
||||
_previewLODsWidgetButtonMenu = null;
|
||||
_showNormalsButton = null;
|
||||
_showTangentsButton = null;
|
||||
_showBitangentsButton = null;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved.
|
||||
|
||||
using FlaxEditor.GUI.ContextMenu;
|
||||
using FlaxEngine;
|
||||
using FlaxEngine.GUI;
|
||||
@@ -14,11 +15,7 @@ namespace FlaxEditor.Viewport.Previews
|
||||
{
|
||||
private bool _showCurrentLOD;
|
||||
private ContextMenuButton _showCurrentLODButton;
|
||||
|
||||
/// <summary>
|
||||
/// The "PreviewLODS" widget button context menu.
|
||||
/// </summary>
|
||||
private ContextMenu previewLODSWidgetButtonMenu;
|
||||
private ContextMenu _previewLODsWidgetButtonMenu;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value that shows LOD statistics
|
||||
@@ -31,8 +28,6 @@ namespace FlaxEditor.Viewport.Previews
|
||||
if (_showCurrentLOD == value)
|
||||
return;
|
||||
_showCurrentLOD = value;
|
||||
if (value)
|
||||
ShowDebugDraw = true;
|
||||
if (_showCurrentLODButton != null)
|
||||
_showCurrentLODButton.Checked = value;
|
||||
}
|
||||
@@ -57,9 +52,29 @@ namespace FlaxEditor.Viewport.Previews
|
||||
|
||||
// PreviewLODS mode widget
|
||||
var PreviewLODSMode = new ViewportWidgetsContainer(ViewportWidgetLocation.UpperRight);
|
||||
previewLODSWidgetButtonMenu = new ContextMenu();
|
||||
previewLODSWidgetButtonMenu.VisibleChanged += PreviewLODSWidgetMenuOnVisibleChanged;
|
||||
var previewLODSModeButton = new ViewportWidgetButton("Preview LOD", SpriteHandle.Invalid, previewLODSWidgetButtonMenu)
|
||||
_previewLODsWidgetButtonMenu = new ContextMenu();
|
||||
_previewLODsWidgetButtonMenu.VisibleChanged += control =>
|
||||
{
|
||||
if (!control.Visible)
|
||||
return;
|
||||
var skinned = _previewModel.SkinnedModel;
|
||||
if (skinned && !skinned.WaitForLoaded())
|
||||
{
|
||||
_previewLODsWidgetButtonMenu.ItemsContainer.DisposeChildren();
|
||||
var lods = skinned.LODs.Length;
|
||||
for (int i = -1; i < lods; i++)
|
||||
{
|
||||
var index = i;
|
||||
var button = _previewLODsWidgetButtonMenu.AddButton("LOD " + (index == -1 ? "Auto" : index));
|
||||
button.ButtonClicked += (button) => _previewModel.ForcedLOD = index;
|
||||
button.Checked = _previewModel.ForcedLOD == index;
|
||||
button.Tag = index;
|
||||
if (lods <= 1)
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
new ViewportWidgetButton("Preview LOD", SpriteHandle.Invalid, _previewLODsWidgetButtonMenu)
|
||||
{
|
||||
TooltipText = "Preview LOD properties",
|
||||
Parent = PreviewLODSMode,
|
||||
@@ -68,33 +83,6 @@ namespace FlaxEditor.Viewport.Previews
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fill out all SkinnedModel LODS
|
||||
/// </summary>
|
||||
/// <param name="control"></param>
|
||||
private void PreviewLODSWidgetMenuOnVisibleChanged(Control control)
|
||||
{
|
||||
if (!control.Visible)
|
||||
return;
|
||||
|
||||
var skinned = _previewModel.SkinnedModel;
|
||||
if (skinned && !skinned.WaitForLoaded() && skinned.IsLoaded)
|
||||
{
|
||||
previewLODSWidgetButtonMenu.ItemsContainer.DisposeChildren();
|
||||
var lods = skinned.LODs.Length;
|
||||
for (int i = -1; i < lods; i++)
|
||||
{
|
||||
var index = i;
|
||||
var button = previewLODSWidgetButtonMenu.AddButton("LOD " + (index == -1 ? "Auto" : index));
|
||||
button.ButtonClicked += (button) => _previewModel.ForcedLOD = index;
|
||||
button.Checked = _previewModel.ForcedLOD == index;
|
||||
button.Tag = index;
|
||||
if (lods <= 1) return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
private int ComputeLODIndex(SkinnedModel model, out float screenSize)
|
||||
{
|
||||
screenSize = 1.0f;
|
||||
@@ -181,6 +169,7 @@ namespace FlaxEditor.Viewport.Previews
|
||||
public override void OnDestroy()
|
||||
{
|
||||
_showCurrentLODButton = null;
|
||||
_previewLODsWidgetButtonMenu = null;
|
||||
|
||||
base.OnDestroy();
|
||||
}
|
||||
|
||||
@@ -182,9 +182,7 @@ namespace FlaxEditor.Windows.Assets
|
||||
{
|
||||
// Toolstrip
|
||||
_toolstrip.AddSeparator();
|
||||
|
||||
_toolstrip.AddButton(editor.Icons.CenterView64, () => _preview.CallSetArcBallView()).LinkTooltip("Show whole collision");
|
||||
|
||||
_toolstrip.AddButton(editor.Icons.CenterView64, () => _preview.ResetCamera()).LinkTooltip("Show whole collision");
|
||||
_toolstrip.AddButton(editor.Icons.Docs64, () => Platform.OpenUrl(Utilities.Constants.DocsUrl + "manual/physics/colliders/collision-data.html")).LinkTooltip("See documentation to learn more");
|
||||
|
||||
// Split Panel
|
||||
|
||||
@@ -788,9 +788,7 @@ namespace FlaxEditor.Windows.Assets
|
||||
// Toolstrip
|
||||
_toolstrip.AddSeparator();
|
||||
_showCurrentLODButton = (ToolStripButton)_toolstrip.AddButton(editor.Icons.Info64, () => _preview.ShowCurrentLOD = !_preview.ShowCurrentLOD).LinkTooltip("Show LOD statistics");
|
||||
|
||||
_toolstrip.AddButton(editor.Icons.CenterView64, () => _preview.CallSetArcBallView()).LinkTooltip("Show whole model");
|
||||
|
||||
_toolstrip.AddButton(editor.Icons.CenterView64, () => _preview.ResetCamera()).LinkTooltip("Show whole model");
|
||||
_toolstrip.AddSeparator();
|
||||
_toolstrip.AddButton(editor.Icons.Docs64, () => Platform.OpenUrl(Utilities.Constants.DocsUrl + "manual/graphics/models/index.html")).LinkTooltip("See documentation to learn more");
|
||||
|
||||
|
||||
@@ -1117,13 +1117,9 @@ namespace FlaxEditor.Windows.Assets
|
||||
{
|
||||
// Toolstrip
|
||||
_toolstrip.AddSeparator();
|
||||
|
||||
_showCurrentLODButton = (ToolStripButton)_toolstrip.AddButton(editor.Icons.Info64, () => _preview.ShowCurrentLOD = !_preview.ShowCurrentLOD).LinkTooltip("Show LOD statistics");
|
||||
|
||||
_showNodesButton = (ToolStripButton)_toolstrip.AddButton(editor.Icons.Bone64, () => _preview.ShowNodes = !_preview.ShowNodes).LinkTooltip("Show animated model nodes debug view");
|
||||
|
||||
_toolstrip.AddButton(editor.Icons.CenterView64, () => _preview.CallSetArcBallView()).LinkTooltip("Show whole model");
|
||||
|
||||
_toolstrip.AddButton(editor.Icons.CenterView64, () => _preview.ResetCamera()).LinkTooltip("Show whole model");
|
||||
_toolstrip.AddSeparator();
|
||||
_toolstrip.AddButton(editor.Icons.Docs64, () => Platform.OpenUrl(Utilities.Constants.DocsUrl + "manual/animation/skinned-model/index.html")).LinkTooltip("See documentation to learn more");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user