2016-12-08 08:52:44 -05:00
|
|
|
// Copyright 1998-2017 Epic Games, Inc. All Rights Reserved.
|
2014-08-04 10:14:05 -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 "LandscapeDataAccess.h"
|
|
|
|
|
#include "LandscapeComponent.h"
|
2014-08-04 11:19:20 -04:00
|
|
|
|
|
|
|
|
#if WITH_EDITOR
|
|
|
|
|
|
2014-08-04 10:14:05 -04:00
|
|
|
|
2014-10-16 05:16:44 -04:00
|
|
|
LANDSCAPE_API FLandscapeComponentDataInterface::FLandscapeComponentDataInterface(ULandscapeComponent* InComponent, int32 InMipLevel) :
|
2014-08-04 10:14:05 -04:00
|
|
|
Component(InComponent),
|
|
|
|
|
HeightMipData(NULL),
|
|
|
|
|
XYOffsetMipData(NULL),
|
|
|
|
|
MipLevel(InMipLevel)
|
|
|
|
|
{
|
|
|
|
|
// Offset and stride for this component's data in heightmap texture
|
|
|
|
|
HeightmapStride = Component->HeightmapTexture->Source.GetSizeX() >> MipLevel;
|
|
|
|
|
HeightmapComponentOffsetX = FMath::RoundToInt((float)(Component->HeightmapTexture->Source.GetSizeX() >> MipLevel) * Component->HeightmapScaleBias.Z);
|
|
|
|
|
HeightmapComponentOffsetY = FMath::RoundToInt((float)(Component->HeightmapTexture->Source.GetSizeY() >> MipLevel) * Component->HeightmapScaleBias.W);
|
|
|
|
|
HeightmapSubsectionOffset = (Component->SubsectionSizeQuads + 1) >> MipLevel;
|
|
|
|
|
|
|
|
|
|
ComponentSizeVerts = (Component->ComponentSizeQuads + 1) >> MipLevel;
|
|
|
|
|
SubsectionSizeVerts = (Component->SubsectionSizeQuads + 1) >> MipLevel;
|
2014-09-11 12:39:28 -04:00
|
|
|
ComponentNumSubsections = Component->NumSubsections;
|
2014-08-04 10:14:05 -04:00
|
|
|
|
|
|
|
|
if (MipLevel < Component->HeightmapTexture->Source.GetNumMips())
|
|
|
|
|
{
|
2016-07-18 11:58:33 -04:00
|
|
|
HeightMipData = (FColor*)DataInterface.LockMip(Component->HeightmapTexture, MipLevel);
|
2014-08-04 10:14:05 -04:00
|
|
|
if (Component->XYOffsetmapTexture)
|
|
|
|
|
{
|
2016-07-18 11:58:33 -04:00
|
|
|
XYOffsetMipData = (FColor*)DataInterface.LockMip(Component->XYOffsetmapTexture, MipLevel);
|
2014-08-04 10:14:05 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-16 05:16:44 -04:00
|
|
|
LANDSCAPE_API FLandscapeComponentDataInterface::~FLandscapeComponentDataInterface()
|
2014-08-04 10:14:05 -04:00
|
|
|
{
|
|
|
|
|
if (HeightMipData)
|
|
|
|
|
{
|
2016-07-18 11:58:33 -04:00
|
|
|
DataInterface.UnlockMip(Component->HeightmapTexture, MipLevel);
|
2014-08-04 10:14:05 -04:00
|
|
|
if (Component->XYOffsetmapTexture)
|
|
|
|
|
{
|
2016-07-18 11:58:33 -04:00
|
|
|
DataInterface.UnlockMip(Component->XYOffsetmapTexture, MipLevel);
|
2014-08-04 10:14:05 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-22 14:39:16 -05:00
|
|
|
LANDSCAPE_API void FLandscapeComponentDataInterface::GetHeightmapTextureData(TArray<FColor>& OutData, bool bOkToFail)
|
2014-08-04 10:14:05 -04:00
|
|
|
{
|
2015-01-22 14:39:16 -05:00
|
|
|
if (bOkToFail && !HeightMipData)
|
|
|
|
|
{
|
|
|
|
|
OutData.Empty();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2014-08-04 10:14:05 -04:00
|
|
|
#if LANDSCAPE_VALIDATE_DATA_ACCESS
|
|
|
|
|
check(HeightMipData);
|
|
|
|
|
#endif
|
|
|
|
|
int32 HeightmapSize = ((Component->SubsectionSizeQuads + 1) * Component->NumSubsections) >> MipLevel;
|
|
|
|
|
OutData.Empty(FMath::Square(HeightmapSize));
|
|
|
|
|
OutData.AddUninitialized(FMath::Square(HeightmapSize));
|
|
|
|
|
|
|
|
|
|
for (int32 SubY = 0; SubY < HeightmapSize; SubY++)
|
|
|
|
|
{
|
|
|
|
|
// X/Y of the vertex we're looking at in component's coordinates.
|
|
|
|
|
int32 CompY = SubY;
|
|
|
|
|
|
|
|
|
|
// UV coordinates of the data offset into the texture
|
|
|
|
|
int32 TexV = SubY + HeightmapComponentOffsetY;
|
|
|
|
|
|
|
|
|
|
// Copy the data
|
|
|
|
|
FMemory::Memcpy(&OutData[CompY * HeightmapSize], &HeightMipData[HeightmapComponentOffsetX + TexV * HeightmapStride], HeightmapSize * sizeof(FColor));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-16 05:16:44 -04:00
|
|
|
LANDSCAPE_API bool FLandscapeComponentDataInterface::GetWeightmapTextureData(ULandscapeLayerInfoObject* LayerInfo, TArray<uint8>& OutData)
|
2014-08-04 10:14:05 -04:00
|
|
|
{
|
|
|
|
|
int32 LayerIdx = INDEX_NONE;
|
|
|
|
|
for (int32 Idx = 0; Idx < Component->WeightmapLayerAllocations.Num(); Idx++)
|
|
|
|
|
{
|
|
|
|
|
if (Component->WeightmapLayerAllocations[Idx].LayerInfo == LayerInfo)
|
|
|
|
|
{
|
|
|
|
|
LayerIdx = Idx;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (LayerIdx < 0)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (Component->WeightmapLayerAllocations[LayerIdx].WeightmapTextureIndex >= Component->WeightmapTextures.Num())
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (Component->WeightmapLayerAllocations[LayerIdx].WeightmapTextureChannel >= 4)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int32 WeightmapSize = ((Component->SubsectionSizeQuads + 1) * Component->NumSubsections) >> MipLevel;
|
|
|
|
|
OutData.Empty(FMath::Square(WeightmapSize));
|
|
|
|
|
OutData.AddUninitialized(FMath::Square(WeightmapSize));
|
|
|
|
|
|
2016-07-18 11:58:33 -04:00
|
|
|
FColor* WeightMipData = (FColor*)DataInterface.LockMip(Component->WeightmapTextures[Component->WeightmapLayerAllocations[LayerIdx].WeightmapTextureIndex], MipLevel);
|
2014-08-04 10:14:05 -04:00
|
|
|
|
|
|
|
|
// Channel remapping
|
|
|
|
|
int32 ChannelOffsets[4] = { (int32)STRUCT_OFFSET(FColor, R), (int32)STRUCT_OFFSET(FColor, G), (int32)STRUCT_OFFSET(FColor, B), (int32)STRUCT_OFFSET(FColor, A) };
|
|
|
|
|
|
|
|
|
|
uint8* SrcTextureData = (uint8*)WeightMipData + ChannelOffsets[Component->WeightmapLayerAllocations[LayerIdx].WeightmapTextureChannel];
|
|
|
|
|
|
|
|
|
|
for (int32 i = 0; i < FMath::Square(WeightmapSize); i++)
|
|
|
|
|
{
|
|
|
|
|
OutData[i] = SrcTextureData[i * 4];
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-18 11:58:33 -04:00
|
|
|
DataInterface.UnlockMip(Component->WeightmapTextures[Component->WeightmapLayerAllocations[LayerIdx].WeightmapTextureIndex], MipLevel);
|
2014-08-04 10:14:05 -04:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-16 05:16:44 -04:00
|
|
|
LANDSCAPE_API FColor* FLandscapeComponentDataInterface::GetXYOffsetData(int32 LocalX, int32 LocalY) const
|
2014-08-04 10:14:05 -04:00
|
|
|
{
|
|
|
|
|
#if LANDSCAPE_VALIDATE_DATA_ACCESS
|
|
|
|
|
check(Component);
|
|
|
|
|
check(LocalX >= 0 && LocalY >= 0 && LocalX < Component->ComponentSizeQuads + 1 && LocalY < Component->ComponentSizeQuads + 1);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
const int32 WeightmapSize = (Component->SubsectionSizeQuads + 1) * Component->NumSubsections;
|
|
|
|
|
int32 SubNumX;
|
|
|
|
|
int32 SubNumY;
|
|
|
|
|
int32 SubX;
|
|
|
|
|
int32 SubY;
|
|
|
|
|
ComponentXYToSubsectionXY(LocalX, LocalY, SubNumX, SubNumY, SubX, SubY);
|
|
|
|
|
|
|
|
|
|
return &XYOffsetMipData[SubX + SubNumX*SubsectionSizeVerts + (SubY + SubNumY*SubsectionSizeVerts)*WeightmapSize];
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-16 05:16:44 -04:00
|
|
|
LANDSCAPE_API FVector FLandscapeComponentDataInterface::GetLocalVertex(int32 LocalX, int32 LocalY) const
|
2014-08-04 10:14:05 -04:00
|
|
|
{
|
|
|
|
|
const float ScaleFactor = (float)Component->ComponentSizeQuads / (float)(ComponentSizeVerts - 1);
|
|
|
|
|
float XOffset, YOffset;
|
|
|
|
|
GetXYOffset(LocalX, LocalY, XOffset, YOffset);
|
|
|
|
|
return FVector(LocalX * ScaleFactor + XOffset, LocalY * ScaleFactor + YOffset, LandscapeDataAccess::GetLocalHeight(GetHeight(LocalX, LocalY)));
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-16 05:16:44 -04:00
|
|
|
LANDSCAPE_API FVector FLandscapeComponentDataInterface::GetWorldVertex(int32 LocalX, int32 LocalY) const
|
2014-08-04 10:14:05 -04:00
|
|
|
{
|
|
|
|
|
return Component->ComponentToWorld.TransformPosition(GetLocalVertex(LocalX, LocalY));
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-16 05:16:44 -04:00
|
|
|
LANDSCAPE_API void FLandscapeComponentDataInterface::GetWorldTangentVectors(int32 LocalX, int32 LocalY, FVector& WorldTangentX, FVector& WorldTangentY, FVector& WorldTangentZ) const
|
2014-08-04 10:14:05 -04:00
|
|
|
{
|
|
|
|
|
FColor* Data = GetHeightData(LocalX, LocalY);
|
|
|
|
|
WorldTangentZ.X = 2.f * (float)Data->B / 255.f - 1.f;
|
|
|
|
|
WorldTangentZ.Y = 2.f * (float)Data->A / 255.f - 1.f;
|
|
|
|
|
WorldTangentZ.Z = FMath::Sqrt(1.f - (FMath::Square(WorldTangentZ.X) + FMath::Square(WorldTangentZ.Y)));
|
|
|
|
|
WorldTangentX = FVector(-WorldTangentZ.Z, 0.f, WorldTangentZ.X);
|
|
|
|
|
WorldTangentY = FVector(0.f, WorldTangentZ.Z, -WorldTangentZ.Y);
|
|
|
|
|
|
|
|
|
|
WorldTangentX = Component->ComponentToWorld.TransformVectorNoScale(WorldTangentX);
|
|
|
|
|
WorldTangentY = Component->ComponentToWorld.TransformVectorNoScale(WorldTangentY);
|
|
|
|
|
WorldTangentZ = Component->ComponentToWorld.TransformVectorNoScale(WorldTangentZ);
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-16 05:16:44 -04:00
|
|
|
LANDSCAPE_API void FLandscapeComponentDataInterface::GetWorldPositionTangents(int32 LocalX, int32 LocalY, FVector& WorldPos, FVector& WorldTangentX, FVector& WorldTangentY, FVector& WorldTangentZ) const
|
2014-08-04 10:14:05 -04:00
|
|
|
{
|
|
|
|
|
FColor* Data = GetHeightData(LocalX, LocalY);
|
|
|
|
|
|
|
|
|
|
WorldTangentZ.X = 2.f * (float)Data->B / 255.f - 1.f;
|
|
|
|
|
WorldTangentZ.Y = 2.f * (float)Data->A / 255.f - 1.f;
|
|
|
|
|
WorldTangentZ.Z = FMath::Sqrt(1.f - (FMath::Square(WorldTangentZ.X) + FMath::Square(WorldTangentZ.Y)));
|
|
|
|
|
WorldTangentX = FVector(WorldTangentZ.Z, 0.f, -WorldTangentZ.X);
|
|
|
|
|
WorldTangentY = WorldTangentZ ^ WorldTangentX;
|
|
|
|
|
|
|
|
|
|
uint16 Height = (Data->R << 8) + Data->G;
|
|
|
|
|
|
|
|
|
|
const float ScaleFactor = (float)Component->ComponentSizeQuads / (float)(ComponentSizeVerts - 1);
|
|
|
|
|
float XOffset, YOffset;
|
|
|
|
|
GetXYOffset(LocalX, LocalY, XOffset, YOffset);
|
|
|
|
|
WorldPos = Component->ComponentToWorld.TransformPosition(FVector(LocalX * ScaleFactor + XOffset, LocalY * ScaleFactor + YOffset, LandscapeDataAccess::GetLocalHeight(Height)));
|
|
|
|
|
WorldTangentX = Component->ComponentToWorld.TransformVectorNoScale(WorldTangentX);
|
|
|
|
|
WorldTangentY = Component->ComponentToWorld.TransformVectorNoScale(WorldTangentY);
|
|
|
|
|
WorldTangentZ = Component->ComponentToWorld.TransformVectorNoScale(WorldTangentZ);
|
2014-08-04 11:19:20 -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
|
|
|
#endif // WITH_EDITOR
|