UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
MorphTarget.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "UObject/Object.h"
6#include "PackedNormal.h"
9
10#include "MorphTarget.generated.h"
11
12class USkeletalMesh;
13class UStaticMesh;
14
44
45#if !WITH_EDITOR
58#endif
59
60
62{
63public:
68
69 // Support the minimal functionality required for a ranged-for.
71 {
72 return CurrentDelta;
73 }
74
76 {
77 return &CurrentDelta;
78 }
79
81 {
82 Advance();
83 return *this;
84 }
85
86 [[nodiscard]] bool AtEnd() const
87 {
88 return Token == InvalidToken;
89 }
90
91private:
92 static constexpr uint64 InvalidToken = std::numeric_limits<uint64>::max();
93 friend class UMorphTarget;
94
97 ) :
98 Token(0),
99 RawDeltas(InRawDeltas)
100 {
101 Advance();
102 }
103#if !WITH_EDITOR
106 ) :
107 Token(0),
108 CompressedDelta(&InCompressedDeltas)
109 {
110 if (!InCompressedDeltas.PackedDeltaHeaders.IsEmpty() && !InCompressedDeltas.PackedDeltaData.IsEmpty())
111 {
112 Advance();
113 }
114 else
115 {
116 Clear();
117 }
118 }
119#endif
120
121 void Advance()
122 {
123 if (!RawDeltas.IsEmpty())
124 {
125 if (Token < RawDeltas.Num())
126 {
127 CurrentDelta = RawDeltas[static_cast<int32>(Token++)];
128 }
129 else
130 {
131 Clear();
132 }
133 }
134#if !WITH_EDITOR
135 else if (!CompressedDelta || !IterativeDecode(Token, CompressedDelta->PackedDeltaHeaders, CompressedDelta->PackedDeltaData, CompressedDelta->PositionPrecision, CompressedDelta->TangentPrecision, CurrentDelta))
136 {
137 // If the decode failed, we're either at the end, or the data is invalid. Stop any further decoding.
138 Clear();
139 }
140#endif
141 }
142
143 void Clear()
144 {
145 Token = InvalidToken;
146 RawDeltas = {};
147#if !WITH_EDITOR
148 CompressedDelta = nullptr;
149#endif
150 }
151
152 uint64 Token = InvalidToken;
154#if !WITH_EDITOR
155 const FMorphTargetCompressedLODModel* CompressedDelta = nullptr;
156#endif
157 FMorphTargetDelta CurrentDelta;
158};
159
160
165{
168
171
174
177
179 bool bGeneratedByEngine = false;
180
185
187
190
191 void Reset()
192 {
193 Vertices.Reset();
194 NumVertices = 0;
197 // since engine cleared it, we mark as engine generated
198 // this makes it clear to clear up later
199 bGeneratedByEngine = true;
200 SourceFilename.Empty();
201 }
202};
203
204
205#if WITH_EDITOR
210{
211public:
213 {}
214
217
219 ENGINE_API virtual void ApplyEditorData(USkeletalMesh * SkeletalMesh, bool bIsSerializeSaving) const;
220
221protected:
222 bool bApplyMorphTargetsData = false;
224 };
225#endif
226
227UCLASS(hidecategories=Object, MinimalAPI)
230{
232
233public:
234
236 UPROPERTY(AssetRegistrySearchable)
237 TObjectPtr<class USkeletalMesh> BaseSkelMesh;
238
240 virtual const TArray<FMorphTargetLODModel>& GetMorphLODModels() const { return MorphLODModels; }
241
243 virtual TArray<FMorphTargetLODModel>& GetMorphLODModels() { return MorphLODModels; }
244
245protected:
248#if !WITH_EDITOR
250#endif
251
252public:
253
254#if WITH_EDITOR
256 UE_DEPRECATED(5.7, "Use the TConstArrayView version of GetMorphTargetDelta instead.")
258
262
263#endif
264
267 ENGINE_API virtual FMorphTargetDeltaIterator GetDeltaIteratorForLOD(int32 LODIndex) const;
268
274 ENGINE_API virtual int32 GetNumDeltasForLOD(int32 LODIndex) const;
275
277 ENGINE_API virtual bool HasDataForLOD(int32 LODIndex) const;
278
280 ENGINE_API virtual bool HasDataForSection(int32 LODIndex, int32 SectionIndex) const;
281
283 ENGINE_API virtual bool HasValidData() const;
284 ENGINE_API virtual void EmptyMorphLODModels();
285
287 ENGINE_API virtual bool IsCustomImported(int32 LODIndex) const;
288 ENGINE_API virtual const FString& GetCustomImportedSourceFilename(int32 LODIndex) const;
289 ENGINE_API virtual void SetCustomImportedSourceFilename(int32 LODIndex, const FString& InSourceFilename);
290
292 ENGINE_API virtual bool IsGeneratedByEngine(int32 LODIndex) const;
293 ENGINE_API virtual void SetGeneratedByEngine(int32 LODIndex, bool bInGeneratedByEngine);
294
296 virtual bool UsesBuiltinMorphTargetCompression() const { return true; }
297
298#if WITH_EDITOR
300 ENGINE_API virtual void PopulateDeltas(const TArray<FMorphTargetDelta>& Deltas, const int32 LODIndex, const TArray<struct FSkelMeshSection>& Sections, const bool bCompareNormal = false, const bool bGeneratedByReductionSetting = false, const float PositionThreshold = UE_THRESH_POINTS_ARE_NEAR);
302 ENGINE_API virtual void RemoveEmptyMorphTargets();
305#endif // WITH_EDITOR
306
307 //~ UObject interface
308
309 ENGINE_API virtual void Serialize(FArchive& Ar) override;
310#if WITH_EDITORONLY_DATA
312#endif
313 ENGINE_API virtual void PostLoad() override;
314
316 ENGINE_API virtual void SerializeMemoryArchive(FMemoryArchive& Ar);
317};
#define UE_DEPRECATED(Version, Message)
Definition CoreMiscDefines.h:302
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
FPlatformTypes::uint64 uint64
A 64-bit unsigned integer.
Definition Platform.h:1117
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
#define UPROPERTY(...)
UObject definition macros.
Definition ObjectMacros.h:744
#define GENERATED_UCLASS_BODY(...)
Definition ObjectMacros.h:768
#define UCLASS(...)
Definition ObjectMacros.h:776
@ VER_UE4_MORPHTARGET_CPU_TANGENTZDELTA_FORMATCHANGE
Definition ObjectVersion.h:386
#define UE_THRESH_POINTS_ARE_NEAR
Definition UnrealMathUtility.h:202
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition Archive.h:1208
UE_FORCEINLINE_HINT bool IsLoading() const
Definition Archive.h:236
UE_FORCEINLINE_HINT FPackageFileVersion UEVer() const
Definition Archive.h:204
Definition PackedNormal.h:66
Definition MemoryArchive.h:15
Definition MorphTarget.h:62
FMorphTargetDeltaIterator & operator=(const FMorphTargetDeltaIterator &)=default
const FMorphTargetDelta & operator*() const
Definition MorphTarget.h:70
FMorphTargetDeltaIterator & operator++()
Definition MorphTarget.h:80
FMorphTargetDeltaIterator(FMorphTargetDeltaIterator &&)=default
FMorphTargetDeltaIterator()=default
const FMorphTargetDelta * operator->() const
Definition MorphTarget.h:75
FMorphTargetDeltaIterator(const FMorphTargetDeltaIterator &)=default
bool AtEnd() const
Definition MorphTarget.h:86
Definition Array.h:670
void Reset(SizeType NewSize=0)
Definition Array.h:2246
Definition UnrealString.h.inl:34
Definition UniquePtr.h:107
Definition Class.h:3793
Definition MorphTarget.h:230
virtual bool UsesBuiltinMorphTargetCompression() const
Definition MorphTarget.h:296
TArray< FMorphTargetCompressedLODModel > CompressedLODModels
Definition MorphTarget.h:249
TArray< FMorphTargetLODModel > MorphLODModels
Definition MorphTarget.h:247
virtual TArray< FMorphTargetLODModel > & GetMorphLODModels()
Definition MorphTarget.h:243
Definition Object.h:95
Definition SkeletalMesh.h:440
Definition StaticMesh.h:593
bool IterativeDecode(uint64 &InOutNextItemToken, TConstArrayView< FDeltaBatchHeader > InBatchHeaders, TConstArrayView< uint32 > InCompressedVertices, const float InPositionPrecision, const float InTangentZPrecision, FMorphTargetDelta &OutMorphTargetDelta)
Definition MorphTargetVertexCodec.cpp:378
Definition MorphTarget.h:52
TArray< uint32 > PackedDeltaData
Definition MorphTarget.h:54
TArray< UE::MorphTargetVertexCodec::FDeltaBatchHeader > PackedDeltaHeaders
Definition MorphTarget.h:53
float PositionPrecision
Definition MorphTarget.h:55
float TangentPrecision
Definition MorphTarget.h:56
Definition MorphTarget.h:17
FVector3f TangentZDelta
Definition MorphTarget.h:22
uint32 SourceIdx
Definition MorphTarget.h:25
friend FArchive & operator<<(FArchive &Ar, FMorphTargetDelta &V)
Definition MorphTarget.h:28
FVector3f PositionDelta
Definition MorphTarget.h:19
Definition MorphTarget.h:165
FMorphTargetLODModel()=default
void Reset()
Definition MorphTarget.h:191
int32 NumVertices
Definition MorphTarget.h:170
bool bGeneratedByEngine
Definition MorphTarget.h:179
friend FArchive & operator<<(FArchive &Ar, FMorphTargetLODModel &M)
Definition MorphTarget.cpp:17
int32 NumBaseMeshVerts
Definition MorphTarget.h:173
TArray< FMorphTargetDelta > Vertices
Definition MorphTarget.h:167
TArray< int32 > SectionIndices
Definition MorphTarget.h:176
FString SourceFilename
Definition MorphTarget.h:184
Definition ObjectPtr.h:488
static CORE_API const TVector< float > ZeroVector
Definition Vector.h:79