This commit is contained in:
Blyron 2024-07-31 14:39:42 +02:00 committed by GitHub
commit 2478083e46
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 187 additions and 0 deletions

View File

@ -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["UE5_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.split()
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 = command + 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)

View File

@ -0,0 +1,100 @@
// 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"
#include <iostream>
#include <fstream>
#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);
AActor* QueryActor = UGameplayStatics::GetActorOfClass( GEditor->GetEditorWorldContext().World(), ALargeMapManager::StaticClass());
if (QueryActor != nullptr) {
ALargeMapManager* LmManager = Cast<ALargeMapManager>(QueryActor);
const FIntVector NumTilesInXY = LmManager->GetNumTilesInXY();
const float TileSize = LmManager->GetTileSize();
UE_LOG(LogCarlaToolsMapSetProperPositionForWorldPartitionCommandlet, Warning, TEXT("NumTilesInXY is %s"), *(NumTilesInXY.ToString()));
UE_LOG(LogCarlaToolsMapSetProperPositionForWorldPartitionCommandlet, Warning, TEXT("TileSize is %f"), (TileSize));
UEditorLevelLibrary::SaveCurrentLevel();
UEditorLevelLibrary::LoadLevel(*BaseLevelName);
ProcessTile(FIntVector(CurrentTilesInXY.X, CurrentTilesInXY.Y, 0), TileSize);
UEditorLevelLibrary::SaveCurrentLevel();
}
else {
UE_LOG(LogCarlaToolsMapSetProperPositionForWorldPartitionCommandlet, Error, TEXT("Largemapmanager not found "));
}
//UEditorLoadingAndSavingUtils::SaveDirtyPackages(true, true);
UEditorLevelLibrary::SaveCurrentLevel();
return 0;
}
void USetProperPositionForWorldPartitionCommandlet::ProcessTile(const FIntVector CurrentTilesInXY, const float TileSize)
{
AActor* QueryActor = UGameplayStatics::GetActorOfClass( GEditor->GetEditorWorldContext().World(), ALargeMapManager::StaticClass());
if (QueryActor != nullptr)
{
ALargeMapManager* LmManager = Cast<ALargeMapManager>(QueryActor);
UE_LOG(LogCarlaToolsMapSetProperPositionForWorldPartitionCommandlet, Warning, TEXT("Current Tile is %s"), *(CurrentTilesInXY.ToString()));
const FCarlaMapTile& CarlaTile = LmManager->GetCarlaMapTile(CurrentTilesInXY);
UE_LOG(LogCarlaToolsMapSetProperPositionForWorldPartitionCommandlet, Warning, TEXT("Tile Name is %s"), *(CarlaTile.Name));
UEditorLevelLibrary::LoadLevel(CarlaTile.Name);
const FVector MinPosition = FVector(CurrentTilesInXY.X * TileSize, CurrentTilesInXY.Y * -TileSize, 0.0f);
TArray<AActor*> FoundActors;
UGameplayStatics::GetAllActorsOfClass(GEditor->GetEditorWorldContext().World(), AActor::StaticClass(), FoundActors);
for (AActor* CA : FoundActors)
{
CA->AddActorWorldOffset(MinPosition, false, nullptr, ETeleportType::ResetPhysics);
}
UEditorLevelLibrary::SaveCurrentLevel();
}
}
#endif

View File

@ -0,0 +1,44 @@
// 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>.
#pragma once
#include "Runtime/Engine/Classes/Engine/ObjectLibrary.h"
#include "Commandlets/Commandlet.h"
#include <compiler/disable-ue4-macros.h>
#include <compiler/enable-ue4-macros.h>
#include "OpenDriveToMap.h"
#include "SetProperPositionForWorldPartitionCommandlet.generated.h"
// Each commandlet should generate only 1 Tile
DECLARE_LOG_CATEGORY_EXTERN(LogCarlaToolsMapSetProperPositionForWorldPartitionCommandlet, Log, All);
UCLASS()
class CARLATOOLS_API USetProperPositionForWorldPartitionCommandlet
: public UCommandlet
{
GENERATED_BODY()
public:
/// Default constructor.
USetProperPositionForWorldPartitionCommandlet();
USetProperPositionForWorldPartitionCommandlet(const FObjectInitializer &);
#if WITH_EDITORONLY_DATA
virtual int32 Main(const FString &Params) override;
void ProcessTile(const FIntVector CurrentTilesInXY, const float TileSize);
#endif // WITH_EDITORONLY_DATA
};