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 "Materials/MaterialParameterCollection.h" 28 #include "Materials/MaterialParameterCollectionInstance.h" 29 #include "Misc/FileHelper.h" 30 #include "Misc/Paths.h" 37 case TSS::TrafficLightRed:
38 case TSS::TrafficLightYellow:
39 case TSS::TrafficLightGreen:
return TEXT(
"traffic.traffic_light");
40 case TSS::SpeedLimit_30:
return TEXT(
"traffic.speed_limit.30");
41 case TSS::SpeedLimit_40:
return TEXT(
"traffic.speed_limit.40");
42 case TSS::SpeedLimit_50:
return TEXT(
"traffic.speed_limit.50");
43 case TSS::SpeedLimit_60:
return TEXT(
"traffic.speed_limit.60");
44 case TSS::SpeedLimit_90:
return TEXT(
"traffic.speed_limit.90");
45 case TSS::SpeedLimit_100:
return TEXT(
"traffic.speed_limit.100");
46 case TSS::SpeedLimit_120:
return TEXT(
"traffic.speed_limit.120");
47 case TSS::SpeedLimit_130:
return TEXT(
"traffic.speed_limit.130");
48 case TSS::StopSign:
return TEXT(
"traffic.stop");
49 case TSS::YieldSign:
return TEXT(
"traffic.yield");
50 default:
return TEXT(
"traffic.unknown");
55 : Super(ObjectInitializer),
58 ActorDispatcher = CreateDefaultSubobject<UActorDispatcher>(TEXT(
"ActorDispatcher"));
64 bool bIsFileFound =
false;
66 FString FinalPath = MapString.IsEmpty() ?
GetMapName() : MapString;
67 FinalPath += !MapString.EndsWith(
".umap") ?
".umap" :
"";
69 if (MapString.StartsWith(
"/Game"))
72 FinalPath.RemoveFromStart(TEXT(
"/Game/"));
73 FinalPath = FPaths::ProjectContentDir() + FinalPath;
74 FinalPath =
IFileManager::Get().ConvertToAbsolutePathForExternalAppForRead(*FinalPath);
76 if (FPaths::FileExists(FinalPath)) {
78 FinalPath = MapString;
83 if (MapString.Contains(
"/"))
return false;
86 TArray<FString> TempStrArray, PathList;
87 IFileManager::Get().FindFilesRecursive(PathList, *FPaths::ProjectContentDir(), *FinalPath,
true,
false,
false);
88 if (PathList.Num() > 0)
90 FinalPath = PathList[0];
91 FinalPath.ParseIntoArray(TempStrArray, TEXT(
"Content/"),
true);
92 FinalPath = TempStrArray[1];
93 FinalPath.ParseIntoArray(TempStrArray, TEXT(
"."),
true);
94 FinalPath =
"/Game/" + TempStrArray[0];
102 UE_LOG(LogCarla, Warning, TEXT(
"Loading a new episode: %s"), *FinalPath);
103 UGameplayStatics::OpenLevel(GetWorld(), *FinalPath,
true);
115 if (SecondaryServer->HasClientsConnected())
117 SecondaryServer->GetCommander().SendLoadMap(std::string(TCHAR_TO_UTF8(*FinalPath)));
129 const FString RecastToolName =
"RecastBuilder.exe";
131 const FString RecastToolName =
"RecastBuilder";
132 #endif // PLATFORM_WINDOWS 135 #if UE_BUILD_SHIPPING 136 const FString AbsoluteRecastBuilderPath = FPaths::ConvertRelativePathToFull(
137 FPaths::RootDir() +
"Tools/" + RecastToolName);
139 const FString AbsoluteRecastBuilderPath = FPaths::ConvertRelativePathToFull(
140 FPaths::ProjectDir() +
"../../Util/DockerUtils/dist/" + RecastToolName);
142 return AbsoluteRecastBuilderPath;
146 const FString &OpenDriveString,
149 if (OpenDriveString.IsEmpty())
151 UE_LOG(LogCarla, Error, TEXT(
"The OpenDrive string is empty."));
157 carla::rpc::FromLongFString(OpenDriveString));
160 if (!CarlaMap.has_value())
162 UE_LOG(LogCarla, Error, TEXT(
"The OpenDrive string is invalid or not supported"));
168 const auto CrosswalksMesh = CarlaMap->GetAllCrosswalkMesh();
169 const auto RecastOBJ = (RoadMesh + CrosswalksMesh).GenerateOBJForRecast();
171 const FString AbsoluteOBJPath = FPaths::ConvertRelativePathToFull(
172 FPaths::ProjectContentDir() +
"Carla/Maps/Nav/OpenDriveMap.obj");
175 FFileHelper::SaveStringToFile(
176 carla::rpc::ToLongFString(RecastOBJ),
178 FFileHelper::EEncodingOptions::ForceUTF8,
181 const FString AbsoluteXODRPath = FPaths::ConvertRelativePathToFull(
182 FPaths::ProjectContentDir() +
"Carla/Maps/OpenDrive/OpenDriveMap.xodr");
185 FFileHelper::SaveStringToFile(
188 FFileHelper::EEncodingOptions::ForceUTF8,
191 if (!FPaths::FileExists(AbsoluteXODRPath))
193 UE_LOG(LogCarla, Error, TEXT(
"ERROR: XODR not copied!"));
209 if (FPaths::FileExists(AbsoluteRecastBuilderPath) &&
214 FPlatformProcess::CreateProc(
215 *AbsoluteRecastBuilderPath, *AbsoluteOBJPath,
216 true,
true,
true,
nullptr, 0,
nullptr,
nullptr);
220 UE_LOG(LogCarla, Warning, TEXT(
"'RecastBuilder' not present under '%s', " 221 "the binaries for pedestrian navigation will not be created."),
222 *AbsoluteRecastBuilderPath);
233 UE_LOG(LogCarla, Warning, TEXT(
"Setting ActorActiveDistance is smaller that TileStreamingDistance, TileStreamingDistance will be increased"));
260 UE_LOG(LogCarla, Warning, TEXT(
"Trying to serialize invalid actor"));
277 SerializedActor.
id = 0u;
279 TSet<crp::CityObjectLabel> SemanticTags;
285 for (
auto &&Tag : SemanticTags)
287 using tag_t = decltype(SerializedActor.
semantic_tags)::value_type;
288 SerializedActor.
semantic_tags.emplace_back(static_cast<tag_t>(Tag));
290 return SerializedActor;
324 auto World = GetWorld();
325 check(World !=
nullptr);
326 auto PlayerController = UGameplayStatics::GetPlayerController(World, 0);
327 if (PlayerController ==
nullptr)
329 UE_LOG(LogCarla, Error, TEXT(
"Can't find player controller!"));
336 Description.
Id = TEXT(
"spectator");
342 UE_LOG(LogCarla, Error, TEXT(
"Can't find spectator!"));
346 UMaterialParameterCollection *Collection = LoadObject<UMaterialParameterCollection>(
nullptr, TEXT(
"/Game/Carla/Blueprints/Game/CarlaParameters.CarlaParameters"),
nullptr, LOAD_None,
nullptr);
347 if (Collection !=
nullptr)
352 UE_LOG(LogCarla, Error, TEXT(
"Can't find CarlaParameters instance!"));
357 UE_LOG(LogCarla, Error, TEXT(
"Can't find CarlaParameters asset!"));
360 for (TActorIterator<ATrafficSignBase> It(World); It; ++It)
363 check(Actor !=
nullptr);
366 Description.
Class = Actor->GetClass();
372 uint32 StaticMeshUId = 0;
373 for (
auto& Definition : Definitions)
375 if (Definition.Id ==
"static.prop.mesh")
377 StaticMeshUId = Definition.UId;
382 for (TActorIterator<AStaticMeshActor> It(World); It; ++It)
385 check(
Actor !=
nullptr);
386 auto MeshComponent =
Actor->GetStaticMeshComponent();
387 check(MeshComponent !=
nullptr);
388 if (MeshComponent->Mobility == EComponentMobility::Movable)
391 Description.
Id = TEXT(
"static.prop.mesh");
392 Description.
UId = StaticMeshUId;
396 MeshComponent->GetStaticMesh()->GetPathName()});
399 FString::SanitizeFloat(MeshComponent->GetMass())});
428 result =
"Recorder is not ready";
453 result.Value->GetActorId(),
454 static_cast<uint8_t
>(result.Value->GetActorType()),
462 result.Value->GetActorId(),
463 static_cast<uint8_t
>(result.Value->GetActorType()),
465 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.
std::shared_ptr< carla::multigpu::Router > GetSecondaryServer()
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)
void SetEpisode(UCarlaEpisode *ThisEpisode)
std::vector< uint8_t > semantic_tags
UCarlaEpisode(const FObjectInitializer &ObjectInitializer)
FFrameData & GetFrameData()
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
FCarlaEngine * GetCarlaEngine()
ETrafficSignState GetTrafficSignState() const
void SetOpendriveGenerationParameters(const carla::rpc::OpendriveGenerationParameters &Parameters)
void CreateRecorderEventAdd(uint32_t DatabaseId, uint8_t Type, const FTransform &Transform, FActorDescription ActorDescription, bool bAddOtherRelatedInfo=true)
An actor attribute, may be an intrinsic (non-modifiable) attribute of the actor or an user-defined ac...
void AddEvent(const CarlaRecorderEventAdd &Event)
UMaterialParameterCollectionInstance * MaterialParameters
geom::Transform Transform
const TArray< FTransform > & GetSpawnPointsTransforms() const
A view over an actor and its properties.
void ApplySettings(const FEpisodeSettings &Settings)