UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
Constraint.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3/*=============================================================================
4 Constraint.h: Constraint data structures
5
6 This section has and will change a lot while working on our rigging system
7 We strongly recommend not to use this directly yet but by provided tool, such
8 as Constraint AnimNode.
9=============================================================================*/
10
11#pragma once
12
13#include "CommonAnimTypes.h"
15#include "CoreMinimal.h"
16#include "CoreTypes.h"
17#include "EulerTransform.h"
18#include "Math/Quat.h"
19#include "Math/Rotator.h"
20#include "Math/Transform.h"
22#include "Math/UnrealMathSSE.h"
23#include "Math/Vector.h"
27#include "UObject/Class.h"
28#include "UObject/NameTypes.h"
30#include "UObject/UnrealNames.h"
31
32#include "Constraint.generated.h"
33
35
41USTRUCT(BlueprintType)
43{
45
46 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Axis Filter")
47 bool bX;
48
49 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Axis Filter")
50 bool bY;
51
52 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Axis Filter")
53 bool bZ;
54
56 : bX(true)
57 , bY(true)
58 , bZ(true)
59 {}
60
61 FFilterOptionPerAxis(bool X, bool Y, bool Z)
62 : bX(X)
63 , bY(Y)
64 , bZ(Z)
65 {}
66
67 void FilterVector(FVector& Input, const FVector& ResetValue = FVector::ZeroVector) const
68 {
69 if (!bX)
70 {
71 Input.X = ResetValue.X;
72 }
73
74 if (!bY)
75 {
76 Input.Y = ResetValue.Y;
77 }
78
79 if (!bZ)
80 {
81 Input.Z = ResetValue.Z;
82 }
83 }
84
85 void FilterQuat(FQuat& Input, const FQuat& ResetValue = FQuat::Identity) const
86 {
87 FRotator Rotator = Input.Rotator();
88
89 FilterRotator(Rotator, ResetValue.Rotator());
90
91 Input = Rotator.Quaternion();
92 }
93
94 void FilterRotator(FRotator& Input, const FRotator& ResetValue = FRotator::ZeroRotator) const
95 {
96 if (!bX)
97 {
98 Input.Roll = ResetValue.Roll;
99 }
100
101 if (!bY)
102 {
103 Input.Pitch = ResetValue.Pitch;
104 }
105
106 if (!bZ)
107 {
108 Input.Yaw = ResetValue.Yaw;
109 }
110 }
111
113 {
114 Ar << D.bX;
115 Ar << D.bY;
116 Ar << D.bZ;
117
118 return Ar;
119 }
120
121 bool IsValid() const
122 {
123 // if none of them is set, it's not valid
124 return bX || bY || bZ;
125 }
126
127 bool HasNoEffect() const
128 {
129 // if all of them are set the filter won't affect anything
130 return bX && bY && bZ;
131 }
132};
133
135USTRUCT(BlueprintType)
137{
139
140 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Axis Filter")
141 FFilterOptionPerAxis TranslationFilter;
142
143 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Axis Filter")
144 FFilterOptionPerAxis RotationFilter;
145
146 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Axis Filter")
148
149 void FilterTransform(FTransform& Input) const
150 {
151 FVector Location = Input.GetLocation();
152 TranslationFilter.FilterVector(Location);
153 Input.SetLocation(Location);
154
155 FQuat Rotation = Input.GetRotation();
156 RotationFilter.FilterQuat(Rotation);
157 Input.SetRotation(Rotation);
158
159 FVector Scale3D = Input.GetScale3D();
160 ScaleFilter.FilterVector(Scale3D, FVector::OneVector);
161 Input.SetScale3D(Scale3D);
162 }
163
165 {
166 FVector Location = Input.Location;
167 TranslationFilter.FilterVector(Location);
168 Input.Location = Location;
169
170 FRotator Rotation = Input.Rotation;
171 RotationFilter.FilterRotator(Rotation);
172 Input.Rotation = Rotation;
173
174 FVector Scale = Input.Scale;
175 ScaleFilter.FilterVector(Scale, FVector::OneVector);
176 Input.Scale = Scale;
177 }
178};
179
181USTRUCT(BlueprintType)
183{
185
186 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Constraint")
187 bool bTranslation;
188
189 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Constraint")
190 bool bRotation;
191
192 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Constraint")
193 bool bScale;
194
195 // this does composed transform - where as individual will accumulate per component
196 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Constraint")
197 bool bParent;
198
199 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Constraint")
200 FFilterOptionPerAxis TranslationAxes;
201
202 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Constraint")
204
205 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Constraint")
207
209 : bTranslation(true)
210 , bRotation(true)
211 , bScale(false)
212 , bParent(false)
213 {
214 }
215
217 {
218 Ar << D.bTranslation;
219 Ar << D.bRotation;
220 Ar << D.bScale;
221 Ar << D.bParent;
222 Ar << D.TranslationAxes;
223 Ar << D.RotationAxes;
224 Ar << D.ScaleAxes;
225
226 return Ar;
227 }
228};
229
236USTRUCT()
238{
240
241 UPROPERTY()
243
244 UPROPERTY()
246
247 UPROPERTY()
249
250 UPROPERTY()
252
254 : Translation(FVector::ZeroVector)
255 , Rotation(FQuat::Identity)
256 , Scale(FVector::OneVector)
257 , Parent(FTransform::Identity)
258 {}
259
260 /* Apply the Inverse offset */
261 ANIMATIONCORE_API void ApplyInverseOffset(const FTransform& InTarget, FTransform& OutSource) const;
262 /* Save the Inverse offset */
263 ANIMATIONCORE_API void SaveInverseOffset(const FTransform& Source, const FTransform& Target, const FConstraintDescription& Operator);
272
274 {
275 Ar << D.Translation;
276 Ar << D.Rotation;
277 Ar << D.Scale;
278 Ar << D.Parent;
279
280 return Ar;
281 }
282};
283
284USTRUCT(BlueprintType)
286{
288
289 // @note thought of separating this out per each but we'll have an issue with applying transform in what order
290 // but something to think about if that seems better
291 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Transform Constraint")
293
294 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Transform Constraint")
295 FName SourceNode;
296
297 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Transform Constraint")
298 FName TargetNode;
299
300 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Transform Constraint")
301 float Weight;
302
304 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Transform Constraint")
305 bool bMaintainOffset;
306
308 : SourceNode(NAME_None)
309 , TargetNode(NAME_None)
310 , Weight(1.f)
311 , bMaintainOffset(true)
312 {}
313
315 {
316 Ar << D.Operator;
317 Ar << D.SourceNode;
318 Ar << D.TargetNode;
319 Ar << D.Weight;
320 Ar << D.bMaintainOffset;
321
322 return Ar;
323 }
324};
325
328
330UENUM(BlueprintType)
332{
334 Transform,
335
337 Aim,
338
340 MAX,
341};
342
344USTRUCT()
346{
348
349 UPROPERTY(EditAnywhere, Category = FAimConstraintDescription)
350 FFilterOptionPerAxis AxesFilterOption;
351
354
366 virtual void AccumulateConstraintTransform(const FTransform& TargetTransform, const FTransform& CurrentTransform, const FTransform& CurrentParentTransform, float Weight, FMultiTransformBlendHelper& BlendHelperInLocalSpace) const PURE_VIRTUAL(AccumulateConstraintTransform, );
367
373 virtual bool DoesAffectRotation() const { return false; }
374 virtual bool DoesAffectTranslation() const { return false; }
375 virtual bool DoesAffectScale() const { return false; }
380 virtual bool DoesAffectTransform() const { return false; }
381
382 virtual FString GetDisplayString() const PURE_VIRTUAL(GetDisplayString, return TEXT("None"););
383
388 {
389 Ar << AxesFilterOption;
390 }
391
393 {
394 D.Serialize(Ar);
395 return Ar;
396 }
397};
398template<>
400{
401 enum
402 {
404 };
405};
406
408UENUM(Blueprintable)
410{
412 Rotation,
413 Scale,
414 Parent,
415 LookAt
416};
417
419USTRUCT()
421{
423
424 UPROPERTY(EditAnywhere, Category = FAimConstraintDescription)
426
430
431 ANIMATIONCORE_API virtual void AccumulateConstraintTransform(const FTransform& TargetTransform, const FTransform& CurrentTransform, const FTransform& CurrentParentTransform, float Weight, FMultiTransformBlendHelper& BlendHelperInLocalSpace) const override;
432 virtual bool DoesAffectRotation() const override { return TransformType == ETransformConstraintType::Rotation; }
433 virtual bool DoesAffectTranslation() const override { return TransformType == ETransformConstraintType::Translation; }
434 virtual bool DoesAffectScale() const override { return TransformType == ETransformConstraintType::Scale; }
435 virtual bool DoesAffectTransform() const override { return TransformType == ETransformConstraintType::Parent; }
436
437 virtual FString GetDisplayString() const override
438 {
439 switch (TransformType)
440 {
442 return TEXT("Parent");
444 return TEXT("Translation");
446 return TEXT("Rotation");
448 return TEXT("Scale");
449 default:
450 ensure(false);
451 }
452
453 return TEXT("None");
454 }
455
456 virtual void Serialize(FArchive& Ar) override
457 {
459 Ar << TransformType;
460 }
461};
462
464USTRUCT()
466{
468
469 UPROPERTY(EditAnywhere, Category = FAimConstraintDescription)
470 FAxis LookAt_Axis;
471 UPROPERTY(EditAnywhere, Category = FAimConstraintDescription)
472 FAxis LookUp_Axis;
473 UPROPERTY(EditAnywhere, Category = FAimConstraintDescription)
474 bool bUseLookUp;
475 UPROPERTY(EditAnywhere, Category = FAimConstraintDescription)
476 FVector LookUpTarget;
477
479 : LookAt_Axis()
480 , LookUp_Axis(FVector::UpVector)
481 , bUseLookUp(false)
482 , LookUpTarget(ForceInitToZero)
483 {
484 }
485
486 ANIMATIONCORE_API virtual void AccumulateConstraintTransform(const FTransform& TargetTransform, const FTransform& CurrentTransform, const FTransform& CurrentParentTransform, float Weight, FMultiTransformBlendHelper& BlendHelperInLocalSpace) const override;
487 virtual bool DoesAffectRotation() const override { return true; }
488 virtual FString GetDisplayString() const override
489 {
490 return TEXT("Aim");
491 }
492
493 virtual void Serialize(FArchive& Ar) override
494 {
496
497 Ar << LookAt_Axis;
498 Ar << LookUp_Axis;
499 Ar << bUseLookUp;
500 }
501};
502
509USTRUCT()
511{
513
514 UPROPERTY()
516
517 FConstraintDescriptionEx* ConstraintDescription;
518
520 : Type(EConstraintType::MAX)
521 , ConstraintDescription(nullptr)
522 {
523 }
524
527 , ConstraintDescription(nullptr)
528 {
529 Set(InT);
530 }
531
533 : Type(EConstraintType::Aim)
534 , ConstraintDescription(nullptr)
535 {
536 Set(InA);
537 }
538
540 : ConstraintDescription(nullptr)
541 {
542 *this = InOther;
543 }
544
545 FString GetDisplayString() const
546 {
547 if (ConstraintDescription)
548 {
549 return ConstraintDescription->GetDisplayString();
550 }
551
552 return TEXT("Null");
553 }
554
556 {
557 this->Clear();
558
559 this->Type = Other.Type;
560 if (Other.IsValid())
561 {
563 {
565 }
566 else if (Other.Type == EConstraintType::Aim)
567 {
569 }
570 }
571
572 return *this;
573 }
574
575private:
577 {
578 Clear();
579 ConstraintDescription = new FAimConstraintDescription(InA);
580 }
581
583 {
584 Clear();
585 ConstraintDescription = new FTransformConstraintDescription(InT);
586 }
587
588 void Clear()
589 {
590 if (ConstraintDescription)
591 {
592 delete ConstraintDescription;
593 ConstraintDescription = nullptr;
594 }
595 }
596
597public:
598 // this does not check type - we can, but that is hard to maintain, maybe I'll change later
599 template <typename T>
601 {
602 return static_cast<T*>(ConstraintDescription);
603 }
604
606 {
607 Clear();
608 }
610 {
611 Ar << D.Type;
612
613 if (D.Type == EConstraintType::Transform)
614 {
616 Ar << Trans;
617 D.Set(Trans);
618 }
619 else if (D.Type == EConstraintType::Aim)
620 {
622 Ar << Aim;
623 D.Set(Aim);
624 }
625 else
626 {
627 ensure(false);
628 }
629
630 return Ar;
631 }
632
633 bool IsValid() const
634 {
635 return (ConstraintDescription != nullptr);
636 }
638 {
639 if (ConstraintDescription)
640 {
641 return ConstraintDescription->DoesAffectRotation();
642 }
643 return false;
644 }
645
647 {
648 if (ConstraintDescription)
649 {
650 return ConstraintDescription->DoesAffectTranslation();
651 }
652 return false;
653 }
654
655 bool DoesAffectScale() const
656 {
657 if (ConstraintDescription)
658 {
659 return ConstraintDescription->DoesAffectScale();
660 }
661 return false;
662 }
663
665 {
666 if (ConstraintDescription)
667 {
668 return ConstraintDescription->DoesAffectTransform();
669 }
670 return false;
671 }
672
674 {
675 if (ConstraintDescription)
676 {
677 return ConstraintDescription->AccumulateConstraintTransform(TargetTransform, CurrentTransform, CurrentParentTransform, Weight, BlendHelperInLocalSpace);
678 }
679 }
680};
681
686USTRUCT()
688{
690
691
692 UPROPERTY()
695 UPROPERTY()
696 float Weight;
698 UPROPERTY()
699 bool bMaintainOffset;
701 UPROPERTY()
703
705 FTransform CurrentTransform;
706
708 : Weight(1.f)
709 , bMaintainOffset(true)
710 , Offset(FTransform::Identity)
711 {}
712
714 : Constraint(InTrans)
716 , bMaintainOffset(bInMaintainOffset)
717 , Offset(InOffset)
718 {}
719
721 : Constraint(InAim)
723 , bMaintainOffset(bInMaintainOffset)
724 , Offset(InOffset)
725 {}
726
728 {
729 Ar << D.Constraint;
730 Ar << D.Weight;
731 Ar << D.bMaintainOffset;
732 Ar << D.Offset;
733
734 return Ar;
735 }
736
737 ANIMATIONCORE_API void ApplyInverseOffset(const FTransform& InTarget, FTransform& OutSource, const FTransform& InBaseTransform) const;
738 ANIMATIONCORE_API void SaveInverseOffset(const FTransform& Source, const FTransform& Target, const FTransform& InBaseTransform);
740 {
742 }
743
744 ANIMATIONCORE_API void ApplyConstraintTransform(const FTransform& TargetTransform, const FTransform& InCurrentTransform, const FTransform& CurrentParentTransform, FMultiTransformBlendHelper& BlendHelperInLocalSpace) const;
745};
#define ensure( InExpression)
Definition AssertionMacros.h:464
ETransformConstraintType
Definition Constraint.h:410
EConstraintType
new changes of constraints
Definition Constraint.h:332
#define PURE_VIRTUAL(func,...)
Definition CoreMiscDefines.h:103
@ ForceInitToZero
Definition CoreMiscDefines.h:156
#define TEXT(x)
Definition Platform.h:1272
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
return true
Definition ExternalRpcRegistry.cpp:601
#define X(Name, Desc)
Definition FormatStringSan.h:47
const bool
Definition NetworkReplayStreaming.h:178
#define UPROPERTY(...)
UObject definition macros.
Definition ObjectMacros.h:744
#define GENERATED_BODY(...)
Definition ObjectMacros.h:765
#define UENUM(...)
Definition ObjectMacros.h:749
#define USTRUCT(...)
Definition ObjectMacros.h:746
#define GENERATED_USTRUCT_BODY(...)
Definition ObjectMacros.h:767
uint32 Offset
Definition VulkanMemory.cpp:4033
uint8_t uint8
Definition binka_ue_file_header.h:8
Definition Archive.h:1208
virtual void Serialize(void *V, int64 Length)
Definition Archive.h:1689
Definition NameTypes.h:617
@ false
Definition radaudio_common.h:23
Definition Constraint.h:466
virtual bool DoesAffectRotation() const override
Definition Constraint.h:487
virtual FString GetDisplayString() const override
Definition Constraint.h:488
virtual void Serialize(FArchive &Ar) override
Definition Constraint.h:493
Definition CommonAnimTypes.h:14
Definition Constraint.h:688
friend FArchive & operator<<(FArchive &Ar, FConstraintData &D)
Definition Constraint.h:727
FConstraintData(const FAimConstraintDescription &InAim, FName InTargetNode=NAME_None, float InWeight=1.f, bool bInMaintainOffset=true, const FTransform &InOffset=FTransform::Identity)
Definition Constraint.h:720
void ResetOffset()
Definition Constraint.h:739
FConstraintData(const FTransformConstraintDescription &InTrans, FName InTargetNode=NAME_None, float InWeight=1.f, bool bInMaintainOffset=true, const FTransform &InOffset=FTransform::Identity)
Definition Constraint.h:713
Definition Constraint.h:346
virtual bool DoesAffectTransform() const
Definition Constraint.h:380
virtual void AccumulateConstraintTransform(const FTransform &TargetTransform, const FTransform &CurrentTransform, const FTransform &CurrentParentTransform, float Weight, FMultiTransformBlendHelper &BlendHelperInLocalSpace) const PURE_VIRTUAL(AccumulateConstraintTransform
virtual bool DoesAffectScale() const
Definition Constraint.h:375
virtual FString GetDisplayString() const PURE_VIRTUAL(GetDisplayString
virtual void Serialize(FArchive &Ar)
Definition Constraint.h:387
virtual bool DoesAffectTranslation() const
Definition Constraint.h:374
friend FArchive & operator<<(FArchive &Ar, FConstraintDescriptionEx &D)
Definition Constraint.h:392
virtual void virtual bool DoesAffectRotation() const
Definition Constraint.h:373
Definition Constraint.h:183
friend FArchive & operator<<(FArchive &Ar, FConstraintDescription &D)
Definition Constraint.h:216
Definition Constraint.h:511
FString GetDisplayString() const
Definition Constraint.h:545
bool DoesAffectScale() const
Definition Constraint.h:655
FConstraintDescriptor(const FAimConstraintDescription &InA)
Definition Constraint.h:532
bool DoesAffectTranslation() const
Definition Constraint.h:646
void ApplyConstraintTransform(const FTransform &TargetTransform, const FTransform &CurrentTransform, const FTransform &CurrentParentTransform, float Weight, FMultiTransformBlendHelper &BlendHelperInLocalSpace) const
Definition Constraint.h:673
FConstraintDescriptor(const FTransformConstraintDescription &InT)
Definition Constraint.h:525
FConstraintDescriptor(const FConstraintDescriptor &InOther)
Definition Constraint.h:539
T * GetTypedConstraint() const
Definition Constraint.h:600
FConstraintDescriptor & operator=(const FConstraintDescriptor &Other)
Definition Constraint.h:555
bool DoesAffectRotation() const
Definition Constraint.h:637
bool IsValid() const
Definition Constraint.h:633
friend FArchive & operator<<(FArchive &Ar, FConstraintDescriptor &D)
Definition Constraint.h:609
bool DoesAffectTransform() const
Definition Constraint.h:664
~FConstraintDescriptor()
Definition Constraint.h:605
Definition Constraint.h:238
friend FArchive & operator<<(FArchive &Ar, FConstraintOffset &D)
Definition Constraint.h:273
void Reset()
Definition Constraint.h:265
Definition EulerTransform.h:32
Definition Constraint.h:43
friend FArchive & operator<<(FArchive &Ar, FFilterOptionPerAxis &D)
Definition Constraint.h:112
void FilterRotator(FRotator &Input, const FRotator &ResetValue=FRotator::ZeroRotator) const
Definition Constraint.h:94
void FilterQuat(FQuat &Input, const FQuat &ResetValue=FQuat::Identity) const
Definition Constraint.h:85
void FilterVector(FVector &Input, const FVector &ResetValue=FVector::ZeroVector) const
Definition Constraint.h:67
FFilterOptionPerAxis(bool X, bool Y, bool Z)
Definition Constraint.h:61
bool HasNoEffect() const
Definition Constraint.h:127
bool IsValid() const
Definition Constraint.h:121
Definition AnimationCoreUtil.h:207
Definition Constraint.h:421
virtual bool DoesAffectScale() const override
Definition Constraint.h:434
virtual FString GetDisplayString() const override
Definition Constraint.h:437
virtual bool DoesAffectTranslation() const override
Definition Constraint.h:433
virtual void Serialize(FArchive &Ar) override
Definition Constraint.h:456
virtual bool DoesAffectRotation() const override
Definition Constraint.h:432
virtual bool DoesAffectTransform() const override
Definition Constraint.h:435
Definition Constraint.h:286
friend FArchive & operator<<(FArchive &Ar, FTransformConstraint &D)
Definition Constraint.h:314
Definition Constraint.h:137
void FilterTransform(FEulerTransform &Input) const
Definition Constraint.h:164
Definition StructOpsTypeTraits.h:11
@ WithPureVirtual
Definition StructOpsTypeTraits.h:33
Definition StructOpsTypeTraits.h:46
static CORE_API const TQuat< double > Identity
Definition Quat.h:63
static CORE_API const TRotator< double > ZeroRotator
Definition Rotator.h:57
static CORE_API const TTransform< double > Identity
Definition TransformNonVectorized.h:58
static CORE_API const TVector< double > ZeroVector
Definition Vector.h:79
static CORE_API const TVector< double > OneVector
Definition Vector.h:82