第一次提交

This commit is contained in:
不明不惑
2026-03-03 01:23:02 +08:00
commit 3e434877e8
1053 changed files with 102411 additions and 0 deletions

View File

@@ -0,0 +1,61 @@
// Copyright 2025 https://yuewu.dev/en All Rights Reserved.
#pragma once
#include "Animation/AnimNodeBase.h"
#include "GMS_AnimNode_CurvesBlend.generated.h"
UENUM(BlueprintType)
enum class EGMS_CurvesBlendMode : uint8
{
// Blend poses using blend amount. Same as ECurveBlendOption::BlendByWeight.
BlendByAmount,
// Only set the value if the curves pose has the curve value. Same as ECurveBlendOption::Override.
Combine,
// Only set the value if the source pose doesn't have the curve value. Same as ECurveBlendOption::DoNotOverride.
CombinePreserved,
// Find the highest curve value from multiple poses and use that. Same as ECurveBlendOption::UseMaxValue.
UseMaxValue,
// Find the lowest curve value from multiple poses and use that. Same as ECurveBlendOption::UseMinValue.
UseMinValue,
// Completely override source pose. Same as ECurveBlendOption::UseBasePose.
Override
};
USTRUCT(BlueprintInternalUseOnly)
struct GENERICMOVEMENTSYSTEM_API FGMS_AnimNode_CurvesBlend : public FAnimNode_Base
{
GENERATED_BODY()
public:
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Settings")
FPoseLink SourcePose;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Settings")
FPoseLink CurvesPose;
#if WITH_EDITORONLY_DATA
UPROPERTY(EditAnywhere, Category = "Settings", Meta = (ClampMin = 0, ClampMax = 1, FoldProperty, PinShownByDefault))
float BlendAmount{1.0f};
UPROPERTY(EditAnywhere, Category = "Settings", Meta = (FoldProperty))
EGMS_CurvesBlendMode BlendMode{EGMS_CurvesBlendMode::BlendByAmount};
#endif
public:
virtual void Initialize_AnyThread(const FAnimationInitializeContext& Context) override;
virtual void CacheBones_AnyThread(const FAnimationCacheBonesContext& Context) override;
virtual void Update_AnyThread(const FAnimationUpdateContext& Context) override;
virtual void Evaluate_AnyThread(FPoseContext& Output) override;
virtual void GatherDebugData(FNodeDebugData& DebugData) override;
public:
float GetBlendAmount() const;
EGMS_CurvesBlendMode GetBlendMode() const;
};

View File

@@ -0,0 +1,34 @@
// Copyright 2025 https://yuewu.dev/en All Rights Reserved.
#pragma once
#include "GameplayTagContainer.h"
#include "AnimNodes/AnimNode_BlendListBase.h"
#include "GMS_AnimNode_GameplayTagsBlend.generated.h"
USTRUCT()
struct GENERICMOVEMENTSYSTEM_API FGMS_AnimNode_GameplayTagsBlend : public FAnimNode_BlendListBase
{
GENERATED_BODY()
public:
#if WITH_EDITORONLY_DATA
UPROPERTY(EditAnywhere, Category="Settings", Meta = (FoldProperty, PinShownByDefault))
FGameplayTag ActiveTag;
UPROPERTY(EditAnywhere, Category="Settings", Meta = (FoldProperty))
TArray<FGameplayTag> Tags;
#endif
protected:
virtual int32 GetActiveChildIndex() override;
public:
const FGameplayTag& GetActiveTag() const;
const TArray<FGameplayTag>& GetTags() const;
#if WITH_EDITOR
void RefreshPoses();
#endif
};

View File

