UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
MinimalBoxMeshGenerator.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
6#include "OrientedBoxTypes.h"
7#include "Util/IndexUtil.h"
8
9namespace UE
10{
11namespace Geometry
12{
13
17class /*GEOMETRYCORE_API*/ FMinimalBoxMeshGenerator : public FMeshShapeGenerator
18{
19public:
22
25
26public:
27
29 virtual FMeshShapeGenerator& Generate() override
30 {
31 // box has 8 corners, 6 quad-faces, each face has 2 triangles and 4 attribute-corners
32 SetBufferSizes(8, 12, 24, 24);
33
34
35 for (int i = 0; i < 8; ++i)
36 {
37 Vertices[i] = Box.GetCorner(i);
38 }
39
40 double MaxDimension = MaxAbsElement(2.0*Box.Extents);
41 float UVScale = (bScaleUVByAspectRatio) ? (1.0f / (float)MaxDimension) : 1.0f;
42
43 int TriIndex = 0;
44 int AttribIndex = 0;
45 for (int fi = 0; fi < 6; ++fi)
46 {
48 FVector3f FaceNormal = (FVector3f)((double)FMath::Sign(NormalAxisIdx) * Box.GetAxis(FMath::Abs(NormalAxisIdx) - 1));
49
52 double WidthUVScale = FaceWidth * UVScale;
53 double HeightUVScale = FaceHeight * UVScale;
54
55 int ElementIndices[4];
56
57 for (int j = 0; j < 4; ++j)
58 {
59 Normals[AttribIndex] = FaceNormal;
64 }
65
66
72 TriIndex++;
73
79 TriIndex++;
80
81
82 }
83
84 return *this;
85 }
86
87};
88
89
90} // end namespace UE::Geometry
91} // end namespace UE
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
UE::Math::TVector2< float > FVector2f
Definition MathFwd.h:74
UE::Math::TVector< float > FVector3f
Definition MathFwd.h:73
Definition MeshShapeGenerator.h:19
TArray< FVector2f > UVs
Definition MeshShapeGenerator.h:25
TArray< FVector3d > Vertices
Definition MeshShapeGenerator.h:22
TArray< FVector3f > Normals
Definition MeshShapeGenerator.h:30
void SetTriangle(int Index, const FIndex3i &Tri)
Definition MeshShapeGenerator.h:193
void SetTriangleUVs(int Index, const FIndex3i &Tri)
Definition MeshShapeGenerator.h:217
void SetTrianglePolygon(int Index, int PolygonID)
Definition MeshShapeGenerator.h:244
void SetTriangleNormals(int Index, const FIndex3i &Tri)
Definition MeshShapeGenerator.h:231
void SetBufferSizes(int NumVertices, int NumTriangles, int NumUVs, int NumNormals)
Definition MeshShapeGenerator.h:97
Definition MinimalBoxMeshGenerator.h:18
virtual FMeshShapeGenerator & Generate() override
Definition MinimalBoxMeshGenerator.h:29
FOrientedBox3d Box
Definition MinimalBoxMeshGenerator.h:21
bool bScaleUVByAspectRatio
Definition MinimalBoxMeshGenerator.h:24
GEOMETRYCORE_API const int BoxFaces[6][4]
Definition IndexUtil.cpp:65
GEOMETRYCORE_API const int BoxFaceNormals[6]
Definition IndexUtil.cpp:82
GEOMETRYCORE_API const FVector2i BoxFacesUV[4]
Definition IndexUtil.cpp:80
constexpr T MaxAbsElement(const UE::Math::TVector< T > &Vector)
Definition VectorTypes.h:324
Definition AdvancedWidgetsModule.cpp:13
Definition IntVectorTypes.h:20
TVector< RealType > GetCorner(int Index) const
Definition OrientedBoxTypes.h:156
TVector< RealType > GetAxis(int AxisIndex) const
Definition OrientedBoxTypes.h:104
TVector< RealType > Extents
Definition OrientedBoxTypes.h:32