UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
LandscapeConfigHelper.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"
8#include "LandscapeConfigHelper.generated.h"
9
10UENUM()
12{
13 Resample = 0,
14 Clip = 1,
15 Expand = 2
16};
17
18#if WITH_EDITOR
19
20class ULandscapeInfo;
21class ULandscapeComponent;
22class ALandscapeProxy;
24
29{
31 : ComponentNumSubsections(InComponentNumSubSections)
32 , SubsectionSizeQuads(InSubsectionSizeQuads)
34 {
35 }
36
38
39 int32 GetComponentSizeQuads() const { return SubsectionSizeQuads * ComponentNumSubsections; }
40 int32 GetComponentSizeVerts() const { return (SubsectionSizeQuads + 1) * ComponentNumSubsections; }
42
43 int32 ComponentNumSubsections;
44 int32 SubsectionSizeQuads;
46
49};
50
52{
55 , ResizeMode(InResizeMode)
57 {
58 }
59
60 LANDSCAPE_API bool Validate() const;
61
62 ELandscapeResizeMode ResizeMode;
63 bool bZeroBased;
64};
65
67{
68public:
73
74private:
76 static void CopyRegionToComponent(ULandscapeInfo* LandscapeInfo, const FIntRect& Region, bool bResample, ULandscapeComponent* Component);
80
81public:
82 template<typename T>
83 static void CopyData(const TArray<T>& InData, TArray<T>& OutData, const FIntRect& InSrcRegion, const FIntRect& InDestRegion, bool bInResample)
84 {
85 if (bInResample)
86 {
88 }
89 else
90 {
91 ExpandData(InData, OutData, InSrcRegion, InDestRegion, true);
92 }
93 }
94
95 template<typename T>
96 static void ExpandData(const TArray<T>& InData, TArray<T>& OutData, const FIntRect& InSrcRegion, const FIntRect& InDestRegion, bool bOffset)
97 {
98 // Regions are in ComponentQuads and we want Vertices (+1)
99 const int32 SrcWidth = InSrcRegion.Width() + 1;
100 const int32 SrcHeight = InSrcRegion.Height() + 1;
101 const int32 DstWidth = InDestRegion.Width() + 1;
102 const int32 DstHeight = InDestRegion.Height() + 1;
103 const int32 OffsetX = bOffset ? InDestRegion.Min.X - InSrcRegion.Min.X : 0;
104 const int32 OffsetY = bOffset ? InDestRegion.Min.Y - InSrcRegion.Min.Y : 0;
105
106 OutData.Empty(DstWidth * DstHeight);
108
109 for (int32 DstY = 0; DstY < DstHeight; ++DstY)
110 {
111 const int32 SrcY = FMath::Clamp<int32>(DstY + OffsetY, 0, SrcHeight - 1);
112
113 // Pad anything to the left
114 const T PadLeft = InData[SrcY * SrcWidth];
115 int32 EndPadLeft = FMath::Min<int32>(-OffsetX, DstWidth);
116 for (int32 DstX = 0; DstX < EndPadLeft; ++DstX)
117 {
118 OutData[DstY * DstWidth + DstX] = PadLeft;
119 }
120
121 {
122 const int32 DstX = FMath::Max(0, -OffsetX);
123 const int32 SrcX = FMath::Clamp<int32>(DstX + OffsetX, 0, SrcWidth - 1);
124 // Limit to DstWidth-DstX to avoid writing past the end of the destination scanline. This will also make CopySize negative if the target
125 // starts past the end of the scanline.
126 const int32 CopySize = FMath::Min<int32>(SrcWidth - SrcX, DstWidth - DstX) * sizeof(T);
127 if (CopySize > 0)
128 {
129 FMemory::Memcpy(&OutData[DstY * DstWidth + DstX], &InData[SrcY * SrcWidth + SrcX], CopySize);
130 }
131 }
132
133 const T PadRight = InData[SrcY * SrcWidth + SrcWidth - 1];
134 int32 StartPadRight = FMath::Max<int32>(-OffsetX + SrcWidth, 0);
136 {
137 OutData[DstY * DstWidth + DstX] = PadRight;
138 }
139 }
140 }
141
142 template<typename T>
144 {
145 check(InData.Size() >= InSrcRegion.Area());
146
147 const int32 SrcWidth = InSrcRegion.Width();
148 const int32 SrcHeight = InSrcRegion.Height();
149
150 OutData.Empty(SrcWidth * SrcHeight);
152
153 for (int32 Y = 0; Y < SrcHeight; ++Y)
154 {
155 for (int32 X = 0; X < SrcWidth; ++X)
156 {
157 const int32 SrcX = X + InSrcRegion.Min.X;
158 const int32 SrcY = Y + InSrcRegion.Min.Y;
159
160 const int32 SrcIndex = SrcX + SrcY * InSrcDataPitch;
161 const int32 DstIndex = X + Y * InSrcRegion.Width();
162
163 OutData[DstIndex] = InData[SrcIndex];
164 }
165 }
166 }
167
168 template<typename T>
169 static void ResampleData(const TArray<T>& InData, TArray<T>& OutData, const FIntRect& InSrcRegion, const FIntRect& InDestRegion)
170 {
171 // Regions are in ComponentQuads and we want Vertices (+1)
172 const int32 SrcWidth = InSrcRegion.Width() + 1;
173 const int32 SrcHeight = InSrcRegion.Height() + 1;
174 const int32 DestWidth = InDestRegion.Width() + 1;
175 const int32 DestHeight = InDestRegion.Height() + 1;
176
177 OutData.Empty(DestWidth * DestHeight);
179
180 const float XScale = (float)(SrcWidth - 1) / (DestWidth - 1);
181 const float YScale = (float)(SrcHeight - 1) / (DestHeight - 1);
182 for (int32 Y = 0; Y < DestHeight; ++Y)
183 {
184 for (int32 X = 0; X < DestWidth; ++X)
185 {
186 const float OldY = Y * YScale;
187 const float OldX = X * XScale;
188 const int32 X0 = FMath::FloorToInt(OldX);
189 const int32 X1 = FMath::Min(FMath::FloorToInt(OldX) + 1, SrcWidth - 1);
190 const int32 Y0 = FMath::FloorToInt(OldY);
191 const int32 Y1 = FMath::Min(FMath::FloorToInt(OldY) + 1, SrcHeight - 1);
192 const T& Original00 = InData[Y0 * SrcWidth + X0];
193 const T& Original10 = InData[Y0 * SrcWidth + X1];
194 const T& Original01 = InData[Y1 * SrcWidth + X0];
195 const T& Original11 = InData[Y1 * SrcWidth + X1];
196 int32 Index = Y * DestWidth + X;
197 check(Index < OutData.Num());
198 OutData[Y * DestWidth + X] = FMath::BiLerp(Original00, Original10, Original01, Original11, FMath::Fractional(OldX), FMath::Fractional(OldY));
199 }
200 }
201 }
202};
203
204#endif
#define check(expr)
Definition AssertionMacros.h:314
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 X(Name, Desc)
Definition FormatStringSan.h:47
ELandscapeResizeMode
Definition LandscapeConfigHelper.h:12
#define UENUM(...)
Definition ObjectMacros.h:749
@ CopyData
Definition RecastNavMeshDataChunk.h:56
USkinnedMeshComponent float
Definition SkinnedMeshComponent.h:60
uint8_t uint8
Definition binka_ue_file_header.h:8
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition ArrayView.h:139
Definition Array.h:670
UE_FORCEINLINE_HINT SizeType AddUninitialized()
Definition Array.h:1664
UE_REWRITE SizeType Num() const
Definition Array.h:1144
void Empty(SizeType Slack=0)
Definition Array.h:2273
Definition ActorPartitionSubsystem.h:88
Definition LandscapeInfo.h:109
Definition World.h:918
U16 Index
Definition radfft.cpp:71
Definition Guid.h:109
Definition LandscapeProxy.h:165
static constexpr T BiLerp(const T &P00, const T &P10, const T &P01, const T &P11, const U &FracX, const U &FracY)
Definition UnrealMathUtility.h:1178
static UE_FORCEINLINE_HINT void * Memcpy(void *Dest, const void *Src, SIZE_T Count)
Definition UnrealMemory.h:160
Definition ActorPartitionSubsystem.h:95
Definition IntPoint.h:25