You've already forked UnrealEngineUWP
mirror of
https://github.com/izzy2lost/UnrealEngineUWP.git
synced 2026-03-26 18:15:20 -07:00
- Engine - IAnimationDataModel interface - AnimationData plugin - AnimSequencerDataModel, sequencer based implementation of IAnimationDataModel - AnimSequencerDataController, controller for above (implementation of IAnimationDataController) - Added FCompressedRichCurve::PopulateCurve, allowing users to convert back to a FRichCurve for validation/debugging - Added DefaultFrameRate to AnimationSettings, this replaces the hardcoded 30FPS in code - Added ::GetKeyIndicesFromTime which takes FFrameRate - Added AnimSequenceBase::OnAnimModelLoaded, this is required for correct postloading behaviour of data model (specifically AnimSequencerDataModel, as it depends on data from its outer ? anim sequence) - Added IAnimationDataModel ::Evaluate which now takes responsibility for evaluating raw animation bone, curve and attribute data. And moved all trackbased evaluation code into AnimDataModel.cpp - Added a.ForceEvalRawData allowing to force evaluation of source data - Added a.SkipDDC to force compressing animation data locally **Changed** - Reparent UAnimDataModel to IAnimationDataModel interface, and rejig behaviour - AnimSequenceBase now reference AnimDataModel as IAnimationDataModel - Upgrade path for legacy to IAnimationDataModel and existing UAnimDataModel to IAnimationDataModel through IAnimationDataController::PopulateWithExisting - IAnimationDataModel data is now frame(number/rate/time) based rather than seconds/keyindices. This enforces frameborder aligned data from now on. - Moved RichCurve evaluation code from RichCurve.cpp to separate file and consolidated all instances of copy-pasta behaviour - Updated/removed deprecated EngineTests around AnimSequences - Changed many instances to use a FFrameTime together with a known FFrameRate versus seconds and sequencelength in float involving frame \/ time calculations (including instances of FAnimKeyHelper) - Switched anim sequence evaluation to use double in Extraction context for time value and patched up places with static\_cast\<double\> - FRichCurve::Eval - Make sure we always evaluate keys when T >= Key0.Time and T <= KeyN.Time to deal with crazy userweighted tangents - Fixed WeightedKeyDataAdapter::GetKeyInterpMode/GetKeyTangentWeightMode retrieving invalid values, as it was indexing according to KeyIndex rather than KeyIndex\*2. This made it so that values were misinterpreted. - Fixed WeightedEvalForTwoKeys for compressed data retrieving GetKeyInterpMode and GetKeyTangentWeightMode using the wrong index value. As they are not indexed using KeyDataHandle type. - Fixed issue where compression could crash when containing zero-key scale additivebase track (tries to retrieve) - Replaced instances of NULL with nullptr - Moved required decompression information into FAnimSequenceDecompressionContext and reimplemented decompression within UE::Anim::Decompression namespace and new file - Deprecated ::GetRawDataGuid and replaced with GetDataModel()->GenerateGuid() - Fixed UAnimStreamable evaluation/compression (previously broken with MVC refactor) - Updated Animation exporting pipeline to be frame-based rather than seconds - Deprecated RetargetPose, replaced with FRetargetingScope (used within AnimModel::Evaluate) - Fixed BaseAdditiveAnimation array become invalid/incorrect when removing zero-additve tracks during compression - Updated EngineTest animation sequence related tests to new APIs (while maintaining deprecated path testing as well for now) - AnimDataController / Animation Sequence tests now generate a USkeleton for the transient animation sequence (used to perform the test on) **Removed** - Unused file/class AnimData/AnimDataNotifyCollector.h #rb Thomas.Sarkanen, Martin.Wilson, Alexis.Matte, Mike.Zyracki #jira UE-131296 #preflight 62a308a8b0150a87f9d6891b [CL 20593017 by Jurre deBaare in ue5-main branch]
612 lines
18 KiB
C++
612 lines
18 KiB
C++
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
#include "SAnimationScrubPanel.h"
|
|
#include "Widgets/SBoxPanel.h"
|
|
#include "Animation/AnimSequenceBase.h"
|
|
#include "Animation/AnimSequence.h"
|
|
#include "Animation/AnimBlueprintGeneratedClass.h"
|
|
#include "Animation/AnimBlueprint.h"
|
|
#include "AnimPreviewInstance.h"
|
|
#include "SScrubControlPanel.h"
|
|
#include "ScopedTransaction.h"
|
|
#include "Animation/BlendSpace.h"
|
|
#include "AnimationEditorPreviewScene.h"
|
|
#include "Animation/AnimData/IAnimationDataModel.h"
|
|
#include "Animation/AnimSequenceHelpers.h"
|
|
|
|
#define LOCTEXT_NAMESPACE "AnimationScrubPanel"
|
|
|
|
void SAnimationScrubPanel::Construct( const SAnimationScrubPanel::FArguments& InArgs, const TSharedRef<IPersonaPreviewScene>& InPreviewScene)
|
|
{
|
|
bSliderBeingDragged = false;
|
|
LockedSequence = InArgs._LockedSequence;
|
|
OnSetInputViewRange = InArgs._OnSetInputViewRange;
|
|
|
|
PreviewScenePtr = InPreviewScene;
|
|
|
|
this->ChildSlot
|
|
[
|
|
SNew(SHorizontalBox)
|
|
.AddMetaData<FTagMetaData>(TEXT("AnimScrub.Scrub"))
|
|
+SHorizontalBox::Slot()
|
|
.HAlign(HAlign_Fill)
|
|
.VAlign(VAlign_Center)
|
|
.FillWidth(1)
|
|
.Padding(0.0f)
|
|
[
|
|
SAssignNew(ScrubControlPanel, SScrubControlPanel)
|
|
.IsEnabled(true)//this, &SAnimationScrubPanel::DoesSyncViewport)
|
|
.Value(this, &SAnimationScrubPanel::GetScrubValue)
|
|
.NumOfKeys(this, &SAnimationScrubPanel::GetNumberOfKeys)
|
|
.SequenceLength(this, &SAnimationScrubPanel::GetSequenceLength)
|
|
.DisplayDrag(this, &SAnimationScrubPanel::GetDisplayDrag)
|
|
.OnValueChanged(this, &SAnimationScrubPanel::OnValueChanged)
|
|
.OnBeginSliderMovement(this, &SAnimationScrubPanel::OnBeginSliderMovement)
|
|
.OnEndSliderMovement(this, &SAnimationScrubPanel::OnEndSliderMovement)
|
|
.OnClickedForwardPlay(this, &SAnimationScrubPanel::OnClick_Forward)
|
|
.OnClickedForwardStep(this, &SAnimationScrubPanel::OnClick_Forward_Step)
|
|
.OnClickedForwardEnd(this, &SAnimationScrubPanel::OnClick_Forward_End)
|
|
.OnClickedBackwardPlay(this, &SAnimationScrubPanel::OnClick_Backward)
|
|
.OnClickedBackwardStep(this, &SAnimationScrubPanel::OnClick_Backward_Step)
|
|
.OnClickedBackwardEnd(this, &SAnimationScrubPanel::OnClick_Backward_End)
|
|
.OnClickedToggleLoop(this, &SAnimationScrubPanel::OnClick_ToggleLoop)
|
|
.OnClickedRecord(this, &SAnimationScrubPanel::OnClick_Record)
|
|
.OnGetLooping(this, &SAnimationScrubPanel::IsLoopStatusOn)
|
|
.OnGetPlaybackMode(this, &SAnimationScrubPanel::GetPlaybackMode)
|
|
.OnGetRecording(this, &SAnimationScrubPanel::IsRecording)
|
|
.ViewInputMin(InArgs._ViewInputMin)
|
|
.ViewInputMax(InArgs._ViewInputMax)
|
|
.bDisplayAnimScrubBarEditing(InArgs._bDisplayAnimScrubBarEditing)
|
|
.OnSetInputViewRange(InArgs._OnSetInputViewRange)
|
|
.OnCropAnimSequence( this, &SAnimationScrubPanel::OnCropAnimSequence )
|
|
.OnAddAnimSequence( this, &SAnimationScrubPanel::OnInsertAnimSequence )
|
|
.OnAppendAnimSequence(this, &SAnimationScrubPanel::OnAppendAnimSequence )
|
|
.OnReZeroAnimSequence( this, &SAnimationScrubPanel::OnReZeroAnimSequence )
|
|
.bAllowZoom(InArgs._bAllowZoom)
|
|
.IsRealtimeStreamingMode(this, &SAnimationScrubPanel::IsRealtimeStreamingMode)
|
|
]
|
|
];
|
|
}
|
|
|
|
FReply SAnimationScrubPanel::OnClick_Forward_Step()
|
|
{
|
|
UDebugSkelMeshComponent* SMC = GetPreviewScene()->GetPreviewMeshComponent();
|
|
|
|
if (UAnimSingleNodeInstance* PreviewInstance = GetPreviewInstance())
|
|
{
|
|
bool bShouldStepCloth = FMath::Abs(PreviewInstance->GetLength() - PreviewInstance->GetCurrentTime()) > SMALL_NUMBER;
|
|
|
|
PreviewInstance->SetPlaying(false);
|
|
PreviewInstance->StepForward();
|
|
|
|
if(SMC && bShouldStepCloth)
|
|
{
|
|
SMC->bPerformSingleClothingTick = true;
|
|
}
|
|
}
|
|
else if (SMC)
|
|
{
|
|
// BlendSpaces and Animation Blueprints combine animations so there's no such thing as a frame. However, 1/30 is a sensible/common rate.
|
|
const float FixedFrameRate = 30.0f;
|
|
|
|
// Advance a single frame, leaving it paused afterwards
|
|
SMC->GlobalAnimRateScale = 1.0f;
|
|
GetPreviewScene()->Tick(1.0f / FixedFrameRate);
|
|
SMC->GlobalAnimRateScale = 0.0f;
|
|
}
|
|
|
|
return FReply::Handled();
|
|
}
|
|
|
|
FReply SAnimationScrubPanel::OnClick_Forward_End()
|
|
{
|
|
UAnimSingleNodeInstance* PreviewInstance = GetPreviewInstance();
|
|
if (PreviewInstance)
|
|
{
|
|
PreviewInstance->SetPlaying(false);
|
|
PreviewInstance->SetPosition(PreviewInstance->GetLength(), false);
|
|
}
|
|
|
|
return FReply::Handled();
|
|
}
|
|
|
|
FReply SAnimationScrubPanel::OnClick_Backward_Step()
|
|
{
|
|
UAnimSingleNodeInstance* PreviewInstance = GetPreviewInstance();
|
|
UDebugSkelMeshComponent* SMC = GetPreviewScene()->GetPreviewMeshComponent();
|
|
if (PreviewInstance)
|
|
{
|
|
bool bShouldStepCloth = PreviewInstance->GetCurrentTime() > SMALL_NUMBER;
|
|
|
|
PreviewInstance->SetPlaying(false);
|
|
PreviewInstance->StepBackward();
|
|
|
|
if(SMC && bShouldStepCloth)
|
|
{
|
|
SMC->bPerformSingleClothingTick = true;
|
|
}
|
|
}
|
|
return FReply::Handled();
|
|
}
|
|
|
|
FReply SAnimationScrubPanel::OnClick_Backward_End()
|
|
{
|
|
UAnimSingleNodeInstance* PreviewInstance = GetPreviewInstance();
|
|
if (PreviewInstance)
|
|
{
|
|
PreviewInstance->SetPlaying(false);
|
|
PreviewInstance->SetPosition(0.f, false);
|
|
}
|
|
return FReply::Handled();
|
|
}
|
|
|
|
FReply SAnimationScrubPanel::OnClick_Forward()
|
|
{
|
|
UAnimSingleNodeInstance* PreviewInstance = GetPreviewInstance();
|
|
UDebugSkelMeshComponent* SMC = GetPreviewScene()->GetPreviewMeshComponent();
|
|
|
|
if (PreviewInstance)
|
|
{
|
|
bool bIsReverse = PreviewInstance->IsReverse();
|
|
bool bIsPlaying = PreviewInstance->IsPlaying();
|
|
// if current bIsReverse and bIsPlaying, we'd like to just turn off reverse
|
|
if (bIsReverse && bIsPlaying)
|
|
{
|
|
PreviewInstance->SetReverse(false);
|
|
}
|
|
// already playing, simply pause
|
|
else if (bIsPlaying)
|
|
{
|
|
PreviewInstance->SetPlaying(false);
|
|
|
|
if(SMC && SMC->bPauseClothingSimulationWithAnim)
|
|
{
|
|
SMC->SuspendClothingSimulation();
|
|
}
|
|
}
|
|
// if not playing, play forward
|
|
else
|
|
{
|
|
//if we're at the end of the animation, jump back to the beginning before playing
|
|
if ( GetScrubValue() >= GetSequenceLength() )
|
|
{
|
|
PreviewInstance->SetPosition(0.0f, false);
|
|
}
|
|
|
|
PreviewInstance->SetReverse(false);
|
|
PreviewInstance->SetPlaying(true);
|
|
|
|
if(SMC && SMC->bPauseClothingSimulationWithAnim)
|
|
{
|
|
SMC->ResumeClothingSimulation();
|
|
}
|
|
}
|
|
}
|
|
else if(SMC)
|
|
{
|
|
SMC->GlobalAnimRateScale = (SMC->GlobalAnimRateScale > 0.0f) ? 0.0f : 1.0f;
|
|
}
|
|
|
|
return FReply::Handled();
|
|
}
|
|
|
|
FReply SAnimationScrubPanel::OnClick_Backward()
|
|
{
|
|
UAnimSingleNodeInstance* PreviewInstance = GetPreviewInstance();
|
|
if (PreviewInstance)
|
|
{
|
|
bool bIsReverse = PreviewInstance->IsReverse();
|
|
bool bIsPlaying = PreviewInstance->IsPlaying();
|
|
// if currently playing forward, just simply turn on reverse
|
|
if (!bIsReverse && bIsPlaying)
|
|
{
|
|
PreviewInstance->SetReverse(true);
|
|
}
|
|
else if (bIsPlaying)
|
|
{
|
|
PreviewInstance->SetPlaying(false);
|
|
}
|
|
else
|
|
{
|
|
//if we're at the beginning of the animation, jump back to the end before playing
|
|
if ( GetScrubValue() <= 0.0f )
|
|
{
|
|
PreviewInstance->SetPosition(GetSequenceLength(), false);
|
|
}
|
|
|
|
PreviewInstance->SetPlaying(true);
|
|
PreviewInstance->SetReverse(true);
|
|
}
|
|
}
|
|
return FReply::Handled();
|
|
}
|
|
|
|
FReply SAnimationScrubPanel::OnClick_ToggleLoop()
|
|
{
|
|
UAnimSingleNodeInstance* PreviewInstance = GetPreviewInstance();
|
|
if (PreviewInstance)
|
|
{
|
|
bool bIsLooping = PreviewInstance->IsLooping();
|
|
PreviewInstance->SetLooping(!bIsLooping);
|
|
}
|
|
return FReply::Handled();
|
|
}
|
|
|
|
FReply SAnimationScrubPanel::OnClick_Record()
|
|
{
|
|
StaticCastSharedRef<FAnimationEditorPreviewScene>(GetPreviewScene())->RecordAnimation();
|
|
|
|
return FReply::Handled();
|
|
}
|
|
|
|
bool SAnimationScrubPanel::IsLoopStatusOn() const
|
|
{
|
|
UAnimSingleNodeInstance* PreviewInstance = GetPreviewInstance();
|
|
return (PreviewInstance && PreviewInstance->IsLooping());
|
|
}
|
|
|
|
EPlaybackMode::Type SAnimationScrubPanel::GetPlaybackMode() const
|
|
{
|
|
if (UAnimSingleNodeInstance* PreviewInstance = GetPreviewInstance())
|
|
{
|
|
if (PreviewInstance->IsPlaying())
|
|
{
|
|
return PreviewInstance->IsReverse() ? EPlaybackMode::PlayingReverse : EPlaybackMode::PlayingForward;
|
|
}
|
|
return EPlaybackMode::Stopped;
|
|
}
|
|
else if (UDebugSkelMeshComponent* SMC = GetPreviewScene()->GetPreviewMeshComponent())
|
|
{
|
|
return (SMC->GlobalAnimRateScale > 0.0f) ? EPlaybackMode::PlayingForward : EPlaybackMode::Stopped;
|
|
}
|
|
|
|
return EPlaybackMode::Stopped;
|
|
}
|
|
|
|
bool SAnimationScrubPanel::IsRecording() const
|
|
{
|
|
return StaticCastSharedRef<FAnimationEditorPreviewScene>(GetPreviewScene())->IsRecording();
|
|
}
|
|
|
|
bool SAnimationScrubPanel::IsRealtimeStreamingMode() const
|
|
{
|
|
UAnimSingleNodeInstance* PreviewInstance = GetPreviewInstance();
|
|
return ( ! (PreviewInstance && PreviewInstance->GetCurrentAsset()) );
|
|
}
|
|
|
|
void SAnimationScrubPanel::OnValueChanged(float NewValue)
|
|
{
|
|
if (UAnimSingleNodeInstance* PreviewInstance = GetPreviewInstance())
|
|
{
|
|
PreviewInstance->SetPosition(NewValue);
|
|
}
|
|
else
|
|
{
|
|
UAnimInstance* Instance;
|
|
FAnimBlueprintDebugData* DebugData;
|
|
if (GetAnimBlueprintDebugData(/*out*/ Instance, /*out*/ DebugData))
|
|
{
|
|
DebugData->SetSnapshotIndexByTime(Instance, NewValue);
|
|
}
|
|
}
|
|
}
|
|
|
|
// make sure viewport is freshes
|
|
void SAnimationScrubPanel::OnBeginSliderMovement()
|
|
{
|
|
bSliderBeingDragged = true;
|
|
|
|
if (UAnimSingleNodeInstance* PreviewInstance = GetPreviewInstance())
|
|
{
|
|
PreviewInstance->SetPlaying(false);
|
|
}
|
|
}
|
|
|
|
void SAnimationScrubPanel::OnEndSliderMovement(float NewValue)
|
|
{
|
|
bSliderBeingDragged = false;
|
|
}
|
|
|
|
uint32 SAnimationScrubPanel::GetNumberOfKeys() const
|
|
{
|
|
if (DoesSyncViewport())
|
|
{
|
|
UAnimSingleNodeInstance* PreviewInstance = GetPreviewInstance();
|
|
float Length = PreviewInstance->GetLength();
|
|
// if anim sequence, use correct num frames
|
|
int32 NumKeys = (int32) (Length/0.0333f);
|
|
if (PreviewInstance->GetCurrentAsset())
|
|
{
|
|
if (PreviewInstance->GetCurrentAsset()->IsA(UAnimSequenceBase::StaticClass()))
|
|
{
|
|
NumKeys = CastChecked<UAnimSequenceBase>(PreviewInstance->GetCurrentAsset())->GetNumberOfSampledKeys();
|
|
}
|
|
else if(PreviewInstance->GetCurrentAsset()->IsA(UBlendSpace::StaticClass()))
|
|
{
|
|
// Blendspaces dont display frame notches, so just return 0 here
|
|
NumKeys = 0;
|
|
}
|
|
}
|
|
return NumKeys;
|
|
}
|
|
else if (LockedSequence)
|
|
{
|
|
return LockedSequence->GetNumberOfSampledKeys();
|
|
}
|
|
else
|
|
{
|
|
UAnimInstance* Instance;
|
|
FAnimBlueprintDebugData* DebugData;
|
|
if (GetAnimBlueprintDebugData(/*out*/ Instance, /*out*/ DebugData))
|
|
{
|
|
return DebugData->GetSnapshotLengthInFrames();
|
|
}
|
|
}
|
|
|
|
return 1;
|
|
}
|
|
|
|
float SAnimationScrubPanel::GetSequenceLength() const
|
|
{
|
|
if (DoesSyncViewport())
|
|
{
|
|
UAnimSingleNodeInstance* PreviewInstance = GetPreviewInstance();
|
|
return PreviewInstance->GetLength();
|
|
}
|
|
else if (LockedSequence)
|
|
{
|
|
return LockedSequence->GetPlayLength();
|
|
}
|
|
else
|
|
{
|
|
UAnimInstance* Instance;
|
|
FAnimBlueprintDebugData* DebugData;
|
|
if (GetAnimBlueprintDebugData(/*out*/ Instance, /*out*/ DebugData))
|
|
{
|
|
return Instance->LifeTimer;
|
|
}
|
|
}
|
|
|
|
return 0.f;
|
|
}
|
|
|
|
bool SAnimationScrubPanel::DoesSyncViewport() const
|
|
{
|
|
UAnimSingleNodeInstance* PreviewInstance = GetPreviewInstance();
|
|
|
|
return (( LockedSequence==nullptr && PreviewInstance ) || ( LockedSequence && PreviewInstance && PreviewInstance->GetCurrentAsset() == LockedSequence ));
|
|
}
|
|
|
|
void SAnimationScrubPanel::Tick( const FGeometry& AllottedGeometry, const double InCurrentTime, const float InDeltaTime )
|
|
{
|
|
if (bSliderBeingDragged)
|
|
{
|
|
GetPreviewScene()->InvalidateViews();
|
|
}
|
|
}
|
|
|
|
class UAnimSingleNodeInstance* SAnimationScrubPanel::GetPreviewInstance() const
|
|
{
|
|
UDebugSkelMeshComponent* PreviewMeshComponent = GetPreviewScene()->GetPreviewMeshComponent();
|
|
return PreviewMeshComponent && PreviewMeshComponent->IsPreviewOn()? PreviewMeshComponent->PreviewInstance : nullptr;
|
|
}
|
|
|
|
float SAnimationScrubPanel::GetScrubValue() const
|
|
{
|
|
if (DoesSyncViewport())
|
|
{
|
|
UAnimSingleNodeInstance* PreviewInstance = GetPreviewInstance();
|
|
if (PreviewInstance)
|
|
{
|
|
return PreviewInstance->GetCurrentTime();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
UAnimInstance* Instance;
|
|
FAnimBlueprintDebugData* DebugData;
|
|
if (GetAnimBlueprintDebugData(/*out*/ Instance, /*out*/ DebugData))
|
|
{
|
|
return Instance->CurrentLifeTimerScrubPosition;
|
|
}
|
|
}
|
|
|
|
return 0.f;
|
|
}
|
|
|
|
void SAnimationScrubPanel::ReplaceLockedSequence(class UAnimSequenceBase* NewLockedSequence)
|
|
{
|
|
LockedSequence = NewLockedSequence;
|
|
}
|
|
|
|
UAnimInstance* SAnimationScrubPanel::GetAnimInstanceWithBlueprint() const
|
|
{
|
|
if (UDebugSkelMeshComponent* DebugComponent = GetPreviewScene()->GetPreviewMeshComponent())
|
|
{
|
|
UAnimInstance* Instance = DebugComponent->GetAnimInstance();
|
|
|
|
if ((Instance != nullptr) && (Instance->GetClass()->ClassGeneratedBy != nullptr))
|
|
{
|
|
return Instance;
|
|
}
|
|
}
|
|
|
|
return nullptr;
|
|
}
|
|
|
|
bool SAnimationScrubPanel::GetAnimBlueprintDebugData(UAnimInstance*& Instance, FAnimBlueprintDebugData*& DebugInfo) const
|
|
{
|
|
Instance = GetAnimInstanceWithBlueprint();
|
|
|
|
if (Instance != nullptr)
|
|
{
|
|
// Avoid updating the instance if we're replaying the past
|
|
if (UAnimBlueprintGeneratedClass* AnimBlueprintClass = Cast<UAnimBlueprintGeneratedClass>(Instance->GetClass()))
|
|
{
|
|
if (UAnimBlueprint* Blueprint = Cast<UAnimBlueprint>(AnimBlueprintClass->ClassGeneratedBy))
|
|
{
|
|
if (Blueprint->GetObjectBeingDebugged() == Instance)
|
|
{
|
|
DebugInfo = &(AnimBlueprintClass->GetAnimBlueprintDebugData());
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
void SAnimationScrubPanel::OnCropAnimSequence( bool bFromStart, float CurrentTime )
|
|
{
|
|
UAnimSingleNodeInstance* PreviewInstance = GetPreviewInstance();
|
|
if(PreviewInstance)
|
|
{
|
|
float Length = PreviewInstance->GetLength();
|
|
if (PreviewInstance->GetCurrentAsset())
|
|
{
|
|
UAnimSequence* AnimSequence = Cast<UAnimSequence>( PreviewInstance->GetCurrentAsset() );
|
|
if( AnimSequence )
|
|
{
|
|
const FScopedTransaction Transaction( LOCTEXT("CropAnimSequence", "Crop Animation Sequence") );
|
|
|
|
//Call modify to restore slider position
|
|
PreviewInstance->Modify();
|
|
|
|
//Call modify to restore anim sequence current state
|
|
AnimSequence->Modify();
|
|
|
|
|
|
const float TrimStart = bFromStart ? 0.f : CurrentTime;
|
|
const float TrimEnd = bFromStart ? CurrentTime : AnimSequence->GetPlayLength();
|
|
|
|
// Trim off the user-selected part of the raw anim data.
|
|
UE::Anim::AnimationData::Trim(AnimSequence, TrimStart, TrimEnd);
|
|
|
|
//Resetting slider position to the first frame
|
|
PreviewInstance->SetPosition( 0.0f, false );
|
|
|
|
OnSetInputViewRange.ExecuteIfBound(0, AnimSequence->GetPlayLength());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void SAnimationScrubPanel::OnAppendAnimSequence( bool bFromStart, int32 NumOfFrames )
|
|
{
|
|
UAnimSingleNodeInstance* PreviewInstance = GetPreviewInstance();
|
|
if(PreviewInstance && PreviewInstance->GetCurrentAsset())
|
|
{
|
|
UAnimSequence* AnimSequence = Cast<UAnimSequence>(PreviewInstance->GetCurrentAsset());
|
|
if(AnimSequence)
|
|
{
|
|
const FScopedTransaction Transaction(LOCTEXT("InsertAnimSequence", "Insert Animation Sequence"));
|
|
|
|
//Call modify to restore slider position
|
|
PreviewInstance->Modify();
|
|
|
|
//Call modify to restore anim sequence current state
|
|
AnimSequence->Modify();
|
|
|
|
// Crop the raw anim data.
|
|
int32 StartFrame = (bFromStart)? 0 : AnimSequence->GetDataModel()->GetNumberOfFrames() - 1;
|
|
int32 EndFrame = StartFrame + NumOfFrames;
|
|
int32 CopyFrame = StartFrame;
|
|
UE::Anim::AnimationData::DuplicateKeys(AnimSequence, StartFrame, NumOfFrames, CopyFrame);
|
|
|
|
OnSetInputViewRange.ExecuteIfBound(0, AnimSequence->GetPlayLength());
|
|
}
|
|
}
|
|
}
|
|
|
|
void SAnimationScrubPanel::OnInsertAnimSequence( bool bBefore, int32 CurrentFrame )
|
|
{
|
|
UAnimSingleNodeInstance* PreviewInstance = GetPreviewInstance();
|
|
if(PreviewInstance && PreviewInstance->GetCurrentAsset())
|
|
{
|
|
UAnimSequence* AnimSequence = Cast<UAnimSequence>(PreviewInstance->GetCurrentAsset());
|
|
if(AnimSequence)
|
|
{
|
|
const FScopedTransaction Transaction(LOCTEXT("InsertAnimSequence", "Insert Animation Sequence"));
|
|
|
|
//Call modify to restore slider position
|
|
PreviewInstance->Modify();
|
|
|
|
//Call modify to restore anim sequence current state
|
|
AnimSequence->Modify();
|
|
|
|
// Duplicate specified key
|
|
const int32 StartFrame = (bBefore)? CurrentFrame : CurrentFrame + 1;
|
|
UE::Anim::AnimationData::DuplicateKeys(AnimSequence, StartFrame, 1, CurrentFrame);
|
|
|
|
OnSetInputViewRange.ExecuteIfBound(0, AnimSequence->GetPlayLength());
|
|
}
|
|
}
|
|
}
|
|
|
|
void SAnimationScrubPanel::OnReZeroAnimSequence(int32 FrameIndex)
|
|
{
|
|
UAnimSingleNodeInstance* PreviewInstance = GetPreviewInstance();
|
|
if(PreviewInstance)
|
|
{
|
|
UDebugSkelMeshComponent* PreviewSkelComp = GetPreviewScene()->GetPreviewMeshComponent();
|
|
|
|
if (PreviewInstance->GetCurrentAsset() && PreviewSkelComp )
|
|
{
|
|
UAnimSequence* AnimSequence = Cast<UAnimSequence>( PreviewInstance->GetCurrentAsset() );
|
|
if( AnimSequence )
|
|
{
|
|
const FScopedTransaction Transaction( LOCTEXT("ReZeroAnimation", "ReZero Animation Sequence") );
|
|
|
|
//Call modify to restore anim sequence current state
|
|
AnimSequence->Modify();
|
|
|
|
// As above, animations don't have any idea of hierarchy, so we don't know for sure if track 0 is the root bone's track.
|
|
const FBoneAnimationTrack& AnimationTrack = AnimSequence->GetDataModel()->GetBoneTrackByIndex(0);
|
|
FRawAnimSequenceTrack RawTrack = AnimationTrack.InternalTrackData;
|
|
|
|
// Find vector that would translate current root bone location onto origin.
|
|
FVector FrameTransform = FVector::ZeroVector;
|
|
if (FrameIndex == INDEX_NONE)
|
|
{
|
|
// Use current transform
|
|
FrameTransform = PreviewSkelComp->GetComponentSpaceTransforms()[0].GetLocation();
|
|
}
|
|
else if(RawTrack.PosKeys.IsValidIndex(FrameIndex))
|
|
{
|
|
// Use transform at frame
|
|
FrameTransform = (FVector)RawTrack.PosKeys[FrameIndex];
|
|
}
|
|
|
|
FVector ApplyTranslation = -1.f * FrameTransform;
|
|
|
|
// Convert into world space
|
|
FVector WorldApplyTranslation = PreviewSkelComp->GetComponentTransform().TransformVector(ApplyTranslation);
|
|
ApplyTranslation = PreviewSkelComp->GetComponentTransform().InverseTransformVector(WorldApplyTranslation);
|
|
|
|
for(int32 i=0; i<RawTrack.PosKeys.Num(); i++)
|
|
{
|
|
RawTrack.PosKeys[i] += (FVector3f)ApplyTranslation;
|
|
}
|
|
|
|
IAnimationDataController& Controller = AnimSequence->GetController();
|
|
Controller.SetBoneTrackKeys(AnimationTrack.Name, RawTrack.PosKeys, RawTrack.RotKeys, RawTrack.ScaleKeys);
|
|
|
|
AnimSequence->MarkPackageDirty();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
bool SAnimationScrubPanel::GetDisplayDrag() const
|
|
{
|
|
UAnimSingleNodeInstance* PreviewInstance = GetPreviewInstance();
|
|
if (PreviewInstance && PreviewInstance->GetCurrentAsset())
|
|
{
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
#undef LOCTEXT_NAMESPACE
|