Lake generation supported
This commit is contained in:
parent
703b957674
commit
339df37c4e
Binary file not shown.
|
@ -30,9 +30,32 @@ UProceduralWaterManager::UProceduralWaterManager()
|
||||||
RiverBlueprintClass = (UClass*)RiverBlueprint.Object->GeneratedClass;
|
RiverBlueprintClass = (UClass*)RiverBlueprint.Object->GeneratedClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static ConstructorHelpers::FObjectFinder<UBlueprint> LakeBlueprint(TEXT("Blueprint'/CarlaTools/ProceduralWaterManager/DummyActor.DummyActor'"));
|
||||||
|
if (LakeBlueprint.Object){
|
||||||
|
LakeBlueprintClass = (UClass*)LakeBlueprint.Object->GeneratedClass;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FString UProceduralWaterManager::StartWaterGeneration(const FProceduralRiversMetaInfo metaInfo)
|
FString UProceduralWaterManager::StartWaterGeneration(const FProceduralRiversMetaInfo metaInfo)
|
||||||
|
{
|
||||||
|
FString errorMsg="";
|
||||||
|
|
||||||
|
if(metaInfo.WaterGenerationType == EWaterGenerationType::RIVERS)
|
||||||
|
{
|
||||||
|
errorMsg = RiverGeneration(metaInfo);
|
||||||
|
}
|
||||||
|
else if(metaInfo.WaterGenerationType == EWaterGenerationType::LAKE)
|
||||||
|
{
|
||||||
|
errorMsg = LakeGeneration(metaInfo);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
errorMsg = "Error in Water Generation Type";
|
||||||
|
|
||||||
|
return errorMsg;
|
||||||
|
}
|
||||||
|
|
||||||
|
FString UProceduralWaterManager::RiverGeneration(const FProceduralRiversMetaInfo metaInfo)
|
||||||
{
|
{
|
||||||
FString errorMsg;
|
FString errorMsg;
|
||||||
|
|
||||||
|
@ -82,7 +105,12 @@ FString UProceduralWaterManager::StartWaterGeneration(const FProceduralRiversMet
|
||||||
inputKeyCount = 0.0f;
|
inputKeyCount = 0.0f;
|
||||||
iterationNumber = -1; // Wildcard value used for headers
|
iterationNumber = -1; // Wildcard value used for headers
|
||||||
}
|
}
|
||||||
else{
|
else if (line == "# _L")
|
||||||
|
{
|
||||||
|
return "This is a LAKE file. Check the water type and the file content.";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
if(!line.Split(TEXT(" "), &y_str, &x_str))
|
if(!line.Split(TEXT(" "), &y_str, &x_str))
|
||||||
{
|
{
|
||||||
return "ERROR: Coordinated cannot be proccess... Check file format";
|
return "ERROR: Coordinated cannot be proccess... Check file format";
|
||||||
|
@ -122,6 +150,81 @@ FString UProceduralWaterManager::StartWaterGeneration(const FProceduralRiversMet
|
||||||
return "Successfully processed";
|
return "Successfully processed";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FString UProceduralWaterManager::LakeGeneration(const FProceduralRiversMetaInfo metaInfo)
|
||||||
|
{
|
||||||
|
const FString WaterInfoPath = metaInfo.WaterInfoPath;
|
||||||
|
if(!FPlatformFileManager::Get().GetPlatformFile().FileExists(*WaterInfoPath))
|
||||||
|
{
|
||||||
|
|
||||||
|
DEBUG_MSG("File Not Found!! :(");
|
||||||
|
return "File Not Found!! :(";
|
||||||
|
}
|
||||||
|
|
||||||
|
TArray<FString> file;
|
||||||
|
FFileHelper::LoadFileToStringArray(file, *WaterInfoPath);
|
||||||
|
|
||||||
|
if(file.Num() == 0)
|
||||||
|
return "Error processing file. Check file path and it content.";
|
||||||
|
|
||||||
|
FString centerX_str, centerY_str, sizeX_str, sizeY_str, angle_str;
|
||||||
|
|
||||||
|
AActor* lakeActor = nullptr;
|
||||||
|
|
||||||
|
for(FString line : file)
|
||||||
|
{
|
||||||
|
if(line == "# _L")
|
||||||
|
{
|
||||||
|
lakeActor = SpawnLakeBlueprintActor();
|
||||||
|
}
|
||||||
|
else if(line == "# _")
|
||||||
|
{
|
||||||
|
return "This is a RIVER file. Check the water type and the file content.";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// if(!line.Split(TEXT(" "), ¢erX_str, ¢erY_str, &sizeX_str, &sizeY_str, &angle_str))
|
||||||
|
// {
|
||||||
|
// return "ERROR: Coordinated cannot be proccess... Check file format";
|
||||||
|
// }
|
||||||
|
|
||||||
|
TArray<FString> lineArray;
|
||||||
|
|
||||||
|
line.ParseIntoArray(lineArray, TEXT(" "));
|
||||||
|
|
||||||
|
float centerX = FCString::Atof(*lineArray[0]);
|
||||||
|
float centerY = FCString::Atof(*lineArray[1]);
|
||||||
|
float sizeX = FCString::Atof(*lineArray[2]);
|
||||||
|
float sizeY = FCString::Atof(*lineArray[3]);
|
||||||
|
float angle = FCString::Atof(*lineArray[4]);
|
||||||
|
|
||||||
|
float centerZ;
|
||||||
|
|
||||||
|
if(metaInfo.CustomHeight > -100000000.0f)
|
||||||
|
centerZ = metaInfo.CustomHeight;
|
||||||
|
else
|
||||||
|
centerZ = GetLandscapeSurfaceHeight(centerX, centerY, false);
|
||||||
|
|
||||||
|
FVector location(metaInfo.CustomScaleFactor*centerX, metaInfo.CustomScaleFactor*centerY, centerZ);
|
||||||
|
location += metaInfo.CustomLocationOffset;
|
||||||
|
|
||||||
|
FRotator rotation(0.0f, angle,0.0f);
|
||||||
|
|
||||||
|
FVector scale(metaInfo.CustomRiverWidth*sizeX, metaInfo.CustomRiverWidth*sizeY, 1.0f);
|
||||||
|
|
||||||
|
lakeActor->SetActorScale3D(scale);
|
||||||
|
lakeActor->SetActorLocationAndRotation(location, rotation, false, 0, ETeleportType::None);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Last river created must be destroyed as it is a wildcard
|
||||||
|
if(lakeActor != nullptr)
|
||||||
|
lakeActor->Destroy();
|
||||||
|
|
||||||
|
return "Successfully processed";
|
||||||
|
}
|
||||||
|
|
||||||
AActor* UProceduralWaterManager::SpawnRiverBlueprintActor()
|
AActor* UProceduralWaterManager::SpawnRiverBlueprintActor()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -135,6 +238,19 @@ AActor* UProceduralWaterManager::SpawnRiverBlueprintActor()
|
||||||
return riverActor;
|
return riverActor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AActor* UProceduralWaterManager::SpawnLakeBlueprintActor()
|
||||||
|
{
|
||||||
|
|
||||||
|
FVector location(0, 0, 0);
|
||||||
|
FRotator rotation(0,0,0);
|
||||||
|
FActorSpawnParameters spawnInfo;
|
||||||
|
|
||||||
|
UWorld* World = GetWorld();
|
||||||
|
AActor* riverActor = World->SpawnActor<AActor>(LakeBlueprintClass, location, rotation, spawnInfo);
|
||||||
|
|
||||||
|
return riverActor;
|
||||||
|
}
|
||||||
|
|
||||||
float UProceduralWaterManager::GetLandscapeSurfaceHeight(float x, float y, bool bDrawDebugLines)
|
float UProceduralWaterManager::GetLandscapeSurfaceHeight(float x, float y, bool bDrawDebugLines)
|
||||||
{
|
{
|
||||||
UWorld* world = GetWorld();
|
UWorld* world = GetWorld();
|
||||||
|
|
|
@ -10,11 +10,21 @@
|
||||||
|
|
||||||
#include "ProceduralWaterManager.generated.h"
|
#include "ProceduralWaterManager.generated.h"
|
||||||
|
|
||||||
|
UENUM(BlueprintType)
|
||||||
|
enum EWaterGenerationType
|
||||||
|
{
|
||||||
|
RIVERS = 0,
|
||||||
|
LAKE = 1
|
||||||
|
};
|
||||||
|
|
||||||
USTRUCT(BlueprintType)
|
USTRUCT(BlueprintType)
|
||||||
struct CARLATOOLS_API FProceduralRiversMetaInfo
|
struct CARLATOOLS_API FProceduralRiversMetaInfo
|
||||||
{
|
{
|
||||||
GENERATED_USTRUCT_BODY();
|
GENERATED_USTRUCT_BODY();
|
||||||
|
|
||||||
|
UPROPERTY(BlueprintReadWrite)
|
||||||
|
TEnumAsByte<EWaterGenerationType> WaterGenerationType;
|
||||||
|
|
||||||
UPROPERTY(BlueprintReadWrite)
|
UPROPERTY(BlueprintReadWrite)
|
||||||
FString WaterInfoPath;
|
FString WaterInfoPath;
|
||||||
|
|
||||||
|
@ -68,12 +78,24 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TSubclassOf<class AActor> RiverBlueprintClass;
|
TSubclassOf<class AActor> RiverBlueprintClass;
|
||||||
|
TSubclassOf<class AActor> LakeBlueprintClass;
|
||||||
|
|
||||||
|
UFUNCTION()
|
||||||
|
FString RiverGeneration(const FProceduralRiversMetaInfo metaInfo);
|
||||||
|
|
||||||
|
UFUNCTION()
|
||||||
|
FString LakeGeneration(const FProceduralRiversMetaInfo metaInfo);
|
||||||
|
|
||||||
/// Instantiate a new actor of type RiverBlueprintClass
|
/// Instantiate a new actor of type RiverBlueprintClass
|
||||||
/// Returns the the actor created
|
/// Returns the the actor created
|
||||||
UFUNCTION()
|
UFUNCTION()
|
||||||
AActor* SpawnRiverBlueprintActor();
|
AActor* SpawnRiverBlueprintActor();
|
||||||
|
|
||||||
|
/// Instantiate a new actor of type LakeBlueprintClass
|
||||||
|
/// Returns the the actor created
|
||||||
|
UFUNCTION()
|
||||||
|
AActor* SpawnLakeBlueprintActor();
|
||||||
|
|
||||||
/// Calculates the height of the landscape in an specific 2D coordinate ( @a x, @a y)
|
/// Calculates the height of the landscape in an specific 2D coordinate ( @a x, @a y)
|
||||||
/// throwing rays and detecting the hit point. @a bDrawDebugLines allows to visualize
|
/// throwing rays and detecting the hit point. @a bDrawDebugLines allows to visualize
|
||||||
/// the rays in the viewport, only for debug purposes.
|
/// the rays in the viewport, only for debug purposes.
|
||||||
|
|
Loading…
Reference in New Issue