Files
UnrealEngineUWP/Engine/Plugins/Animation/AnimationLocomotionLibrary/Source/Editor/Public/DistanceCurveModifier.h
jose villarroel b3528e3c8d Added option to specify the last frame as the root motion stop of a distance matched anim
[at]Aaron.Cox
#preflight 61b2907fc01c89f906c514ae
#preflight 61b2907fc01c89f906c514ae

#ROBOMERGE-AUTHOR: jose.villarroel
#ROBOMERGE-SOURCE: CL 18426828 in //UE5/Release-5.0/... via CL 18427088
#ROBOMERGE-BOT: STARSHIP (Release-Engine-Staging -> Release-Engine-Test) (v897-18405271)

[CL 18427124 by jose villarroel in ue5-release-engine-test branch]
2021-12-09 18:58:48 -05:00

62 lines
1.9 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
#include "AnimationModifier.h"
#include "DistanceCurveModifier.generated.h"
// @todo: Consolidate with EMotionExtractor_Axis
/** Axes to calculate the distance value from */
UENUM(BlueprintType)
enum class EDistanceCurve_Axis : uint8
{
X,
Y,
Z,
XY,
XZ,
YZ,
XYZ
};
/** Extracts traveling distance information from root motion and bakes it to a curve.
* A negative value indicates distance remaining to a stop or pivot point.
* A positive value indicates distance traveled from a start point or from the beginning of the clip.
*/
UCLASS()
class UDistanceCurveModifier : public UAnimationModifier
{
GENERATED_BODY()
public:
/** Rate used to sample the animation. */
UPROPERTY(EditAnywhere, Category = Settings, meta = (ClampMin = "1"))
int32 SampleRate = 30;
/** Name for the generated curve. */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Settings)
FName CurveName = "Distance";
/** Root motion speed must be below this threshold to be considered stopped. */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Settings, meta=(EditCondition="!bStopAtEnd"))
float StopSpeedThreshold = 5.0f;
/** Axes to calculate the distance value from. */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Settings)
EDistanceCurve_Axis Axis = EDistanceCurve_Axis::XY;
/** Root motion is considered to be stopped at the clip's end */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Settings)
bool bStopAtEnd = false;
virtual void OnApply_Implementation(UAnimSequence* Animation) override;
virtual void OnRevert_Implementation(UAnimSequence* Animation) override;
private:
/** Helper functions to calculate the magnitude of a vector only considering a specific axis or axes */
static float CalculateMagnitude(const FVector& Vector, EDistanceCurve_Axis Axis);
static float CalculateMagnitudeSq(const FVector& Vector, EDistanceCurve_Axis Axis);
};