UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
UVChannelDensity.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3/*=============================================================================
4UVChannelDensity.h: Helpers to compute UV channel density.
5=============================================================================*/
6
7#pragma once
8
9#include "CoreMinimal.h"
10
11#if WITH_EDITORONLY_DATA
12
13#include "MeshTypes.h"
14
15struct FMeshDescription;
17
19{
20private:
21
22 struct FElementInfo
23 {
24 float Weight;
25 float UVDensity;
26 FElementInfo(float InWeight, float InUVDensity) : Weight(InWeight), UVDensity(InUVDensity) {}
27 };
28
29 TArray<FElementInfo> Elements;
30
31public:
32
33 void Reserve(int32 Size) { Elements.Reserve(Size); }
34
35 void PushTriangle(float InArea, float InUVArea)
36 {
38 {
39 Elements.Add(FElementInfo(FMath::Sqrt(InArea), FMath::Sqrt(InArea / InUVArea)));
40 }
41 }
42
43 void AccumulateDensity(float& WeightedUVDensity, float& Weight, float DiscardPercentage = .10f)
44 {
46 {
47 FORCEINLINE bool operator()(FElementInfo const& A, FElementInfo const& B) const { return A.UVDensity < B.UVDensity; }
48 };
49
50 Elements.Sort(FCompareUVDensity());
51
52 // Remove 10% of higher and lower texel factors.
53 const int32 Threshold = FMath::FloorToInt(DiscardPercentage * (float)Elements.Num());
54 for (int32 Index = Threshold; Index < Elements.Num() - Threshold; ++Index)
55 {
56 const FElementInfo& Element = Elements[Index];
57 WeightedUVDensity += Element.UVDensity * Element.Weight;
58 Weight += Element.Weight;
59 }
60 }
61
62 float GetDensity(float DiscardPercentage = .10f)
63 {
64 float WeightedUVDensity = 0;
65 float Weight = 0;
66
68
70 }
71
73 static float GetTriangleArea(const FVector3f& Pos0, const FVector3f& Pos1, const FVector3f& Pos2)
74 {
75 FVector3f P01 = Pos1 - Pos0;
76 FVector3f P02 = Pos2 - Pos0;
78 }
79
81 static float GetUVChannelArea(const FVector2f& UV0, const FVector2f& UV1, const FVector2f& UV2)
82 {
83 FVector2f UV01 = UV1 - UV0;
84 FVector2f UV02 = UV2 - UV0;
85 return FMath::Abs<float>(UV01.X * UV02.Y - UV01.Y * UV02.X);
86 }
87};
88
90{
91public:
92 static const int32 MaxUVChannels = 8;
93
97 : MeshDescription(&InMeshDescription)
99 {
100 }
101
103
104private:
105 FMeshDescription* MeshDescription;
107
109 const FStaticMeshAttributes& MeshAttributes,
110 FPolygonGroupID PolygonGroupID,
113 float* OutLocalWeights);
114
115 void FinalAccumulate(
117 const float* LocalWeightedUVDensities,
118 const float* LocalWeights,
121};
122
123#endif
#define FORCEINLINE
Definition AndroidPlatform.h:140
#define FORCEINLINE_DEBUGGABLE
Definition CoreMiscDefines.h:74
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
#define UE_SMALL_NUMBER
Definition UnrealMathUtility.h:130
uint32 Size
Definition VulkanMemory.cpp:4034
Definition NameTypes.h:617
Definition StaticMeshAttributes.h:54
Definition ArrayView.h:139
Definition Array.h:670
UE_REWRITE SizeType Num() const
Definition Array.h:1144
UE_NODEBUG UE_FORCEINLINE_HINT SizeType Add(ElementType &&Item)
Definition Array.h:2696
UE_NODEBUG void Sort()
Definition Array.h:3418
UE_FORCEINLINE_HINT void Reserve(SizeType Number)
Definition Array.h:3016
@ Element
Definition Visu.h:18
U16 Index
Definition radfft.cpp:71
Definition MeshDescription.h:94
Definition MeshTypes.h:236
T Y
Definition Vector2D.h:52
T X
Definition Vector2D.h:49
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