UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
StaticMeshLODResourcesAdapter.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5// HEADER_UNIT_SKIP - Bad includes
6
7#include "CoreMinimal.h"
10#include "TransformTypes.h"
11
12
18{
20protected:
22
25 bool bScaleNormals = false;
26
30
31protected:
33 : Mesh(nullptr)
34 , NumTriangles(0)
35 {
36 }
37
38public:
40 : Mesh(MeshIn)
41 , NumTriangles(0)
42 {
43 TriangleOffsetArray.Reserve(MeshIn->Sections.Num() + 1);
44 ValidSections.Reserve(MeshIn->Sections.Num());
45
46 for (const FStaticMeshSection& Section : MeshIn->Sections)
47 {
49 NumTriangles += Section.NumTriangles;
50 ValidSections.Add(&Section);
51 }
52
54 }
55
62
63 bool IsTriangle(int32 TID) const
64 {
65 return TID >= 0 && TID < MaxTriangleID();
66 }
67 bool IsVertex(int32 VID) const
68 {
69 return VID >= 0 && VID < MaxVertexID();
70 }
71 // ID and Count are the same for StaticMeshLODResources because it's compact
73 {
74 return TriangleCount();
75 }
77 {
79 }
81 {
82 return VertexCount();
83 }
89 {
90 // FStaticMeshLODResource doesn't provide any mechanism to know if it's been modified so just return 1
91 // and leave it to the caller to not build an aabb and then change the underlying mesh
92 return 1;
93 }
94
96 {
98 InOutIDValue -= TriangleOffsetArray[SectionIdx];
99 return *ValidSections[SectionIdx];
100 }
101
102 inline FIndex3i GetTriangle(int32 IDValue) const
103 {
106 return FIndex3i(IndexArrayView[TriSection.FirstIndex + IDValue * 3 + 0],
107 IndexArrayView[TriSection.FirstIndex + IDValue * 3 + 1],
108 IndexArrayView[TriSection.FirstIndex + IDValue * 3 + 2]);
109 }
110
111 inline FVector3d GetVertex(int32 IDValue) const
112 {
114 return FVector3d(BuildScale.X * (double)Position.X, BuildScale.Y * (double)Position.Y, BuildScale.Z * (double)Position.Z);
115 }
116
117 inline void GetTriVertices(int32 IDValue, FVector3d& V0, FVector3d& V1, FVector3d& V2) const
118 {
120
121 V0 = GetVertex(VtxIndices.A);
122 V1 = GetVertex(VtxIndices.B);
123 V2 = GetVertex(VtxIndices.C);
124 }
125
126 template<typename VectorType>
127 inline void GetTriVertices(int32 IDValue, VectorType& V0, VectorType& V1, VectorType& V2) const
128 {
130
131 V0 = GetVertex(VtxIndices.A);
132 V1 = GetVertex(VtxIndices.B);
133 V2 = GetVertex(VtxIndices.C);
134 }
135
140 inline bool IsNormal(int32 NID) const
141 {
142 return NID >= 0 && NID < NormalCount();
143 }
144 inline int32 MaxNormalID() const
145 {
146 return NormalCount();
147 }
148 inline int32 NormalCount() const
149 {
150 return HasNormals() ? VertexCount() : 0;
151 }
152
159
161 template<typename VectorType>
162 inline void GetTriNormals(int32 TriId, VectorType& N0, VectorType& N1, VectorType& N2)
163 {
165
169 }
170
171
172 inline FVector3f GetTangentX(int32 IDValue) const
173 {
175 return (!bScaleNormals) ? FVector3f(TangentX.X, TangentX.Y, TangentX.Z) :
176 UE::Geometry::Normalized(FVector3f(TangentX.X * BuildScale.X, TangentX.Y * BuildScale.Y, TangentX.Z * BuildScale.Z));
177 }
178
180 template<typename VectorType>
181 inline void GetTriTangentsX(int32 TriId, VectorType& T0, VectorType& T1, VectorType& T2)
182 {
184 T0 = GetTangentX(VtxIndices.A);
185 T1 = GetTangentX(VtxIndices.B);
187 }
188
189
190 inline FVector3f GetTangentY(int32 IDValue) const
191 {
193 return (!bScaleNormals) ? FVector3f(TangentY.X, TangentY.Y, TangentY.Z) :
194 UE::Geometry::Normalized(FVector3f(TangentY.X * BuildScale.X, TangentY.Y * BuildScale.Y, TangentY.Z * BuildScale.Z));
195 }
196
198 template<typename VectorType>
199 inline void GetTriTangentsY(int32 TriId, VectorType& T0, VectorType& T1, VectorType& T2)
200 {
202 T0 = GetTangentY(VtxIndices.A);
203 T1 = GetTangentY(VtxIndices.B);
205 }
206
207
217 inline bool IsUV(const int32 UVId) const
218 {
219 return HasUVs() && UVId >= 0 && UVId < UVCount();
220 }
221 inline int32 MaxUVID() const
222 {
223 return UVCount();
224 }
225 inline int32 UVCount() const
226 {
227 return HasUVs() ? Mesh->GetNumVertices() : 0;
228 }
229
231 inline FVector2f GetUV(const int32 IDValue, const int32 UVLayer) const
232 {
234 }
235
237 template<typename VectorType>
238 inline void GetTriUVs(const int32 TriId, const int32 UVLayer, VectorType& UV0, VectorType& UV1, VectorType& UV2)
239 {
241
242 UV0 = GetUV(VtxIndices.A, UVLayer);
243 UV1 = GetUV(VtxIndices.B, UVLayer);
244 UV2 = GetUV(VtxIndices.C, UVLayer);
245 }
246
247
248 inline bool HasColors() const
249 {
251 }
252 inline bool IsColor(int32 ColorIndex) const
253 {
254 return ColorIndex >= 0 && ColorIndex < ColorCount();
255 }
256 inline int32 MaxColorID() const
257 {
258 return ColorCount();
259 }
260 inline int32 ColorCount() const
261 {
262 return HasColors() ? VertexCount() : 0;
263 }
264
265 inline FColor GetColor(int32 IDValue) const
266 {
268 }
269
271 inline void GetTriColors(int32 TriId, FColor& C0, FColor& C1, FColor& C2)
272 {
275 C1 = GetColor(VtxIndices.B);
276 C2 = GetColor(VtxIndices.C);
277 }
278
279};
@ Normal
Definition AndroidInputInterface.h:116
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
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
Definition RawIndexBuffer.h:92
FVector3f & VertexPosition(uint32 VertexIndex)
Definition PositionVertexBuffer.h:85
ENGINE_API bool GetAllowCPUAccess() const
Definition PositionVertexBuffer.cpp:200
bool GetAllowCPUAccess() const
Definition RawIndexBuffer.h:271
ENGINE_API FIndexArrayView GetArrayView() const
Definition RawIndexBuffer.cpp:333
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 StaticMeshLODResourcesAdapter.h:18
bool bScaleNormals
Definition StaticMeshLODResourcesAdapter.h:25
FVector3f GetNormal(int32 IDValue) const
Definition StaticMeshLODResourcesAdapter.h:153
UE::Geometry::FIndex3i FIndex3i
Definition StaticMeshLODResourcesAdapter.h:19
void GetTriVertices(int32 IDValue, VectorType &V0, VectorType &V1, VectorType &V2) const
Definition StaticMeshLODResourcesAdapter.h:127
void GetTriTangentsX(int32 TriId, VectorType &T0, VectorType &T1, VectorType &T2)
Definition StaticMeshLODResourcesAdapter.h:181
FVector3d BuildScale
Definition StaticMeshLODResourcesAdapter.h:23
bool IsVertex(int32 VID) const
Definition StaticMeshLODResourcesAdapter.h:67
int32 UVCount() const
Definition StaticMeshLODResourcesAdapter.h:225
int32 NumTriangles
Definition StaticMeshLODResourcesAdapter.h:29
int32 TriangleCount() const
Definition StaticMeshLODResourcesAdapter.h:76
FVector3d GetVertex(int32 IDValue) const
Definition StaticMeshLODResourcesAdapter.h:111
FStaticMeshLODResourcesMeshAdapter(const FStaticMeshLODResources *MeshIn)
Definition StaticMeshLODResourcesAdapter.h:39
bool HasColors() const
Definition StaticMeshLODResourcesAdapter.h:248
FVector3f GetTangentX(int32 IDValue) const
Definition StaticMeshLODResourcesAdapter.h:172
void GetTriColors(int32 TriId, FColor &C0, FColor &C1, FColor &C2)
Definition StaticMeshLODResourcesAdapter.h:271
bool IsNormal(int32 NID) const
Definition StaticMeshLODResourcesAdapter.h:140
void SetBuildScale(const FVector3d &BuildScaleIn, bool bScaleNormalsIn)
Definition StaticMeshLODResourcesAdapter.h:56
int32 MaxVertexID() const
Definition StaticMeshLODResourcesAdapter.h:80
FStaticMeshLODResourcesMeshAdapter()
Definition StaticMeshLODResourcesAdapter.h:32
void GetTriTangentsY(int32 TriId, VectorType &T0, VectorType &T1, VectorType &T2)
Definition StaticMeshLODResourcesAdapter.h:199
TArray< int32 > TriangleOffsetArray
Definition StaticMeshLODResourcesAdapter.h:28
bool HasNormals() const
Definition StaticMeshLODResourcesAdapter.h:136
bool HasUVs(const int32 UVLayer=0) const
Definition StaticMeshLODResourcesAdapter.h:208
bool IsTriangle(int32 TID) const
Definition StaticMeshLODResourcesAdapter.h:63
TArray< const FStaticMeshSection * > ValidSections
Definition StaticMeshLODResourcesAdapter.h:27
bool IsColor(int32 ColorIndex) const
Definition StaticMeshLODResourcesAdapter.h:252
FVector2f GetUV(const int32 IDValue, const int32 UVLayer) const
Definition StaticMeshLODResourcesAdapter.h:231
FColor GetColor(int32 IDValue) const
Definition StaticMeshLODResourcesAdapter.h:265
int32 NormalCount() const
Definition StaticMeshLODResourcesAdapter.h:148
const FStaticMeshSection & TriangleToSection(int32 &InOutIDValue) const
Definition StaticMeshLODResourcesAdapter.h:95
int32 MaxColorID() const
Definition StaticMeshLODResourcesAdapter.h:256
void GetTriVertices(int32 IDValue, FVector3d &V0, FVector3d &V1, FVector3d &V2) const
Definition StaticMeshLODResourcesAdapter.h:117
bool IsUV(const int32 UVId) const
Definition StaticMeshLODResourcesAdapter.h:217
const FStaticMeshLODResources * Mesh
Definition StaticMeshLODResourcesAdapter.h:21
FVector3f GetTangentY(int32 IDValue) const
Definition StaticMeshLODResourcesAdapter.h:190
int32 ColorCount() const
Definition StaticMeshLODResourcesAdapter.h:260
FVector3d InvBuildScale
Definition StaticMeshLODResourcesAdapter.h:24
int32 NumUVLayers() const
Definition StaticMeshLODResourcesAdapter.h:212
int32 MaxUVID() const
Definition StaticMeshLODResourcesAdapter.h:221
void GetTriNormals(int32 TriId, VectorType &N0, VectorType &N1, VectorType &N2)
Definition StaticMeshLODResourcesAdapter.h:162
int32 VertexCount() const
Definition StaticMeshLODResourcesAdapter.h:84
int32 MaxTriangleID() const
Definition StaticMeshLODResourcesAdapter.h:72
uint64 GetChangeStamp() const
Definition StaticMeshLODResourcesAdapter.h:88
FIndex3i GetTriangle(int32 IDValue) const
Definition StaticMeshLODResourcesAdapter.h:102
void GetTriUVs(const int32 TriId, const int32 UVLayer, VectorType &UV0, VectorType &UV1, VectorType &UV2)
Definition StaticMeshLODResourcesAdapter.h:238
int32 MaxNormalID() const
Definition StaticMeshLODResourcesAdapter.h:144
Definition StaticMeshResources.h:426
ENGINE_API int32 GetNumVertices() const
Definition StaticMesh.cpp:1065
FRawStaticIndexBuffer IndexBuffer
Definition StaticMeshResources.h:489
FStaticMeshVertexBuffers VertexBuffers
Definition StaticMeshResources.h:486
Definition StaticMeshResources.h:202
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