CARLA
Toggle main menu visibility
Loading...
Searching...
No Matches
Unreal
CarlaUnreal
Plugins
Carla
Source
Carla
Util
NavigationMesh.cpp
Go to the documentation of this file.
1
// Copyright (c) 2026 Computer Vision Center (CVC) at the Universitat Autonoma
2
// de Barcelona (UAB).
3
//
4
// This work is licensed under the terms of the MIT license.
5
// For a copy, see <https://opensource.org/licenses/MIT>.
6
7
#include "
Carla/Util/NavigationMesh.h
"
8
#include "
Carla.h
"
9
#include "
Carla/ContentPacks/ContentPackManager.h
"
10
11
#include <util/ue-header-guard-begin.h>
12
#include "Misc/FileHelper.h"
13
#include <util/ue-header-guard-end.h>
14
15
TArray<uint8>
FNavigationMesh::Load
(FString MapName)
16
{
17
#if WITH_EDITOR
18
{
19
// When playing in editor the map name gets an extra prefix, here we
20
// remove it.
21
FString CorrectedMapName = MapName;
22
constexpr
auto
PIEPrefix = TEXT(
"UEDPIE_0_"
);
23
CorrectedMapName.RemoveFromStart(PIEPrefix);
24
UE_LOG(LogCarla, Log, TEXT(
"FNavigationMesh: Corrected map name from %s to %s"
), *MapName, *CorrectedMapName);
25
MapName = CorrectedMapName;
26
}
27
#endif
// WITH_EDITOR
28
29
const
auto
FileName = MapName +
".bin"
;
30
31
TArray<FString> Files;
32
33
// Generated OpenDRIVE worlds get their navmesh built into Saved/Nav/ (the
34
// content dir is pak-backed in a packaged build); that copy is current.
35
const
FString SavedFilePath = FPaths::ConvertRelativePathToFull(
36
FPaths::ProjectSavedDir() / TEXT(
"Nav"
) / FileName);
37
if
(IFileManager::Get().FileExists(*SavedFilePath))
38
{
39
Files.Add(SavedFilePath);
40
}
41
42
// Mounted content packs ship <Content>/Maps/Nav/<Map>.bin.
43
if
(
const
UCarlaContentPackManager
*ContentPacks =
UCarlaContentPackManager::Get
())
44
{
45
for
(
const
FString &PackContentDir : ContentPacks->GetPackContentDirs())
46
{
47
if
(Files.Num())
48
{
49
break
;
50
}
51
const
FString PackFilePath = PackContentDir / TEXT(
"Maps/Nav"
) / FileName;
52
if
(IFileManager::Get().FileExists(*PackFilePath))
53
{
54
Files.Add(PackFilePath);
55
}
56
}
57
}
58
59
if
(!Files.Num())
60
{
61
IFileManager::Get().FindFilesRecursive(Files, *FPaths::ProjectContentDir(), *FileName,
true
,
false
,
false
);
62
}
63
64
TArray<uint8> Content;
65
66
if
(!Files.Num())
67
{
68
UE_LOG(LogTemp, Error, TEXT(
"Failed to find the navigation mesh file '%s' for map '%s'"
), *FileName, *MapName);
69
}
70
else
if
(FFileHelper::LoadFileToArray(Content, *Files[0], 0))
71
{
72
UE_LOG(LogCarla, Log, TEXT(
"Loading Navigation Mesh file '%s'"
), *Files[0]);
73
}
74
else
75
{
76
UE_LOG(LogTemp, Error, TEXT(
"Failed to load Navigation Mesh file '%s'"
), *Files[0]);
77
}
78
79
return
Content;
80
}
Carla.h
ContentPackManager.h
NavigationMesh.h
FNavigationMesh::Load
static TArray< uint8 > Load(FString MapName)
Return the Navigation Mesh Binary associated to MapName, or empty if the such file wasn't serialized.
Definition
NavigationMesh.cpp:15
UCarlaContentPackManager
Mounts CARLA content packs (content-only Unreal plugins cooked as DLC against a base release,...
Definition
ContentPackManager.h:61
UCarlaContentPackManager::Get
static UCarlaContentPackManager * Get()
Definition
ContentPackManager.cpp:38
Generated by
1.18.0