@@ -0,0 +1,168 @@
// Copyright 2025 https://yuewu.dev/en All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
#include "UObject/ObjectMacros.h"
#include "Animation/AnimTypes.h"
#include "Animation/AnimNodeBase.h"
#include "Animation/AnimData/BoneMaskFilter.h"
#include "Settings/GMS_SettingStructLibrary.h"
#include "GMS_AnimNode_LayeredBoneBlend.generated.h"
// Layered blend (per bone); has dynamic number of blendposes that can blend per different bone sets
USTRUCT(BlueprintInternalUseOnly)
struct FGMS_AnimNode_LayeredBoneBlend : public FAnimNode_Base
{
GENERATED_USTRUCT_BODY()
public:
/** The source pose */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=Links)
FPoseLink BasePose;
/** Each layer's blended pose */
UPROPERTY(EditAnywhere, BlueprintReadWrite, editfixedsize, Category=Links, meta=(BlueprintCompilerGeneratedDefaults))
TArray<FPoseLink> BlendPoses;
/** Whether to use branch filters or a blend mask to specify an input pose per-bone influence */
// UPROPERTY(EditAnywhere, Category = Config)
// ELayeredBoneBlendMode BlendMode;
/**
* The blend masks to use for our layer inputs. Allows the use of per-bone alphas.
* Blend masks are used when BlendMode is BlendMask.
*/
// UPROPERTY(EditAnywhere, editfixedsize, Category=Config, meta=(UseAsBlendMask=true))
// TArray<TObjectPtr<UBlendProfile>> BlendMasks;
/**
* Configuration for the parts of the skeleton to blend for each layer. Allows
* certain parts of the tree to be blended out or omitted from the pose.
* LayerSetup is used when BlendMode is BranchFilter.
*/
UPROPERTY()
TArray<FInputBlendPose> LayerSetup;
UPROPERTY(EditAnywhere, BlueprintReadWrite, meta=(PinShownByDefault), Category=GMS)
FGMS_InputBlendPose ExternalLayerSetup;
/** The weights of each layer */
UPROPERTY(EditAnywhere, BlueprintReadWrite, editfixedsize, Category=GMS, meta=(BlueprintCompilerGeneratedDefaults, PinShownByDefault))
TArray<float> BlendWeights;
/** Whether to blend bone rotations in mesh space or in local space */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=Config, meta=(PinShownByDefault))
bool bMeshSpaceRotationBlend;
/** Whether to blend bone scales in mesh space or in local space */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=Config)
bool bMeshSpaceScaleBlend;
/** How to blend the layers together */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=Config)
TEnumAsByte<enum ECurveBlendOption::Type> CurveBlendOption;
/** Whether to incorporate the per-bone blend weight of the root bone when lending root motion */
UPROPERTY(EditAnywhere, Category = Config)
bool bBlendRootMotionBasedOnRootBone;
bool bHasRelevantPoses;
/*
* Max LOD that this node is allowed to run
* For example if you have LODThreshold to be 2, it will run until LOD 2 (based on 0 index)
* when the component LOD becomes 3, it will stop update/evaluate
* currently transition would be issue and that has to be re-visited
*/
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Performance, meta = (DisplayName = "LOD Threshold"))
int32 LODThreshold;
protected:
// Per-bone weights for the skeleton. Serialized as these are only relative to the skeleton, but can potentially
// be regenerated at runtime if the GUIDs dont match
UPROPERTY()
TArray<FPerBoneBlendWeight> PerBoneBlendWeights;
// Guids for skeleton used to determine whether the PerBoneBlendWeights need rebuilding
UPROPERTY()
FGuid SkeletonGuid;
// Guid for virtual bones used to determine whether the PerBoneBlendWeights need rebuilding
UPROPERTY()
FGuid VirtualBoneGuid;
// transient data to handle weight and target weight
// this array changes based on required bones
TArray<FPerBoneBlendWeight> DesiredBoneBlendWeights;
TArray<FPerBoneBlendWeight> CurrentBoneBlendWeights;
// Per-curve source pose index
TBaseBlendedCurve<FDefaultAllocator, UE::Anim::FCurveElementIndexed> CurvePoseSourceIndices;
// Serial number of the required bones container
uint16 RequiredBonesSerialNumber;
public:
FGMS_AnimNode_LayeredBoneBlend()
: bMeshSpaceRotationBlend(false)
, bMeshSpaceScaleBlend(false)
, CurveBlendOption(ECurveBlendOption::Override)
, bBlendRootMotionBasedOnRootBone(true)
, bHasRelevantPoses(false)
, LODThreshold(INDEX_NONE)
, RequiredBonesSerialNumber(0)
{
}
// FAnimNode_Base interface
GENERICMOVEMENTSYSTEM_API virtual void Initialize_AnyThread(const FAnimationInitializeContext& Context) override;
GENERICMOVEMENTSYSTEM_API virtual void CacheBones_AnyThread(const FAnimationCacheBonesContext& Context) override;
GENERICMOVEMENTSYSTEM_API virtual void Update_AnyThread(const FAnimationUpdateContext& Context) override;
GENERICMOVEMENTSYSTEM_API virtual void Evaluate_AnyThread(FPoseContext& Output) override;
GENERICMOVEMENTSYSTEM_API virtual void GatherDebugData(FNodeDebugData& DebugData) override;
virtual int32 GetLODThreshold() const override { return LODThreshold; }
// End of FAnimNode_Base interface
void AddPose()
{
BlendWeights.Add(1.f);
BlendPoses.AddDefaulted();
LayerSetup.AddDefaulted();
}
void RemovePose(int32 PoseIndex)
{
BlendWeights.RemoveAt(PoseIndex);
BlendPoses.RemoveAt(PoseIndex);
if (LayerSetup.IsValidIndex(PoseIndex))
{
LayerSetup.RemoveAt(PoseIndex);
}
}
// Invalidate the cached per-bone blend weights from the skeleton
void InvalidatePerBoneBlendWeights()
{
RequiredBonesSerialNumber = 0;
SkeletonGuid = FGuid();
VirtualBoneGuid = FGuid();
}
// Invalidates the cached bone data so it is recalculated the next time this node is updated
void InvalidateCachedBoneData() { RequiredBonesSerialNumber = 0; }
public:
// Rebuild cache per bone blend weights from the skeleton
GENERICMOVEMENTSYSTEM_API void RebuildPerBoneBlendWeights(const USkeleton* InSkeleton);
// Check whether per-bone blend weights are valid according to the skeleton (GUID check)
GENERICMOVEMENTSYSTEM_API bool ArePerBoneBlendWeightsValid(const USkeleton* InSkeleton) const;
// Update cached data if required
GENERICMOVEMENTSYSTEM_API void UpdateCachedBoneData(const FBoneContainer& RequiredBones, const USkeleton* Skeleton);
friend class UAnimGraphNode_LayeredBoneBlend;
};

