UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
SkeletalMeshLODRenderDataMeshAdapter.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc.All Rights Reserved.
2
3#pragma once
4
5
6
7#include "CoreMinimal.h"
8#include "TransformTypes.h"
10
16{
18protected:
20
23 bool bScaleNormals = false;
24
28
30
32
33protected:
35 : Mesh(nullptr)
36 , NumTriangles(0)
37 {
38 }
39
40public:
42 : Mesh(MeshIn)
43 , NumTriangles(0)
44 {
45 if (MeshIn)
46 {
47 TriangleOffsetArray.Reserve(MeshIn->RenderSections.Num() + 1);
48 ValidSections.Reserve(MeshIn->RenderSections.Num());
49
50 for (const FSkelMeshRenderSection& Section : MeshIn->RenderSections)
51 {
53 NumTriangles += Section.NumTriangles;
54 ValidSections.Add(&Section);
55 }
56
58
59 MeshIn->MultiSizeIndexContainer.GetIndexBuffer(SrcIndexBuffer);
60
61 const FSkinWeightVertexBuffer* SkinWeightBuffer = &MeshIn->SkinWeightVertexBuffer;
62 const bool bSkinWeightsValid = SkinWeightBuffer->GetDataVertexBuffer() && SkinWeightBuffer->GetDataVertexBuffer()->IsInitialized() && SkinWeightBuffer->GetDataVertexBuffer()->GetNumVertices() > 0;
64 {
66
68 for (const FSkelMeshRenderSection& Section : MeshIn->RenderSections)
69 {
70 const int32 BaseVertexIndex = static_cast<int32>(Section.BaseVertexIndex);
71 const int32 NumSectionVtx = static_cast<int32>(Section.NumVertices);
72 for (int32 VtxIndex = BaseVertexIndex; VtxIndex < NumSectionVtx + BaseVertexIndex; ++VtxIndex)
73 {
74 FSkinWeightInfo SrcWeights = SkinWeightBuffer->GetVertexSkinWeights(VtxIndex);
75
76 for (int32 Idx = 0; Idx < MAX_TOTAL_INFLUENCES; ++Idx)
77 {
78 const int32 SectionBoneIdx = static_cast<int32>(SrcWeights.InfluenceBones[Idx]);
79 if (ensure(SectionBoneIdx < Section.BoneMap.Num()))
80 {
81 SrcWeights.InfluenceBones[Idx] = Section.BoneMap[SectionBoneIdx];
82 }
83 }
85 }
86 }
87 }
88 }
89 }
90
97
98 bool IsTriangle(int32 TID) const
99 {
100 return TID >= 0 && TID < MaxTriangleID();
101 }
102 bool IsVertex(int32 VID) const
103 {
104 return VID >= 0 && VID < MaxVertexID();
105 }
106 // ID and Count are the same for StaticMeshLODResources because it's compact
108 {
109 return TriangleCount();
110 }
116 {
117 return VertexCount();
118 }
124 {
125 // FSkeletalMeshLODRenderData doesn't provide any mechanism to know if it's been modified so just return 1
126 // and leave it to the caller to not build an aabb and then change the underlying mesh
127 return 1;
128 }
129
131 {
133 InOutIDValue -= TriangleOffsetArray[SectionIdx];
134 return *ValidSections[SectionIdx];
135 }
136
137 inline FIndex3i GetTriangle(int32 IDValue) const
138 {
140
141 return FIndex3i(SrcIndexBuffer[TriSection.BaseIndex + IDValue * 3 + 0],
142 SrcIndexBuffer[TriSection.BaseIndex + IDValue * 3 + 1],
143 SrcIndexBuffer[TriSection.BaseIndex + IDValue * 3 + 2]);
144 }
145
146 inline FVector3d GetVertex(int32 IDValue) const
147 {
149 return FVector3d(BuildScale.X * (double)Position.X, BuildScale.Y * (double)Position.Y, BuildScale.Z * (double)Position.Z);
150 }
151
152 inline void GetTriVertices(int32 IDValue, FVector3d& V0, FVector3d& V1, FVector3d& V2) const
153 {
155
156 V0 = GetVertex(VtxIndices.A);
157 V1 = GetVertex(VtxIndices.B);
158 V2 = GetVertex(VtxIndices.C);
159 }
160
161 template<typename VectorType>
162 inline void GetTriVertices(int32 IDValue, VectorType& V0, VectorType& V1, VectorType& V2) const
163 {
165
166 V0 = GetVertex(VtxIndices.A);
167 V1 = GetVertex(VtxIndices.B);
168 V2 = GetVertex(VtxIndices.C);
169 }
170
175 inline bool IsNormal(int32 NID) const
176 {
177 return NID >= 0 && NID < NormalCount();
178 }
179 inline int32 MaxNormalID() const
180 {
181 return NormalCount();
182 }
183 inline int32 NormalCount() const
184 {
185 return HasNormals() ? VertexCount() : 0;
186 }
187
194
196 template<typename VectorType>
197 inline void GetTriNormals(int32 TriId, VectorType& N0, VectorType& N1, VectorType& N2)
198 {
200
204 }
205
206
207 inline FVector3f GetTangentX(int32 IDValue) const
208 {
210 return (!bScaleNormals) ? FVector3f(TangentX.X, TangentX.Y, TangentX.Z) :
211 UE::Geometry::Normalized(FVector3f(TangentX.X * BuildScale.X, TangentX.Y * BuildScale.Y, TangentX.Z * BuildScale.Z));
212 }
213
215 template<typename VectorType>
216 inline void GetTriTangentsX(int32 TriId, VectorType& T0, VectorType& T1, VectorType& T2)
217 {
219 T0 = GetTangentX(VtxIndices.A);
220 T1 = GetTangentX(VtxIndices.B);
222 }
223
224
225 inline FVector3f GetTangentY(int32 IDValue) const
226 {
228 return (!bScaleNormals) ? FVector3f(TangentY.X, TangentY.Y, TangentY.Z) :
229 UE::Geometry::Normalized(FVector3f(TangentY.X * BuildScale.X, TangentY.Y * BuildScale.Y, TangentY.Z * BuildScale.Z));
230 }
231
233 template<typename VectorType>
234 inline void GetTriTangentsY(int32 TriId, VectorType& T0, VectorType& T1, VectorType& T2)
235 {
237 T0 = GetTangentY(VtxIndices.A);
238 T1 = GetTangentY(VtxIndices.B);
240 }
241
242
252 inline bool IsUV(const int32 UVId) const
253 {
254 return HasUVs() && UVId >= 0 && UVId < UVCount();
255 }
256 inline int32 MaxUVID() const
257 {
258 return UVCount();
259 }
260 inline int32 UVCount() const
261 {
262 return HasUVs() ? Mesh->GetNumVertices() : 0;
263 }
264
266 inline FVector2f GetUV(const int32 IDValue, const int32 UVLayer) const
267 {
269 }
270
272 template<typename VectorType>
273 inline void GetTriUVs(const int32 TriId, const int32 UVLayer, VectorType& UV0, VectorType& UV1, VectorType& UV2)
274 {
276
277 UV0 = GetUV(VtxIndices.A, UVLayer);
278 UV1 = GetUV(VtxIndices.B, UVLayer);
279 UV2 = GetUV(VtxIndices.C, UVLayer);
280 }
281
282
283 inline bool HasColors() const
284 {
286 }
287 inline bool IsColor(int32 ColorIndex) const
288 {
289 return ColorIndex >= 0 && ColorIndex < ColorCount();
290 }
291 inline int32 MaxColorID() const
292 {
293 return ColorCount();
294 }
295 inline int32 ColorCount() const
296 {
297 return HasColors() ? VertexCount() : 0;
298 }
299
300 inline FColor GetColor(int32 IDValue) const
301 {
303 }
304
306 inline void GetTriColors(int32 TriId, FColor& C0, FColor& C1, FColor& C2)
307 {
310 C1 = GetColor(VtxIndices.B);
311 C2 = GetColor(VtxIndices.C);
312 }
313
323
325 {
326 return SkinWeights[VID];
327 }
328};
@ Normal
Definition AndroidInputInterface.h:116
#define ensure( InExpression)
Definition AssertionMacros.h:464
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 MAX_TOTAL_INFLUENCES
Definition GPUSkinPublicDefs.h:12
UE::Math::TVector< float > FVector3f
Definition MathFwd.h:73
UE::Math::TVector< double > FVector3d
Definition MathFwd.h:60
ENGINE_API bool GetAllowCPUAccess() const
Definition ColorVertexBuffer.cpp:383
FColor & VertexColor(uint32 VertexIndex)
Definition ColorVertexBuffer.h:88
bool IsIndexBufferValid() const
Definition MultiSizeIndexContainer.h:73
FVector3f & VertexPosition(uint32 VertexIndex)
Definition PositionVertexBuffer.h:85
ENGINE_API bool GetAllowCPUAccess() const
Definition PositionVertexBuffer.cpp:200
bool IsInitialized() const
Definition RenderResource.h:114
Definition SkeletalMeshLODRenderData.h:128
FSkinWeightVertexBuffer SkinWeightVertexBuffer
Definition SkeletalMeshLODRenderData.h:141
uint32 GetNumVertices() const
Definition SkeletalMeshLODRenderData.h:263
FStaticMeshVertexBuffers StaticVertexBuffers
Definition SkeletalMeshLODRenderData.h:138
FMultiSizeIndexContainer MultiSizeIndexContainer
Definition SkeletalMeshLODRenderData.h:135
uint32 GetNumVertices() const
Definition SkinWeightVertexBuffer.h:223
Definition SkinWeightVertexBuffer.h:364
FSkinWeightDataVertexBuffer * GetDataVertexBuffer()
Definition SkinWeightVertexBuffer.h:451
FVector2f GetVertexUV(uint32 VertexIndex, uint32 UVIndex) const
Definition StaticMeshVertexBuffer.h:391
bool GetAllowCPUAccess() const
Definition StaticMeshVertexBuffer.h:471
void * GetTangentData()
Definition StaticMeshVertexBuffer.h:461
uint32 GetNumTexCoords() const
Definition StaticMeshVertexBuffer.h:411
FVector4f VertexTangentZ(uint32 VertexIndex) const
Definition StaticMeshVertexBuffer.h:265
FVector3f VertexTangentY(uint32 VertexIndex) const
Definition StaticMeshVertexBuffer.h:295
FVector4f VertexTangentX(uint32 VertexIndex) const
Definition StaticMeshVertexBuffer.h:241
void * GetTexCoordData()
Definition StaticMeshVertexBuffer.h:464
Definition Array.h:670
UE_NODEBUG UE_FORCEINLINE_HINT SizeType Add(ElementType &&Item)
Definition Array.h:2696
UE_FORCEINLINE_HINT void Reserve(SizeType Number)
Definition Array.h:3016
static TVector< double > GetSafeScaleReciprocal(const TVector< double > &InScale, double Tolerance=TMathUtil< double >::ZeroTolerance)
Definition TransformTypes.h:388
UE_REWRITE auto UpperBound(const RangeType &Range, const ValueType &Value, SortPredicateType SortPredicate) -> decltype(GetNum(Range))
Definition BinarySearch.h:133
UE::Math::TVector2< T > Normalized(const UE::Math::TVector2< T > &Vector, const T Epsilon=0)
Definition VectorTypes.h:61
Definition Color.h:486
Definition SkeletalMeshLODRenderData.h:28
Definition SkeletalMeshLODRenderDataMeshAdapter.h:16
FVector3d BuildScale
Definition SkeletalMeshLODRenderDataMeshAdapter.h:21
void SetBuildScale(const FVector3d &BuildScaleIn, bool bScaleNormalsIn)
Definition SkeletalMeshLODRenderDataMeshAdapter.h:91
void GetTriNormals(int32 TriId, VectorType &N0, VectorType &N1, VectorType &N2)
Definition SkeletalMeshLODRenderDataMeshAdapter.h:197
FSkeletalMeshLODRenderDataMeshAdapter()
Definition SkeletalMeshLODRenderDataMeshAdapter.h:34
int32 NumTriangles
Definition SkeletalMeshLODRenderDataMeshAdapter.h:27
bool IsColor(int32 ColorIndex) const
Definition SkeletalMeshLODRenderDataMeshAdapter.h:287
FVector3f GetNormal(int32 IDValue) const
Definition SkeletalMeshLODRenderDataMeshAdapter.h:188
bool IsVertex(int32 VID) const
Definition SkeletalMeshLODRenderDataMeshAdapter.h:102
FVector3f GetTangentX(int32 IDValue) const
Definition SkeletalMeshLODRenderDataMeshAdapter.h:207
FIndex3i GetTriangle(int32 IDValue) const
Definition SkeletalMeshLODRenderDataMeshAdapter.h:137
FSkeletalMeshLODRenderDataMeshAdapter(const FSkeletalMeshLODRenderData *MeshIn)
Definition SkeletalMeshLODRenderDataMeshAdapter.h:41
int32 UVCount() const
Definition SkeletalMeshLODRenderDataMeshAdapter.h:260
FVector3d GetVertex(int32 IDValue) const
Definition SkeletalMeshLODRenderDataMeshAdapter.h:146
UE::Geometry::FIndex3i FIndex3i
Definition SkeletalMeshLODRenderDataMeshAdapter.h:17
int32 NormalCount() const
Definition SkeletalMeshLODRenderDataMeshAdapter.h:183
TArray< int32 > TriangleOffsetArray
Definition SkeletalMeshLODRenderDataMeshAdapter.h:26
int32 VertexCount() const
Definition SkeletalMeshLODRenderDataMeshAdapter.h:119
FVector2f GetUV(const int32 IDValue, const int32 UVLayer) const
Definition SkeletalMeshLODRenderDataMeshAdapter.h:266
int32 MaxNormalID() const
Definition SkeletalMeshLODRenderDataMeshAdapter.h:179
bool HasSkinWeights()
Definition SkeletalMeshLODRenderDataMeshAdapter.h:314
FVector3f GetTangentY(int32 IDValue) const
Definition SkeletalMeshLODRenderDataMeshAdapter.h:225
FColor GetColor(int32 IDValue) const
Definition SkeletalMeshLODRenderDataMeshAdapter.h:300
bool IsTriangle(int32 TID) const
Definition SkeletalMeshLODRenderDataMeshAdapter.h:98
int32 TriangleCount() const
Definition SkeletalMeshLODRenderDataMeshAdapter.h:111
void GetTriUVs(const int32 TriId, const int32 UVLayer, VectorType &UV0, VectorType &UV1, VectorType &UV2)
Definition SkeletalMeshLODRenderDataMeshAdapter.h:273
bool bScaleNormals
Definition SkeletalMeshLODRenderDataMeshAdapter.h:23
bool HasColors() const
Definition SkeletalMeshLODRenderDataMeshAdapter.h:283
TArray< const FSkelMeshRenderSection * > ValidSections
Definition SkeletalMeshLODRenderDataMeshAdapter.h:25
int32 MaxColorID() const
Definition SkeletalMeshLODRenderDataMeshAdapter.h:291
bool HasNormals() const
Definition SkeletalMeshLODRenderDataMeshAdapter.h:171
void GetTriTangentsY(int32 TriId, VectorType &T0, VectorType &T1, VectorType &T2)
Definition SkeletalMeshLODRenderDataMeshAdapter.h:234
FSkinWeightInfo GetSkinWeightInfo(int32 VID)
Definition SkeletalMeshLODRenderDataMeshAdapter.h:324
int32 ColorCount() const
Definition SkeletalMeshLODRenderDataMeshAdapter.h:295
uint64 GetChangeStamp() const
Definition SkeletalMeshLODRenderDataMeshAdapter.h:123
void GetTriTangentsX(int32 TriId, VectorType &T0, VectorType &T1, VectorType &T2)
Definition SkeletalMeshLODRenderDataMeshAdapter.h:216
void GetTriVertices(int32 IDValue, VectorType &V0, VectorType &V1, VectorType &V2) const
Definition SkeletalMeshLODRenderDataMeshAdapter.h:162
TArray< uint32 > SrcIndexBuffer
Definition SkeletalMeshLODRenderDataMeshAdapter.h:29
bool IsNormal(int32 NID) const
Definition SkeletalMeshLODRenderDataMeshAdapter.h:175
int32 MaxTriangleID() const
Definition SkeletalMeshLODRenderDataMeshAdapter.h:107
FVector3d InvBuildScale
Definition SkeletalMeshLODRenderDataMeshAdapter.h:22
bool HasUVs(const int32 UVLayer=0) const
Definition SkeletalMeshLODRenderDataMeshAdapter.h:243
bool IsUV(const int32 UVId) const
Definition SkeletalMeshLODRenderDataMeshAdapter.h:252
const FSkeletalMeshLODRenderData * Mesh
Definition SkeletalMeshLODRenderDataMeshAdapter.h:19
int32 MaxUVID() const
Definition SkeletalMeshLODRenderDataMeshAdapter.h:256
int32 MaxVertexID() const
Definition SkeletalMeshLODRenderDataMeshAdapter.h:115
const FSkelMeshRenderSection & TriangleToSection(int32 &InOutIDValue) const
Definition SkeletalMeshLODRenderDataMeshAdapter.h:130
TArray< FSkinWeightInfo > SkinWeights
Definition SkeletalMeshLODRenderDataMeshAdapter.h:31
int32 NumUVLayers() const
Definition SkeletalMeshLODRenderDataMeshAdapter.h:247
void GetTriVertices(int32 IDValue, FVector3d &V0, FVector3d &V1, FVector3d &V2) const
Definition SkeletalMeshLODRenderDataMeshAdapter.h:152
void GetTriColors(int32 TriId, FColor &C0, FColor &C1, FColor &C2)
Definition SkeletalMeshLODRenderDataMeshAdapter.h:306
Definition SkinWeightVertexBuffer.h:60
FBoneIndexType InfluenceBones[MAX_TOTAL_INFLUENCES]
Definition SkinWeightVertexBuffer.h:61
FColorVertexBuffer ColorVertexBuffer
Definition StaticMeshResources.h:328
FStaticMeshVertexBuffer StaticMeshVertexBuffer
Definition StaticMeshResources.h:322
FPositionVertexBuffer PositionVertexBuffer
Definition StaticMeshResources.h:325
Definition IndexTypes.h:158
T Y
Definition Vector4.h:46
T Z
Definition Vector4.h:49
T X
Definition Vector4.h:43
static TVector< double > One()
Definition Vector.h:115
T Z
Definition Vector.h:68
T Y
Definition Vector.h:65
T X
Definition Vector.h:62