22 #include "Engine/StaticMeshActor.h" 23 #include "EngineUtils.h" 24 #include "GameFramework/SpectatorPawn.h" 25 #include "GenericPlatform/GenericPlatformProcess.h" 26 #include "Kismet/GameplayStatics.h" 27 #include "Misc/FileHelper.h" 28 #include "Misc/Paths.h" 35 case TSS::TrafficLightRed:
36 case TSS::TrafficLightYellow:
37 case TSS::TrafficLightGreen:
return TEXT(
"traffic.traffic_light");
38 case TSS::SpeedLimit_30:
return TEXT(
"traffic.speed_limit.30");
39 case TSS::SpeedLimit_40:
return TEXT(
"traffic.speed_limit.40");
40 case TSS::SpeedLimit_50:
return TEXT(
"traffic.speed_limit.50");
41 case TSS::SpeedLimit_60:
return TEXT(
"traffic.speed_limit.60");
42 case TSS::SpeedLimit_90:
return TEXT(
"traffic.speed_limit.90");
43 case TSS::SpeedLimit_100:
return TEXT(
"traffic.speed_limit.100");
44 case TSS::SpeedLimit_120:
return TEXT(
"traffic.speed_limit.120");
45 case TSS::SpeedLimit_130:
return TEXT(
"traffic.speed_limit.130");
46 case TSS::StopSign:
return TEXT(
"traffic.stop");
47 case TSS::YieldSign:
return TEXT(
"traffic.yield");
48 default:
return TEXT(
"traffic.unknown");
53 : Super(ObjectInitializer),
56 ActorDispatcher = CreateDefaultSubobject<UActorDispatcher>(TEXT(
"ActorDispatcher"));
61 bool bIsFileFound =
false;
63 FString FinalPath = MapString.IsEmpty() ?
GetMapName() : MapString;
64 FinalPath += !MapString.EndsWith(
".umap") ?
".umap" :
"";
66 if (MapString.StartsWith(
"/Game"))
69 FinalPath.RemoveFromStart(TEXT(
"/Game/"));
70 FinalPath = FPaths::ProjectContentDir() + FinalPath;
71 FinalPath =
IFileManager::Get().ConvertToAbsolutePathForExternalAppForRead(*FinalPath);
73 if (FPaths::FileExists(FinalPath)) {
75 FinalPath = MapString;
80 if (MapString.Contains(
"/"))
return false;
83 TArray<FString> TempStrArray, PathList;
84 IFileManager::Get().FindFilesRecursive(PathList, *FPaths::ProjectContentDir(), *FinalPath,
true,
false,
false);
85 if (PathList.Num() > 0)
87 FinalPath = PathList[0];
88 FinalPath.ParseIntoArray(TempStrArray, TEXT(
"Content/"),
true);
89 FinalPath = TempStrArray[1];
90 FinalPath.ParseIntoArray(TempStrArray, TEXT(
"."),
true);
91 FinalPath =
"/Game/" + TempStrArray[0];
99 UE_LOG(LogCarla, Warning, TEXT(
"Loading a new episode: %s"), *FinalPath);
100 UGameplayStatics::OpenLevel(GetWorld(), *FinalPath,
true);
111 const FString RecastToolName =
"RecastBuilder.exe";
113 const FString RecastToolName =
"RecastBuilder";
114 #endif // PLATFORM_WINDOWS 117 #if UE_BUILD_SHIPPING 118 const FString AbsoluteRecastBuilderPath = FPaths::ConvertRelativePathToFull(
119 FPaths::RootDir() +
"Tools/" + RecastToolName);
121 const FString AbsoluteRecastBuilderPath = FPaths::ConvertRelativePathToFull(
122 FPaths::ProjectDir() +
"../../Util/DockerUtils/dist/" + RecastToolName);
124 return AbsoluteRecastBuilderPath;
128 const FString &OpenDriveString,
131 if (OpenDriveString.IsEmpty())
133 UE_LOG(LogCarla, Error, TEXT(
"The OpenDrive string is empty."));
139 carla::rpc::FromLongFString(OpenDriveString));
142 if (!CarlaMap.has_value())
144 UE_LOG(LogCarla, Error, TEXT(
"The OpenDrive string is invalid or not supported"));
150 const auto CrosswalksMesh = CarlaMap->GetAllCrosswalkMesh();
151 const auto RecastOBJ = (RoadMesh + CrosswalksMesh).GenerateOBJForRecast();
153 const FString AbsoluteOBJPath = FPaths::ConvertRelativePathToFull(
154 FPaths::ProjectContentDir() +
"Carla/Maps/Nav/OpenDriveMap.obj");
157 FFileHelper::SaveStringToFile(
158 carla::rpc::ToLongFString(RecastOBJ),
160 FFileHelper::EEncodingOptions::ForceUTF8,
163 const FString AbsoluteXODRPath = FPaths::ConvertRelativePathToFull(
164 FPaths::ProjectContentDir() +
"Carla/Maps/OpenDrive/OpenDriveMap.xodr");
167 FFileHelper::SaveStringToFile(
170 FFileHelper::EEncodingOptions::ForceUTF8,
173 if (!FPaths::FileExists(AbsoluteXODRPath))
175 UE_LOG(LogCarla, Error, TEXT(
"ERROR: XODR not copied!"));
191 if (FPaths::FileExists(AbsoluteRecastBuilderPath) &&
196 FPlatformProcess::CreateProc(
197 *AbsoluteRecastBuilderPath, *AbsoluteOBJPath,
198 true,
true,
true,
nullptr, 0,
nullptr,
nullptr);
202 UE_LOG(LogCarla, Warning, TEXT(
"'RecastBuilder' not present under '%s', " 203 "the binaries for pedestrian navigation will not be created."),
204 *AbsoluteRecastBuilderPath);
215 UE_LOG(LogCarla, Warning, TEXT(
"Setting ActorActiveDistance is smaller that TileStreamingDistance, TileStreamingDistance will be increased"));
242 UE_LOG(LogCarla, Warning, TEXT(
"Trying to serialize invalid actor"));
259 SerializedActor.
id = 0u;
261 TSet<crp::CityObjectLabel> SemanticTags;
267 for (
auto &&Tag : SemanticTags)
269 using tag_t = decltype(SerializedActor.
semantic_tags)::value_type;
270 SerializedActor.
semantic_tags.emplace_back(static_cast<tag_t>(Tag));
272 return SerializedActor;
299 auto World = GetWorld();
300 check(World !=
nullptr);
301 auto PlayerController = UGameplayStatics::GetPlayerController(World, 0);
302 if (PlayerController ==
nullptr)
304 UE_LOG(LogCarla, Error, TEXT(
"Can't find player controller!"));
311 Description.
Id = TEXT(
"spectator");
317 UE_LOG(LogCarla, Error, TEXT(
"Can't find spectator!"));
320 for (TActorIterator<ATrafficSignBase> It(World); It; ++It)
323 check(Actor !=
nullptr);
326 Description.
Class = Actor->GetClass();
332 uint32 StaticMeshUId = 0;
333 for (
auto& Definition : Definitions)
335 if (Definition.Id ==
"static.prop.mesh")
337 StaticMeshUId = Definition.UId;
342 for (TActorIterator<AStaticMeshActor> It(World); It; ++It)
345 check(
Actor !=
nullptr);
346 auto MeshComponent =
Actor->GetStaticMeshComponent();
347 check(MeshComponent !=
nullptr);
348 if (MeshComponent->Mobility == EComponentMobility::Movable)
351 Description.
Id = TEXT(
"static.prop.mesh");
352 Description.
UId = StaticMeshUId;
356 MeshComponent->GetStaticMesh()->GetPathName()});
359 FString::SanitizeFloat(MeshComponent->GetMass())});
388 result =
"Recorder is not ready";
410 if (result.Key == EActorSpawnResultStatus::Success)
413 result.Value->GetActorId(),
414 static_cast<uint8_t
>(result.Value->GetActorType()),
416 std::move(thisActorDescription)
FCarlaActor * FindCarlaActor(FCarlaActor::IdType ActorId)
Find a Carla actor by id.
Seting for map generation from opendrive without additional geometry.
bool LoadNewOpendriveEpisode(const FString &OpenDriveString, const carla::rpc::OpendriveGenerationParameters &Params)
Load a new map generating the mesh from OpenDRIVE data and start a new episode.
std::string Start(std::string Name, FString MapName, bool AdditionalData=false)
TPair< EActorSpawnResultStatus, FCarlaActor * > SpawnActor(const FTransform &Transform, FActorDescription ActorDescription, FCarlaActor::IdType DesiredId=0)
Spawns an actor based on ActorDescription at Transform.
UActorDispatcher * ActorDispatcher
FCarlaActor * RegisterActor(AActor &Actor, FActorDescription ActorDescription, FActorRegistry::IdType DesiredId=0)
Register an actor that was not created using "SpawnActor" function but that should be kept in the reg...
static void AttachActors(AActor *Child, AActor *Parent, EAttachmentType AttachmentType)
bool enable_pedestrian_navigation
The game instance contains elements that must be kept alive in between levels.
carla::rpc::Actor SerializeActor(FCarlaActor *CarlaActor) const
Create a serializable object describing the actor.
float TileStreamingDistance
float ActorActiveDistance
static FOnEpisodeSettingsChange OnEpisodeSettingsChange
TArray< FTransform > GetRecommendedSpawnPoints() const
Return the list of recommended spawn points for vehicles.
void AddEvent(const CarlaRecorderEventAdd &Event)
static void GetTagsOfTaggedActor(const AActor &Actor, TSet< crp::CityObjectLabel > &Tags)
Retrieve the tags of an already tagged actor.
FIntVector CurrentMapOrigin
CarlaReplayer * GetReplayer(void)
static FString BuildRecastBuilderFile()
static T Get(carla::rpc::Response< T > &response)
ActorDescription description
static ACarlaGameModeBase * GetGameMode(const UObject *WorldContextObject)
static boost::optional< road::Map > Load(const std::string &opendrive)
const FString & GetMapName() const
Return the name of the map loaded in this episode.
geom::BoundingBox bounding_box
void CreateRecorderEventAdd(uint32_t DatabaseId, uint8_t Type, const FTransform &Transform, FActorDescription ActorDescription)
TMap< FString, FActorAttribute > Variations
User selected variations of the actor.
std::string StartRecorder(std::string name, bool AdditionalData)
static FString GetRelevantTagAsString(const TSet< crp::CityObjectLabel > &SemanticTags)
static UCarlaGameInstance * GetGameInstance(const UObject *WorldContextObject)
carla::SharedPtr< cc::Actor > Actor
crp::Actor SerializedData
TPair< EActorSpawnResultStatus, FCarlaActor * > SpawnActorWithInfo(const FTransform &Transform, FActorDescription thisActorDescription, FCarlaActor::IdType DesiredId=0)
Spawns an actor based on ActorDescription at Transform.
bool LoadNewEpisode(const FString &MapString, bool ResetSettings=true)
Load a new map and start a new episode.
const TArray< FActorDefinition > & GetActorDefinitions() const
Return the list of actor definitions that are available to be spawned this episode.
FString Id
Display ID that identifies the actor.
TSubclassOf< AActor > Class
Class of the actor to be spawned.
static FBoundingBox GetActorBoundingBox(const AActor *Actor, uint8 InTagQueried=0xFF)
Compute the bounding box of the given Carla actor.
A description of a Carla Actor with all its variation.
static void log_warning(Args &&... args)
const FActorInfo * GetActorInfo() const
static FString UCarlaEpisode_GetTrafficSignId(ETrafficSignState State)
std::vector< uint8_t > semantic_tags
UCarlaEpisode(const FObjectInitializer &ObjectInitializer)
void AttachActors(AActor *Child, AActor *Parent, EAttachmentType InAttachmentType=EAttachmentType::Rigid)
Attach Child to Parent.
FTransform GlobalToLocalTransform(const FTransform &InTransform) const
ACarlaRecorder * Recorder
static ALargeMapManager * GetLargeMapManager(const UObject *WorldContextObject)
uint32 UId
UId of the definition in which this description was based.
Base class for the CARLA Game Mode.
void InitializeAtBeginPlay()
FEpisodeSettings EpisodeSettings
void Stop(bool KeepActors=false)
IdType GetActorId() const
ETrafficSignState GetTrafficSignState() const
void SetOpendriveGenerationParameters(const carla::rpc::OpendriveGenerationParameters &Parameters)
An actor attribute, may be an intrinsic (non-modifiable) attribute of the actor or an user-defined ac...
geom::Transform Transform
const TArray< FTransform > & GetSpawnPointsTransforms() const
A view over an actor and its properties.
void ApplySettings(const FEpisodeSettings &Settings)