View File

@@ -0,0 +1,205 @@
// Copyright 2025 https://yuewu.dev/en All Rights Reserved.
#pragma once
#include "BoneControllers/AnimNode_OrientationWarping.h"
#include "BoneControllers/BoneControllerTypes.h"
#include "BoneControllers/AnimNode_SkeletalControlBase.h"
#include "Settings/GMS_SettingStructLibrary.h"
#include "GMS_AnimNode_OrientationWarping.generated.h"
struct FAnimationInitializeContext;
struct FComponentSpacePoseContext;
struct FNodeDebugData;
USTRUCT(BlueprintInternalUseOnly)
struct GENERICMOVEMENTSYSTEM_API FGMS_AnimNode_OrientationWarping : public FAnimNode_SkeletalControlBase
{
GENERATED_BODY()
// Orientation warping evaluation mode (Graph or Manual)
UPROPERTY(EditAnywhere,BlueprintReadWrite, Category=Evaluation, meta=(PinShownByDefault))
EWarpingEvaluationMode Mode = EWarpingEvaluationMode::Manual;
// The desired orientation angle (in degrees) to warp by relative to the specified RotationAxis
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=Evaluation, meta=(PinShownByDefault))
float OrientationAngle = 0.f;
// The character locomotion angle (in degrees) relative to the specified RotationAxis
// This will be used in the following equation for computing the orientation angle: [Orientation = RotationBetween(RootMotionDirection, LocomotionDirection)]
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=Evaluation, meta=(PinShownByDefault))
float LocomotionAngle = 0.f;
// The character movement direction vector in world space
// This will be used to compute LocomotionAngle automatically
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=Evaluation, meta=(PinShownByDefault))
FVector LocomotionDirection = { 0.f, 0.f, 0.f };
// Minimum root motion speed required to apply orientation warping
// This is useful to prevent unnatural re-orientation when the animation has a portion with no root motion (i.e starts/stops/idles)
// When this value is greater than 0, it's recommended to enable interpolation with RotationInterpSpeed > 0
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=Evaluation, meta = (ClampMin = "0.0", PinHiddenByDefault))
float MinRootMotionSpeedThreshold = 10.0f;
// Specifies an angle threshold to prevent erroneous over-rotation of the character, disabled with a value of 0
//
// When the effective orientation warping angle is detected to be greater than this value (default: 90 degrees) the locomotion direction will be inverted prior to warping
// This will be used in the following equation: [Orientation = RotationBetween(RootMotionDirection, -LocomotionDirection)]
//
// Example: Playing a forward running animation while the motion is going backward
// Rather than orientation warping by 180 degrees, the system will warp by 0 degrees
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=Evaluation, meta=(PinHiddenByDefault), meta=(ClampMin="0.0", ClampMax="180.0"))
float LocomotionAngleDeltaThreshold = 90.f;
// Spine bone definitions
// Used to counter rotate the body in order to keep the character facing forward
// The amount of counter rotation applied is driven by DistributedBoneOrientationAlpha
// UPROPERTY(EditAnywhere, Category="Settings") 由ExternalBoneReference代替代替。
UPROPERTY()
TArray<FBoneReference> SpineBones;
// IK Foot Root Bone definition
// UPROPERTY(EditAnywhere, Category="Settings", meta=(DisplayName="IK Foot Root Bone")) 由ExternalBoneReference代替。
UPROPERTY()
FBoneReference IKFootRootBone;
// IK Foot definitions
// UPROPERTY(EditAnywhere, Category="Settings", meta=(DisplayName="IK Foot Bones")) 由ExternalBoneReference代替。
UPROPERTY()
TArray<FBoneReference> IKFootBones;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category= Settings, meta=(PinShownByDefault))
FGMS_OrientationWarpingBoneReference ExternalBoneReference;
// Rotation axis used when rotating the character body
UPROPERTY(EditAnywhere, Category=Settings)
TEnumAsByte<EAxis::Type> RotationAxis = EAxis::Z;
// Specifies how much rotation is applied to the character body versus IK feet
UPROPERTY(EditAnywhere, Category=Settings, meta=(ClampMin="0.0", ClampMax="1.0", PinHiddenByDefault))
float DistributedBoneOrientationAlpha = 0.5f;
// Specifies the interpolation speed (in Alpha per second) towards reaching the final warped rotation angle
// A value of 0 will cause instantaneous rotation, while a greater value will introduce smoothing
UPROPERTY(EditAnywhere, Category=Settings, meta=(ClampMin="0.0"))
float RotationInterpSpeed = 10.f;
// Max correction we're allowed to do per-second when using interpolation.
// This minimizes pops when we have a large difference between current and target orientation.
UPROPERTY(EditAnywhere, Category=Settings, meta=(ClampMin="0.0", EditCondition="RotationInterpSpeed > 0.0f"))
float MaxCorrectionDegrees = 180.f;
// Don't compensate our interpolator when the instantaneous root motion delta is higher than this. This is likely a pivot.
UPROPERTY(EditAnywhere, Category=Settings, meta=(ClampMin="0.0", EditCondition="RotationInterpSpeed > 0.0f"))
float MaxRootMotionDeltaToCompensateDegrees = 45.f;
// Whether to counter compensate interpolation by the animated root motion angle change over time.
// This helps to conserve the motion from our animation.
// Disable this if your root motion is expected to be jittery, and you want orientation warping to smooth it out.
UPROPERTY(EditAnywhere, Category=Settings, meta=(EditCondition="RotationInterpSpeed > 0.0f"))
bool bCounterCompenstateInterpolationByRootMotion = true;
UPROPERTY(EditAnywhere, Category=Experimental, meta=(PinHiddenByDefault))
bool bScaleByGlobalBlendWeight = false;
UPROPERTY(EditAnywhere, Category=Experimental, meta=(PinHiddenByDefault))
bool bUseManualRootMotionVelocity = false;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=Experimental, meta=(PinHiddenByDefault))
FVector ManualRootMotionVelocity = FVector::ZeroVector;
//RootBoneTransform is the same as CustomTransform as
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=Evaluation, meta=(PinHiddenByDefault))
EOrientationWarpingSpace WarpingSpace = EOrientationWarpingSpace::ComponentTransform;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=Evaluation, meta=(PinHiddenByDefault))
FTransform WarpingSpaceTransform;
#if WITH_EDITORONLY_DATA
// Scale all debug drawing visualization by a factor
UPROPERTY(EditAnywhere, Category=Debug, meta=(ClampMin="0.0"))
float DebugDrawScale = 1.f;
// Enable/Disable orientation warping debug drawing
UPROPERTY(EditAnywhere, Category=Debug)
bool bEnableDebugDraw = false;
#endif
public:
// FAnimNode_Base interface
virtual void GatherDebugData(FNodeDebugData& DebugData) override;
virtual void UpdateInternal(const FAnimationUpdateContext& Context) override;
// End of FAnimNode_Base interface
// FAnimNode_SkeletalControlBase interface
virtual void Initialize_AnyThread(const FAnimationInitializeContext& Context) override;
virtual void EvaluateSkeletalControl_AnyThread(FComponentSpacePoseContext& Output, TArray<FBoneTransform>& OutBoneTransforms) override;
virtual bool IsValidToEvaluate(const USkeleton* Skeleton, const FBoneContainer& RequiredBones) override;
// End of FAnimNode_SkeletalControlBase interface
private:
// FAnimNode_SkeletalControlBase interface
virtual void InitializeBoneReferences(const FBoneContainer& RequiredBones) override;
// End of FAnimNode_SkeletalControlBase interface
struct FOrientationWarpingSpineBoneData
{
FCompactPoseBoneIndex BoneIndex;
float Weight;
FOrientationWarpingSpineBoneData()
: BoneIndex(INDEX_NONE)
, Weight(0.f)
{
}
FOrientationWarpingSpineBoneData(FCompactPoseBoneIndex InBoneIndex)
: BoneIndex(InBoneIndex)
, Weight(0.f)
{
}
// Comparison Operator for Sorting
struct FCompareBoneIndex
{
FORCEINLINE bool operator()(const FOrientationWarpingSpineBoneData& A, const FOrientationWarpingSpineBoneData& B) const
{
return A.BoneIndex < B.BoneIndex;
}
};
};
struct FOrientationWarpingFootData
{
TArray<FCompactPoseBoneIndex> IKFootBoneIndexArray;
FCompactPoseBoneIndex IKFootRootBoneIndex;
FOrientationWarpingFootData()
: IKFootBoneIndexArray()
, IKFootRootBoneIndex(INDEX_NONE)
{
}
};
// Computed spine bone indices and alpha weights for the specified spine definition
TArray<FOrientationWarpingSpineBoneData> SpineBoneDataArray;
// Computed IK bone indices for the specified foot definitions
FOrientationWarpingFootData IKFootData;
// Internal current frame root motion delta direction
FVector RootMotionDeltaDirection = FVector::ZeroVector;
// Internal orientation warping angle
float ActualOrientationAngleRad = 0.f;
float BlendWeight = 0.0f;
FGraphTraversalCounter UpdateCounter;
bool bIsFirstUpdate = false;
void Reset(const FAnimationBaseContext& Context);
#if WITH_EDITORONLY_DATA
// Whether we found a root motion delta attribute in the attribute stream on graph driven mode
bool bFoundRootMotionAttribute = false;
#endif
};