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 "CookAssetsCommandlet.h"
|
||||||
#include "GameFramework/WorldSettings.h"
|
#include "GameFramework/WorldSettings.h"
|
||||||
|
#include "HAL/PlatformFilemanager.h"
|
||||||
|
#include "HAL/PlatformFile.h"
|
||||||
|
|
||||||
#include "UObject/MetaData.h"
|
#include "UObject/MetaData.h"
|
||||||
|
|
||||||
// #include "CommandletPluginPrivate.h"
|
// #include "CommandletPluginPrivate.h"
|
||||||
|
|
||||||
UCookAssetsCommandlet::UCookAssetsCommandlet()
|
UCookAssetsCommandlet::UCookAssetsCommandlet()
|
||||||
|
@ -12,7 +16,7 @@ UCookAssetsCommandlet::UCookAssetsCommandlet()
|
||||||
IsServer = false;
|
IsServer = false;
|
||||||
LogToConsole = true;
|
LogToConsole = true;
|
||||||
|
|
||||||
#if WITH_EDITORONLY_DATA
|
#if WITH_EDITORONLY_DATA
|
||||||
static ConstructorHelpers::FObjectFinder<UMaterial> MarkingNode(TEXT(
|
static ConstructorHelpers::FObjectFinder<UMaterial> MarkingNode(TEXT(
|
||||||
"Material'/Game/Carla/Static/GenericMaterials/LaneMarking/M_MarkingLane_W.M_MarkingLane_W'"));
|
"Material'/Game/Carla/Static/GenericMaterials/LaneMarking/M_MarkingLane_W.M_MarkingLane_W'"));
|
||||||
static ConstructorHelpers::FObjectFinder<UMaterial> RoadNode(TEXT(
|
static ConstructorHelpers::FObjectFinder<UMaterial> RoadNode(TEXT(
|
||||||
|
@ -25,7 +29,7 @@ UCookAssetsCommandlet::UCookAssetsCommandlet()
|
||||||
MarkingNodeMaterial = (UMaterial *) MarkingNode.Object;
|
MarkingNodeMaterial = (UMaterial *) MarkingNode.Object;
|
||||||
RoadNodeMaterial = (UMaterial *) RoadNode.Object;
|
RoadNodeMaterial = (UMaterial *) RoadNode.Object;
|
||||||
MarkingNodeMaterialAux = (UMaterial *) RoadNodeAux.Object;
|
MarkingNodeMaterialAux = (UMaterial *) RoadNodeAux.Object;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
#if WITH_EDITORONLY_DATA
|
#if WITH_EDITORONLY_DATA
|
||||||
|
|
||||||
|
@ -60,13 +64,12 @@ void UCookAssetsCommandlet::LoadWorld(FAssetData &AssetData)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void UCookAssetsCommandlet::AddMeshesToWorld(
|
TArray<AStaticMeshActor *> UCookAssetsCommandlet::AddMeshesToWorld(
|
||||||
const TArray<FString> &AssetsPaths,
|
const TArray<FString> &AssetsPaths,
|
||||||
bool bUseCarlaMaterials)
|
bool bUseCarlaMaterials)
|
||||||
{
|
{
|
||||||
for (auto s : AssetsPaths) {
|
TArray<AStaticMeshActor *> SpawnedMeshes;
|
||||||
UE_LOG(LogTemp, Log, TEXT("MESH: %s"), *s)
|
|
||||||
}
|
|
||||||
AssetsObjectLibrary = UObjectLibrary::CreateLibrary(UStaticMesh::StaticClass(), false, GIsEditor);
|
AssetsObjectLibrary = UObjectLibrary::CreateLibrary(UStaticMesh::StaticClass(), false, GIsEditor);
|
||||||
AssetsObjectLibrary->AddToRoot();
|
AssetsObjectLibrary->AddToRoot();
|
||||||
AssetsObjectLibrary->LoadAssetDataFromPaths(AssetsPaths);
|
AssetsObjectLibrary->LoadAssetDataFromPaths(AssetsPaths);
|
||||||
|
@ -82,19 +85,14 @@ void UCookAssetsCommandlet::AddMeshesToWorld(
|
||||||
UStaticMesh *MeshAsset;
|
UStaticMesh *MeshAsset;
|
||||||
AStaticMeshActor *MeshActor;
|
AStaticMeshActor *MeshActor;
|
||||||
|
|
||||||
if(MapContents.Num() <= 0) {
|
|
||||||
UE_LOG(LogTemp, Log, TEXT("EMPTY MAP CONTENTS FOUND"));
|
|
||||||
}
|
|
||||||
|
|
||||||
for (auto MapAsset : MapContents)
|
for (auto MapAsset : MapContents)
|
||||||
{
|
{
|
||||||
UE_LOG(LogTemp, Log, TEXT("ADDING MESHES"));
|
|
||||||
MeshAsset = CastChecked<UStaticMesh>(MapAsset.GetAsset());
|
MeshAsset = CastChecked<UStaticMesh>(MapAsset.GetAsset());
|
||||||
MeshActor = World->SpawnActor<AStaticMeshActor>(AStaticMeshActor::StaticClass(),
|
MeshActor = World->SpawnActor<AStaticMeshActor>(AStaticMeshActor::StaticClass(),
|
||||||
initialVector,
|
initialVector,
|
||||||
initialRotator);
|
initialRotator);
|
||||||
MeshActor->GetStaticMeshComponent()->SetStaticMesh(CastChecked<UStaticMesh>(MeshAsset));
|
MeshActor->GetStaticMeshComponent()->SetStaticMesh(CastChecked<UStaticMesh>(MeshAsset));
|
||||||
|
SpawnedMeshes.Add(MeshActor);
|
||||||
if (bUseCarlaMaterials)
|
if (bUseCarlaMaterials)
|
||||||
{
|
{
|
||||||
FString AssetName;
|
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();
|
World->MarkPackageDirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,13 +147,11 @@ bool UCookAssetsCommandlet::SaveWorld(FAssetData &AssetData, FString &DestPath,
|
||||||
World->GetOuter()->MarkPackageDirty();
|
World->GetOuter()->MarkPackageDirty();
|
||||||
|
|
||||||
// Filling the map stuff (Code only applied for maps)
|
// Filling the map stuff (Code only applied for maps)
|
||||||
// AOpenDriveActor *OpenWorldActor =
|
AOpenDriveActor *OpenWorldActor =
|
||||||
//
|
CastChecked<AOpenDriveActor>(World->SpawnActor(AOpenDriveActor::StaticClass(),
|
||||||
//
|
new FVector(), NULL));
|
||||||
// CastChecked<AOpenDriveActor>(World->SpawnActor(AOpenDriveActor::StaticClass(),
|
OpenWorldActor->BuildRoutes(WorldName);
|
||||||
// new FVector(), NULL));
|
OpenWorldActor->AddSpawners();
|
||||||
// OpenWorldActor->BuildRoutes(WorldName);
|
|
||||||
// OpenWorldActor->AddSpawners();
|
|
||||||
|
|
||||||
// Saving the package
|
// Saving the package
|
||||||
FString PackageFileName = FPackageName::LongPackageNameToFilename(PackageName,
|
FString PackageFileName = FPackageName::LongPackageNameToFilename(PackageName,
|
||||||
|
@ -200,60 +207,79 @@ FAssetsPaths UCookAssetsCommandlet::GetAssetsPathFromPackage(const FString &Pack
|
||||||
return AssetsPaths;
|
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)
|
int32 UCookAssetsCommandlet::Main(const FString &Params)
|
||||||
{
|
{
|
||||||
FPackageParams PackageParams = ParseParams(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
|
// Get Props and Maps Path
|
||||||
UE_LOG(LogTemp, Log, TEXT("------ GET ASSETS PATH ------"));
|
|
||||||
FAssetsPaths AssetsPaths = GetAssetsPathFromPackage(PackageParams.Name);
|
FAssetsPaths AssetsPaths = GetAssetsPathFromPackage(PackageParams.Name);
|
||||||
|
|
||||||
UE_LOG(LogTemp, Log, TEXT("------ ADDING MAPS TO WORLD ------"));
|
// Load World
|
||||||
|
FAssetData AssetData;
|
||||||
|
LoadWorld(AssetData);
|
||||||
|
World = CastChecked<UWorld>(AssetData.GetAsset());
|
||||||
|
|
||||||
|
FString MapPathData;
|
||||||
for (auto Map : AssetsPaths.MapsPaths)
|
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 RoadsPath = TEXT("/Game/") + PackageParams.Name + TEXT("/Static/RoadNode/") + Map.Name;
|
||||||
FString MarkingLinePath = TEXT("/Game/") + PackageParams.Name + TEXT("/Static/MarkingNode/") + Map.Name;
|
FString MarkingLinePath = TEXT("/Game/") + PackageParams.Name + TEXT("/Static/MarkingNode/") + Map.Name;
|
||||||
FString TerrainPath = TEXT("/Game/") + PackageParams.Name + TEXT("/Static/TerrainNode/") + 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};
|
TArray<FString> DataPath = {RoadsPath, MarkingLinePath, TerrainPath};
|
||||||
|
|
||||||
FAssetData AssetData;
|
// Add Map Meshes to World
|
||||||
LoadWorld(AssetData);
|
TArray<AStaticMeshActor *> SpawnedActors = AddMeshesToWorld(DataPath, Map.bUseCarlaMapMaterials);
|
||||||
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("-------------------------------"));
|
|
||||||
|
|
||||||
|
// Save the World in specified path
|
||||||
SaveWorld(AssetData, Map.Path, Map.Name);
|
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 ------"));
|
// Save Map Path File for further use
|
||||||
// FAssetData AssetData;
|
FString SaveDirectory = FString("/Game/") + PackageParams.Name + TEXT("/Config");
|
||||||
// LoadWorld(AssetData);
|
FString FileName = FString("MapPaths.txt");
|
||||||
// World = CastChecked<UWorld>(AssetData.GetAsset());
|
|
||||||
// // Add props in a single base map
|
|
||||||
// AddMeshesToWorld(AssetsPaths.PropsPaths, false);
|
|
||||||
|
|
||||||
// UE_LOG(LogTemp, Log, TEXT("------ SAVING BASEMAP WORLD ------"));
|
// TODO: This throws a weird error when saving, we need to fix it
|
||||||
// FString WorldDestPath = TEXT("/Game/") + PackageParams.Name +
|
// SaveStringTextToFile(SaveDirectory, FileName, MapPathData, true);
|
||||||
// "/Maps/MapName";
|
|
||||||
// FString MapName("MapName");
|
// Add props in a single Base Map
|
||||||
// SaveWorld(AssetData, WorldDestPath, MapName);
|
AddMeshesToWorld(AssetsPaths.PropsPaths, false);
|
||||||
|
|
||||||
|
FString MapName("PropsMap");
|
||||||
|
FString WorldDestPath = TEXT("/Game/") + PackageParams.Name +
|
||||||
|
TEXT("/Maps/") + MapName;
|
||||||
|
SaveWorld(AssetData, WorldDestPath, MapName);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,12 +77,12 @@ public:
|
||||||
/**
|
/**
|
||||||
* Add StaticMeshes from a folder into the World loaded as UPROPERTY.
|
* Add StaticMeshes from a folder into the World loaded as UPROPERTY.
|
||||||
* @param SrcPath - Array containing the folders from which the Assets will be
|
* @param SrcPath - Array containing the folders from which the Assets will be
|
||||||
*loaded
|
* loaded
|
||||||
* @param bMaterialWorkaround - Flag that will trigger a change in the
|
* @param bMaterialWorkaround - Flag that will trigger a change in the
|
||||||
*materials to fix a known bug
|
* materials to fix a known bug
|
||||||
* in RoadRunner.
|
* 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.
|
* 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);
|
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
|
* Get Path of all the Assets contained in the package to cook
|
||||||
* @param PackageName - The name of the package to cook
|
* @param PackageName - The name of the package to cook
|
||||||
|
@ -111,7 +113,7 @@ public:
|
||||||
private:
|
private:
|
||||||
|
|
||||||
UPROPERTY()
|
UPROPERTY()
|
||||||
UObjectLibrary* MapObjectLibrary;
|
UObjectLibrary *MapObjectLibrary;
|
||||||
|
|
||||||
UPROPERTY()
|
UPROPERTY()
|
||||||
UObjectLibrary *AssetsObjectLibrary;
|
UObjectLibrary *AssetsObjectLibrary;
|
||||||
|
@ -125,26 +127,25 @@ private:
|
||||||
UPROPERTY()
|
UPROPERTY()
|
||||||
TArray<FAssetData> MapContents;
|
TArray<FAssetData> MapContents;
|
||||||
|
|
||||||
|
|
||||||
/** Materials for the workaround */
|
/** Materials for the workaround */
|
||||||
/**
|
/**
|
||||||
* Workaround material for MarkingNodes mesh
|
* Workaround material for MarkingNodes mesh
|
||||||
*/
|
*/
|
||||||
UMaterial* MarkingNodeMaterial;
|
UMaterial *MarkingNodeMaterial;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Workaround material for the RoadNode mesh
|
* Workaround material for the RoadNode mesh
|
||||||
*/
|
*/
|
||||||
UMaterial* RoadNodeMaterial;
|
UMaterial *RoadNodeMaterial;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Workaround material for the second material for the MarkingNodes
|
* Workaround material for the second material for the MarkingNodes
|
||||||
*/
|
*/
|
||||||
UMaterial* MarkingNodeMaterialAux;
|
UMaterial *MarkingNodeMaterialAux;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Workaround material for the TerrainNodes
|
* Workaround material for the TerrainNodes
|
||||||
*/
|
*/
|
||||||
UMaterial* TerrainNodeMaterial;
|
UMaterial *TerrainNodeMaterial;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -234,11 +234,11 @@ def move_uassets(package_name, maps):
|
||||||
# Move uassets to correspoding folder
|
# Move uassets to correspoding folder
|
||||||
for filename in os.listdir(origin_path):
|
for filename in os.listdir(origin_path):
|
||||||
if "MarkingNode" in filename:
|
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:
|
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:
|
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