10 #include "GenericPlatform/GenericPlatformProcess.h" 12 #include "Runtime/Core/Public/HAL/FileManagerGeneric.h" 23 FString CorrectedMapName =
MapName;
24 constexpr
auto PIEPrefix = TEXT(
"UEDPIE_0_");
25 CorrectedMapName.RemoveFromStart(PIEPrefix);
26 MapName = CorrectedMapName;
30 MapName += TEXT(
".xodr");
32 const FString DefaultFilePath =
33 FPaths::ProjectContentDir() +
34 TEXT(
"Carla/Maps/OpenDrive/") +
39 if (FileManager.FileExists(*DefaultFilePath))
41 return DefaultFilePath;
44 TArray<FString> FilesFound;
45 FileManager.FindFilesRecursive(
47 *FPaths::ProjectContentDir(),
53 return FilesFound.Num() > 0 ? FilesFound[0u] : FString{};
58 auto MapName = World->GetMapName();
64 FString CorrectedMapName =
MapName;
65 constexpr
auto PIEPrefix = TEXT(
"UEDPIE_0_");
66 CorrectedMapName.RemoveFromStart(PIEPrefix);
74 const auto FolderDir = MapDir +
"/OpenDrive/";
78 TArray<FString> Files;
79 IFileManager::Get().FindFilesRecursive(Files, *FolderDir, *FString(FileName +
".xodr"),
true,
false,
false);
85 UE_LOG(LogTemp, Error, TEXT(
"Failed to find OpenDrive file for map '%s'"), *
MapName);
87 else if (FFileHelper::LoadFileToString(Content, *Files[0]))
89 UE_LOG(LogTemp, Log, TEXT(
"Loaded OpenDrive file '%s'"), *Files[0]);
93 UE_LOG(LogTemp, Error, TEXT(
"Failed to load OpenDrive file '%s'"), *Files[0]);
105 if (FilePath.IsEmpty())
107 UE_LOG(LogTemp, Error, TEXT(
"Failed to find OpenDrive file for map '%s'"), *MapName);
109 else if (FFileHelper::LoadFileToString(Content, *FilePath))
111 UE_LOG(LogTemp, Log, TEXT(
"Loaded OpenDrive file '%s'"), *FilePath);
115 UE_LOG(LogTemp, Error, TEXT(
"Failed to load OpenDrive file '%s'"), *FilePath);
127 FString CorrectedMapName =
MapName;
128 constexpr
auto PIEPrefix = TEXT(
"UEDPIE_0_");
129 CorrectedMapName.RemoveFromStart(PIEPrefix);
130 MapName = CorrectedMapName;
132 #endif // WITH_EDITOR 134 FString FileName = XODRPath.EndsWith(MapName) ?
"*" :
MapName;
135 FString FolderDir = XODRPath;
136 FolderDir.RemoveFromEnd(MapName +
".xodr");
139 TArray<FString> Files;
140 IFileManager::Get().FindFilesRecursive(Files, *FolderDir, *FString(FileName +
".xodr"),
true,
false,
false);
146 UE_LOG(LogTemp, Error, TEXT(
"Failed to find OpenDrive file for map '%s'"), *MapName);
148 else if (FFileHelper::LoadFileToString(Content, *Files[0]))
150 UE_LOG(LogTemp, Log, TEXT(
"Loaded OpenDrive file '%s'"), *Files[0]);
159 auto XODRContent =
LoadXODR(MapName);
160 if (!XODRContent.IsEmpty())
162 Map = NewObject<UOpenDriveMap>();
163 Map->
Load(XODRContent);
170 UWorld *World = GEngine->GetWorldFromContextObject(WorldContextObject, EGetWorldErrorMode::LogAndReturnNull);
171 return World !=
nullptr ?
static FString LoadXODR(const FString &MapName)
static FString FindPathToXODRFile(const FString &InMapName)
static T Get(carla::rpc::Response< T > &response)
static ACarlaGameModeBase * GetGameMode(const UObject *WorldContextObject)
static FString GetXODRByPath(FString XODRPath, FString MapName)
Return the OpenDrive XML associated to MapName, or empty if the file is not found.
Helper class for exposing CARLA OpenDrive API to blueprints.
static FString GetXODR(const UWorld *World)
Return the OpenDrive XML associated to MapName, or empty if the file is not found.
static UOpenDriveMap * LoadOpenDriveMap(const FString &MapName)
Load OpenDriveMap associated to the given MapName.
Base class for the CARLA Game Mode.
bool Load(const FString &XODRContent)
Load this map with an OpenDrive (XODR) file.
const FString GetFullMapPath() const
static UOpenDriveMap * LoadCurrentOpenDriveMap(const UObject *WorldContextObject)
Load OpenDriveMap associated to the currently loaded map.