From d5585a30fdcea6acd06a59ed1aa89a60a33cebff Mon Sep 17 00:00:00 2001 From: Wojciech Figat Date: Fri, 10 Dec 2021 12:42:11 +0100 Subject: [PATCH] Fix missing root motion preview in Animation preview panels (with option to disable it) --- .../Viewport/Previews/AnimatedModelPreview.cs | 12 +++++++-- .../Viewport/Previews/AnimationPreview.cs | 27 +++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/Source/Editor/Viewport/Previews/AnimatedModelPreview.cs b/Source/Editor/Viewport/Previews/AnimatedModelPreview.cs index f3b1d263e..7337bd78b 100644 --- a/Source/Editor/Viewport/Previews/AnimatedModelPreview.cs +++ b/Source/Editor/Viewport/Previews/AnimatedModelPreview.cs @@ -23,6 +23,11 @@ namespace FlaxEditor.Viewport.Previews private bool _playAnimation, _playAnimationOnce; private float _playSpeed = 1.0f; + /// + /// Snaps the preview actor to the world origin. + /// + protected bool _snapToOrigin = true; + /// /// Gets or sets the skinned model asset to preview. /// @@ -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; } diff --git a/Source/Editor/Viewport/Previews/AnimationPreview.cs b/Source/Editor/Viewport/Previews/AnimationPreview.cs index 6e7903c7b..9ef6fedb9 100644 --- a/Source/Editor/Viewport/Previews/AnimationPreview.cs +++ b/Source/Editor/Viewport/Previews/AnimationPreview.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 FlaxEditor.Viewport.Widgets; @@ -15,6 +16,20 @@ namespace FlaxEditor.Viewport.Previews { private ViewportWidgetButton _playPauseButton; + /// + /// Gets or sets a value indicating whether enable root motion. + /// + public bool RootMotion + { + get => !_snapToOrigin; + set + { + if (!_snapToOrigin == value) + return; + _snapToOrigin = !value; + } + } + /// /// Initializes a new instance of the class. /// @@ -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;