Updating commandlet file for world partition.
This commit is contained in:
parent
fa7c187fb0
commit
b3fc04064d
|
@ -0,0 +1,43 @@
|
|||
#!/usr/bin/env python
|
||||
import unreal
|
||||
import argparse
|
||||
import json
|
||||
import os
|
||||
import subprocess
|
||||
|
||||
|
||||
"""Generic function for running a commandlet with its arguments."""
|
||||
ue4_path = os.environ["UE4_ROOT"]
|
||||
uproject_path = unreal.Paths.project_dir() + ("CarlaUE4.uproject")
|
||||
run = "-run=%s" % ("SetProperPositionForWorldPartitionCommandlet")
|
||||
|
||||
print("Before any Commandlet:")
|
||||
|
||||
argparser = argparse.ArgumentParser()
|
||||
|
||||
argparser.add_argument(
|
||||
'-s', '--paramstring',
|
||||
metavar='S',
|
||||
default='',
|
||||
type=str,
|
||||
help='String to put as arguments')
|
||||
args = argparser.parse_args()
|
||||
|
||||
arguments = args.paramstring
|
||||
|
||||
if os.name == "nt":
|
||||
sys_name = "Win64"
|
||||
editor_path = "%s/Engine/Binaries/%s/UnrealEditor" % (ue4_path, sys_name)
|
||||
command = [editor_path, uproject_path, run]
|
||||
command.extend(arguments)
|
||||
print("Commandlet:", command)
|
||||
print("Arguments:", arguments)
|
||||
subprocess.check_call(command, shell=True)
|
||||
elif os.name == "posix":
|
||||
sys_name = "Linux"
|
||||
editor_path = "%s/Engine/Binaries/%s/UnrealEditor" % (ue4_path, sys_name)
|
||||
full_command = editor_path + " " + uproject_path + " " + run + " " + arguments
|
||||
print("Commandlet:", full_command)
|
||||
print("Arguments:", arguments)
|
||||
subprocess.call([full_command], shell=True)
|
||||
|
|
@ -1,97 +0,0 @@
|
|||
// Copyright (c) 2024 Computer Vision Center (CVC) at the Universitat Autonoma
|
||||
// de Barcelona (UAB).
|
||||
//
|
||||
// This work is licensed under the terms of the MIT license.
|
||||
// For a copy, see <https://opensource.org/licenses/MIT>.
|
||||
|
||||
#include "Commandlet/SetProperPositionForWorldPartition.h"
|
||||
|
||||
#if WITH_EDITOR
|
||||
#include "FileHelpers.h"
|
||||
#endif
|
||||
#include "UObject/ConstructorHelpers.h"
|
||||
#include "EditorLevelLibrary.h"
|
||||
|
||||
DEFINE_LOG_CATEGORY(LogCarlaToolsMapSetProperPositionForWorldPartitionCommandlet);
|
||||
|
||||
|
||||
USetProperPositionForWorldPartition::USetProperPositionForWorldPartition()
|
||||
{
|
||||
#if WITH_EDITOR
|
||||
ConstructorHelpers::FClassFinder<UOpenDriveToMap> OpenDrivelassFinder(TEXT("/CarlaTools/OnroadMapGenerator/BP_OpenDriveToMap"));
|
||||
OpenDriveClass = OpenDrivelassFinder.Class;
|
||||
#endif
|
||||
}
|
||||
|
||||
USetProperPositionForWorldPartition::USetProperPositionForWorldPartition(const FObjectInitializer& Initializer)
|
||||
: Super(Initializer)
|
||||
{
|
||||
#if WITH_EDITOR
|
||||
ConstructorHelpers::FClassFinder<UOpenDriveToMap> OpenDrivelassFinder(TEXT("/CarlaTools/OnroadMapGenerator/BP_OpenDriveToMap"));
|
||||
OpenDriveClass = OpenDrivelassFinder.Class;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if WITH_EDITORONLY_DATA
|
||||
|
||||
int32 USetProperPositionForWorldPartition::Main(const FString &Params)
|
||||
{
|
||||
UE_LOG(LogCarlaToolsMapGenerateTileCommandlet, Log, TEXT("UGenerateTileCommandlet::Main Arguments %s"), *Params);
|
||||
TArray<FString> Tokens;
|
||||
TArray<FString> Switches;
|
||||
TMap<FString,FString> ParamsMap;
|
||||
|
||||
ParseCommandLine(*Params, Tokens, Switches, ParamsMap );
|
||||
|
||||
OpenDriveMap = NewObject<UOpenDriveToMap>(this, OpenDriveClass);
|
||||
FString FilePath = ParamsMap["FilePath"];
|
||||
FString BaseLevelName = ParamsMap["BaseLevelName"];
|
||||
FIntVector CurrentTilesInXY = FIntVector(FCString::Atof(*ParamsMap["CTileX"]),FCString::Atof(*ParamsMap["CTileY"]), 0);
|
||||
|
||||
UEditorLevelLibrary::LoadLevel(*BaseLevelName);
|
||||
UE_LOG(LogCarlaToolsMapGenerator, Warning, TEXT("Valid Map loaded"));
|
||||
UE_LOG(LogCarlaToolsMapGenerator, Warning, TEXT("MapName %s"), *MapName);
|
||||
|
||||
AActor* QueryActor = UGameplayStatics::GetActorOfClass(
|
||||
GEditor->GetEditorWorldContext().World(),
|
||||
ALargeMapManager::StaticClass());
|
||||
if (QueryActor != nullptr) {
|
||||
ALargeMapManager* LmManager = Cast<ALargeMapManager>(QueryActor);
|
||||
NumTilesInXY = LmManager->GetNumTilesInXY();
|
||||
TileSize = LmManager->GetTileSize();
|
||||
Tile0Offset = LmManager->GetTile0Offset();
|
||||
|
||||
FCarlaMapTile& CarlaTile = LmManager->GetCarlaMapTile(CurrentTilesInXY);
|
||||
UEditorLevelLibrary::SaveCurrentLevel();
|
||||
|
||||
UE_LOG(LogCarlaToolsMapGenerator, Warning, TEXT("Current Tile is %s"), *(CurrentTilesInXY.ToString()));
|
||||
UE_LOG(LogCarlaToolsMapGenerator, Warning, TEXT("NumTilesInXY is %s"), *(NumTilesInXY.ToString()));
|
||||
UE_LOG(LogCarlaToolsMapGenerator, Warning, TEXT("TileSize is %f"), (TileSize));
|
||||
UE_LOG(LogCarlaToolsMapGenerator, Warning, TEXT("Tile0Offset is %s"), *(Tile0Offset.ToString()));
|
||||
UE_LOG(LogCarlaToolsMapGenerator, Warning, TEXT("Tile Name is %s"), *(CarlaTile.Name));
|
||||
|
||||
UEditorLevelLibrary::LoadLevel(CarlaTile.Name);
|
||||
|
||||
MinPosition = FVector(CurrentTilesInXY.X * TileSize, CurrentTilesInXY.Y * -TileSize, 0.0f);
|
||||
MaxPosition = FVector((CurrentTilesInXY.X + 1.0f) * TileSize, (CurrentTilesInXY.Y + 1.0f) * -TileSize, 0.0f);
|
||||
|
||||
|
||||
TArray<AActor*> FoundActors;
|
||||
UGameplayStatics::GetAllActorsOfClass(GetWorld(), AActor::StaticClass(), FoundActors);
|
||||
|
||||
for (AActor* CA : FoundActors)
|
||||
{
|
||||
CA->AddActorWorldOffset(MinPosition, false, nullptr, ETeleportType::ResetPhysics);
|
||||
}
|
||||
}
|
||||
else {
|
||||
UE_LOG(LogCarlaToolsMapGenerator, Error, TEXT("Largemapmanager not found "));
|
||||
}
|
||||
|
||||
UEditorLoadingAndSavingUtils::SaveDirtyPackages(true, true);
|
||||
UEditorLevelLibrary::SaveCurrentLevel();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
|
@ -0,0 +1,88 @@
|
|||
// Copyright (c) 2024 Computer Vision Center (CVC) at the Universitat Autonoma
|
||||
// de Barcelona (UAB).
|
||||
//
|
||||
// This work is licensed under the terms of the MIT license.
|
||||
// For a copy, see <https://opensource.org/licenses/MIT>.
|
||||
|
||||
#include "Commandlet/SetProperPositionForWorldPartitionCommandlet.h"
|
||||
|
||||
#if WITH_EDITOR
|
||||
#include "FileHelpers.h"
|
||||
#endif
|
||||
#include "UObject/ConstructorHelpers.h"
|
||||
#include "EditorLevelLibrary.h"
|
||||
#include "MapGen/LargeMapManager.h"
|
||||
|
||||
DEFINE_LOG_CATEGORY(LogCarlaToolsMapSetProperPositionForWorldPartitionCommandlet);
|
||||
|
||||
|
||||
USetProperPositionForWorldPartitionCommandlet::USetProperPositionForWorldPartitionCommandlet()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
USetProperPositionForWorldPartitionCommandlet::USetProperPositionForWorldPartitionCommandlet(const FObjectInitializer& Initializer)
|
||||
: Super(Initializer)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
#if WITH_EDITORONLY_DATA
|
||||
|
||||
int32 USetProperPositionForWorldPartitionCommandlet::Main(const FString &Params)
|
||||
{
|
||||
UE_LOG(LogCarlaToolsMapSetProperPositionForWorldPartitionCommandlet, Log, TEXT("USetProperPositionForWorldPartition::Main Arguments %s"), *Params);
|
||||
TArray<FString> Tokens;
|
||||
TArray<FString> Switches;
|
||||
TMap<FString,FString> ParamsMap;
|
||||
|
||||
ParseCommandLine(*Params, Tokens, Switches, ParamsMap );
|
||||
|
||||
FString BaseLevelName = ParamsMap["BaseLevelName"];
|
||||
FIntVector CurrentTilesInXY = FIntVector(FCString::Atof(*ParamsMap["CTileX"]),FCString::Atof(*ParamsMap["CTileY"]), 0);
|
||||
|
||||
UEditorLevelLibrary::LoadLevel(*BaseLevelName);
|
||||
UE_LOG(LogCarlaToolsMapSetProperPositionForWorldPartitionCommandlet, Warning, TEXT("Valid Map loaded"));
|
||||
UE_LOG(LogCarlaToolsMapSetProperPositionForWorldPartitionCommandlet, Warning, TEXT("MapName %s"), *BaseLevelName);
|
||||
|
||||
AActor* QueryActor = UGameplayStatics::GetActorOfClass( GEditor->GetEditorWorldContext().World(), ALargeMapManager::StaticClass());
|
||||
if (QueryActor != nullptr) {
|
||||
ALargeMapManager* LmManager = Cast<ALargeMapManager>(QueryActor);
|
||||
FIntVector NumTilesInXY = LmManager->GetNumTilesInXY();
|
||||
float TileSize = LmManager->GetTileSize();
|
||||
FVector Tile0Offset = LmManager->GetTile0Offset();
|
||||
|
||||
FCarlaMapTile& CarlaTile = LmManager->GetCarlaMapTile(CurrentTilesInXY);
|
||||
UEditorLevelLibrary::SaveCurrentLevel();
|
||||
|
||||
UE_LOG(LogCarlaToolsMapSetProperPositionForWorldPartitionCommandlet, Warning, TEXT("Current Tile is %s"), *(CurrentTilesInXY.ToString()));
|
||||
UE_LOG(LogCarlaToolsMapSetProperPositionForWorldPartitionCommandlet, Warning, TEXT("NumTilesInXY is %s"), *(NumTilesInXY.ToString()));
|
||||
UE_LOG(LogCarlaToolsMapSetProperPositionForWorldPartitionCommandlet, Warning, TEXT("TileSize is %f"), (TileSize));
|
||||
UE_LOG(LogCarlaToolsMapSetProperPositionForWorldPartitionCommandlet, Warning, TEXT("Tile0Offset is %s"), *(Tile0Offset.ToString()));
|
||||
UE_LOG(LogCarlaToolsMapSetProperPositionForWorldPartitionCommandlet, Warning, TEXT("Tile Name is %s"), *(CarlaTile.Name));
|
||||
|
||||
UEditorLevelLibrary::LoadLevel(CarlaTile.Name);
|
||||
|
||||
FVector MinPosition = FVector(CurrentTilesInXY.X * TileSize, CurrentTilesInXY.Y * -TileSize, 0.0f);
|
||||
FVector MaxPosition = FVector((CurrentTilesInXY.X + 1.0f) * TileSize, (CurrentTilesInXY.Y + 1.0f) * -TileSize, 0.0f);
|
||||
|
||||
|
||||
TArray<AActor*> FoundActors;
|
||||
UGameplayStatics::GetAllActorsOfClass(GetWorld(), AActor::StaticClass(), FoundActors);
|
||||
|
||||
for (AActor* CA : FoundActors)
|
||||
{
|
||||
CA->AddActorWorldOffset(MinPosition, false, nullptr, ETeleportType::ResetPhysics);
|
||||
}
|
||||
}
|
||||
else {
|
||||
UE_LOG(LogCarlaToolsMapSetProperPositionForWorldPartitionCommandlet, Error, TEXT("Largemapmanager not found "));
|
||||
}
|
||||
|
||||
UEditorLoadingAndSavingUtils::SaveDirtyPackages(true, true);
|
||||
UEditorLevelLibrary::SaveCurrentLevel();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
|
@ -15,7 +15,7 @@
|
|||
|
||||
#include "OpenDriveToMap.h"
|
||||
|
||||
#include "SetProperPositionForWorldPartition.generated.h"
|
||||
#include "SetProperPositionForWorldPartitionCommandlet.generated.h"
|
||||
|
||||
// Each commandlet should generate only 1 Tile
|
||||
|
||||
|
@ -23,7 +23,7 @@ DECLARE_LOG_CATEGORY_EXTERN(LogCarlaToolsMapSetProperPositionForWorldPartitionCo
|
|||
|
||||
|
||||
UCLASS()
|
||||
class CARLATOOLS_API USetProperPositionForWorldPartition
|
||||
class CARLATOOLS_API USetProperPositionForWorldPartitionCommandlet
|
||||
: public UCommandlet
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
@ -31,16 +31,12 @@ class CARLATOOLS_API USetProperPositionForWorldPartition
|
|||
public:
|
||||
|
||||
/// Default constructor.
|
||||
USetProperPositionForWorldPartition();
|
||||
USetProperPositionForWorldPartition(const FObjectInitializer &);
|
||||
USetProperPositionForWorldPartitionCommandlet();
|
||||
USetProperPositionForWorldPartitionCommandlet(const FObjectInitializer &);
|
||||
|
||||
#if WITH_EDITORONLY_DATA
|
||||
|
||||
virtual int32 Main(const FString &Params) override;
|
||||
|
||||
#endif // WITH_EDITORONLY_DATA
|
||||
UPROPERTY()
|
||||
UOpenDriveToMap* OpenDriveMap;
|
||||
UPROPERTY()
|
||||
UClass* OpenDriveClass;
|
||||
};
|
Loading…
Reference in New Issue