UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
MeshUtilitiesCommon.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
22
28{
29 // Invariant: Arrays should be same length!
32};
33
36{
37 float Z;
39
42
45 {
46 Z = 0.30f * V.X + 0.33f * V.Y + 0.37f * V.Z;
47 Index = InIndex;
48 }
49};
50
53{
54 inline bool operator()(FIndexAndZ const& A, FIndexAndZ const& B) const { return A.Z < B.Z; }
55};
56
60inline bool PointsEqual(const FVector3f& V1, const FVector3f& V2, float ComparisonThreshold)
61{
62 if (FMath::Abs(V1.X - V2.X) > ComparisonThreshold
63 || FMath::Abs(V1.Y - V2.Y) > ComparisonThreshold
64 || FMath::Abs(V1.Z - V2.Z) > ComparisonThreshold)
65 {
66 return false;
67 }
68 return true;
69}
70
72{
73 /*
74 * This function compute the area of a triangle, it will return zero if the triangle is degenerated
75 */
76 static float ComputeTriangleArea(const FVector3f& PointA, const FVector3f& PointB, const FVector3f& PointC)
77 {
78 return FVector3f::CrossProduct((PointB - PointA), (PointC - PointA)).Size() / 2.0f;
79 }
80
81 /*
82 * This function compute the angle of a triangle corner, it will return zero if the triangle is degenerated
83 */
84 static float ComputeTriangleCornerAngle(const FVector3f& PointA, const FVector3f& PointB, const FVector3f& PointC)
85 {
86 FVector3f E1 = (PointB - PointA);
87 FVector3f E2 = (PointC - PointA);
88 //Normalize both edges (unit vector) of the triangle so we get a dotProduct result that will be a valid acos input [-1, 1]
89 if (!E1.Normalize() || !E2.Normalize())
90 {
91 //Return a null ratio if the polygon is degenerate
92 return 0.0f;
93 }
94 float DotProduct = FVector3f::DotProduct(E1, E2);
95 return FMath::Acos(DotProduct);
96 }
97}
98
103{
104 FVector3f TangentX;
105 FVector3f TangentY;
106
107 if (TangentZ.Z < -0.9999999f)
108 {
109 TangentX = FVector3f(0, -1, 0);
110 TangentY = FVector3f(-1, 0, 0);
111 }
112 else
113 {
114 float A = 1.0f / (1.0f + TangentZ.Z);
115 float B = -TangentZ.X * TangentZ.Y * A;
116 TangentX = FVector3f(1.0f - TangentZ.X * TangentZ.X * A, B, -TangentZ.X);
117 TangentY = FVector3f(B, 1.0f - TangentZ.Y * TangentZ.Y * A, -TangentZ.Y);
118 }
119
122 LocalBasis.SetAxis(0, TangentX);
123 LocalBasis.SetAxis(1, TangentY);
124 LocalBasis.SetAxis(2, TangentZ);
125 return LocalBasis;
126}
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
UE::Math::TVector< float > FVector3f
Definition MathFwd.h:73
ELightmapUVVersion
Definition MeshUtilitiesCommon.h:8
FMatrix44f GetTangentBasisFrisvad(FVector3f TangentZ)
Definition MeshUtilitiesCommon.h:102
bool PointsEqual(const FVector3f &V1, const FVector3f &V2, float ComparisonThreshold)
Definition MeshUtilitiesCommon.h:60
Definition Array.h:670
Definition MeshUtilitiesCommon.h:72
U16 Index
Definition radfft.cpp:71
Definition MeshUtilitiesCommon.h:28
TArray< FVector3f > Normals
Definition MeshUtilitiesCommon.h:31
TArray< FVector3f > Positions
Definition MeshUtilitiesCommon.h:30
Definition MeshUtilitiesCommon.h:53
bool operator()(FIndexAndZ const &A, FIndexAndZ const &B) const
Definition MeshUtilitiesCommon.h:54
Definition MeshUtilitiesCommon.h:36
FIndexAndZ(int32 InIndex, FVector3f V)
Definition MeshUtilitiesCommon.h:44
float Z
Definition MeshUtilitiesCommon.h:37
int32 Index
Definition MeshUtilitiesCommon.h:38
FIndexAndZ()
Definition MeshUtilitiesCommon.h:41
void SetIdentity()
Definition Matrix.inl:48
T Z
Definition Vector.h:68
T Y
Definition Vector.h:65
static UE_FORCEINLINE_HINT float DotProduct(const TVector< float > &A, const TVector< float > &B)
Definition Vector.h:1559
bool Normalize(T Tolerance=UE_SMALL_NUMBER)
Definition Vector.h:1767
T X
Definition Vector.h:62
static UE_FORCEINLINE_HINT TVector< float > CrossProduct(const TVector< float > &A, const TVector< float > &B)
Definition Vector.h:1541
T Size() const
Definition Vector.h:1716