UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
MeshDescriptionAdapter.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "CoreMinimal.h"
6#include "MeshDescription.h"
9#include "MeshAdapter.h"
10
11
21struct /*MESHCONVERSION_API*/ FMeshDescriptionTriangleMeshAdapter
22{
24protected:
30
32 bool bScaleNormals = false;
33
34public:
36 {
42 // @todo: can we hold TArrayViews of the attribute arrays here? Do we guarantee not to mutate the mesh description for the duration of this object?
43 }
44
50
51 bool IsTriangle(int32 TID) const
52 {
53 return TID >= 0 && TID < Mesh->Triangles().Num();
54 }
55 bool IsVertex(int32 VID) const
56 {
57 return VID >= 0 && VID < Mesh->Vertices().Num();
58 }
59 // ID and Count are the same for MeshDescription because it's compact
61 {
62 return Mesh->Triangles().Num();
63 }
65 {
66 return Mesh->Triangles().Num();
67 }
69 {
70 return Mesh->Vertices().Num();
71 }
73 {
74 return Mesh->Vertices().Num();
75 }
77 {
78 // MeshDescription doesn't provide any mechanism to know if it's been modified so just return 1
79 // and leave it to the caller to not build an aabb and then change the underlying mesh
80 return 1;
81 }
82 FIndex3i GetTriangle(int32 IDValue) const
83 {
85 return FIndex3i(TriVertIDs[0].GetValue(), TriVertIDs[1].GetValue(), TriVertIDs[2].GetValue());
86 }
87 FVector3d GetVertex(int32 IDValue) const
88 {
90 return FVector3d(BuildScale.X * (double)Position.X, BuildScale.Y * (double)Position.Y, BuildScale.Z * (double)Position.Z);
91 }
92
93 inline void GetTriVertices(int32 IDValue, FVector3d& V0, FVector3d& V1, FVector3d& V2) const
94 {
97 V0 = FVector3d(BuildScale.X * (double)A.X, BuildScale.Y * (double)A.Y, BuildScale.Z * (double)A.Z);
99 V1 = FVector3d(BuildScale.X * (double)B.X, BuildScale.Y * (double)B.Y, BuildScale.Z * (double)B.Z);
101 V2 = FVector3d(BuildScale.X * (double)C.X, BuildScale.Y * (double)C.Y, BuildScale.Z * (double)C.Z);
102 }
103
104 template<typename VectorType>
105 inline void GetTriVertices(int32 IDValue, VectorType& V0, VectorType& V1, VectorType& V2) const
106 {
109 V0 = VectorType(BuildScale.X * (double)A.X, BuildScale.Y * (double)A.Y, BuildScale.Z * (double)A.Z);
111 V1 = VectorType(BuildScale.X * (double)B.X, BuildScale.Y * (double)B.Y, BuildScale.Z * (double)B.Z);
113 V2 = VectorType(BuildScale.X * (double)C.X, BuildScale.Y * (double)C.Y, BuildScale.Z * (double)C.Z);
114 }
115
116 inline bool HasNormals() const
117 {
118 return VertexInstanceNormals.IsValid();
119 }
120 inline bool IsNormal(int32 NID) const
121 {
122 return HasNormals() && NID >= 0 && NID < NormalCount();
123 }
124 inline int32 MaxNormalID() const
125 {
126 return HasNormals() ? VertexInstanceNormals.GetNumElements() : 0;
127 }
128 inline int32 NormalCount() const
129 {
130 return HasNormals() ? VertexInstanceNormals.GetNumElements() : 0;
131 }
132
140
142 template<typename VectorType>
143 void GetTriNormals(int32 TriId, VectorType& N0, VectorType& N1, VectorType& N2)
144 {
148 }
149
150 inline bool HasUVs(const int32 UVLayer=0) const
151 {
152 return VertexInstanceUVs.IsValid() && Mesh && UVLayer >= 0 && UVLayer < Mesh->GetNumUVElementChannels();
153 }
154 inline bool IsUV(const int32 UVId) const
155 {
156 return HasUVs() && UVId >= 0 && UVId < UVCount();
157 }
158 inline int32 MaxUVID() const
159 {
160 return HasUVs() ? VertexInstanceUVs.GetNumElements() : 0;
161 }
162 inline int32 UVCount() const
163 {
164 return HasUVs() ? VertexInstanceUVs.GetNumElements() : 0;
165 }
166
168 FVector2f GetUV(const int32 IDValue, const int32 UVLayer) const
169 {
170 return VertexInstanceUVs.Get(FVertexInstanceID(IDValue), UVLayer);
171 }
172
174 template<typename VectorType>
175 void GetTriUVs(const int32 TriId, const int32 UVLayer, VectorType& UV0, VectorType& UV1, VectorType& UV2)
176 {
180 }
181};
182
183
189{
191protected:
195
196public:
203
204 bool IsTriangle(int32 TID) const
205 {
206 return TID >= 0 && TID < Mesh->Triangles().Num();
207 }
208 bool IsVertex(int32 VID) const
209 {
210 return VID >= 0 && VID < Mesh->Vertices().Num();
211 }
212 // ID and Count are the same for MeshDescription because it's compact
214 {
215 return Mesh->Triangles().Num();
216 }
218 {
219 return Mesh->Triangles().Num();
220 }
222 {
223 return Mesh->Vertices().Num();
224 }
226 {
227 return Mesh->Vertices().Num();
228 }
230 {
231 // MeshDescription doesn't provide any mechanism to know if it's been modified so just return 1
232 // and leave it to the caller to not build an aabb and then change the underlying mesh
233 return 1;
234 }
236 {
238 return FIndex3i(TriVertIDs[0].GetValue(), TriVertIDs[1].GetValue(), TriVertIDs[2].GetValue());
239 }
240 FVector3d GetVertex(int32 IDValue) const
241 {
242 return FVector3d(VertexPositions[FVertexID(IDValue)]);
243 }
244 void SetVertex(int32 IDValue, const FVector3d& NewPos)
245 {
247 }
248
256
257
258 inline bool HasNormals() const
259 {
260 return VertexInstanceNormals.IsValid();
261 }
262 inline bool IsNormal(int32 NID) const
263 {
264 return HasNormals() && NID >= 0 && NID < NormalCount();
265 }
266 inline int32 MaxNormalID() const
267 {
268 return HasNormals() ? VertexInstanceNormals.GetNumElements() : 0;
269 }
270 inline int32 NormalCount() const
271 {
272 return HasNormals() ? VertexInstanceNormals.GetNumElements() : 0;
273 }
274 FVector3f GetNormal(int32 IDValue) const
275 {
277 }
278 void SetNormal(int32 IDValue, const FVector3f& Normal)
279 {
281 }
282};
283
284
285
290{
292
294 {
295 IsTriangle = [this](int index) { return ParentAdapter.IsTriangle(index);};
296 IsVertex = [this](int index) { return ParentAdapter.IsVertex(index); };
297 MaxTriangleID = [this]() { return ParentAdapter.MaxTriangleID();};
298 MaxVertexID = [this]() { return ParentAdapter.MaxVertexID();};
299 TriangleCount = [this]() { return ParentAdapter.TriangleCount();};
300 VertexCount = [this]() { return ParentAdapter.VertexCount();};
301 GetChangeStamp = [this]() { return ParentAdapter.GetChangeStamp();};
302 GetTriangle = [this](int32 TriangleID) { return ParentAdapter.GetTriangle(TriangleID); };
303 GetVertex = [this](int32 VertexID) { return ParentAdapter.GetVertex(VertexID); };
304 }
305
307 {
308 IsTriangle = [this](int index) { return ParentAdapter.IsTriangle(index);};
309 IsVertex = [this](int index) { return ParentAdapter.IsVertex(index); };
310 MaxTriangleID = [this]() { return ParentAdapter.MaxTriangleID();};
311 MaxVertexID = [this]() { return ParentAdapter.MaxVertexID();};
312 TriangleCount = [this]() { return ParentAdapter.TriangleCount();};
313 VertexCount = [this]() { return ParentAdapter.VertexCount();};
314 GetChangeStamp = [this]() { return ParentAdapter.GetChangeStamp();};
315 GetTriangle = [this](int32 TriangleID) { return ParentAdapter.GetTriangle(TriangleID); };
316 GetVertex = [this](int32 VertexID) { return ParentAdapter.GetVertex(VertexID); };
317 }
318
319};
@ 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
TVertexAttributesRef< FVector3f > GetVertexPositions()
Definition MeshAttributes.h:85
TVertexAttributesConstRef< FVector3f > GetVertexPositions() const
Definition MeshAttributes.h:208
TTriangleAttributesConstRef< TArrayView< FVertexInstanceID > > GetTriangleVertexInstanceIndices() const
Definition MeshAttributes.h:223
int32 Num() const
Definition MeshElementContainer.h:120
Definition StaticMeshAttributes.h:54
TVertexInstanceAttributesRef< FVector3f > GetVertexInstanceNormals()
Definition StaticMeshAttributes.h:91
Definition StaticMeshAttributes.h:125
TVertexInstanceAttributesConstRef< FVector3f > GetVertexInstanceNormals() const
Definition StaticMeshAttributes.h:133
TVertexInstanceAttributesConstRef< FVector2f > GetVertexInstanceUVs() const
Definition StaticMeshAttributes.h:132
Definition ArrayView.h:139
Definition MeshAttributeArray.h:836
UE::Math::TVector2< T > Normalized(const UE::Math::TVector2< T > &Vector, const T Epsilon=0)
Definition VectorTypes.h:61
Definition MeshDescriptionAdapter.h:189
TVertexAttributesRef< FVector3f > VertexPositions
Definition MeshDescriptionAdapter.h:193
FVector3f GetNormal(int32 IDValue) const
Definition MeshDescriptionAdapter.h:274
bool HasNormals() const
Definition MeshDescriptionAdapter.h:258
FMeshDescriptionEditableTriangleMeshAdapter(FMeshDescription *MeshIn)
Definition MeshDescriptionAdapter.h:197
FIndex3i GetTriangle(int32 IDValue) const
Definition MeshDescriptionAdapter.h:235
bool IsTriangle(int32 TID) const
Definition MeshDescriptionAdapter.h:204
void SetVertex(int32 IDValue, const FVector3d &NewPos)
Definition MeshDescriptionAdapter.h:244
int32 MaxVertexID() const
Definition MeshDescriptionAdapter.h:221
FVector3d GetVertex(int32 IDValue) const
Definition MeshDescriptionAdapter.h:240
UE::Geometry::FIndex3i FIndex3i
Definition MeshDescriptionAdapter.h:190
uint64 GetChangeStamp() const
Definition MeshDescriptionAdapter.h:229
bool IsVertex(int32 VID) const
Definition MeshDescriptionAdapter.h:208
bool IsNormal(int32 NID) const
Definition MeshDescriptionAdapter.h:262
int32 MaxTriangleID() const
Definition MeshDescriptionAdapter.h:213
int32 MaxNormalID() const
Definition MeshDescriptionAdapter.h:266
FMeshDescription * Mesh
Definition MeshDescriptionAdapter.h:192
int32 VertexCount() const
Definition MeshDescriptionAdapter.h:225
int32 NormalCount() const
Definition MeshDescriptionAdapter.h:270
void GetTriVertices(int32 IDValue, FVector3d &V0, FVector3d &V1, FVector3d &V2) const
Definition MeshDescriptionAdapter.h:249
int32 TriangleCount() const
Definition MeshDescriptionAdapter.h:217
void SetNormal(int32 IDValue, const FVector3f &Normal)
Definition MeshDescriptionAdapter.h:278
TVertexInstanceAttributesRef< FVector3f > VertexInstanceNormals
Definition MeshDescriptionAdapter.h:194
Definition MeshDescriptionAdapter.h:290
FMeshDescriptionMeshAdapterd(FMeshDescriptionTriangleMeshAdapter ParentAdapterIn)
Definition MeshDescriptionAdapter.h:306
FMeshDescriptionMeshAdapterd(const FMeshDescription *MeshIn)
Definition MeshDescriptionAdapter.h:293
FMeshDescriptionTriangleMeshAdapter ParentAdapter
Definition MeshDescriptionAdapter.h:291
Definition MeshDescriptionAdapter.h:22
bool IsUV(const int32 UVId) const
Definition MeshDescriptionAdapter.h:154
void GetTriVertices(int32 IDValue, VectorType &V0, VectorType &V1, VectorType &V2) const
Definition MeshDescriptionAdapter.h:105
const FMeshDescription * Mesh
Definition MeshDescriptionAdapter.h:25
uint64 GetChangeStamp() const
Definition MeshDescriptionAdapter.h:76
bool HasNormals() const
Definition MeshDescriptionAdapter.h:116
FMeshDescriptionTriangleMeshAdapter(const FMeshDescription *MeshIn)
Definition MeshDescriptionAdapter.h:35
int32 VertexCount() const
Definition MeshDescriptionAdapter.h:72
TVertexAttributesConstRef< FVector3f > VertexPositions
Definition MeshDescriptionAdapter.h:26
void GetTriVertices(int32 IDValue, FVector3d &V0, FVector3d &V1, FVector3d &V2) const
Definition MeshDescriptionAdapter.h:93
TVertexInstanceAttributesConstRef< FVector2f > VertexInstanceUVs
Definition MeshDescriptionAdapter.h:28
void SetBuildScale(const FVector3d &BuildScaleIn, bool bScaleNormalsIn)
Definition MeshDescriptionAdapter.h:45
int32 MaxNormalID() const
Definition MeshDescriptionAdapter.h:124
bool HasUVs(const int32 UVLayer=0) const
Definition MeshDescriptionAdapter.h:150
void GetTriNormals(int32 TriId, VectorType &N0, VectorType &N1, VectorType &N2)
Definition MeshDescriptionAdapter.h:143
TVertexInstanceAttributesConstRef< FVector3f > VertexInstanceNormals
Definition MeshDescriptionAdapter.h:27
bool bScaleNormals
Definition MeshDescriptionAdapter.h:32
bool IsVertex(int32 VID) const
Definition MeshDescriptionAdapter.h:55
FVector3d GetVertex(int32 IDValue) const
Definition MeshDescriptionAdapter.h:87
int32 MaxUVID() const
Definition MeshDescriptionAdapter.h:158
TArrayView< const FVertexInstanceID > TriangleVertexInstanceIndices
Definition MeshDescriptionAdapter.h:29
void GetTriUVs(const int32 TriId, const int32 UVLayer, VectorType &UV0, VectorType &UV1, VectorType &UV2)
Definition MeshDescriptionAdapter.h:175
FVector3f GetNormal(int32 IDValue) const
Definition MeshDescriptionAdapter.h:134
int32 UVCount() const
Definition MeshDescriptionAdapter.h:162
bool IsNormal(int32 NID) const
Definition MeshDescriptionAdapter.h:120
int32 MaxTriangleID() const
Definition MeshDescriptionAdapter.h:60
FIndex3i GetTriangle(int32 IDValue) const
Definition MeshDescriptionAdapter.h:82
FVector2f GetUV(const int32 IDValue, const int32 UVLayer) const
Definition MeshDescriptionAdapter.h:168
int32 NormalCount() const
Definition MeshDescriptionAdapter.h:128
FVector3d BuildScale
Definition MeshDescriptionAdapter.h:31
UE::Geometry::FIndex3i FIndex3i
Definition MeshDescriptionAdapter.h:23
int32 TriangleCount() const
Definition MeshDescriptionAdapter.h:64
int32 MaxVertexID() const
Definition MeshDescriptionAdapter.h:68
bool IsTriangle(int32 TID) const
Definition MeshDescriptionAdapter.h:51
Definition MeshDescription.h:94
int32 GetNumUVElementChannels() const
Definition MeshDescription.h:1216
FVertexArray & Vertices()
Definition MeshDescription.h:129
void GetTriangleVertices(const FTriangleID TriangleID, TArrayView< FVertexID > OutVertexIDs) const
Definition MeshDescription.h:792
FTriangleArray & Triangles()
Definition MeshDescription.h:141
Definition MeshTypes.h:206
Definition MeshTypes.h:90
Definition MeshTypes.h:120
Definition IndexTypes.h:158
Definition MeshAdapter.h:24
TFunction< FIndex3i(int32)> GetTriangle
Definition MeshAdapter.h:32
TFunction< bool(int32 index)> IsVertex
Definition MeshAdapter.h:26
TFunction< int32()> MaxVertexID
Definition MeshAdapter.h:28
TFunction< int32()> MaxTriangleID
Definition MeshAdapter.h:27
TFunction< bool(int32 index)> IsTriangle
Definition MeshAdapter.h:25
TFunction< uint64()> GetChangeStamp
Definition MeshAdapter.h:31
TFunction< int32()> VertexCount
Definition MeshAdapter.h:30
TFunction< TVector< double >(int32)> GetVertex
Definition MeshAdapter.h:33
TFunction< int32()> TriangleCount
Definition MeshAdapter.h:29
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