Now we can import multiple maps and props! :D
This commit is contained in:
parent
b96ea36d6f
commit
60a45199ea
|
@ -2,7 +2,11 @@
|
|||
|
||||
#include "CookAssetsCommandlet.h"
|
||||
#include "GameFramework/WorldSettings.h"
|
||||
#include "HAL/PlatformFilemanager.h"
|
||||
#include "HAL/PlatformFile.h"
|
||||
|
||||
#include "UObject/MetaData.h"
|
||||
|
||||
// #include "CommandletPluginPrivate.h"
|
||||
|
||||
UCookAssetsCommandlet::UCookAssetsCommandlet()
|
||||
|
@ -60,13 +64,12 @@ void UCookAssetsCommandlet::LoadWorld(FAssetData &AssetData)
|
|||
}
|
||||
}
|
||||
|
||||
void UCookAssetsCommandlet::AddMeshesToWorld(
|
||||
TArray<AStaticMeshActor *> UCookAssetsCommandlet::AddMeshesToWorld(
|
||||
const TArray<FString> &AssetsPaths,
|
||||
bool bUseCarlaMaterials)
|
||||
{
|
||||
for (auto s : AssetsPaths) {
|
||||
UE_LOG(LogTemp, Log, TEXT("MESH: %s"), *s)
|
||||
}
|
||||
TArray<AStaticMeshActor *> SpawnedMeshes;
|
||||
|
||||
AssetsObjectLibrary = UObjectLibrary::CreateLibrary(UStaticMesh::StaticClass(), false, GIsEditor);
|
||||
AssetsObjectLibrary->AddToRoot();
|
||||
AssetsObjectLibrary->LoadAssetDataFromPaths(AssetsPaths);
|
||||
|
@ -82,19 +85,14 @@ void UCookAssetsCommandlet::AddMeshesToWorld(
|
|||
UStaticMesh *MeshAsset;
|
||||
AStaticMeshActor *MeshActor;
|
||||
|
||||
if(MapContents.Num() <= 0) {
|
||||
UE_LOG(LogTemp, Log, TEXT("EMPTY MAP CONTENTS FOUND"));
|
||||
}
|
||||
|
||||
for (auto MapAsset : MapContents)
|
||||
{
|
||||
UE_LOG(LogTemp, Log, TEXT("ADDING MESHES"));
|
||||
MeshAsset = CastChecked<UStaticMesh>(MapAsset.GetAsset());
|
||||
MeshActor = World->SpawnActor<AStaticMeshActor>(AStaticMeshActor::StaticClass(),
|
||||
initialVector,
|
||||
initialRotator);
|
||||
MeshActor->GetStaticMeshComponent()->SetStaticMesh(CastChecked<UStaticMesh>(MeshAsset));
|
||||
|
||||
SpawnedMeshes.Add(MeshActor);
|
||||
if (bUseCarlaMaterials)
|
||||
{
|
||||
FString AssetName;
|
||||
|
@ -119,6 +117,17 @@ void UCookAssetsCommandlet::AddMeshesToWorld(
|
|||
}
|
||||
}
|
||||
|
||||
World->MarkPackageDirty();
|
||||
return SpawnedMeshes;
|
||||
}
|
||||
|
||||
void UCookAssetsCommandlet::DestroyWorldSpawnedActors(TArray<AStaticMeshActor *> &SpawnedActors)
|
||||
{
|
||||
for (auto Actor : SpawnedActors)
|
||||
{
|
||||
Actor->Destroy();
|
||||
}
|
||||
|
||||
World->MarkPackageDirty();
|
||||
}
|
||||
|
||||
|
@ -138,13 +147,11 @@ bool UCookAssetsCommandlet::SaveWorld(FAssetData &AssetData, FString &DestPath,
|
|||
World->GetOuter()->MarkPackageDirty();
|
||||
|
||||
// Filling the map stuff (Code only applied for maps)
|
||||
// AOpenDriveActor *OpenWorldActor =
|
||||
//
|
||||
//
|
||||
// CastChecked<AOpenDriveActor>(World->SpawnActor(AOpenDriveActor::StaticClass(),
|
||||
// new FVector(), NULL));
|
||||
// OpenWorldActor->BuildRoutes(WorldName);
|
||||
// OpenWorldActor->AddSpawners();
|
||||
AOpenDriveActor *OpenWorldActor =
|
||||
CastChecked<AOpenDriveActor>(World->SpawnActor(AOpenDriveActor::StaticClass(),
|
||||
new FVector(), NULL));
|
||||
OpenWorldActor->BuildRoutes(WorldName);
|
||||
OpenWorldActor->AddSpawners();
|
||||
|
||||
// Saving the package
|
||||
FString PackageFileName = FPackageName::LongPackageNameToFilename(PackageName,
|
||||
|
@ -200,60 +207,79 @@ FAssetsPaths UCookAssetsCommandlet::GetAssetsPathFromPackage(const FString &Pack
|
|||
return AssetsPaths;
|
||||
}
|
||||
|
||||
bool SaveStringTextToFile(
|
||||
FString SaveDirectory,
|
||||
FString FileName,
|
||||
FString SaveText,
|
||||
bool bAllowOverWriting)
|
||||
{
|
||||
IPlatformFile &PlatformFile = FPlatformFileManager::Get().GetPlatformFile();
|
||||
|
||||
// CreateDirectoryTree returns true if the destination
|
||||
// directory existed prior to call or has been created
|
||||
// during the call.
|
||||
if (PlatformFile.CreateDirectoryTree(*SaveDirectory))
|
||||
{
|
||||
// Get absolute file path
|
||||
FString AbsoluteFilePath = SaveDirectory + "/" + FileName;
|
||||
|
||||
// Allow overwriting or file doesn't already exist
|
||||
if (bAllowOverWriting || !PlatformFile.FileExists(*AbsoluteFilePath))
|
||||
{
|
||||
FFileHelper::SaveStringToFile(SaveText, *AbsoluteFilePath);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
int32 UCookAssetsCommandlet::Main(const FString &Params)
|
||||
{
|
||||
FPackageParams PackageParams = ParseParams(Params);
|
||||
UE_LOG(LogTemp, Log, TEXT("Call to Cook Assets Commandlet"));
|
||||
UE_LOG(LogTemp, Log, TEXT("Package Name: %s"), *PackageParams.Name);
|
||||
|
||||
// Get Props and Maps Path
|
||||
UE_LOG(LogTemp, Log, TEXT("------ GET ASSETS PATH ------"));
|
||||
FAssetsPaths AssetsPaths = GetAssetsPathFromPackage(PackageParams.Name);
|
||||
|
||||
UE_LOG(LogTemp, Log, TEXT("------ ADDING MAPS TO WORLD ------"));
|
||||
for (auto Map : AssetsPaths.MapsPaths)
|
||||
{
|
||||
UE_LOG(LogTemp, Log, TEXT("MAP NAME: %s"), *Map.Name);
|
||||
UE_LOG(LogTemp, Log, TEXT("MAP PATH: %s"), *Map.Path);
|
||||
|
||||
// Load World
|
||||
FString RoadsPath = TEXT("/Game/") + PackageParams.Name + TEXT("/Static/RoadNode/") + Map.Name;
|
||||
FString MarkingLinePath = TEXT("/Game/") + PackageParams.Name + TEXT("/Static/MarkingNode/") + Map.Name;
|
||||
FString TerrainPath = TEXT("/Game/") + PackageParams.Name + TEXT("/Static/TerrainNode/") + Map.Name;
|
||||
|
||||
UE_LOG(LogTemp, Log, TEXT("ROADS PATH: %s"), *RoadsPath);
|
||||
UE_LOG(LogTemp, Log, TEXT("MARKING PATH: %s"), *MarkingLinePath);
|
||||
UE_LOG(LogTemp, Log, TEXT("TERRAIN PATH: %s"), *TerrainPath);
|
||||
|
||||
TArray<FString> DataPath = {RoadsPath, MarkingLinePath, TerrainPath};
|
||||
|
||||
FAssetData AssetData;
|
||||
LoadWorld(AssetData);
|
||||
World = CastChecked<UWorld>(AssetData.GetAsset());
|
||||
|
||||
UE_LOG(LogTemp, Log, TEXT("------ ADD MESHES TO MAP ------"));
|
||||
// MoveMapMeshes(Map.Path, DataPath);
|
||||
// FString Path = TEXT("/Game/") + PackageParams.Name + TEXT("/Maps/") + Map.Name;
|
||||
// TArray<FString> Paths;
|
||||
// Paths.Add(Path);
|
||||
AddMeshesToWorld(DataPath, Map.bUseCarlaMapMaterials);
|
||||
UE_LOG(LogTemp, Log, TEXT("-------------------------------"));
|
||||
FString MapPathData;
|
||||
for (auto Map : AssetsPaths.MapsPaths)
|
||||
{
|
||||
|
||||
FString RoadsPath = TEXT("/Game/") + PackageParams.Name + TEXT("/Static/RoadNode/") + Map.Name;
|
||||
FString MarkingLinePath = TEXT("/Game/") + PackageParams.Name + TEXT("/Static/MarkingNode/") + Map.Name;
|
||||
FString TerrainPath = TEXT("/Game/") + PackageParams.Name + TEXT("/Static/TerrainNode/") + Map.Name;
|
||||
|
||||
TArray<FString> DataPath = {RoadsPath, MarkingLinePath, TerrainPath};
|
||||
|
||||
// Add Map Meshes to World
|
||||
TArray<AStaticMeshActor *> SpawnedActors = AddMeshesToWorld(DataPath, Map.bUseCarlaMapMaterials);
|
||||
|
||||
// Save the World in specified path
|
||||
SaveWorld(AssetData, Map.Path, Map.Name);
|
||||
|
||||
// Remove spawned actors from world to keep equal as BaseMap
|
||||
DestroyWorldSpawnedActors(SpawnedActors);
|
||||
|
||||
MapPathData.Append(Map.Path + TEXT("\n"));
|
||||
}
|
||||
|
||||
// UE_LOG(LogTemp, Log, TEXT("------ ADDING PROPS TO WORLD ------"));
|
||||
// FAssetData AssetData;
|
||||
// LoadWorld(AssetData);
|
||||
// World = CastChecked<UWorld>(AssetData.GetAsset());
|
||||
// // Add props in a single base map
|
||||
// AddMeshesToWorld(AssetsPaths.PropsPaths, false);
|
||||
// Save Map Path File for further use
|
||||
FString SaveDirectory = FString("/Game/") + PackageParams.Name + TEXT("/Config");
|
||||
FString FileName = FString("MapPaths.txt");
|
||||
|
||||
// UE_LOG(LogTemp, Log, TEXT("------ SAVING BASEMAP WORLD ------"));
|
||||
// FString WorldDestPath = TEXT("/Game/") + PackageParams.Name +
|
||||
// "/Maps/MapName";
|
||||
// FString MapName("MapName");
|
||||
// SaveWorld(AssetData, WorldDestPath, MapName);
|
||||
// TODO: This throws a weird error when saving, we need to fix it
|
||||
// SaveStringTextToFile(SaveDirectory, FileName, MapPathData, true);
|
||||
|
||||
// Add props in a single Base Map
|
||||
AddMeshesToWorld(AssetsPaths.PropsPaths, false);
|
||||
|
||||
FString MapName("PropsMap");
|
||||
FString WorldDestPath = TEXT("/Game/") + PackageParams.Name +
|
||||
TEXT("/Maps/") + MapName;
|
||||
SaveWorld(AssetData, WorldDestPath, MapName);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -82,7 +82,7 @@ public:
|
|||
* materials to fix a known bug
|
||||
* in RoadRunner.
|
||||
*/
|
||||
void AddMeshesToWorld(const TArray<FString> &AssetsPaths, bool bUseCarlaMaterials);
|
||||
TArray<AStaticMeshActor *> AddMeshesToWorld(const TArray<FString> &AssetsPaths, bool bUseCarlaMaterials);
|
||||
|
||||
/**
|
||||
* Save a given Asset containing a World into a given path with a given name.
|
||||
|
@ -92,6 +92,8 @@ public:
|
|||
*/
|
||||
bool SaveWorld(FAssetData &AssetData, FString &DestPath, FString &WorldName);
|
||||
|
||||
void DestroyWorldSpawnedActors(TArray<AStaticMeshActor *> &SpawnedActors);
|
||||
|
||||
/**
|
||||
* Get Path of all the Assets contained in the package to cook
|
||||
* @param PackageName - The name of the package to cook
|
||||
|
@ -125,7 +127,6 @@ private:
|
|||
UPROPERTY()
|
||||
TArray<FAssetData> MapContents;
|
||||
|
||||
|
||||
/** Materials for the workaround */
|
||||
/**
|
||||
* Workaround material for MarkingNodes mesh
|
||||
|
|
|
@ -234,11 +234,11 @@ def move_uassets(package_name, maps):
|
|||
# Move uassets to correspoding folder
|
||||
for filename in os.listdir(origin_path):
|
||||
if "MarkingNode" in filename:
|
||||
shutil.move(os.path.join(origin_path, filename), marking_dir)
|
||||
shutil.move(os.path.join(origin_path, filename), os.path.join(marking_dir, filename))
|
||||
if "RoadNode" in filename:
|
||||
shutil.move(os.path.join(origin_path, filename), road_dir)
|
||||
shutil.move(os.path.join(origin_path, filename), os.path.join(road_dir, filename))
|
||||
if "TerrainNode" in filename:
|
||||
shutil.move(os.path.join(origin_path, filename), terrain_dir)
|
||||
shutil.move(os.path.join(origin_path, filename), os.path.join(terrain_dir, filename))
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue