Fix missing root motion preview in Animation preview panels (with option to disable it)

This commit is contained in:
Wojciech Figat
2021-12-10 12:42:11 +01:00
parent f1b3f71b09
commit d5585a30fd
2 changed files with 37 additions and 2 deletions

View File

@@ -23,6 +23,11 @@ namespace FlaxEditor.Viewport.Previews
private bool _playAnimation, _playAnimationOnce;
private float _playSpeed = 1.0f;
/// <summary>
/// Snaps the preview actor to the world origin.
/// </summary>
protected bool _snapToOrigin = true;
/// <summary>
/// Gets or sets the skinned model asset to preview.
/// </summary>
@@ -249,8 +254,11 @@ namespace FlaxEditor.Viewport.Previews
{
if (!ScaleToFit)
{
_previewModel.Scale = Vector3.One;
_previewModel.Position = Vector3.Zero;
if (_snapToOrigin)
{
_previewModel.Scale = Vector3.One;
_previewModel.Position = Vector3.Zero;
}
return;
}

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 FlaxEditor.Viewport.Widgets;
@@ -15,6 +16,20 @@ namespace FlaxEditor.Viewport.Previews
{
private ViewportWidgetButton _playPauseButton;
/// <summary>
/// Gets or sets a value indicating whether enable root motion.
/// </summary>
public bool RootMotion
{
get => !_snapToOrigin;
set
{
if (!_snapToOrigin == value)
return;
_snapToOrigin = !value;
}
}
/// <summary>
/// Initializes a new instance of the <see cref="AnimationPreview"/> class.
/// </summary>
@@ -24,6 +39,7 @@ namespace FlaxEditor.Viewport.Previews
{
PlayAnimation = true;
PlayAnimationChanged += OnPlayAnimationChanged;
_snapToOrigin = false;
// Playback Speed
{
@@ -48,6 +64,17 @@ namespace FlaxEditor.Viewport.Previews
playPauseWidget.Parent = this;
}
// Play Root Motion
{
var button = ViewWidgetButtonMenu.AddButton("Root Motion");
var buttonValue = new CheckBox(90, 2, !_snapToOrigin)
{
Parent = button
};
buttonValue.StateChanged += checkbox => RootMotion = !RootMotion;
ViewWidgetButtonMenu.VisibleChanged += control => buttonValue.Checked = RootMotion;
}
// Enable shadows
PreviewLight.ShadowsMode = ShadowsCastingMode.All;
PreviewLight.CascadeCount = 2;