UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
ClothingMeshUtils.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "SkeletalMeshTypes.h"
6#include "Chaos/AABBTree.h"
7
9
11struct FPointWeightMap;
12
13namespace ClothingMeshUtils
14{
16 {
17 TSet<int32> SourceTriangles; // Set of triangle index in the source ClothMeshDesc
18 TSet<int32> TargetVertices; // Set of vertex index in the target ClothMeshDesc
19 };
20
22 {
23 public:
31
40
41 /* Construct a mesh descriptor with re-calculated (averaged) normals to match the simulation output. */
43 : Positions(InPositions)
44 , Indices(InIndices)
45 , bHasValidBVH(false)
46 {
47 ComputeAveragedNormals();
48 Normals = TConstArrayView<FVector3f>(AveragedNormals);
49 }
50
51 const TConstArrayView<FVector3f>& GetPositions() const { return Positions; }
52 const TConstArrayView<FVector3f>& GetNormals() const { return Normals; }
53 const TConstArrayView<FVector3f>& GetTangents() const { return Tangents; }
54 const TConstArrayView<uint32>& GetIndices() const { return Indices; }
55
57 bool HasValidMesh() const { return Positions.Num() == Normals.Num() && Indices.Num() % 3 == 0; }
58
60 bool HasTangents() const { return Positions.Num() == Tangents.Num(); }
61
63 bool HasAveragedNormals() const { return Normals.Num() == AveragedNormals.Num(); }
64
67
69 TArray<int32>& GetFilteredTriangles() const { return FilteredTriangles; }
70
73
76
82
83 private:
84 CLOTHINGSYSTEMRUNTIMECOMMON_API void ComputeAveragedNormals();
85
86 struct FClothBvEntry;
87
92
93 TArray<FVector3f> AveragedNormals;
94
95 mutable bool bHasValidBVH;
97
98 mutable TArray<float> MaxEdgeLengths;
99 mutable TArray<int32> FilteredTriangles;
100 };
101
106 const TArray<int32>& BoneMap, // UClothingAssetCommon::UsedBoneIndices
108 const FTransform& PostTransform, // Final transform to apply to component space positions and normals
113
128 const ClothMeshDesc& TargetMesh,
129 const ClothMeshDesc& SourceMesh,
130 const FPointWeightMap* MaxDistances,
132 bool bUseMultipleInfluences,
133 float KernelMaxDistance,
135
142 const FPointWeightMap* const InMaxDistances,
143 const bool bInSmoothTransition,
144 const bool bInUseMultipleInfluences = false);
145
159 const FVector3f& A,
160 const FVector3f& B,
161 const FVector3f& C,
162 const FVector3f& Point);
163
177 const FVector3f& A,
178 const FVector3f& B,
179 const FVector3f& C,
180 const FVector3f& NA,
181 const FVector3f& NB,
182 const FVector3f& NC,
183 const FVector3f& Point);
184
190 {
191 public:
193
206
208 template<typename T, typename Lambda>
209 void Map(TConstArrayView<T>& SourceData, TArray<T>& DestData, const Lambda& Func)
210 {
211 // Enforce the interp func signature (returns T and takes a bary and 3 Ts)
212 // If you hit this then either the return type isn't T or your arguments aren't convertible to T
213 static_assert(std::is_same_v<T, typename TDecay<decltype(Func(DeclVal<FVector3f>(), DeclVal<T>(), DeclVal<T>(), DeclVal<T>()))>::Type>, "Invalid Lambda signature passed to Map");
214
215 const int32 NumMesh0Positions = Mesh0Positions.Num();
216 const int32 NumMesh0Normals = Mesh0Normals.Num();
217
218 const int32 NumMesh1Positions = Mesh1Positions.Num();
219 const int32 NumMesh1Normals = Mesh1Normals.Num();
220 const int32 NumMesh1Indices = Mesh1Indices.Num();
221
222 // Validate mesh data
225 check(NumMesh1Indices % 3 == 0);
226 check(SourceData.Num() == NumMesh1Positions);
227
228 if(DestData.Num() != NumMesh0Positions)
229 {
230 DestData.Reset();
232 }
233
235 TArray<int32> SourceIndices;
236 GenerateEmbeddedPositions(EmbeddedPositions, SourceIndices);
237
239 {
240 // Truncate the distance from the position data
242
244 T A = SourceData[SourceIndices[SourceTriBaseIdx + 0]];
245 T B = SourceData[SourceIndices[SourceTriBaseIdx + 1]];
246 T C = SourceData[SourceIndices[SourceTriBaseIdx + 2]];
247
248 T& DestVal = DestData[DestVertIndex];
249
250 // If we're super close to a vertex just take it's value.
251 // Otherwise call the provided interp lambda
253 if(FMath::Abs(DiffVec.X) <= SMALL_NUMBER)
254 {
255 DestVal = A;
256 }
257 else if(FMath::Abs(DiffVec.Y) <= SMALL_NUMBER)
258 {
259 DestVal = B;
260 }
261 else if(FMath::Abs(DiffVec.Z) <= SMALL_NUMBER)
262 {
263 DestVal = C;
264 }
265 else
266 {
267 DestVal = Func((FVector3f)Bary, A, B, C);
268 }
269 }
270 }
271
278
279 private:
280
287
288 TConstArrayView<FVector3f> Mesh0Positions;
289 TConstArrayView<FVector3f> Mesh0Normals;
290 TConstArrayView<FVector3f> Mesh1Positions;
291 TConstArrayView<FVector3f> Mesh1Normals;
292 TConstArrayView<uint32> Mesh1Indices;
293 };
294}
#define check(expr)
Definition AssertionMacros.h:314
#define UE_NONCOPYABLE(TypeName)
Definition CoreMiscDefines.h:457
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
#define DECLARE_LOG_CATEGORY_EXTERN(CategoryName, DefaultVerbosity, CompileTimeVerbosity)
Definition LogMacros.h:361
#define SMALL_NUMBER
Definition UnrealMathUtility.h:66
#define KINDA_SMALL_NUMBER
Definition UnrealMathUtility.h:67
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition AABBTree.h:786
Definition ClothingMeshUtils.h:22
bool HasValidMesh() const
Definition ClothingMeshUtils.h:57
bool HasAveragedNormals() const
Definition ClothingMeshUtils.h:63
void GatherAllSourceTrianglesForTargetVertex(const TArray< FMeshToMeshFilterSet > &FilterSets, int32 TargetVertex) const
Definition ClothingMeshUtils.cpp:58
ClothMeshDesc(TConstArrayView< FVector3f > InPositions, TConstArrayView< FVector3f > InNormals, TConstArrayView< FVector3f > InTangents, TConstArrayView< uint32 > InIndices)
Definition ClothingMeshUtils.h:32
ClothMeshDesc(TConstArrayView< FVector3f > InPositions, TConstArrayView< uint32 > InIndices)
Definition ClothingMeshUtils.h:42
TArray< int32 > & GetFilteredTriangles() const
Definition ClothingMeshUtils.h:69
bool HasTangents() const
Definition ClothingMeshUtils.h:60
const TConstArrayView< FVector3f > & GetNormals() const
Definition ClothingMeshUtils.h:52
const TConstArrayView< FVector3f > & GetPositions() const
Definition ClothingMeshUtils.h:51
CLOTHINGSYSTEMRUNTIMECOMMON_API TArray< int32 > FindCandidateTriangles(const FVector &InPoint, float InTolerance=KINDA_SMALL_NUMBER) const
Definition ClothingMeshUtils.cpp:93
const TConstArrayView< FVector3f > & GetTangents() const
Definition ClothingMeshUtils.h:53
ClothMeshDesc(TConstArrayView< FVector3f > InPositions, TConstArrayView< FVector3f > InNormals, TConstArrayView< uint32 > InIndices)
Definition ClothingMeshUtils.h:24
const TConstArrayView< uint32 > & GetIndices() const
Definition ClothingMeshUtils.h:54
CLOTHINGSYSTEMRUNTIMECOMMON_API TConstArrayView< float > GetMaxEdgeLengths() const
Definition ClothingMeshUtils.cpp:147
CLOTHINGSYSTEMRUNTIMECOMMON_API float DistanceToTriangle(const FVector &Position, int32 TriangleBaseIndex) const
Definition ClothingMeshUtils.cpp:79
Definition ClothingMeshUtils.h:190
void Map(TConstArrayView< T > &SourceData, TArray< T > &DestData, const Lambda &Func)
Definition ClothingMeshUtils.h:209
Definition Array.h:670
UE_FORCEINLINE_HINT SizeType AddUninitialized()
Definition Array.h:1664
UE_REWRITE SizeType Num() const
Definition Array.h:1144
void Reset(SizeType NewSize=0)
Definition Array.h:2246
Definition ClothingMeshUtils.cpp:26
FVector4f GetPointBaryAndDist(const FVector3f &A, const FVector3f &B, const FVector3f &C, const FVector3f &Point)
Definition ClothingMeshUtils.cpp:829
void GenerateMeshToMeshVertData(TArray< FMeshToMeshVertData > &OutMeshToMeshVertData, const ClothMeshDesc &TargetMesh, const ClothMeshDesc &SourceMesh, const FPointWeightMap *MaxDistances, bool bUseSmoothTransitions, bool bUseMultipleInfluences, float KernelMaxDistance, const TArray< FMeshToMeshFilterSet > &FilterSets)
Definition ClothingMeshUtils.cpp:678
void ComputeVertexContributions(TArray< FMeshToMeshVertData > &InOutSkinningData, const FPointWeightMap *const InMaxDistances, const bool bInSmoothTransition, const bool bInUseMultipleInfluences)
Definition ClothingMeshUtils.cpp:1150
FVector4f GetPointBaryAndDistWithNormals(const FVector3f &A, const FVector3f &B, const FVector3f &C, const FVector3f &InputNA, const FVector3f &InputNB, const FVector3f &InputNC, const FVector3f &Point)
Definition ClothingMeshUtils.cpp:1035
void SkinPhysicsMesh(const TArray< int32 > &InBoneMap, const FClothPhysicalMeshData &InMesh, const FTransform &PostTransform, const FMatrix44f *InBoneMatrices, const int32 InNumBoneMatrices, TArray< FVector3f > &OutPositions, TArray< FVector3f > &OutNormals)
Definition ClothingMeshUtils.cpp:218
@ false
Definition radaudio_common.h:23
Definition ClothingMeshUtils.h:16
TSet< int32 > TargetVertices
Definition ClothingMeshUtils.h:18
TSet< int32 > SourceTriangles
Definition ClothingMeshUtils.h:17
Definition ClothPhysicalMeshData.h:26
Definition PointWeightMap.h:33
static CORE_API const TVector< double > OneVector
Definition Vector.h:82