2016-12-08 08:52:44 -05:00
|
|
|
// Copyright 1998-2017 Epic Games, Inc. All Rights Reserved.
|
2014-03-14 14:13:41 -04:00
|
|
|
|
Copying //UE4/Dev-Build to //UE4/Dev-Main (Source: //UE4/Dev-Build @ 3209340)
#lockdown Nick.Penwarden
#rb none
==========================
MAJOR FEATURES + CHANGES
==========================
Change 3209340 on 2016/11/23 by Ben.Marsh
Convert UE4 codebase to an "include what you use" model - where every header just includes the dependencies it needs, rather than every source file including large monolithic headers like Engine.h and UnrealEd.h.
Measured full rebuild times around 2x faster using XGE on Windows, and improvements of 25% or more for incremental builds and full rebuilds on most other platforms.
* Every header now includes everything it needs to compile.
* There's a CoreMinimal.h header that gets you a set of ubiquitous types from Core (eg. FString, FName, TArray, FVector, etc...). Most headers now include this first.
* There's a CoreTypes.h header that sets up primitive UE4 types and build macros (int32, PLATFORM_WIN64, etc...). All headers in Core include this first, as does CoreMinimal.h.
* Every .cpp file includes its matching .h file first.
* This helps validate that each header is including everything it needs to compile.
* No engine code includes a monolithic header such as Engine.h or UnrealEd.h any more.
* You will get a warning if you try to include one of these from the engine. They still exist for compatibility with game projects and do not produce warnings when included there.
* There have only been minor changes to our internal games down to accommodate these changes. The intent is for this to be as seamless as possible.
* No engine code explicitly includes a precompiled header any more.
* We still use PCHs, but they're force-included on the compiler command line by UnrealBuildTool instead. This lets us tune what they contain without breaking any existing include dependencies.
* PCHs are generated by a tool to get a statistical amount of coverage for the source files using it, and I've seeded the new shared PCHs to contain any header included by > 15% of source files.
Tool used to generate this transform is at Engine\Source\Programs\IncludeTool.
[CL 3209342 by Ben Marsh in Main branch]
2016-11-23 15:48:37 -05:00
|
|
|
#include "CoreMinimal.h"
|
|
|
|
|
#include "LandscapeToolInterface.h"
|
2014-03-14 14:13:41 -04:00
|
|
|
#include "LandscapeEdMode.h"
|
Copying //UE4/Dev-Build to //UE4/Dev-Main (Source: //UE4/Dev-Build @ 3209340)
#lockdown Nick.Penwarden
#rb none
==========================
MAJOR FEATURES + CHANGES
==========================
Change 3209340 on 2016/11/23 by Ben.Marsh
Convert UE4 codebase to an "include what you use" model - where every header just includes the dependencies it needs, rather than every source file including large monolithic headers like Engine.h and UnrealEd.h.
Measured full rebuild times around 2x faster using XGE on Windows, and improvements of 25% or more for incremental builds and full rebuilds on most other platforms.
* Every header now includes everything it needs to compile.
* There's a CoreMinimal.h header that gets you a set of ubiquitous types from Core (eg. FString, FName, TArray, FVector, etc...). Most headers now include this first.
* There's a CoreTypes.h header that sets up primitive UE4 types and build macros (int32, PLATFORM_WIN64, etc...). All headers in Core include this first, as does CoreMinimal.h.
* Every .cpp file includes its matching .h file first.
* This helps validate that each header is including everything it needs to compile.
* No engine code includes a monolithic header such as Engine.h or UnrealEd.h any more.
* You will get a warning if you try to include one of these from the engine. They still exist for compatibility with game projects and do not produce warnings when included there.
* There have only been minor changes to our internal games down to accommodate these changes. The intent is for this to be as seamless as possible.
* No engine code explicitly includes a precompiled header any more.
* We still use PCHs, but they're force-included on the compiler command line by UnrealBuildTool instead. This lets us tune what they contain without breaking any existing include dependencies.
* PCHs are generated by a tool to get a statistical amount of coverage for the source files using it, and I've seeded the new shared PCHs to contain any header included by > 15% of source files.
Tool used to generate this transform is at Engine\Source\Programs\IncludeTool.
[CL 3209342 by Ben Marsh in Main branch]
2016-11-23 15:48:37 -05:00
|
|
|
#include "LandscapeEditorObject.h"
|
2014-10-16 05:16:44 -04:00
|
|
|
#include "Landscape.h"
|
Copying //UE4/Dev-Build to //UE4/Dev-Main (Source: //UE4/Dev-Build @ 3209340)
#lockdown Nick.Penwarden
#rb none
==========================
MAJOR FEATURES + CHANGES
==========================
Change 3209340 on 2016/11/23 by Ben.Marsh
Convert UE4 codebase to an "include what you use" model - where every header just includes the dependencies it needs, rather than every source file including large monolithic headers like Engine.h and UnrealEd.h.
Measured full rebuild times around 2x faster using XGE on Windows, and improvements of 25% or more for incremental builds and full rebuilds on most other platforms.
* Every header now includes everything it needs to compile.
* There's a CoreMinimal.h header that gets you a set of ubiquitous types from Core (eg. FString, FName, TArray, FVector, etc...). Most headers now include this first.
* There's a CoreTypes.h header that sets up primitive UE4 types and build macros (int32, PLATFORM_WIN64, etc...). All headers in Core include this first, as does CoreMinimal.h.
* Every .cpp file includes its matching .h file first.
* This helps validate that each header is including everything it needs to compile.
* No engine code includes a monolithic header such as Engine.h or UnrealEd.h any more.
* You will get a warning if you try to include one of these from the engine. They still exist for compatibility with game projects and do not produce warnings when included there.
* There have only been minor changes to our internal games down to accommodate these changes. The intent is for this to be as seamless as possible.
* No engine code explicitly includes a precompiled header any more.
* We still use PCHs, but they're force-included on the compiler command line by UnrealBuildTool instead. This lets us tune what they contain without breaking any existing include dependencies.
* PCHs are generated by a tool to get a statistical amount of coverage for the source files using it, and I've seeded the new shared PCHs to contain any header included by > 15% of source files.
Tool used to generate this transform is at Engine\Source\Programs\IncludeTool.
[CL 3209342 by Ben Marsh in Main branch]
2016-11-23 15:48:37 -05:00
|
|
|
#include "LandscapeDataAccess.h"
|
|
|
|
|
#include "LandscapeEdModeTools.h"
|
2014-03-14 14:13:41 -04:00
|
|
|
|
|
|
|
|
namespace
|
|
|
|
|
{
|
|
|
|
|
FORCEINLINE FVector4 GetWorldPos(const FMatrix& LocalToWorld, FVector2D LocalXY, uint16 Height, FVector2D XYOffset)
|
|
|
|
|
{
|
2014-12-18 06:52:06 -05:00
|
|
|
return LocalToWorld.TransformPosition(FVector(LocalXY.X + XYOffset.X, LocalXY.Y + XYOffset.Y, ((float)Height - 32768.0f) * LANDSCAPE_ZSCALE));
|
2014-03-14 14:13:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FORCEINLINE FVector4 GetWorldPos(const FMatrix& LocalToWorld, FVector2D LocalXY, FVector XYOffsetVector)
|
|
|
|
|
{
|
2014-07-17 12:20:34 -04:00
|
|
|
return LocalToWorld.TransformPosition(FVector(LocalXY.X + XYOffsetVector.X, LocalXY.Y + XYOffsetVector.Y, XYOffsetVector.Z));
|
2014-03-14 14:13:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const int32 XOffsets[4] = { 0, 1, 0, 1 };
|
|
|
|
|
const int32 YOffsets[4] = { 0, 0, 1, 1 };
|
|
|
|
|
|
2014-07-17 12:20:34 -04:00
|
|
|
float GetHeight(int32 X, int32 Y, int32 MinX, int32 MinY, int32 MaxX, int32 MaxY, const FVector& XYOffset, const TArray<FVector>& XYOffsetVectorData)
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
|
|
|
|
float Height[4];
|
|
|
|
|
for (int32 Idx = 0; Idx < 4; ++Idx)
|
|
|
|
|
{
|
2014-07-17 12:20:34 -04:00
|
|
|
int32 XX = FMath::Clamp(FMath::FloorToInt(X + XYOffset.X + XOffsets[Idx]), MinX, MaxX);
|
|
|
|
|
int32 YY = FMath::Clamp(FMath::FloorToInt(Y + XYOffset.Y + YOffsets[Idx]), MinY, MaxY);
|
|
|
|
|
Height[Idx] = XYOffsetVectorData[XX - MinX + (YY - MinY) * (MaxX - MinX + 1)].Z;
|
2014-03-14 14:13:41 -04:00
|
|
|
}
|
2014-07-17 12:20:34 -04:00
|
|
|
float FracX = FMath::Fractional(X + XYOffset.X);
|
|
|
|
|
float FracY = FMath::Fractional(Y + XYOffset.Y);
|
|
|
|
|
return FMath::Lerp(FMath::Lerp(Height[0], Height[1], FracX),
|
2014-03-14 14:13:41 -04:00
|
|
|
FMath::Lerp(Height[2], Height[3], FracX),
|
|
|
|
|
FracY);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// FLandscapeToolRetopologize
|
|
|
|
|
//
|
|
|
|
|
|
2014-09-11 12:44:16 -04:00
|
|
|
class FLandscapeToolStrokeRetopologize : public FLandscapeToolStrokeBase
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
|
|
|
|
public:
|
2015-12-09 15:04:15 -05:00
|
|
|
FLandscapeToolStrokeRetopologize(FEdModeLandscape* InEdMode, FEditorViewportClient* InViewportClient, const FLandscapeToolTarget& InTarget)
|
|
|
|
|
: FLandscapeToolStrokeBase(InEdMode, InViewportClient, InTarget)
|
2014-07-17 12:20:34 -04:00
|
|
|
, Cache(InTarget)
|
2014-09-11 12:44:16 -04:00
|
|
|
{
|
|
|
|
|
}
|
2014-03-14 14:13:41 -04:00
|
|
|
|
2016-07-28 10:41:43 -04:00
|
|
|
void Apply(FEditorViewportClient* ViewportClient, FLandscapeBrush* Brush, const ULandscapeEditorObject* UISettings, const TArray<FLandscapeToolInteractorPosition>& InteractorPositions)
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
2014-07-17 12:20:34 -04:00
|
|
|
if (!LandscapeInfo)
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Get list of verts to update
|
2014-12-18 06:52:06 -05:00
|
|
|
// TODO - only retrieve bounds as we don't need the data
|
|
|
|
|
// or use the brush data?
|
2016-07-28 10:41:43 -04:00
|
|
|
FLandscapeBrushData BrushInfo = Brush->ApplyBrush(InteractorPositions);
|
2014-12-18 06:52:06 -05:00
|
|
|
if (!BrushInfo)
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-18 06:52:06 -05:00
|
|
|
int32 X1, Y1, X2, Y2;
|
|
|
|
|
BrushInfo.GetInclusiveBounds(X1, Y1, X2, Y2);
|
|
|
|
|
|
2014-03-14 14:13:41 -04:00
|
|
|
//LandscapeInfo->Modify();
|
|
|
|
|
//LandscapeInfo->LandscapeProxy->Modify();
|
|
|
|
|
|
|
|
|
|
FVector DrawScale3D = LandscapeInfo->DrawScale;
|
|
|
|
|
// Tablet pressure
|
2014-12-18 06:52:06 -05:00
|
|
|
float Pressure = ViewportClient->Viewport->IsPenActive() ? ViewportClient->Viewport->GetTabletPressure() : 1.0f;
|
2014-03-14 14:13:41 -04:00
|
|
|
|
|
|
|
|
// expand the area by one vertex in each direction to ensure normals are calculated correctly
|
2014-07-17 12:20:34 -04:00
|
|
|
/*
|
2014-12-18 06:52:06 -05:00
|
|
|
X1 -= 1;
|
|
|
|
|
Y1 -= 1;
|
|
|
|
|
X2 += 1;
|
|
|
|
|
Y2 += 1;
|
|
|
|
|
*/
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
2014-03-15 01:14:25 -04:00
|
|
|
int32 ValidX1, ValidX2, ValidY1, ValidY2;
|
|
|
|
|
ValidX1 = ValidY1 = INT_MAX;
|
|
|
|
|
ValidX2 = ValidY2 = INT_MIN;
|
|
|
|
|
int32 ComponentIndexX1, ComponentIndexY1, ComponentIndexX2, ComponentIndexY2;
|
|
|
|
|
int32 ComponentSizeQuads = LandscapeInfo->ComponentSizeQuads;
|
|
|
|
|
ALandscape::CalcComponentIndicesOverlap(X1, Y1, X2, Y2, ComponentSizeQuads, ComponentIndexX1, ComponentIndexY1, ComponentIndexX2, ComponentIndexY2);
|
2014-03-14 14:13:41 -04:00
|
|
|
|
2014-07-17 12:20:34 -04:00
|
|
|
for (int32 ComponentIndexY = ComponentIndexY1; ComponentIndexY <= ComponentIndexY2; ComponentIndexY++)
|
2014-03-15 01:14:25 -04:00
|
|
|
{
|
2014-07-17 12:20:34 -04:00
|
|
|
for (int32 ComponentIndexX = ComponentIndexX1; ComponentIndexX <= ComponentIndexX2; ComponentIndexX++)
|
|
|
|
|
{
|
|
|
|
|
ULandscapeComponent* Component = LandscapeInfo->XYtoComponentMap.FindRef(FIntPoint(ComponentIndexX, ComponentIndexY));
|
2014-03-15 01:14:25 -04:00
|
|
|
|
|
|
|
|
if (Component)
|
|
|
|
|
{
|
|
|
|
|
// Update valid region
|
|
|
|
|
ValidX1 = FMath::Min<int32>(Component->GetSectionBase().X, ValidX1);
|
2014-07-17 12:20:34 -04:00
|
|
|
ValidX2 = FMath::Max<int32>(Component->GetSectionBase().X + ComponentSizeQuads, ValidX2);
|
2014-03-15 01:14:25 -04:00
|
|
|
ValidY1 = FMath::Min<int32>(Component->GetSectionBase().Y, ValidY1);
|
2014-07-17 12:20:34 -04:00
|
|
|
ValidY2 = FMath::Max<int32>(Component->GetSectionBase().Y + ComponentSizeQuads, ValidY2);
|
2014-03-15 01:14:25 -04:00
|
|
|
}
|
2014-03-14 14:13:41 -04:00
|
|
|
}
|
|
|
|
|
}
|
2014-03-15 01:14:25 -04:00
|
|
|
|
|
|
|
|
X1 = FMath::Max<int32>(X1, ValidX1);
|
|
|
|
|
X2 = FMath::Min<int32>(X2, ValidX2);
|
|
|
|
|
Y1 = FMath::Max<int32>(Y1, ValidY1);
|
|
|
|
|
Y2 = FMath::Min<int32>(Y2, ValidY2);
|
2014-03-14 14:13:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (X1 > X2 || Y1 > Y2) // No valid region...
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-18 06:52:06 -05:00
|
|
|
const float AreaResolution = LANDSCAPE_XYOFFSET_SCALE; //1.0f/256.0f;
|
2014-03-14 14:13:41 -04:00
|
|
|
|
2014-07-17 12:20:34 -04:00
|
|
|
Cache.CacheData(X1, Y1, X2, Y2);
|
2014-03-14 14:13:41 -04:00
|
|
|
|
|
|
|
|
TArray<FVector> XYOffsetVectorData;
|
2014-07-17 12:20:34 -04:00
|
|
|
Cache.GetCachedData(X1, Y1, X2, Y2, XYOffsetVectorData);
|
2014-03-14 14:13:41 -04:00
|
|
|
TArray<FVector> NewXYOffset;
|
|
|
|
|
NewXYOffset = XYOffsetVectorData;
|
|
|
|
|
|
|
|
|
|
// Retopologize algorithm...
|
|
|
|
|
{
|
|
|
|
|
// Calculate surface world space area without missing area...
|
2014-12-18 06:52:06 -05:00
|
|
|
float TotalArea = 0.0f;
|
2014-03-14 14:13:41 -04:00
|
|
|
int32 QuadNum = 0;
|
|
|
|
|
const int32 MaxIterNum = 300;
|
|
|
|
|
|
|
|
|
|
TArray<int32> QuadX, QuadY, MinX, MaxX, MinY, MaxY;
|
2014-07-17 12:20:34 -04:00
|
|
|
QuadX.AddZeroed(X2 - X1);
|
|
|
|
|
QuadY.AddZeroed(Y2 - Y1);
|
2014-03-14 14:13:41 -04:00
|
|
|
|
2014-07-17 12:20:34 -04:00
|
|
|
MinX.Empty(Y2 - Y1 + 1);
|
|
|
|
|
MaxX.Empty(Y2 - Y1 + 1);
|
|
|
|
|
MinY.Empty(X2 - X1 + 1);
|
|
|
|
|
MaxY.Empty(X2 - X1 + 1);
|
2014-03-14 14:13:41 -04:00
|
|
|
for (int32 X = X1; X <= X2; ++X)
|
|
|
|
|
{
|
|
|
|
|
MinY.Add(INT_MAX);
|
|
|
|
|
MaxY.Add(INT_MIN);
|
|
|
|
|
}
|
|
|
|
|
for (int32 Y = Y1; Y <= Y2; ++Y)
|
|
|
|
|
{
|
|
|
|
|
MinX.Add(INT_MAX);
|
|
|
|
|
MaxX.Add(INT_MIN);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Calculate Average...
|
|
|
|
|
TArray<ULandscapeComponent*> ComponentArray; // Ptr to component
|
2014-07-17 12:20:34 -04:00
|
|
|
ComponentArray.AddZeroed((X2 - X1 + 1)*(Y2 - Y1 + 1));
|
2014-03-14 14:13:41 -04:00
|
|
|
int32 ComponentIndexX1, ComponentIndexY1, ComponentIndexX2, ComponentIndexY2;
|
|
|
|
|
int32 ComponentSizeQuads = LandscapeInfo->ComponentSizeQuads;
|
|
|
|
|
ALandscape::CalcComponentIndicesOverlap(X1, Y1, X2, Y2, ComponentSizeQuads, ComponentIndexX1, ComponentIndexY1, ComponentIndexX2, ComponentIndexY2);
|
|
|
|
|
|
2014-07-17 12:20:34 -04:00
|
|
|
for (int32 ComponentIndexY = ComponentIndexY1; ComponentIndexY <= ComponentIndexY2; ComponentIndexY++)
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
2014-07-17 12:20:34 -04:00
|
|
|
for (int32 ComponentIndexX = ComponentIndexX1; ComponentIndexX <= ComponentIndexX2; ComponentIndexX++)
|
|
|
|
|
{
|
|
|
|
|
ULandscapeComponent* Comp = LandscapeInfo->XYtoComponentMap.FindRef(FIntPoint(ComponentIndexX, ComponentIndexY));
|
2014-03-14 14:13:41 -04:00
|
|
|
|
|
|
|
|
if (Comp)
|
|
|
|
|
{
|
|
|
|
|
const FMatrix LocalToWorld = Comp->GetRenderMatrix();
|
|
|
|
|
|
|
|
|
|
// Find coordinates of box that lies inside component
|
2014-07-17 12:20:34 -04:00
|
|
|
int32 ComponentX1 = FMath::Clamp<int32>(X1 - ComponentIndexX*ComponentSizeQuads, 0, ComponentSizeQuads);
|
|
|
|
|
int32 ComponentY1 = FMath::Clamp<int32>(Y1 - ComponentIndexY*ComponentSizeQuads, 0, ComponentSizeQuads);
|
|
|
|
|
int32 ComponentX2 = FMath::Clamp<int32>(X2 - ComponentIndexX*ComponentSizeQuads, 0, ComponentSizeQuads);
|
|
|
|
|
int32 ComponentY2 = FMath::Clamp<int32>(Y2 - ComponentIndexY*ComponentSizeQuads, 0, ComponentSizeQuads);
|
2014-03-14 14:13:41 -04:00
|
|
|
|
|
|
|
|
// World space area calculation
|
2014-07-17 12:20:34 -04:00
|
|
|
for (int32 Y = ComponentY1; Y <= ComponentY2; ++Y)
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
2014-07-17 12:20:34 -04:00
|
|
|
for (int32 X = ComponentX1; X <= ComponentX2; ++X)
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
2014-07-17 12:20:34 -04:00
|
|
|
if (X < ComponentX2 && Y < ComponentY2)
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
|
|
|
|
// Need to read XY Offset value from XYOffsetTexture before this
|
|
|
|
|
FVector P[4];
|
|
|
|
|
for (int32 Idx = 0; Idx < 4; ++Idx)
|
|
|
|
|
{
|
|
|
|
|
int32 XX = X + XOffsets[Idx];
|
|
|
|
|
int32 YY = Y + YOffsets[Idx];
|
2014-07-17 12:20:34 -04:00
|
|
|
P[Idx] = FVector(GetWorldPos(LocalToWorld, FVector2D(XX, YY),
|
|
|
|
|
XYOffsetVectorData[(ComponentIndexX*ComponentSizeQuads + XX - X1) + (ComponentIndexY*ComponentSizeQuads + YY - Y1)*(X2 - X1 + 1)]
|
2014-03-14 14:13:41 -04:00
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TotalArea += (((P[3] - P[0]) ^ (P[1] - P[0])).Size() + ((P[3] - P[0]) ^ (P[2] - P[0])).Size()) * 0.5f;
|
|
|
|
|
QuadNum++;
|
2014-07-17 12:20:34 -04:00
|
|
|
QuadX[ComponentIndexX*ComponentSizeQuads + X - X1]++;
|
|
|
|
|
QuadY[ComponentIndexY*ComponentSizeQuads + Y - Y1]++;
|
2014-03-14 14:13:41 -04:00
|
|
|
|
|
|
|
|
// Mark valid quad position
|
2014-07-17 12:20:34 -04:00
|
|
|
ComponentArray[(ComponentIndexX*ComponentSizeQuads) + X - X1 + (ComponentIndexY*ComponentSizeQuads + Y - Y1)*(X2 - X1 + 1)] = Comp;
|
2014-03-14 14:13:41 -04:00
|
|
|
}
|
|
|
|
|
|
2014-07-17 12:20:34 -04:00
|
|
|
MinX[ComponentIndexY*ComponentSizeQuads + Y - Y1] = FMath::Min<int32>(MinX[ComponentIndexY*ComponentSizeQuads + Y - Y1], ComponentIndexX*ComponentSizeQuads + X);
|
|
|
|
|
MaxX[ComponentIndexY*ComponentSizeQuads + Y - Y1] = FMath::Max<int32>(MaxX[ComponentIndexY*ComponentSizeQuads + Y - Y1], ComponentIndexX*ComponentSizeQuads + X);
|
|
|
|
|
MinY[ComponentIndexX*ComponentSizeQuads + X - X1] = FMath::Min<int32>(MinY[ComponentIndexX*ComponentSizeQuads + X - X1], ComponentIndexY*ComponentSizeQuads + Y);
|
|
|
|
|
MaxY[ComponentIndexX*ComponentSizeQuads + X - X1] = FMath::Max<int32>(MaxY[ComponentIndexX*ComponentSizeQuads + X - X1], ComponentIndexY*ComponentSizeQuads + Y);
|
2014-03-14 14:13:41 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const float HeightErrorThreshold = DrawScale3D.X * 0.5f;
|
|
|
|
|
// Made XYOffset and new Z value allocation...
|
|
|
|
|
float AreaErrorThreshold = FMath::Square(AreaResolution);
|
|
|
|
|
float RemainArea = TotalArea;
|
|
|
|
|
int32 RemainQuads = QuadNum;
|
|
|
|
|
|
2014-07-17 12:20:34 -04:00
|
|
|
for (int32 Y = Y1; Y < Y2 - 1; ++Y)
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
|
|
|
|
// Like rasterization style
|
|
|
|
|
// Search for Y offset
|
2014-07-17 12:20:34 -04:00
|
|
|
if (MinX[Y - Y1] > MaxX[Y - Y1])
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float AverageArea = RemainArea / RemainQuads;
|
|
|
|
|
float AreaBaseError = AverageArea * 0.5f;
|
2014-12-18 06:52:06 -05:00
|
|
|
float TotalLineArea = 0.0f;
|
2014-03-14 14:13:41 -04:00
|
|
|
float TargetLineArea = AverageArea * QuadY[Y - Y1];
|
2014-07-17 12:20:34 -04:00
|
|
|
float YOffset = Y + 1, PreYOffset = Y + 1; // Need to be bigger than previous Y
|
2014-03-14 14:13:41 -04:00
|
|
|
float StepSize = FPlatformMath::Sqrt(2) * 0.25f;
|
|
|
|
|
float LineAreaDiff = FLT_MAX; //Abs(TotalLineArea - TargetLineArea);
|
|
|
|
|
int32 IterNum = 0;
|
2014-12-18 06:52:06 -05:00
|
|
|
float TotalHeightError = 0.0f;
|
2014-03-14 14:13:41 -04:00
|
|
|
|
2014-07-17 12:20:34 -04:00
|
|
|
while (NewXYOffset[(Y - Y1) * (X2 - X1 + 1)].Y + Y > XYOffsetVectorData[(FPlatformMath::FloorToInt(YOffset) - Y1) * (X2 - X1 + 1)].Y + FPlatformMath::FloorToInt(YOffset))
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
2014-12-18 06:52:06 -05:00
|
|
|
YOffset = YOffset + 1.0f;
|
2014-03-14 14:13:41 -04:00
|
|
|
if (YOffset >= Y2)
|
|
|
|
|
{
|
|
|
|
|
YOffset = Y2;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
PreYOffset = YOffset;
|
|
|
|
|
|
|
|
|
|
while (FMath::Abs(TotalLineArea - TargetLineArea) > AreaErrorThreshold)
|
|
|
|
|
{
|
|
|
|
|
IterNum++;
|
2014-12-18 06:52:06 -05:00
|
|
|
TotalLineArea = 0.0f;
|
|
|
|
|
TotalHeightError = 0.0f;
|
2014-03-14 14:13:41 -04:00
|
|
|
//for (int32 X = X1; X < X2; ++X)
|
2014-07-17 12:20:34 -04:00
|
|
|
for (int32 X = MinX[Y - Y1]; X < MaxX[Y - Y1]; ++X)
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
2014-07-17 12:20:34 -04:00
|
|
|
ULandscapeComponent* Comp = ComponentArray[X - X1 + (Y - Y1)*(X2 - X1 + 1)];
|
2014-03-14 14:13:41 -04:00
|
|
|
if (Comp != NULL) // valid
|
|
|
|
|
{
|
|
|
|
|
const FMatrix LocalToWorld = Comp->GetRenderMatrix();
|
|
|
|
|
FVector P[4];
|
|
|
|
|
for (int32 Idx = 0; Idx < 2; ++Idx)
|
|
|
|
|
{
|
|
|
|
|
int32 XX = FMath::Clamp<int32>(X + XOffsets[Idx], X1, X2);
|
2014-07-17 12:20:34 -04:00
|
|
|
P[Idx] = FVector(GetWorldPos(LocalToWorld, FVector2D(XX - Comp->GetSectionBase().X, Y - Comp->GetSectionBase().Y), NewXYOffset[XX - X1 + (Y - Y1) * (X2 - X1 + 1)]));
|
2014-03-14 14:13:41 -04:00
|
|
|
}
|
|
|
|
|
|
2014-07-17 12:20:34 -04:00
|
|
|
int32 YY0 = FMath::Clamp<int32>(FMath::FloorToInt(YOffset - 1), Y1, Y2);
|
2014-05-06 06:26:25 -04:00
|
|
|
int32 YY1 = FMath::Clamp<int32>(FMath::FloorToInt(YOffset), Y1, Y2);
|
2014-07-17 12:20:34 -04:00
|
|
|
int32 YY2 = FMath::Clamp<int32>(FMath::FloorToInt(1 + YOffset), Y1, Y2);
|
2014-03-14 14:13:41 -04:00
|
|
|
// Search for valid YOffset...
|
|
|
|
|
for (int32 Idx = 2; Idx < 4; ++Idx)
|
|
|
|
|
{
|
|
|
|
|
int32 XX = FMath::Clamp<int32>(X + XOffsets[Idx], X1, X2);
|
2014-07-17 12:20:34 -04:00
|
|
|
FVector P1(GetWorldPos(LocalToWorld, FVector2D(XX - Comp->GetSectionBase().X, YY1 - Comp->GetSectionBase().Y), XYOffsetVectorData[XX - X1 + (YY1 - Y1) * (X2 - X1 + 1)]));
|
|
|
|
|
FVector P2(GetWorldPos(LocalToWorld, FVector2D(XX - Comp->GetSectionBase().X, YY2 - Comp->GetSectionBase().Y), XYOffsetVectorData[XX - X1 + (YY2 - Y1) * (X2 - X1 + 1)]));
|
2014-03-14 14:13:41 -04:00
|
|
|
P[Idx] = FMath::Lerp(P1, P2, FMath::Fractional(YOffset));
|
|
|
|
|
if (Idx == 2)
|
|
|
|
|
{
|
2014-07-17 12:20:34 -04:00
|
|
|
FVector P0(GetWorldPos(LocalToWorld, FVector2D(XX - Comp->GetSectionBase().X, YY0 - Comp->GetSectionBase().Y), XYOffsetVectorData[XX - X1 + (YY0 - Y1) * (X2 - X1 + 1)]));
|
|
|
|
|
TotalHeightError += FMath::Abs(((P[2] - P0) ^ (P2 - P[2])).Size() - ((P1 - P0) ^ (P2 - P1)).Size());
|
2014-03-14 14:13:41 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//TotalHeightError += Abs( XYOffsetVectorData( X - X1 + (YY2 - Y1) * (X2-X1+1) ).Z - XYOffsetVectorData( X - X1 + (YY1 - Y1) * (X2-X1+1) ).Z * appFractional(YOffset) );
|
|
|
|
|
TotalLineArea += (((P[3] - P[0]) ^ (P[1] - P[0])).Size() + ((P[3] - P[0]) ^ (P[2] - P[0])).Size()) * 0.5f;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (TotalLineArea < AreaErrorThreshold || IterNum > MaxIterNum)
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-17 12:20:34 -04:00
|
|
|
if (MaxX[Y - Y1] - MinX[Y - Y1] > 0)
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
2014-07-17 12:20:34 -04:00
|
|
|
TotalHeightError /= (MaxX[Y - Y1] - MinX[Y - Y1]);
|
2014-03-14 14:13:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float NewLineAreaDiff = FMath::Abs(TotalLineArea - TargetLineArea);
|
|
|
|
|
if (NewLineAreaDiff > LineAreaDiff || TotalHeightError > HeightErrorThreshold)
|
|
|
|
|
{
|
|
|
|
|
// backtracking
|
|
|
|
|
YOffset = PreYOffset;
|
|
|
|
|
StepSize *= 0.5f;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
PreYOffset = YOffset;
|
|
|
|
|
LineAreaDiff = FMath::Abs(TotalLineArea - TargetLineArea);
|
|
|
|
|
if (TotalLineArea - TargetLineArea > 0)
|
|
|
|
|
{
|
|
|
|
|
YOffset -= StepSize;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
YOffset += StepSize;
|
|
|
|
|
}
|
|
|
|
|
// clamp
|
2014-07-17 12:20:34 -04:00
|
|
|
if (YOffset < Y1)
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
|
|
|
|
YOffset = Y1;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2014-07-17 12:20:34 -04:00
|
|
|
if (YOffset >= Y2)
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
|
|
|
|
YOffset = Y2;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (StepSize < AreaResolution)
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Set Y Offset
|
|
|
|
|
if (TotalLineArea >= AreaErrorThreshold)
|
|
|
|
|
{
|
|
|
|
|
RemainArea -= TotalLineArea;
|
|
|
|
|
RemainQuads -= QuadY[Y - Y1];
|
2014-07-17 12:20:34 -04:00
|
|
|
for (int32 X = MinX[Y - Y1]; X < MaxX[Y - Y1]; ++X)
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
2014-05-06 06:26:25 -04:00
|
|
|
int32 YY1 = FMath::Clamp<int32>(FMath::FloorToInt(YOffset), Y1, Y2);
|
2014-07-17 12:20:34 -04:00
|
|
|
int32 YY2 = FMath::Clamp<int32>(FMath::FloorToInt(1 + YOffset), Y1, Y2);
|
|
|
|
|
FVector P1 = XYOffsetVectorData[X - X1 + (YY1 - Y1) * (X2 - X1 + 1)];
|
2014-03-14 14:13:41 -04:00
|
|
|
//P1.X = X+P1.X;
|
2014-07-17 12:20:34 -04:00
|
|
|
P1.Y = YY1 + P1.Y;
|
|
|
|
|
FVector P2 = XYOffsetVectorData[X - X1 + (YY2 - Y1) * (X2 - X1 + 1)];
|
2014-03-14 14:13:41 -04:00
|
|
|
//P2.X = X+P2.X;
|
2014-07-17 12:20:34 -04:00
|
|
|
P2.Y = YY2 + P2.Y;
|
|
|
|
|
FVector& XYOffset = NewXYOffset[X - X1 + (Y + 1 - Y1) * (X2 - X1 + 1)];
|
2014-03-14 14:13:41 -04:00
|
|
|
XYOffset = FMath::Lerp(P1, P2, FMath::Fractional(YOffset));
|
|
|
|
|
//XYOffset.X -= X;
|
2014-07-17 12:20:34 -04:00
|
|
|
XYOffset.Y -= Y + 1;
|
2014-03-14 14:13:41 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// X ...
|
|
|
|
|
TArray<FVector> NewYOffsets = NewXYOffset;
|
|
|
|
|
RemainArea = TotalArea;
|
|
|
|
|
RemainQuads = QuadNum;
|
|
|
|
|
|
2014-07-17 12:20:34 -04:00
|
|
|
for (int32 X = X1; X < X2 - 1; ++X)
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
|
|
|
|
// Like rasterization style
|
|
|
|
|
// Search for X offset
|
2014-07-17 12:20:34 -04:00
|
|
|
if (MinY[X - X1] > MaxY[X - X1])
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float AverageArea = RemainArea / RemainQuads;
|
|
|
|
|
float AreaBaseError = AverageArea * 0.5f;
|
2014-12-18 06:52:06 -05:00
|
|
|
float TotalLineArea = 0.0f;
|
2014-03-14 14:13:41 -04:00
|
|
|
float TargetLineArea = AverageArea * QuadX[X - X1];
|
2014-07-17 12:20:34 -04:00
|
|
|
float XOffset = X + 1, PreXOffset = X + 1; // Need to be bigger than previous Y
|
2014-03-14 14:13:41 -04:00
|
|
|
float StepSize = FMath::Sqrt(2) * 0.25f;
|
|
|
|
|
float LineAreaDiff = FLT_MAX; // Abs(TotalLineArea - TargetLineArea);
|
|
|
|
|
int32 IterNum = 0;
|
2014-12-18 06:52:06 -05:00
|
|
|
float TotalHeightError = 0.0f;
|
2014-03-14 14:13:41 -04:00
|
|
|
|
2014-07-17 12:20:34 -04:00
|
|
|
while (NewXYOffset[X - X1].X + X > NewYOffsets[FMath::FloorToInt(XOffset) - X1].X + FMath::FloorToFloat(XOffset))
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
2014-12-18 06:52:06 -05:00
|
|
|
XOffset = XOffset + 1.0f;
|
2014-03-14 14:13:41 -04:00
|
|
|
if (XOffset >= X2)
|
|
|
|
|
{
|
|
|
|
|
XOffset = X2;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
PreXOffset = XOffset;
|
|
|
|
|
|
|
|
|
|
while (FMath::Abs(TotalLineArea - TargetLineArea) > AreaErrorThreshold)
|
|
|
|
|
{
|
2014-12-18 06:52:06 -05:00
|
|
|
TotalLineArea = 0.0f;
|
2014-03-14 14:13:41 -04:00
|
|
|
IterNum++;
|
2014-07-17 12:20:34 -04:00
|
|
|
for (int32 Y = MinY[X - X1]; Y < MaxY[X - X1]; ++Y)
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
2014-07-17 12:20:34 -04:00
|
|
|
ULandscapeComponent* Comp = ComponentArray[X - X1 + (Y - Y1)*(X2 - X1 + 1)];
|
2014-03-14 14:13:41 -04:00
|
|
|
if (Comp != NULL) // valid
|
|
|
|
|
{
|
|
|
|
|
const FMatrix LocalToWorld = Comp->GetRenderMatrix();
|
|
|
|
|
FVector P[4];
|
2014-07-17 12:20:34 -04:00
|
|
|
for (int32 Idx = 0; Idx < 4; Idx += 2)
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
|
|
|
|
int32 YY = FMath::Clamp<int32>(Y + YOffsets[Idx], Y1, Y2);
|
2014-07-17 12:20:34 -04:00
|
|
|
P[Idx] = FVector(GetWorldPos(LocalToWorld, FVector2D(X - Comp->GetSectionBase().X, YY - Comp->GetSectionBase().Y), NewXYOffset[X - X1 + (YY - Y1) * (X2 - X1 + 1)]));
|
2014-03-14 14:13:41 -04:00
|
|
|
}
|
|
|
|
|
|
2014-07-17 12:20:34 -04:00
|
|
|
int32 XX0 = FMath::Clamp<int32>(FMath::FloorToInt(XOffset - 1), X1, X2);
|
2014-05-06 06:26:25 -04:00
|
|
|
int32 XX1 = FMath::Clamp<int32>(FMath::FloorToInt(XOffset), X1, X2);
|
2014-07-17 12:20:34 -04:00
|
|
|
int32 XX2 = FMath::Clamp<int32>(FMath::FloorToInt(1 + XOffset), X1, X2);
|
2014-03-14 14:13:41 -04:00
|
|
|
|
|
|
|
|
// Search for valid YOffset...
|
2014-07-17 12:20:34 -04:00
|
|
|
for (int32 Idx = 1; Idx < 4; Idx += 2)
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
|
|
|
|
int32 YY = FMath::Clamp<int32>(Y + YOffsets[Idx], Y1, Y2);
|
2014-07-17 12:20:34 -04:00
|
|
|
FVector P1(GetWorldPos(LocalToWorld, FVector2D(XX1 - Comp->GetSectionBase().X, YY - Comp->GetSectionBase().Y), NewYOffsets[XX1 - X1 + (YY - Y1) * (X2 - X1 + 1)]));
|
|
|
|
|
FVector P2(GetWorldPos(LocalToWorld, FVector2D(XX2 - Comp->GetSectionBase().X, YY - Comp->GetSectionBase().Y), NewYOffsets[XX2 - X1 + (YY - Y1) * (X2 - X1 + 1)]));
|
2014-03-14 14:13:41 -04:00
|
|
|
P[Idx] = FMath::Lerp(P1, P2, FMath::Fractional(XOffset));
|
|
|
|
|
if (Idx == 1)
|
|
|
|
|
{
|
2014-07-17 12:20:34 -04:00
|
|
|
FVector P0(GetWorldPos(LocalToWorld, FVector2D(XX0 - Comp->GetSectionBase().X, YY - Comp->GetSectionBase().Y), NewYOffsets[XX0 - X1 + (YY - Y1) * (X2 - X1 + 1)]));
|
|
|
|
|
TotalHeightError += FMath::Abs(((P[1] - P0) ^ (P2 - P[1])).Size() - ((P1 - P0) ^ (P2 - P1)).Size());
|
2014-03-14 14:13:41 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//TotalHeightError += Abs( NewYOffsets( XX1 - X1 + (Y - Y1) * (X2-X1+1) ).Z - NewYOffsets( XX2 - X1 + (Y - Y1) * (X2-X1+1) ).Z * appFractional(XOffset) );
|
|
|
|
|
TotalLineArea += (((P[3] - P[0]) ^ (P[1] - P[0])).Size() + ((P[3] - P[0]) ^ (P[2] - P[0])).Size()) * 0.5f;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-17 12:20:34 -04:00
|
|
|
if (TotalLineArea < AreaErrorThreshold || IterNum > MaxIterNum)
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-17 12:20:34 -04:00
|
|
|
if (MaxY[X - X1] - MinY[X - X1] > 0)
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
2014-07-17 12:20:34 -04:00
|
|
|
TotalHeightError /= (MaxY[X - X1] - MinY[X - X1]);
|
2014-03-14 14:13:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float NewLineAreaDiff = FMath::Abs(TotalLineArea - TargetLineArea);
|
|
|
|
|
if (NewLineAreaDiff > LineAreaDiff || TotalHeightError > HeightErrorThreshold)
|
|
|
|
|
{
|
|
|
|
|
// backtracking
|
|
|
|
|
XOffset = PreXOffset;
|
|
|
|
|
StepSize *= 0.5f;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
PreXOffset = XOffset;
|
|
|
|
|
LineAreaDiff = FMath::Abs(TotalLineArea - TargetLineArea);
|
|
|
|
|
if (TotalLineArea - TargetLineArea > 0)
|
|
|
|
|
{
|
|
|
|
|
XOffset -= StepSize;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
XOffset += StepSize;
|
|
|
|
|
}
|
|
|
|
|
// clamp
|
2014-07-17 12:20:34 -04:00
|
|
|
if (XOffset <= X1)
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
|
|
|
|
XOffset = X1;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2014-07-17 12:20:34 -04:00
|
|
|
else if (XOffset >= X2)
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
|
|
|
|
XOffset = X2;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (StepSize < AreaResolution)
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Set X Offset
|
|
|
|
|
if (TotalLineArea >= AreaErrorThreshold)
|
|
|
|
|
{
|
|
|
|
|
RemainArea -= TotalLineArea;
|
|
|
|
|
RemainQuads -= QuadX[X - X1];
|
|
|
|
|
|
2014-07-17 12:20:34 -04:00
|
|
|
for (int32 Y = MinY[X - X1]; Y < MaxY[X - X1]; ++Y)
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
2014-05-06 06:26:25 -04:00
|
|
|
int32 XX1 = FMath::Clamp<int32>(FMath::FloorToInt(XOffset), X1, X2);
|
2014-07-17 12:20:34 -04:00
|
|
|
int32 XX2 = FMath::Clamp<int32>(FMath::FloorToInt(1 + XOffset), X1, X2);
|
|
|
|
|
FVector P1 = NewYOffsets[XX1 - X1 + (Y - Y1) * (X2 - X1 + 1)];
|
|
|
|
|
P1.X = XX1 + P1.X;
|
|
|
|
|
FVector P2 = NewYOffsets[XX2 - X1 + (Y - Y1) * (X2 - X1 + 1)];
|
|
|
|
|
P2.X = XX2 + P2.X;
|
|
|
|
|
FVector& XYOffset = NewXYOffset[X + 1 - X1 + (Y - Y1) * (X2 - X1 + 1)];
|
2014-03-14 14:13:41 -04:00
|
|
|
XYOffset = FMath::Lerp(P1, P2, FMath::Fractional(XOffset));
|
2014-07-17 12:20:34 -04:00
|
|
|
XYOffset.X -= X + 1;
|
2014-03-14 14:13:41 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Same as Gizmo fall off...
|
|
|
|
|
float W = X2 - X1 + 1;
|
|
|
|
|
float H = Y2 - Y1 + 1;
|
|
|
|
|
float FalloffRadius = W * 0.5f * UISettings->BrushFalloff;
|
|
|
|
|
float SquareRadius = W * 0.5f - FalloffRadius;
|
2014-07-17 12:20:34 -04:00
|
|
|
for (int32 Y = 0; Y <= Y2 - Y1; ++Y)
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
2014-07-17 12:20:34 -04:00
|
|
|
for (int32 X = 0; X <= X2 - X1; ++X)
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
2014-07-17 12:20:34 -04:00
|
|
|
int32 Index = X + Y * (X2 - X1 + 1);
|
2014-03-14 14:13:41 -04:00
|
|
|
FVector2D TransformedLocal(FMath::Abs(X - W * 0.5f), FMath::Abs(Y - H * 0.5f) * (W / H));
|
|
|
|
|
float Cos = FMath::Abs(TransformedLocal.X) / TransformedLocal.Size();
|
|
|
|
|
float Sin = FMath::Abs(TransformedLocal.Y) / TransformedLocal.Size();
|
2014-12-18 06:52:06 -05:00
|
|
|
float RatioX = FalloffRadius > 0.0f ? 1.0f - FMath::Clamp((FMath::Abs(TransformedLocal.X) - Cos*SquareRadius) / FalloffRadius, 0.0f, 1.0f) : 1.0f;
|
|
|
|
|
float RatioY = FalloffRadius > 0.0f ? 1.0f - FMath::Clamp((FMath::Abs(TransformedLocal.Y) - Sin*SquareRadius) / FalloffRadius, 0.0f, 1.0f) : 1.0f;
|
2015-09-06 12:42:18 -04:00
|
|
|
float Ratio = TransformedLocal.SizeSquared() > FMath::Square(SquareRadius) ? RatioX * RatioY : 1.0f; //TransformedLocal.X / LW * TransformedLocal.Y / LW;
|
2014-07-17 12:20:34 -04:00
|
|
|
float PaintAmount = Ratio*Ratio*(3 - 2 * Ratio);
|
2014-03-14 14:13:41 -04:00
|
|
|
|
2014-07-17 12:20:34 -04:00
|
|
|
XYOffsetVectorData[Index] = FMath::Lerp(XYOffsetVectorData[Index], NewXYOffset[Index], PaintAmount);
|
2014-03-14 14:13:41 -04:00
|
|
|
//XYOffsetVectorData(Index) = NewXYOffset(Index);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Apply to XYOffset Texture map and Height map
|
|
|
|
|
Cache.SetCachedData(X1, Y1, X2, Y2, XYOffsetVectorData);
|
|
|
|
|
Cache.Flush();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected:
|
2014-07-23 08:24:09 -04:00
|
|
|
FLandscapeXYOffsetCache<false> Cache;
|
2014-03-14 14:13:41 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class FLandscapeToolRetopologize : public FLandscapeToolBase<FLandscapeToolStrokeRetopologize>
|
|
|
|
|
{
|
|
|
|
|
public:
|
2014-07-17 12:20:34 -04:00
|
|
|
FLandscapeToolRetopologize(FEdModeLandscape* InEdMode)
|
2014-03-14 14:13:41 -04:00
|
|
|
: FLandscapeToolBase<FLandscapeToolStrokeRetopologize>(InEdMode)
|
2014-09-11 12:44:16 -04:00
|
|
|
{
|
|
|
|
|
}
|
2014-03-14 14:13:41 -04:00
|
|
|
|
2014-06-13 06:14:46 -04:00
|
|
|
virtual const TCHAR* GetToolName() override { return TEXT("Retopologize"); }
|
|
|
|
|
virtual FText GetDisplayName() override { return NSLOCTEXT("UnrealEd", "LandscapeMode_Retopologize", "Retopologize"); }
|
2014-03-14 14:13:41 -04:00
|
|
|
|
2014-07-17 12:20:34 -04:00
|
|
|
virtual ELandscapeToolTargetTypeMask::Type GetSupportedTargetTypes() override
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
2014-07-17 12:20:34 -04:00
|
|
|
// technically not entirely accurate, also modifies the XYOffset map
|
|
|
|
|
return ELandscapeToolTargetTypeMask::Heightmap;
|
2014-03-14 14:13:41 -04:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2014-07-17 12:20:34 -04:00
|
|
|
void FEdModeLandscape::InitializeTool_Retopologize()
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
2014-07-17 12:20:34 -04:00
|
|
|
auto Tool_Retopologize = MakeUnique<FLandscapeToolRetopologize>(this);
|
|
|
|
|
Tool_Retopologize->ValidBrushes.Add("BrushSet_Circle");
|
|
|
|
|
Tool_Retopologize->ValidBrushes.Add("BrushSet_Alpha");
|
|
|
|
|
Tool_Retopologize->ValidBrushes.Add("BrushSet_Pattern");
|
|
|
|
|
LandscapeTools.Add(MoveTemp(Tool_Retopologize));
|
2014-03-14 14:13:41 -04:00
|
|
|
}
|