Large map and tiles maps generated based on noise render target
This commit is contained in:
parent
41d93b4a65
commit
a237d5bcf1
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -20,41 +20,52 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
FString UMapGeneratorWidget::GenerateMapFiles(const FString& destinationPath, const FString& mapName)
|
FString UMapGeneratorWidget::GenerateMapFiles(const FMapGeneratorMetaInfo& metaInfo)
|
||||||
{
|
{
|
||||||
DEBUG_MSG("Generating new map...");
|
DEBUG_MSG("Generating new map...");
|
||||||
|
|
||||||
FString errorMsg = "";
|
FString errorMsg = "";
|
||||||
|
|
||||||
FAssetData worldAssetData;
|
|
||||||
|
|
||||||
// 1. Creating Levels
|
// 1. Creating Levels
|
||||||
bool bLoaded = LoadWorld(worldAssetData);
|
CreateMainLargeMap(metaInfo);
|
||||||
GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Yellow, bLoaded ? "Loaded CORRECT" : "NOT loaded");
|
CreateTilesMaps(metaInfo);
|
||||||
|
// bool bLoaded = LoadWorld(worldAssetData);
|
||||||
|
// GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Yellow, bLoaded ? "Loaded CORRECT" : "NOT loaded");
|
||||||
|
|
||||||
// 2. Applying heightmap
|
// 2. Applying heightmap
|
||||||
UWorld* world = CastChecked<UWorld>(worldAssetData.GetAsset());
|
// UWorld* world = CastChecked<UWorld>(worldAssetData.GetAsset());
|
||||||
ALandscape* landscape = (ALandscape*) UGameplayStatics::GetActorOfClass(world, ALandscape::StaticClass());
|
// ALandscape* landscape = (ALandscape*) UGameplayStatics::GetActorOfClass(world, ALandscape::StaticClass());
|
||||||
GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Green, landscape!=nullptr ? "L TRUE" : "L FALSE");
|
// GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Green, landscape!=nullptr ? "L TRUE" : "L FALSE");
|
||||||
AssignLandscapeHeightMap(landscape);
|
// AssignLandscapeHeightMap(landscape);
|
||||||
|
|
||||||
// 3. Saving world
|
// 3. Saving world
|
||||||
bool bSaved = SaveWorld(worldAssetData, destinationPath, mapName);
|
// bool bSaved = SaveWorld(worldAssetData, metaInfo.destinationPath, metaInfo.mapName);
|
||||||
GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Green, bSaved ? "Saved CORRECT" : "NOT saved");
|
// GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Green, bSaved ? "Saved CORRECT" : "NOT saved");
|
||||||
|
|
||||||
return errorMsg;
|
return errorMsg;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool UMapGeneratorWidget::LoadWorld(FAssetData& WorldAssetData)
|
bool UMapGeneratorWidget::LoadBaseTileWorld(FAssetData& WorldAssetData)
|
||||||
|
{
|
||||||
|
const FString baseMapPath= TEXT("/CarlaTools/MapGenerator/BaseMap/Tiles");
|
||||||
|
return LoadWorld(WorldAssetData, baseMapPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool UMapGeneratorWidget::LoadBaseLargeMapWorld(FAssetData& WorldAssetData)
|
||||||
|
{
|
||||||
|
const FString baseMapPath= TEXT("/CarlaTools/MapGenerator/BaseMap/MainLargeMap");
|
||||||
|
return LoadWorld(WorldAssetData, baseMapPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool UMapGeneratorWidget::LoadWorld(FAssetData& WorldAssetData, const FString& baseMapPath)
|
||||||
{
|
{
|
||||||
TArray<FAssetData> AssetDatas;
|
TArray<FAssetData> AssetDatas;
|
||||||
UObjectLibrary *MapObjectLibrary;
|
UObjectLibrary *MapObjectLibrary;
|
||||||
const FString BaseMap = TEXT("/CarlaTools/MapGenerator/BaseMap");
|
|
||||||
|
|
||||||
// Loading Map from folder using object library
|
// Loading Map from folder using object library
|
||||||
MapObjectLibrary = UObjectLibrary::CreateLibrary(UWorld::StaticClass(), false, GIsEditor);
|
MapObjectLibrary = UObjectLibrary::CreateLibrary(UWorld::StaticClass(), false, GIsEditor);
|
||||||
MapObjectLibrary->AddToRoot();
|
MapObjectLibrary->AddToRoot();
|
||||||
MapObjectLibrary->LoadAssetDataFromPath(*BaseMap);
|
MapObjectLibrary->LoadAssetDataFromPath(*baseMapPath);
|
||||||
MapObjectLibrary->LoadAssetsFromAssetData();
|
MapObjectLibrary->LoadAssetsFromAssetData();
|
||||||
MapObjectLibrary->GetAssetDataList(AssetDatas);
|
MapObjectLibrary->GetAssetDataList(AssetDatas);
|
||||||
if (AssetDatas.Num() > 0)
|
if (AssetDatas.Num() > 0)
|
||||||
|
@ -103,4 +114,51 @@ bool UMapGeneratorWidget::SaveWorld(FAssetData& WorldToBeSaved, const FString& D
|
||||||
*PackageFileName, GError, nullptr, true, true, SAVE_NoError);
|
*PackageFileName, GError, nullptr, true, true, SAVE_NoError);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool UMapGeneratorWidget::CreateMainLargeMap(const FMapGeneratorMetaInfo& metaInfo)
|
||||||
|
{
|
||||||
|
FAssetData worldAssetData;
|
||||||
|
bool bLoaded = LoadBaseLargeMapWorld(worldAssetData);
|
||||||
|
bool bSaved = SaveWorld(worldAssetData, metaInfo.destinationPath, metaInfo.mapName);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool UMapGeneratorWidget::CreateTilesMaps(const FMapGeneratorMetaInfo& metaInfo)
|
||||||
|
{
|
||||||
|
FAssetData worldAssetData;
|
||||||
|
|
||||||
|
int numberOfTiles = metaInfo.sizeX * metaInfo.sizeY;
|
||||||
|
|
||||||
|
for(int i = 0; i < numberOfTiles; i++)
|
||||||
|
{
|
||||||
|
bool bLoaded = LoadBaseTileWorld(worldAssetData);
|
||||||
|
|
||||||
|
ApplyHeightMapToLandscape(worldAssetData);
|
||||||
|
|
||||||
|
const FString mapName = metaInfo.mapName + "_" + FString::FromInt(i);
|
||||||
|
bool bSaved = SaveWorld(worldAssetData, metaInfo.destinationPath, mapName);
|
||||||
|
GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Green, bSaved ? "Saved CORRECT" : "NOT saved");
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool UMapGeneratorWidget::ApplyHeightMapToLandscape(FAssetData& worldAssetData)
|
||||||
|
{
|
||||||
|
UWorld* world;
|
||||||
|
UObjectRedirector* BaseMapRedirector = Cast<UObjectRedirector>(worldAssetData.GetAsset());
|
||||||
|
if(BaseMapRedirector != nullptr)
|
||||||
|
{
|
||||||
|
world = CastChecked<UWorld>(BaseMapRedirector->DestinationObject);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
world = CastChecked<UWorld>(worldAssetData.GetAsset());
|
||||||
|
}
|
||||||
|
ALandscape* landscape = (ALandscape*) UGameplayStatics::GetActorOfClass(world, ALandscape::StaticClass());
|
||||||
|
GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Green, landscape!=nullptr ? "L TRUE" : "L FALSE");
|
||||||
|
AssignLandscapeHeightMap(landscape);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// #endif
|
// #endif
|
|
@ -17,6 +17,24 @@
|
||||||
|
|
||||||
#include "MapGeneratorWidget.generated.h"
|
#include "MapGeneratorWidget.generated.h"
|
||||||
|
|
||||||
|
USTRUCT(BlueprintType)
|
||||||
|
struct CARLATOOLS_API FMapGeneratorMetaInfo
|
||||||
|
{
|
||||||
|
GENERATED_USTRUCT_BODY();
|
||||||
|
|
||||||
|
UPROPERTY(BlueprintReadWrite)
|
||||||
|
FString destinationPath;
|
||||||
|
|
||||||
|
UPROPERTY(BlueprintReadWrite)
|
||||||
|
FString mapName;
|
||||||
|
|
||||||
|
UPROPERTY(BlueprintReadWrite)
|
||||||
|
int sizeX;
|
||||||
|
|
||||||
|
UPROPERTY(BlueprintReadWrite)
|
||||||
|
int sizeY;
|
||||||
|
};
|
||||||
|
|
||||||
/// Class UMapGeneratorWidget extends the functionality of UEditorUtilityWidget
|
/// Class UMapGeneratorWidget extends the functionality of UEditorUtilityWidget
|
||||||
/// to be able to generate and manage maps and largemaps tiles for procedural
|
/// to be able to generate and manage maps and largemaps tiles for procedural
|
||||||
/// map generation
|
/// map generation
|
||||||
|
@ -25,6 +43,11 @@ class CARLATOOLS_API UMapGeneratorWidget : public UEditorUtilityWidget
|
||||||
{
|
{
|
||||||
GENERATED_BODY()
|
GENERATED_BODY()
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
// UPROPERTY()
|
||||||
|
// UObjectLibrary *MapObjectLibrary;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/// This function invokes a blueprint event defined in widget blueprint
|
/// This function invokes a blueprint event defined in widget blueprint
|
||||||
/// event graph, which sets a heightmap to the @a landscape using
|
/// event graph, which sets a heightmap to the @a landscape using
|
||||||
|
@ -33,26 +56,49 @@ public:
|
||||||
UFUNCTION(BlueprintImplementableEvent)
|
UFUNCTION(BlueprintImplementableEvent)
|
||||||
void AssignLandscapeHeightMap(ALandscape* landscape);
|
void AssignLandscapeHeightMap(ALandscape* landscape);
|
||||||
|
|
||||||
//private:
|
|
||||||
// UPROPERTY()
|
|
||||||
// UObjectLibrary *MapObjectLibrary;
|
|
||||||
|
|
||||||
public:
|
|
||||||
/// Function called by Widget Blueprint which generates all tiles of map
|
/// Function called by Widget Blueprint which generates all tiles of map
|
||||||
/// @a mapName, and saves them in @a destinationPath
|
/// @a mapName, and saves them in @a destinationPath
|
||||||
/// Returns a void string is success and an error message if the process failed
|
/// Returns a void string is success and an error message if the process failed
|
||||||
UFUNCTION(Category="Map Generator",BlueprintCallable)
|
UFUNCTION(Category="Map Generator",BlueprintCallable)
|
||||||
FString GenerateMapFiles(const FString& destinationPath, const FString& mapName);
|
FString GenerateMapFiles(const FMapGeneratorMetaInfo& metaInfo);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/// Loads the base template UWorld object and is return in @a WorldAssetData
|
/// Loads the base tile map and stores it in @a WorldAssetData
|
||||||
/// The funtions return true is success, otherwise false
|
/// The funtions return true is success, otherwise false
|
||||||
UFUNCTION()
|
UFUNCTION()
|
||||||
bool LoadWorld(FAssetData& WorldAssetData);
|
bool LoadBaseTileWorld(FAssetData& WorldAssetData);
|
||||||
|
|
||||||
|
/// Loads the base large map and stores it in @a WorldAssetData
|
||||||
|
/// The funtions return true is success, otherwise false
|
||||||
|
UFUNCTION()
|
||||||
|
bool LoadBaseLargeMapWorld(FAssetData& WorldAssetData);
|
||||||
|
|
||||||
|
/// Loads the base template UWorld object from @a baseMapPath and returns
|
||||||
|
/// it in @a WorldAssetData
|
||||||
|
/// The funtions return true is success, otherwise false
|
||||||
|
UFUNCTION()
|
||||||
|
bool LoadWorld(FAssetData& WorldAssetData, const FString& baseMapPath);
|
||||||
|
|
||||||
/// Saves a world contained in @a WorldToBeSaved, in the path defined in @a DestinationPath
|
/// Saves a world contained in @a WorldToBeSaved, in the path defined in @a DestinationPath
|
||||||
/// named as @a WorldName, as a package .umap
|
/// named as @a WorldName, as a package .umap
|
||||||
UFUNCTION()
|
UFUNCTION()
|
||||||
bool SaveWorld(FAssetData& WorldToBeSaved, const FString& DestinationPath, const FString& WorldName);
|
bool SaveWorld(FAssetData& WorldToBeSaved, const FString& DestinationPath, const FString& WorldName);
|
||||||
|
|
||||||
|
/// Takes the name of the map from @a metaInfo and created the main map
|
||||||
|
/// including all the actors needed by large map system
|
||||||
|
UFUNCTION()
|
||||||
|
bool CreateMainLargeMap(const FMapGeneratorMetaInfo& metaInfo);
|
||||||
|
|
||||||
|
/// Takes @a metaInfo as input and generates all tiles based on the
|
||||||
|
/// dimensions specified for the map
|
||||||
|
/// The funtions return true is success, otherwise false
|
||||||
|
UFUNCTION()
|
||||||
|
bool CreateTilesMaps(const FMapGeneratorMetaInfo& metaInfo);
|
||||||
|
|
||||||
|
/// Gets the landscape from the input world @a worldAssetData and
|
||||||
|
/// applies the heightmap to it
|
||||||
|
/// The funtions return true is success, otherwise false
|
||||||
|
UFUNCTION()
|
||||||
|
bool ApplyHeightMapToLandscape(FAssetData& worldAssetData);
|
||||||
};
|
};
|
||||||
// #endif
|
// #endif
|
Loading…
Reference in New Issue