UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
AnimNode_LegIK.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "CoreMinimal.h"
7#include "BoneIndices.h"
8#include "BoneContainer.h"
9#include "BonePose.h"
11#include "AnimNode_LegIK.generated.h"
12
13class USkeletalMeshComponent;
14struct FAnimLegIKData;
15
16USTRUCT()
18{
20
21public:
23 double Length;
28
30 : Location(FVector::ZeroVector)
31 , Length(0.0)
32 , LinkAxisZ(FVector::ZeroVector)
33 , RealBendDir(FVector::ZeroVector)
34 , BaseBendDir(FVector::ZeroVector)
35 , BoneName(NAME_None)
36 {}
37
39 : Location(InLocation)
41 , LinkAxisZ(FVector::ZeroVector)
42 , RealBendDir(FVector::ZeroVector)
43 , BaseBendDir(FVector::ZeroVector)
44 , BoneName(NAME_None)
45 {}
46};
47
48USTRUCT()
50{
52
53public:
56
57private:
58 FAnimInstanceProxy* MyAnimInstanceProxy;
59 double TotalChainLength;
60 int32 NumLinks;
61 FVector HingeRotationAxis;
62 bool bEnableRotationLimit;
63 bool bInitialized;
64
65public:
67 : MyAnimInstanceProxy(nullptr)
68 , TotalChainLength(0.0)
69 , NumLinks(INDEX_NONE)
70 , HingeRotationAxis(FVector::ZeroVector)
71 , bEnableRotationLimit(false)
72 , bInitialized(false)
73 {}
74
76 void ReachTarget(
78 double InReachPrecision,
80 float SoftPercentLength,
81 float SoftAlpha);
82 void ApplyTwistOffset(const float InTwistOffsetDegrees);
83
84 double GetMaximumReach() const
85 {
86 return TotalChainLength;
87 }
88
89private:
90 void OrientAllLinksToDirection(const FVector& InDirection);
91 void SolveTwoBoneIK(const FVector& InTargetLocation);
92 void SolveFABRIK(const FVector& InTargetLocation, double InReachPrecision, int32 InMaxIterations);
93
94 static void FABRIK_ForwardReach(const FVector& InTargetLocation, FIKChain& IKChain);
95 static void FABRIK_BackwardReach(const FVector& InRootTargetLocation, FIKChain& IKChain);
96 static void FABRIK_ApplyLinkConstraints_Forward(FIKChain& IKChain, int32 LinkIndex);
97 static void FABRIK_ApplyLinkConstraints_Backward(FIKChain& IKChain, int32 LinkIndex);
98
99 static void DrawDebugIKChain(const FIKChain& IKChain, const FColor& InColor);
100};
101
103USTRUCT()
105{
107
108 UPROPERTY(EditAnywhere, Category = "Settings")
109 FBoneReference IKFootBone;
110
111 UPROPERTY(EditAnywhere, Category = "Settings")
112 FBoneReference FKFootBone;
113
114 UPROPERTY(EditAnywhere, Category = "Settings")
115 int32 NumBonesInLimb;
116
119 UPROPERTY(EditAnywhere, Category = "Settings")
120 float MinRotationAngle;
121
123 UPROPERTY(EditAnywhere, Category = "Settings")
124 TEnumAsByte<EAxis::Type> FootBoneForwardAxis;
125
127 UPROPERTY(EditAnywhere, Category = "Settings")
128 TEnumAsByte<EAxis::Type> HingeRotationAxis;
129
131 UPROPERTY(EditAnywhere, Category = "Settings")
132 bool bEnableRotationLimit;
133
135 UPROPERTY(EditAnywhere, Category = "Settings")
136 bool bEnableKneeTwistCorrection;
137
141 UPROPERTY(EditAnywhere, Category = "Settings")
142 FName TwistOffsetCurveName;
143
145 : NumBonesInLimb(2)
146 , MinRotationAngle(15.f)
147 , FootBoneForwardAxis(EAxis::Y)
148 , HingeRotationAxis(EAxis::None)
149 , bEnableRotationLimit(false)
150 , bEnableKneeTwistCorrection(true)
151 , TwistOffsetCurveName(NAME_None)
152 {}
153};
154
156USTRUCT()
183
184USTRUCT()
186{
188
190
192 UPROPERTY(EditAnywhere, Category = "Settings")
193 float ReachPrecision;
194
196 UPROPERTY(EditAnywhere, Category = "Settings")
197 int32 MaxIterations;
198
202 UPROPERTY(EditAnywhere, Category = "Settings", meta = (PinHiddenByDefault, UIMin = "0.01", UIMax = "1", ClampMin = "0.01", ClampMax = "1"))
203 float SoftPercentLength;
204
206 UPROPERTY(EditAnywhere, Category = "Settings", meta = (PinHiddenByDefault, UIMin = "0.0", UIMax = "1", ClampMin = "0.0", ClampMax = "1"))
207 float SoftAlpha;
208
209 UPROPERTY(EditAnywhere, Category = "Settings")
211
213
214 FAnimInstanceProxy* MyAnimInstanceProxy;
215
216public:
217 // FAnimNode_Base interface
218 ANIMGRAPHRUNTIME_API virtual void GatherDebugData(FNodeDebugData& DebugData) override;
219 // End of FAnimNode_Base interface
220
221 // FAnimNode_SkeletalControlBase interface
224 ANIMGRAPHRUNTIME_API virtual bool IsValidToEvaluate(const USkeleton* Skeleton, const FBoneContainer& RequiredBones) override;
225 // End of FAnimNode_SkeletalControlBase interface
226
227 ANIMGRAPHRUNTIME_API bool OrientLegTowardsIK(FAnimLegIKData& InLegData);
229 ANIMGRAPHRUNTIME_API bool AdjustKneeTwist(FAnimLegIKData& InLegData);
230
231private:
232 // FAnimNode_SkeletalControlBase interface
233 ANIMGRAPHRUNTIME_API virtual void InitializeBoneReferences(const FBoneContainer& RequiredBones) override;
234 // End of FAnimNode_SkeletalControlBase interface
235};
@ INDEX_NONE
Definition CoreMiscDefines.h:150
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
return true
Definition ExternalRpcRegistry.cpp:601
#define UPROPERTY(...)
UObject definition macros.
Definition ObjectMacros.h:744
#define USTRUCT(...)
Definition ObjectMacros.h:746
#define GENERATED_USTRUCT_BODY(...)
Definition ObjectMacros.h:767
USkinnedMeshComponent float
Definition SkinnedMeshComponent.h:60
Definition NameTypes.h:617
Definition Array.h:670
Definition EnumAsByte.h:22
Definition Skeleton.h:295
Definition Axis.h:9
@ false
Definition radaudio_common.h:23
Definition AnimInstanceProxy.h:144
Definition AnimNode_LegIK.h:158
FIKChain IKChain
Definition AnimNode_LegIK.h:170
int32 NumBones
Definition AnimNode_LegIK.h:166
FTransform IKFootTransform
Definition AnimNode_LegIK.h:162
FCompactPoseBoneIndex IKFootBoneIndex
Definition AnimNode_LegIK.h:164
void InitializeTransforms(FAnimInstanceProxy *MyAnimInstanceProxy, FCSPose< FCompactPose > &MeshBases)
Definition AnimNode_LegIK.cpp:79
TArray< FTransform > FKLegBoneTransforms
Definition AnimNode_LegIK.h:168
FAnimLegIKDefinition * LegDefPtr
Definition AnimNode_LegIK.h:163
float TwistOffsetDegrees
Definition AnimNode_LegIK.h:165
TArray< FCompactPoseBoneIndex > FKLegBoneIndices
Definition AnimNode_LegIK.h:167
FAnimLegIKData()
Definition AnimNode_LegIK.h:175
Definition AnimNode_LegIK.h:105
Definition AnimNode_LegIK.h:186
Definition AnimNode_SkeletalControlBase.h:22
Definition AnimNodeBase.h:324
Definition BoneContainer.h:192
Definition BoneReference.h:14
Definition BonePose.h:16
Definition BonePose.h:408
Definition Color.h:486
Definition BoneIndices.h:63
Definition AnimNodeBase.h:600
Definition AnimNode_LegIK.h:50
TArray< FIKChainLink > Links
Definition AnimNode_LegIK.h:54
FIKChain()
Definition AnimNode_LegIK.h:66
double GetMaximumReach() const
Definition AnimNode_LegIK.h:84
float MinRotationAngleRadians
Definition AnimNode_LegIK.h:55
Definition AnimNodeBase.h:642