374 BIND_SYNC(get_traffic_manager_running) << [
this] (uint16_t port) ->
R<std::pair<std::string, uint16_t>>
378 return std::pair<std::string, uint16_t>(it->second, it->first);
380 return std::pair<std::string, uint16_t>(
"",0);
384 BIND_SYNC(add_traffic_manager_running) << [
this] (std::pair<std::string, uint16_t> trafficManagerInfo) ->
R<bool>
387 uint16_t port = trafficManagerInfo.second;
391 std::pair<uint16_t, std::string>(port, trafficManagerInfo.first));
411 return carla::version();
429 BIND_SYNC(get_available_maps) << [
this]() ->
R<std::vector<std::string>>
433 std::vector<std::string> result;
434 result.reserve(MapNames.Num());
435 for (
const auto &MapName : MapNames)
437 if (MapName.Contains(
"/Sublevels/"))
439 if (MapName.Contains(
"/BaseMap/"))
441 if (MapName.Contains(
"/BaseLargeMap/"))
443 if (MapName.Contains(
"_Tile_"))
446 result.emplace_back(cr::FromFString(MapName));
451 BIND_SYNC(load_new_episode) << [
this](
const std::string &map_name,
const bool reset_settings, cr::MapLayer MapLayers) ->
R<void>
461 GameInstance->
SetMapLayer(
static_cast<int32
>(MapLayers));
464 const FString MapToLoad = map_name.empty()
466 : cr::ToFString(map_name);
469 FString Str(TEXT(
"Map '"));
470 Str += cr::ToFString(map_name);
471 Str += TEXT(
"' not found");
480 BIND_SYNC(get_content_packs) << [
this]() ->
R<std::vector<cr::ContentPackInfo>>
484 if (ContentPacks ==
nullptr)
488 std::vector<cr::ContentPackInfo> result;
500 if (ContentPacks ==
nullptr)
506 if (!ContentPacks->
Mount(cr::ToFString(path), Error, &Pack))
508 FString Str(TEXT(
"mount_content_pack: "));
515 BIND_SYNC(unmount_content_pack) << [
this](
const std::string &name) ->
R<bool>
520 if (ContentPacks ==
nullptr)
525 if (!ContentPacks->
Unmount(cr::ToFString(name), Error))
527 FString Str(TEXT(
"unmount_content_pack: "));
564 BIND_SYNC(copy_opendrive_to_file) << [
this](
const std::string &opendrive, cr::OpendriveGenerationParameters Params) ->
R<void>
575 BIND_SYNC(apply_texture_to_actor) << [
this](
577 const cr::MaterialParameter& MaterialParameter,
578 const cr::TextureColor& Texture) ->
R<void>
586 BIND_SYNC(apply_texture_to_actor_float) << [
this](
588 const cr::MaterialParameter& MaterialParameter,
589 const cr::TextureFloatColor& Texture) ->
R<void>
597 BIND_SYNC(apply_color_texture_to_objects) << [
this](
598 const std::vector<std::string> &actors_name,
599 const cr::MaterialParameter& parameter,
600 const cr::TextureColor& Texture) ->
R<void>
609 TArray<AActor*> ActorsToPaint;
610 for(
const std::string& actor_name : actors_name)
615 ActorsToPaint.Add(ActorToPaint);
619 if(!ActorsToPaint.Num())
626 for(
AActor* ActorToPaint : ActorsToPaint)
636 BIND_SYNC(apply_float_color_texture_to_objects) << [
this](
637 const std::vector<std::string> &actors_name,
638 const cr::MaterialParameter& parameter,
639 const cr::TextureFloatColor& Texture) ->
R<void>
648 TArray<AActor*> ActorsToPaint;
649 for(
const std::string& actor_name : actors_name)
654 ActorsToPaint.Add(ActorToPaint);
658 if(!ActorsToPaint.Num())
665 for(
AActor* ActorToPaint : ActorsToPaint)
675 BIND_SYNC(get_names_of_all_objects) << [
this]() ->
R<std::vector<std::string>>
684 std::vector<std::string> NamesStd;
685 for (
const FString &Name : NamesFString)
687 NamesStd.emplace_back(cr::FromFString(Name));
706 FString MapDir = FullMapPath.RightChop(FullMapPath.Find(
"Content/", ESearchCase::CaseSensitive) + 8);
709 cr::FromFString(MapDir),
719 BIND_SYNC(get_navigation_mesh) << [
this]() ->
R<std::vector<uint8_t>>
726 return std::vector<uint8_t>{};
732 std::vector<uint8_t> Result(FileContents.Num());
733 memcpy(&Result[0], FileContents.GetData(), FileContents.Num());
737 BIND_SYNC(get_required_files) << [
this](std::string folder =
"") ->
R<std::vector<std::string>>
742 if (!folder.empty() && folder[folder.size() - 1] !=
'/' && folder[folder.size() - 1] !=
'\\') {
749 const auto folderDir = mapDir +
"/" + folder.c_str();
757 const bool bGeneratedWorld =
Episode->
GetMapName().Equals(TEXT(
"OpenDriveMap"), ESearchCase::IgnoreCase);
758 TArray<FString> Files;
759 if (!bGeneratedWorld)
761 IFileManager::Get().FindFilesRecursive(Files, *folderDir, *(fileName +
".xodr"),
true,
false,
false);
762 IFileManager::Get().FindFilesRecursive(Files, *folderDir, *(fileName +
".bin"),
true,
false,
false);
767 if (!bGeneratedWorld && MapPacks !=
nullptr)
769 const auto KindOf = [](
const FString &InFile,
const FString &Root)
771 FString Relative = FPaths::ConvertRelativePathToFull(InFile);
772 Relative.RemoveFromStart(Root / TEXT(
""));
774 if (!Relative.Split(TEXT(
"/"), &Kind, &Rest))
778 return Kind.ToLower() + TEXT(
"|") + FPaths::GetExtension(InFile).ToLower();
780 TSet<FString> FoundKinds;
781 for (
const FString &File : Files)
783 FoundKinds.Add(KindOf(File, mapDir));
788 if (!Pack.bMounted || !Pack.Manifest.GetMapNames().Contains(MapName))
792 const FString PackMapsDir = Pack.ContentDir / TEXT(
"Maps");
793 const FString PackFolderDir = PackMapsDir / UTF8_TO_TCHAR(folder.c_str());
794 TArray<FString> PackFiles;
795 IFileManager::Get().FindFilesRecursive(PackFiles, *PackFolderDir, *(MapName + TEXT(
".xodr")),
true,
false,
false);
796 IFileManager::Get().FindFilesRecursive(PackFiles, *PackFolderDir, *(MapName + TEXT(
".bin")),
true,
false,
false);
797 for (
const FString &File : PackFiles)
799 const FString Kind = KindOf(File, PackMapsDir);
800 if (!FoundKinds.Contains(Kind))
802 FoundKinds.Add(Kind);
812 const FString SavedDir = FPaths::ConvertRelativePathToFull(FPaths::ProjectSavedDir()) / TEXT(
"");
815 const FString Folder = UTF8_TO_TCHAR(folder.c_str());
816 const bool bWantXODR = Folder.IsEmpty() || Folder.StartsWith(TEXT(
"OpenDrive"), ESearchCase::IgnoreCase);
817 const bool bWantNav = Folder.IsEmpty() || Folder.StartsWith(TEXT(
"Nav"), ESearchCase::IgnoreCase);
827 const FString SavedNav = SavedDir / TEXT(
"Nav") / (
Episode->
GetMapName() + TEXT(
".bin"));
828 if (bWantXODR && IFileManager::Get().FileExists(*SavedXODR)) Files.Add(SavedXODR);
829 if (bWantNav && !
bIsSecondaryServer && IFileManager::Get().FileExists(*SavedNav)) Files.Add(SavedNav);
841 const FString ContentDir = FPaths::ConvertRelativePathToFull(FPaths::ProjectContentDir()) / TEXT(
"");
843 std::vector<std::string> result;
844 for (
auto File : Files) {
845 File = FPaths::ConvertRelativePathToFull(File);
846 if (File.StartsWith(SavedDir) && File.EndsWith(TEXT(
".xodr")))
849 File = TEXT(
"Carla/Maps/OpenDrive") / FPaths::GetCleanFilename(File);
851 else if (File.StartsWith(SavedDir))
853 File.RemoveFromStart(SavedDir);
854 File = TEXT(
"Carla/Maps") / File;
856 else if (File.StartsWith(ContentDir))
858 File.RemoveFromStart(ContentDir);
860 else if (ContentPacks !=
nullptr)
864 const FString PackContentDir = Pack.ContentDir / TEXT(
"");
865 if (Pack.bMounted && File.StartsWith(PackContentDir))
867 File.RemoveFromStart(PackContentDir);
868 File = FString::Printf(TEXT(
"Packs/%s"), *Pack.GetName()) / File;
873 result.emplace_back(TCHAR_TO_UTF8(*File));
878 BIND_SYNC(request_file) << [
this](std::string name) ->
R<std::vector<uint8_t>>
885 const FString ContentDir = FPaths::ConvertRelativePathToFull(FPaths::ProjectContentDir());
886 FString path = ContentDir;
887 path.Append(name.c_str());
888 path = FPaths::ConvertRelativePathToFull(path);
889 if (!path.StartsWith(ContentDir))
901 Rest.RemoveFromStart(ContentDir);
902 FString PackName, PackRelative;
903 FString SavedRelative = Rest;
904 if (Rest.RemoveFromStart(TEXT(
"Packs/")) && Rest.Split(TEXT(
"/"), &PackName, &PackRelative))
908 if (Pack !=
nullptr && Pack->
bMounted)
910 const FString PackContentDir = Pack->
ContentDir / TEXT(
"");
911 const FString PackPath = FPaths::ConvertRelativePathToFull(PackContentDir / PackRelative);
912 if (!PackPath.StartsWith(PackContentDir))
914 RESPOND_ERROR(
"file requested outside the content pack folder");
919 else if (SavedRelative.RemoveFromStart(TEXT(
"Carla/Maps/")) &&
920 (SavedRelative.StartsWith(TEXT(
"OpenDrive/")) || SavedRelative.StartsWith(TEXT(
"Nav/"))))
922 const FString SavedDir = FPaths::ConvertRelativePathToFull(FPaths::ProjectSavedDir()) / TEXT(
"");
927 (FPaths::GetPath(SavedRelative) == TEXT(
"OpenDrive")) &&
928 FPaths::GetExtension(SavedRelative).Equals(TEXT(
"xodr"), ESearchCase::IgnoreCase);
929 const FString SavedPath = bOwnXODR ?
931 FPaths::ConvertRelativePathToFull(SavedDir / SavedRelative);
932 if (SavedPath.StartsWith(SavedDir) && IFileManager::Get().FileExists(*SavedPath) &&
941 TArray<uint8_t> Content;
942 FFileHelper::LoadFileToArray(Content, *path, 0);
943 std::vector<uint8_t> Result(Content.Num());
944 memcpy(&Result[0], Content.GetData(), Content.Num());
955 BIND_SYNC(set_episode_settings) << [
this](
956 const cr::EpisodeSettings &settings) ->
R<uint64_t>
976 TrafficLightManager->SetAdjustSignsHeightToGround(
977 settings.adjust_signs_height_to_ground);
983 BIND_SYNC(get_actor_definitions) << [
this]() ->
R<std::vector<cr::ActorDefinition>>
1000 BIND_SYNC(get_all_level_BBs) << [
this](uint8 QueriedTag) ->
R<std::vector<cg::BoundingBox>>
1003 TArray<FBoundingBox> Result;
1013 for(
auto& Box : Result)
1021 BIND_SYNC(get_environment_objects) << [
this](uint8 QueriedTag) ->
R<std::vector<cr::EnvironmentObject>>
1033 for(
auto& Object : Result)
1041 BIND_SYNC(enable_environment_objects) << [
this](std::vector<uint64_t> EnvObjectIds,
bool Enable) ->
R<void>
1051 TSet<uint64> EnvObjectIdsSet;
1052 for(uint64 Id : EnvObjectIds)
1054 EnvObjectIdsSet.Emplace(Id);
1069 UE_LOG(LogCarla, Log, TEXT(
"internal error: unable to find weather:: weather is disabled"));
1070 return cr::WeatherParameters();
1072 return Weather->GetCurrentWeather();
1075 BIND_SYNC(set_weather_parameters) << [
this](
1076 const cr::WeatherParameters &weather) ->
R<void>
1083 RESPOND_ERROR(
"set_weather_parameters internal error: unable to find weather:: weather is disabled");
1085 Weather->ApplyWeather(weather);
1094 const cr::TextureFloatColor &panorama,
float intensity, int32_t face_size) ->
R<void>
1098 if (panorama.GetWidth() < 2 || panorama.GetHeight() < 2)
1100 RESPOND_ERROR(
"set_sky_light_map: panorama must be at least 2x2");
1102 static_assert(
sizeof(cr::FloatColor) == 4 *
sizeof(float),
"FloatColor must be 4 packed floats");
1104 reinterpret_cast<const float*
>(panorama.GetDataPtr()),
1105 int32(panorama.GetWidth()), int32(panorama.GetHeight()),
1106 face_size > 0 ? face_size : 512);
1107 if (Cubemap ==
nullptr)
1109 RESPOND_ERROR(
"set_sky_light_map: could not build the cubemap");
1113 RESPOND_ERROR(
"set_sky_light_map: no sky rig (ASkyBase) in the level");
1138 return GameMode->IMUSensorGravity;
1146 GameMode->IMUSensorGravity = new_imu_gravity;
1165 #if defined(WITH_ROS2)
1169 if (ROS2 && ROS2->IsEnabled()) {
1170 ROS2->SetPublishTF(publish_tf);
1175 RESPOND_ERROR(
"set_publish_tf: Server was compiled without ROS2 support");
1181 #if defined(WITH_ROS2)
1184 if (ROS2 && ROS2->IsEnabled()) {
1185 return ROS2->GetPublishTF();
1193 BIND_SYNC(get_ego_spawn_points) << [
this]() ->
R<std::vector<carla::geom::Transform>>
1204 const std::vector<FCarlaActor::IdType> &ids) ->
R<std::vector<cr::Actor>>
1207 std::vector<cr::Actor> Result;
1208 Result.reserve(ids.size());
1209 for (
auto &&Id : ids)
1221 cr::ActorDescription Description,
1229 if (Result.Key != EActorSpawnResultStatus::Success)
1231 UE_LOG(LogCarla, Error, TEXT(
"Actor not Spawned"));
1245 return SerializedActor;
1248 BIND_SYNC(spawn_actor_with_parent) << [
this](
1249 cr::ActorDescription Description,
1251 cr::ActorId ParentId,
1258 if (Result.Key != EActorSpawnResultStatus::Success)
1266 RESPOND_ERROR(
"internal error: actor could not be spawned");
1271 if (!ParentCarlaActor)
1273 RESPOND_ERROR(
"unable to attach actor: parent actor not found");
1298 return SerializedActor;
1310 UE_LOG(LogCarla, Log, TEXT(
"CarlaServer destroy_actor %d"), ActorId);
1311 std::optional<carla::streaming::detail::stream_id_type> SensorStreamId;
1335 APlayerController* PController= UGameplayStatics::GetPlayerController(
Episode->GetWorld(), 0);
1338 auto result = PController->ConsoleCommand(UTF8_TO_TCHAR(cmd.c_str()),
true);
1340 result.Contains(FString(TEXT(
"Command not recognized"))) ||
1341 result.Contains(FString(TEXT(
"Error")))
1344 bool success =
false;
1346 success = GEngine->Exec(
Episode->GetWorld(), UTF8_TO_TCHAR(cmd.c_str()));
1355 bool ForceInPrimary =
false;
1360 ForceInPrimary =
true;
1366 const bool bOwnWorldObserver = (sensor_id ==
1368 if (!bOwnWorldObserver)
1375 if (Desc ==
"" || Desc ==
"sensor.other.collision")
1377 ForceInPrimary =
true;
1382 if (Desc ==
"sensor.other.v2x" || Desc ==
"sensor.other.v2x_custom")
1384 ForceInPrimary =
true;
1390 UE_LOG(LogCarla, Log, TEXT(
"Sensor %d '%s' created in secondary server"), sensor_id, *Desc);
1392 if (SensorActor ==
nullptr)
1399 RESPOND_ERROR(
"no secondary server could provide a token for this sensor");
1408 UE_LOG(LogCarla, Warning,
1409 TEXT(
"Sensor %d '%s' refused: this server cannot render (-nullrhi) and no secondary server is connected"),
1411 RESPOND_ERROR(
"this server cannot render (-nullrhi) and no rendering secondary server is connected to own this camera sensor");
1413 UE_LOG(LogCarla, Log, TEXT(
"Sensor %d '%s' created in primary server"), sensor_id, *Desc);
1423 bool ForceInPrimary =
false;
1428 ForceInPrimary =
true;
1433 if (Desc ==
"" || Desc ==
"sensor.other.collision")
1435 ForceInPrimary =
true;
1442 if (SensorActor ==
nullptr)
1448 RESPOND_ERROR(
"no secondary server could enable ROS for this sensor");
1456 UE_LOG(LogCarla, Warning,
1457 TEXT(
"ROS 2 for sensor %d '%s' refused: this server cannot render (-nullrhi) and no secondary server is connected"),
1459 RESPOND_ERROR(
"this server cannot render (-nullrhi) and no rendering secondary server is connected to publish this camera sensor");
1471 bool ForceInPrimary =
false;
1476 ForceInPrimary =
true;
1481 if (Desc ==
"" || Desc ==
"sensor.other.collision")
1483 ForceInPrimary =
true;
1503 bool ForceInPrimary =
false;
1508 ForceInPrimary =
true;
1513 if (Desc ==
"" || Desc ==
"sensor.other.collision")
1515 ForceInPrimary =
true;
1531 cr::ActorId ActorId,
1532 cr::CustomV2XBytes Data) ->
R<void>
1542 " Actor Id: " + FString::FromInt(ActorId));
1550 " Actor Id: " + FString::FromInt(ActorId));
1558 " Actor Id: " + FString::FromInt(ActorId));
1567 BIND_SYNC(set_actor_location) << [
this](
1568 cr::ActorId ActorId,
1577 "set_actor_location",
1579 " Actor Id: " + FString::FromInt(ActorId));
1583 Location, ETeleportType::TeleportPhysics);
1587 BIND_SYNC(set_actor_transform) << [
this](
1588 cr::ActorId ActorId,
1597 "set_actor_transform",
1599 " Actor Id: " + FString::FromInt(ActorId));
1603 Transform, ETeleportType::TeleportPhysics);
1608 cr::ActorId ActorId,
1620 " Actor Id: " + FString::FromInt(ActorId));
1634 " Actor Id: " + FString::FromInt(ActorId));
1639 BIND_SYNC(set_actor_target_velocity) << [
this](
1640 cr::ActorId ActorId,
1641 cr::Vector3D vector) ->
R<void>
1649 "set_actor_target_velocity",
1651 " Actor Id: " + FString::FromInt(ActorId));
1658 "set_actor_target_velocity",
1660 " Actor Id: " + FString::FromInt(ActorId));
1665 BIND_SYNC(set_actor_target_angular_velocity) << [
this](
1666 cr::ActorId ActorId,
1667 cr::Vector3D vector) ->
R<void>
1675 "set_actor_target_angular_velocity",
1677 " Actor Id: " + FString::FromInt(ActorId));
1684 "set_actor_target_angular_velocity",
1686 " Actor Id: " + FString::FromInt(ActorId));
1691 BIND_SYNC(enable_actor_constant_velocity) << [
this](
1692 cr::ActorId ActorId,
1693 cr::Vector3D vector) ->
R<void>
1701 "enable_actor_constant_velocity",
1703 " Actor Id: " + FString::FromInt(ActorId));
1711 "enable_actor_constant_velocity",
1713 " Actor Id: " + FString::FromInt(ActorId));
1719 BIND_SYNC(disable_actor_constant_velocity) << [
this](
1720 cr::ActorId ActorId) ->
R<void>
1728 "disable_actor_constant_velocity",
1730 " Actor Id: " + FString::FromInt(ActorId));
1738 "disable_actor_constant_velocity",
1740 " Actor Id: " + FString::FromInt(ActorId));
1746 BIND_SYNC(enable_actor_constant_acceleration) << [
this](
1747 cr::ActorId ActorId,
1748 cr::Vector3D vector) ->
R<void>
1756 "enable_actor_constant_acceleration",
1758 " Actor Id: " + FString::FromInt(ActorId));
1766 "enable_actor_constant_acceleration",
1768 " Actor Id: " + FString::FromInt(ActorId));
1774 BIND_SYNC(disable_actor_constant_acceleration) << [
this](
1775 cr::ActorId ActorId) ->
R<void>
1783 "disable_actor_constant_acceleration",
1785 " Actor Id: " + FString::FromInt(ActorId));
1793 "disable_actor_constant_acceleration",
1795 " Actor Id: " + FString::FromInt(ActorId));
1802 cr::ActorId ActorId,
1803 cr::Vector3D vector) ->
R<void>
1811 "add_actor_impulse",
1813 " Actor Id: " + FString::FromInt(ActorId));
1821 "add_actor_impulse",
1823 " Actor Id: " + FString::FromInt(ActorId));
1828 BIND_SYNC(add_actor_impulse_at_location) << [
this](
1829 cr::ActorId ActorId,
1830 cr::Vector3D impulse,
1831 cr::Vector3D location) ->
R<void>
1839 "add_actor_impulse_at_location",
1841 " Actor Id: " + FString::FromInt(ActorId));
1843 FVector UELocation = location.ToCentimeters().ToFVector();
1855 "add_actor_impulse_at_location",
1857 " Actor Id: " + FString::FromInt(ActorId));
1864 cr::ActorId ActorId,
1865 cr::Vector3D vector) ->
R<void>
1875 " Actor Id: " + FString::FromInt(ActorId));
1878 CarlaActor->
AddActorForce(vector.ToCentimeters().ToFVector());
1884 " Actor Id: " + FString::FromInt(ActorId));
1889 BIND_SYNC(add_actor_force_at_location) << [
this](
1890 cr::ActorId ActorId,
1892 cr::Vector3D location) ->
R<void>
1900 "add_actor_force_at_location",
1902 " Actor Id: " + FString::FromInt(ActorId));
1904 FVector UELocation = location.ToCentimeters().ToFVector();
1916 "add_actor_force_at_location",
1918 " Actor Id: " + FString::FromInt(ActorId));
1923 BIND_SYNC(add_actor_angular_impulse) << [
this](
1924 cr::ActorId ActorId,
1925 cr::Vector3D vector) ->
R<void>
1933 "add_actor_angular_impulse",
1935 " Actor Id: " + FString::FromInt(ActorId));
1942 "add_actor_angular_impulse",
1944 " Actor Id: " + FString::FromInt(ActorId));
1950 cr::ActorId ActorId,
1951 cr::Vector3D vector) ->
R<void>
1961 " Actor Id: " + FString::FromInt(ActorId));
1970 " Actor Id: " + FString::FromInt(ActorId));
1975 BIND_SYNC(get_actor_component_world_transform) << [
this](
1976 cr::ActorId ActorId,
1984 "get_actor_component_world_transform",
1986 " Actor Id: " + FString::FromInt(ActorId));
1989 const FString TargetName(UTF8_TO_TCHAR(component_name.c_str()));
1995 "get_actor_component_world_transform",
1997 " Component Name: " + TargetName);
2002 BIND_SYNC(get_actor_component_relative_transform) << [
this](
2003 cr::ActorId ActorId,
2011 "get_actor_component_relative_transform",
2013 " Actor Id: " + FString::FromInt(ActorId));
2016 const FString TargetName(UTF8_TO_TCHAR(component_name.c_str()));
2022 "get_actor_component_relative_transform",
2024 " Component Name: " + TargetName);
2029 BIND_SYNC(get_actor_bone_world_transforms) << [
this](
2030 cr::ActorId ActorId) ->
R<std::vector<cr::Transform>>
2037 "get_actor_bone_world_transforms",
2039 " Actor Id: " + FString::FromInt(ActorId));
2042 TArray<FTransform> Transforms;
2047 "get_actor_bone_world_transforms",
2049 " Actor Id: " + FString::FromInt(ActorId));
2054 BIND_SYNC(get_actor_bone_relative_transforms) << [
this](
2055 cr::ActorId ActorId) ->
R<std::vector<cr::Transform>>
2062 "get_actor_bone_relative_transforms",
2064 " Actor Id: " + FString::FromInt(ActorId));
2067 TArray<FTransform> Transforms;
2072 "get_actor_bone_relative_transforms",
2074 " Actor Id: " + FString::FromInt(ActorId));
2079 BIND_SYNC(get_actor_component_names) << [
this](
2080 cr::ActorId ActorId) ->
R<std::vector<std::string>>
2087 "get_actor_component_names",
2089 " Actor Id: " + FString::FromInt(ActorId));
2092 TArray<FString> Names;
2097 "get_actor_component_names",
2099 " Actor Id: " + FString::FromInt(ActorId));
2104 BIND_SYNC(get_actor_bone_names) << [
this](
2105 cr::ActorId ActorId) ->
R<std::vector<std::string>>
2112 "get_actor_bone_names",
2114 " Actor Id: " + FString::FromInt(ActorId));
2117 TArray<FString> Names;
2122 "get_actor_bone_names",
2124 " Actor Id: " + FString::FromInt(ActorId));
2129 BIND_SYNC(get_actor_socket_world_transforms) << [
this](
2130 cr::ActorId ActorId) ->
R<std::vector<cr::Transform>>
2137 "get_actor_socket_world_transforms",
2139 " Actor Id: " + FString::FromInt(ActorId));
2142 TArray<FTransform> Transforms;
2147 "get_actor_socket_world_transforms",
2149 " Actor Id: " + FString::FromInt(ActorId));
2154 BIND_SYNC(get_actor_socket_relative_transforms) << [
this](
2155 cr::ActorId ActorId) ->
R<std::vector<cr::Transform>>
2162 "get_actor_socket_relative_transforms",
2164 " Actor Id: " + FString::FromInt(ActorId));
2167 TArray<FTransform> Transforms;
2172 "get_actor_socket_relative_transforms",
2174 " Actor Id: " + FString::FromInt(ActorId));
2179 BIND_SYNC(get_actor_socket_names) << [
this](
2180 cr::ActorId ActorId) ->
R<std::vector<std::string>>
2187 "get_actor_socket_names",
2189 " Actor Id: " + FString::FromInt(ActorId));
2192 TArray<FString> Names;
2197 "get_actor_socket_names",
2199 " Actor Id: " + FString::FromInt(ActorId));
2204 BIND_SYNC(get_physics_control) << [
this](
2212 "get_physics_control",
2214 " Actor Id: " + FString::FromInt(ActorId));
2222 "get_physics_control",
2224 " Actor Id: " + FString::FromInt(ActorId));
2226 return cr::VehiclePhysicsControl::FromFVehiclePhysicsControl(
PhysicsControl);
2229 BIND_SYNC(get_telemetry_data) << [
this](
2238 "get_telemetry_data",
2240 " Actor Id: " + FString::FromInt(ActorId));
2248 "get_telemetry_data",
2250 " Actor Id: " + FString::FromInt(ActorId));
2252 return cr::VehicleTelemetryData(TelemetryData);
2255 BIND_SYNC(get_vehicle_light_state) << [
this](
2263 "get_vehicle_light_state",
2265 " Actor Id: " + FString::FromInt(ActorId));
2273 "get_vehicle_light_state",
2275 " Actor Id: " + FString::FromInt(ActorId));
2277 return cr::VehicleLightState(LightState);
2280 BIND_SYNC(apply_physics_control) << [
this](
2281 cr::ActorId ActorId,
2290 "apply_physics_control",
2292 " Actor Id: " + FString::FromInt(ActorId));
2299 "apply_physics_control",
2301 " Actor Id: " + FString::FromInt(ActorId));
2306 BIND_SYNC(set_vehicle_light_state) << [
this](
2307 cr::ActorId ActorId,
2308 cr::VehicleLightState LightState) ->
R<void>
2316 "set_vehicle_light_state",
2318 " Actor Id: " + FString::FromInt(ActorId));
2325 "set_vehicle_light_state",
2327 " Actor Id: " + FString::FromInt(ActorId));
2334 cr::ActorId ActorId,
2335 cr::VehicleDoor DoorIdx) ->
R<void>
2343 "open_vehicle_door",
2345 " Actor Id: " + FString::FromInt(ActorId));
2352 "open_vehicle_door",
2354 " Actor Id: " + FString::FromInt(ActorId));
2359 BIND_SYNC(close_vehicle_door) << [
this](
2360 cr::ActorId ActorId,
2361 cr::VehicleDoor DoorIdx) ->
R<void>
2369 "close_vehicle_door",
2371 " Actor Id: " + FString::FromInt(ActorId));
2378 "close_vehicle_door",
2380 " Actor Id: " + FString::FromInt(ActorId));
2385 BIND_SYNC(set_wheel_steer_direction) << [
this](
2386 cr::ActorId ActorId,
2387 cr::VehicleWheelLocation WheelLocation,
2395 "set_wheel_steer_direction",
2397 " Actor Id: " + FString::FromInt(ActorId));
2405 "set_wheel_steer_direction",
2407 " Actor Id: " + FString::FromInt(ActorId));
2412 BIND_SYNC(get_wheel_steer_angle) << [
this](
2413 const cr::ActorId ActorId,
2414 cr::VehicleWheelLocation WheelLocation) ->
R<float>
2420 "get_wheel_steer_angle",
2422 " Actor Id: " + FString::FromInt(ActorId));
2431 "get_wheel_steer_angle",
2433 " Actor Id: " + FString::FromInt(ActorId));
2438 BIND_SYNC(set_wheel_pitch_angle) << [
this](
2439 cr::ActorId ActorId,
2440 cr::VehicleWheelLocation WheelLocation,
2448 "set_wheel_pitch_angle",
2450 " Actor Id: " + FString::FromInt(ActorId));
2458 "set_wheel_pitch_angle",
2460 " Actor Id: " + FString::FromInt(ActorId));
2465 BIND_SYNC(get_wheel_pitch_angle) << [
this](
2466 const cr::ActorId ActorId,
2467 cr::VehicleWheelLocation WheelLocation) ->
R<float>
2473 "get_wheel_pitch_angle",
2475 " Actor Id: " + FString::FromInt(ActorId));
2484 "get_wheel_pitch_angle",
2486 " Actor Id: " + FString::FromInt(ActorId));
2491 BIND_SYNC(set_wheel_suspension_offset) << [
this](
2492 cr::ActorId ActorId,
2493 cr::VehicleWheelLocation WheelLocation,
2501 "set_wheel_suspension_offset",
2503 " Actor Id: " + FString::FromInt(ActorId));
2511 "set_wheel_suspension_offset",
2513 " Actor Id: " + FString::FromInt(ActorId));
2518 BIND_SYNC(get_wheel_suspension_offset) << [
this](
2519 const cr::ActorId ActorId,
2520 cr::VehicleWheelLocation WheelLocation) ->
R<float>
2526 "get_wheel_suspension_offset",
2528 " Actor Id: " + FString::FromInt(ActorId));
2537 "get_wheel_suspension_offset",
2539 " Actor Id: " + FString::FromInt(ActorId));
2544 BIND_SYNC(set_wheel_animation_override) << [
this](
2545 cr::ActorId ActorId,
2553 "set_wheel_animation_override",
2555 " Actor Id: " + FString::FromInt(ActorId));
2561 "set_wheel_animation_override",
2563 " Actor Id: " + FString::FromInt(ActorId));
2568 BIND_SYNC(set_actor_simulate_physics) << [
this](
2569 cr::ActorId ActorId,
2578 "set_actor_simulate_physics",
2580 " Actor Id: " + FString::FromInt(ActorId));
2587 "set_actor_simulate_physics",
2589 " Actor Id: " + FString::FromInt(ActorId));
2594 BIND_SYNC(set_actor_collisions) << [
this](
2595 cr::ActorId ActorId,
2604 "set_actor_collisions",
2606 " Actor Id: " + FString::FromInt(ActorId));
2613 "set_actor_collisions",
2615 " Actor Id: " + FString::FromInt(ActorId));
2621 cr::ActorId ActorId) ->
R<void>
2631 " Actor Id: " + FString::FromInt(ActorId));
2640 " Actor Id: " + FString::FromInt(ActorId));
2645 BIND_SYNC(set_actor_enable_gravity) << [
this](
2646 cr::ActorId ActorId,
2655 "set_actor_enable_gravity",
2657 " Actor Id: " + FString::FromInt(ActorId));
2664 "set_actor_enable_gravity",
2666 " Actor Id: " + FString::FromInt(ActorId));
2671 BIND_SYNC(get_vehicle_bone_world_transforms) << [
this](
2672 cr::ActorId ActorId) ->
R<std::vector<cr::Transform>>
2679 "get_vehicle_bone_world_transforms",
2681 " Actor Id: " + FString::FromInt(ActorId));
2683 TArray<FTransform> Transforms;
2688 "get_vehicle_bone_world_transforms",
2690 " Actor Id: " + FString::FromInt(ActorId));
2697 BIND_SYNC(apply_control_to_vehicle) << [
this](
2698 cr::ActorId ActorId,
2699 cr::VehicleControl Control) ->
R<void>
2707 "apply_control_to_vehicle",
2709 " Actor Id: " + FString::FromInt(ActorId));
2716 "apply_control_to_vehicle",
2718 " Actor Id: " + FString::FromInt(ActorId));
2723 BIND_SYNC(apply_ackermann_control_to_vehicle) << [
this](
2724 cr::ActorId ActorId,
2725 cr::VehicleAckermannControl Control) ->
R<void>
2733 "apply_ackermann_control_to_vehicle",
2735 " Actor Id: " + FString::FromInt(ActorId));
2742 "apply_ackermann_control_to_vehicle",
2744 " Actor Id: " + FString::FromInt(ActorId));
2749 BIND_SYNC(get_ackermann_controller_settings) << [
this](
2757 "get_ackermann_controller_settings",
2759 " Actor Id: " + FString::FromInt(ActorId));
2767 "get_ackermann_controller_settings",
2769 " Actor Id: " + FString::FromInt(ActorId));
2771 return cr::AckermannControllerSettings(Settings);
2774 BIND_SYNC(apply_ackermann_controller_settings) << [
this](
2775 cr::ActorId ActorId,
2776 cr::AckermannControllerSettings AckermannSettings) ->
R<void>
2784 "apply_ackermann_controller_settings",
2786 " Actor Id: " + FString::FromInt(ActorId));
2793 "apply_ackermann_controller_settings",
2795 " Actor Id: " + FString::FromInt(ActorId));
2800 BIND_SYNC(apply_control_to_walker) << [
this](
2801 cr::ActorId ActorId,
2802 cr::WalkerControl Control) ->
R<void>
2810 "apply_control_to_walker",
2812 " Actor Id: " + FString::FromInt(ActorId));
2819 "apply_control_to_walker",
2821 " Actor Id: " + FString::FromInt(ActorId));
2826 BIND_SYNC(get_bones_transform) << [
this](
2834 "get_bones_transform",
2836 " Actor Id: " + FString::FromInt(ActorId));
2844 "get_bones_transform",
2846 " Actor Id: " + FString::FromInt(ActorId));
2849 std::vector<carla::rpc::BoneTransformDataOut> BoneData;
2853 Data.
bone_name = std::string(TCHAR_TO_UTF8(*Bone.Get<0>()));
2858 BoneData.push_back(Data);
2863 BIND_SYNC(set_bones_transform) << [
this](
2864 cr::ActorId ActorId,
2873 "set_bones_transform",
2875 " Actor Id: " + FString::FromInt(ActorId));
2883 "set_bones_transform",
2885 " Actor Id: " + FString::FromInt(ActorId));
2897 return (NavSubsystem !=
nullptr) && NavSubsystem->HasServerSideNavigation();
2905 const cr::Location Sentinel{0.0f, 0.0f, -1e6f};
2907 if (NavSubsystem ==
nullptr)
2912 if (!NavSubsystem->GetRandomNavLocation(
Location))
2928 const auto EnsureWalkerNavigationStarted =
2931 if (Controller ==
nullptr)
2935 if (Controller->IsNavigationActive())
2937 return Controller->StartNavigation();
2942 BIND_SYNC(walker_start_navigation) << [
this, EnsureWalkerNavigationStarted](
2943 cr::ActorId ActorId) ->
R<bool>
2948 return EnsureWalkerNavigationStarted(
Episode, Controller);
2951 BIND_SYNC(walker_go_to_location) << [
this, EnsureWalkerNavigationStarted](
2952 cr::ActorId ActorId,
2958 if (!EnsureWalkerNavigationStarted(
Episode, Controller))
2969 return Controller->GoToNavLocation(UELocation);
2972 BIND_SYNC(walker_set_max_speed) << [
this](
2973 cr::ActorId ActorId,
2974 float SpeedMPerSec) ->
R<bool>
2979 constexpr float MeterToCentimeter = 100.0f;
2980 return (Controller !=
nullptr) &&
2981 Controller->SetNavMaxSpeed(MeterToCentimeter * SpeedMPerSec);
2984 BIND_SYNC(walker_stop_navigation) << [
this](cr::ActorId ActorId) ->
R<bool>
2989 return (Controller !=
nullptr) && Controller->StopNavigation();
2992 BIND_SYNC(set_pedestrians_cross_factor) << [
this](
float CrossFactor) ->
R<bool>
3011 cr::ActorId ActorId,
3022 " Actor Id: " + FString::FromInt(ActorId));
3031 " Actor Id: " + FString::FromInt(ActorId));
3037 BIND_SYNC(get_pose_from_animation) << [
this](
3038 cr::ActorId ActorId) ->
R<void>
3046 "get_pose_from_animation",
3048 " Actor Id: " + FString::FromInt(ActorId));
3055 "get_pose_from_animation",
3057 " Actor Id: " + FString::FromInt(ActorId));
3063 BIND_SYNC(set_actor_autopilot) << [
this](
3064 cr::ActorId ActorId,
3073 "set_actor_autopilot",
3075 " Actor Id: " + FString::FromInt(ActorId));
3082 "set_actor_autopilot",
3084 " Actor Id: " + FString::FromInt(ActorId));
3089 BIND_SYNC(show_vehicle_debug_telemetry) << [
this](
3090 cr::ActorId ActorId,
3099 "show_vehicle_debug_telemetry",
3101 " Actor Id: " + FString::FromInt(ActorId));
3108 "show_vehicle_debug_telemetry",
3110 " Actor Id: " + FString::FromInt(ActorId));
3116 cr::ActorId ActorId,
3117 std::string SimfilePath) ->
R<void>
3127 " Actor Id: " + FString::FromInt(ActorId));
3130 CarlaActor->
EnableCarSim(carla::rpc::ToFString(SimfilePath));
3136 " Actor Id: " + FString::FromInt(ActorId));
3142 cr::ActorId ActorId,
3153 " Actor Id: " + FString::FromInt(ActorId));
3162 " Actor Id: " + FString::FromInt(ActorId));
3167 BIND_SYNC(enable_chrono_physics) << [
this](
3168 cr::ActorId ActorId,
3169 uint64_t MaxSubsteps,
3170 float MaxSubstepDeltaTime,
3171 std::string VehicleJSON,
3172 std::string PowertrainJSON,
3173 std::string TireJSON,
3174 std::string BaseJSONPath) ->
R<void>
3182 "enable_chrono_physics",
3184 " Actor Id: " + FString::FromInt(ActorId));
3188 MaxSubsteps, MaxSubstepDeltaTime,
3189 cr::ToFString(VehicleJSON),
3190 cr::ToFString(PowertrainJSON),
3191 cr::ToFString(TireJSON),
3192 cr::ToFString(BaseJSONPath));
3196 "enable_chrono_physics",
3198 " Actor Id: " + FString::FromInt(ActorId));
3205 BIND_SYNC(set_traffic_light_state) << [
this](
3206 cr::ActorId ActorId,
3207 cr::TrafficLightState trafficLightState) ->
R<void>
3215 "set_traffic_light_state",
3217 " Actor Id: " + FString::FromInt(ActorId));
3225 "set_traffic_light_state",
3227 " Actor Id: " + FString::FromInt(ActorId));
3232 BIND_SYNC(set_traffic_light_green_time) << [
this](
3233 cr::ActorId ActorId,
3242 "set_traffic_light_green_time",
3244 " Actor Id: " + FString::FromInt(ActorId));
3251 "set_traffic_light_green_time",
3253 " Actor Id: " + FString::FromInt(ActorId));
3258 BIND_SYNC(set_traffic_light_yellow_time) << [
this](
3259 cr::ActorId ActorId,
3268 "set_traffic_light_yellow_time",
3270 " Actor Id: " + FString::FromInt(ActorId));
3277 "set_traffic_light_yellow_time",
3279 " Actor Id: " + FString::FromInt(ActorId));
3284 BIND_SYNC(set_traffic_light_red_time) << [
this](
3285 cr::ActorId ActorId,
3294 "set_traffic_light_red_time",
3296 " Actor Id: " + FString::FromInt(ActorId));
3303 "set_traffic_light_red_time",
3305 " Actor Id: " + FString::FromInt(ActorId));
3310 BIND_SYNC(freeze_traffic_light) << [
this](
3311 cr::ActorId ActorId,
3320 "freeze_traffic_light",
3322 " Actor Id: " + FString::FromInt(ActorId));
3329 "freeze_traffic_light",
3331 " Actor Id: " + FString::FromInt(ActorId));
3336 BIND_SYNC(reset_traffic_light_group) << [
this](
3337 cr::ActorId ActorId) ->
R<void>
3345 "reset_traffic_light_group",
3347 " Actor Id: " + FString::FromInt(ActorId));
3354 "reset_traffic_light_group",
3356 " Actor Id: " + FString::FromInt(ActorId));
3365 for (TActorIterator<ATrafficLightGroup> It(
Episode->GetWorld()); It; ++It)
3372 BIND_SYNC(freeze_all_traffic_lights) << [
this]
3382 auto* TraffiLightManager = GameMode->GetTrafficLightManager();
3383 TraffiLightManager->SetFrozen(frozen);
3390 cr::VehicleLightStateList List;
3410 cr::VehicleLightState(
Vehicle->GetVehicleLightState()).GetLightStateAsValue());
3418 BIND_SYNC(get_group_traffic_lights) << [
this](
3419 const cr::ActorId ActorId) ->
R<std::vector<cr::ActorId>>
3425 RESPOND_ERROR(
"unable to get group traffic lights: actor not found");
3430 return std::vector<cr::ActorId>();
3437 RESPOND_ERROR(
"unable to get group traffic lights: actor is not a traffic light");
3439 std::vector<cr::ActorId> Result;
3440 for (
auto* TLight :
TrafficLight->GetGroupTrafficLights())
3445 Result.push_back(View->GetActorId());
3453 const cr::ActorId ActorId) ->
R<std::vector<cg::BoundingBox>>
3462 " Actor Id: " + FString::FromInt(ActorId));
3469 " Actor Id: " + FString::FromInt(ActorId));
3479 " Actor Id: " + FString::FromInt(ActorId));
3481 TArray<FBoundingBox> Result;
3482 TArray<uint8> OutTag;
3491 BIND_SYNC(get_gbuffer_token) << [
this](
const cr::ActorId ActorId, uint32_t GBufferId) ->
R<std::vector<unsigned char>>
3499 "get_gbuffer_token",
3501 " Actor Id: " + FString::FromInt(ActorId));
3506 "get_gbuffer_token",
3508 " Actor Id: " + FString::FromInt(ActorId));
3514 "get_gbuffer_token",
3516 " Actor Id: " + FString::FromInt(ActorId));
3518 if (!FApp::CanEverRender())
3521 "get_gbuffer_token",
3522 "this server cannot render (-nullrhi), GBuffer streams are not available",
3523 " Actor Id: " + FString::FromInt(ActorId));
3531 return std::vector<unsigned char>(std::begin(Token.data), std::end(Token.data));
3536 return std::vector<unsigned char>(std::begin(Token.data), std::end(Token.data));
3541 return std::vector<unsigned char>(std::begin(Token.data), std::end(Token.data));
3546 return std::vector<unsigned char>(std::begin(Token.data), std::end(Token.data));
3551 return std::vector<unsigned char>(std::begin(Token.data), std::end(Token.data));
3556 return std::vector<unsigned char>(std::begin(Token.data), std::end(Token.data));
3561 return std::vector<unsigned char>(std::begin(Token.data), std::end(Token.data));
3566 return std::vector<unsigned char>(std::begin(Token.data), std::end(Token.data));
3571 return std::vector<unsigned char>(std::begin(Token.data), std::end(Token.data));
3576 return std::vector<unsigned char>(std::begin(Token.data), std::end(Token.data));
3581 return std::vector<unsigned char>(std::begin(Token.data), std::end(Token.data));
3586 return std::vector<unsigned char>(std::begin(Token.data), std::end(Token.data));
3591 return std::vector<unsigned char>(std::begin(Token.data), std::end(Token.data));
3594 UE_LOG(LogCarla, Error, TEXT(
"Requested invalid GBuffer ID %u"), GBufferId);
3601 BIND_SYNC(start_recorder) << [
this](std::string name,
bool AdditionalData,
bool StopReplayer) ->
R<std::string>
3616 BIND_SYNC(show_recorder_file_info) << [
this](
3626 BIND_SYNC(show_recorder_collisions) << [
this](
3638 BIND_SYNC(show_recorder_actors_blocked) << [
this](
3655 bool replay_sensors,
3656 bool replay_weather,
3657 const cr::Transform& offset,
3673 BIND_SYNC(set_replayer_time_factor) << [
this](
double time_factor) ->
R<void>
3689 BIND_SYNC(set_replayer_ignore_spectator) << [
this](
bool ignore_spectator) ->
R<void>
3707 BIND_SYNC(draw_debug_shape) << [
this](
const cr::DebugShape &shape) ->
R<void>
3711 auto *World =
Episode->GetWorld();
3712 check(World !=
nullptr);
3724 auto *World =
Episode->GetWorld();
3725 check(World !=
nullptr);
3734 std::vector<float> vertices,
3735 std::vector<uint32_t> triangles,
3736 std::string material) ->
R<void>
3740 auto *World =
Episode->GetWorld();
3741 check(World !=
nullptr);
3742 if (vertices.empty() || (vertices.size() % 3u) != 0u)
3744 RESPOND_ERROR(
"spawn_custom_mesh: vertices must be a non-empty flat (x, y, z) triple list");
3746 if (triangles.empty() || (triangles.size() % 3u) != 0u)
3748 RESPOND_ERROR(
"spawn_custom_mesh: triangles must be a non-empty index-triple list");
3750 const uint32_t NumVertices = vertices.size() / 3u;
3751 for (
const uint32_t Index : triangles)
3753 if (Index >= NumVertices)
3755 RESPOND_ERROR(
"spawn_custom_mesh: triangle index out of range");
3760 TArray<FVector> Verts;
3761 Verts.Reserve(NumVertices);
3762 for (uint32_t i = 0u; i < NumVertices; ++i)
3765 vertices[3u * i + 0u] * 100.0f,
3766 vertices[3u * i + 1u] * 100.0f,
3767 vertices[3u * i + 2u] * 100.0f));
3770 Tris.Reserve(triangles.size());
3771 for (
const uint32_t Index : triangles)
3773 Tris.Add(
static_cast<int32
>(Index));
3779 TArray<FVector> Normals;
3780 Normals.Init(FVector::ZeroVector, Verts.Num());
3781 for (int32 i = 0; i + 2 < Tris.Num(); i += 3)
3783 const FVector &V0 = Verts[Tris[i]];
3784 const FVector &V1 = Verts[Tris[i + 1]];
3785 const FVector &V2 = Verts[Tris[i + 2]];
3786 const FVector FaceNormal = FVector::CrossProduct(V2 - V0, V1 - V0);
3787 Normals[Tris[i]] += FaceNormal;
3788 Normals[Tris[i + 1]] += FaceNormal;
3789 Normals[Tris[i + 2]] += FaceNormal;
3791 for (FVector &Normal : Normals)
3793 Normal = Normal.GetSafeNormal(1e-8, FVector::UpVector);
3797 TArray<FVector2D> UV0;
3798 UV0.Reserve(Verts.Num());
3799 for (
const FVector &V : Verts)
3801 UV0.Add(FVector2D(V.X / 500.0f, V.Y / 500.0f));
3805 if (MeshActor ==
nullptr)
3807 RESPOND_ERROR(
"spawn_custom_mesh: failed to spawn mesh actor");
3810 PMC->bUseAsyncCooking =
true;
3811 PMC->bUseComplexAsSimpleCollision =
true;
3812 PMC->SetCollisionEnabled(ECollisionEnabled::QueryAndPhysics);
3813 PMC->CreateMeshSection_LinearColor(
3819 TArray<FLinearColor>(),
3820 TArray<FProcMeshTangent>(),
3823 static const TMap<FString, FString> MaterialHints = {
3824 {TEXT(
"grass"), TEXT(
"/Game/Carla/Static/GenericMaterials/Ground/MI_LargeLandscape_Grass.MI_LargeLandscape_Grass")},
3825 {TEXT(
"dirt"), TEXT(
"/Game/Carla/Static/GenericMaterials/Ground/MI_Dirt.MI_Dirt")},
3826 {TEXT(
"road"), TEXT(
"/Game/Carla/Static/GenericMaterials/Roads/MI_RoadAsphalt_Town15.MI_RoadAsphalt_Town15")},
3827 {TEXT(
"sidewalk"), TEXT(
"/Game/Carla/Static/GenericMaterials/Sidewalk/MI_Sidewalk_Apartment.MI_Sidewalk_Apartment")}};
3828 const FString MaterialName = cr::ToFString(material);
3829 const FString *MaterialPath = MaterialHints.Find(MaterialName.ToLower());
3830 const FString ResolvedPath = (MaterialPath !=
nullptr) ? *MaterialPath : MaterialName;
3831 if (UMaterialInterface *Material = LoadObject<UMaterialInterface>(
nullptr, *ResolvedPath))
3833 PMC->SetMaterial(0, Material);
3850 auto *World =
Episode->GetWorld();
3851 check(World !=
nullptr);
3852 APlayerController *PlayerController = World->GetFirstPlayerController();
3853 if (PlayerController !=
nullptr)
3855 ACarlaHUD *CarlaHUD = Cast<ACarlaHUD>(PlayerController->GetHUD());
3856 if (CarlaHUD !=
nullptr)
3861 if (GEngine !=
nullptr)
3863 GEngine->ClearOnScreenDebugMessages();
3870 using C = cr::Command;
3871 using CR = cr::CommandResponse;
3874 auto parse_result = [](ActorId id,
const auto &response) {
3875 return response.HasError() ? CR{response.GetError()} : CR{
id};
3878#define MAKE_RESULT(operation) return parse_result(c.actor, operation);
3881 [=](
auto self,
const C::SpawnActor &c) -> CR {
3882 auto result = c.parent.has_value() ?
3883 spawn_actor_with_parent(
3887 cr::AttachmentType::Rigid) :
3888 spawn_actor(c.description, c.transform);
3889 if (!result.HasError())
3891 ActorId
id = result.Get().id;
3893 [](C::SpawnActor &) {},
3894 [](C::ConsoleCommand &) {},
3895 [id](
auto &s) { s.actor = id; });
3896 for (
auto command : c.do_after)
3898 std::visit(set_id, command.command);
3899 std::visit(self, command.command);
3903 return result.GetError();
3905 [=](
auto,
const C::DestroyActor &c) {
MAKE_RESULT(destroy_actor(c.actor)); },
3906 [=](
auto,
const C::ApplyVehicleControl &c) {
MAKE_RESULT(apply_control_to_vehicle(c.actor, c.control)); },
3907 [=](
auto,
const C::ApplyVehicleAckermannControl &c) {
MAKE_RESULT(apply_ackermann_control_to_vehicle(c.actor, c.control)); },
3908 [=](
auto,
const C::ApplyWalkerControl &c) {
MAKE_RESULT(apply_control_to_walker(c.actor, c.control)); },
3909 [=](
auto,
const C::ApplyVehiclePhysicsControl &c) {
MAKE_RESULT(apply_physics_control(c.actor, c.physics_control)); },
3910 [=](
auto,
const C::ApplyTransform &c) {
MAKE_RESULT(set_actor_transform(c.actor, c.transform)); },
3911 [=](
auto,
const C::ApplyTargetVelocity &c) {
MAKE_RESULT(set_actor_target_velocity(c.actor, c.velocity)); },
3912 [=](
auto,
const C::ApplyTargetAngularVelocity &c) {
MAKE_RESULT(set_actor_target_angular_velocity(c.actor, c.angular_velocity)); },
3913 [=](
auto,
const C::ApplyImpulse &c) {
MAKE_RESULT(add_actor_impulse(c.actor, c.impulse)); },
3914 [=](
auto,
const C::ApplyForce &c) {
MAKE_RESULT(add_actor_force(c.actor, c.force)); },
3915 [=](
auto,
const C::ApplyAngularImpulse &c) {
MAKE_RESULT(add_actor_angular_impulse(c.actor, c.impulse)); },
3916 [=](
auto,
const C::ApplyTorque &c) {
MAKE_RESULT(add_actor_torque(c.actor, c.torque)); },
3917 [=](
auto,
const C::SetSimulatePhysics &c) {
MAKE_RESULT(set_actor_simulate_physics(c.actor, c.enabled)); },
3918 [=](
auto,
const C::SetEnableGravity &c) {
MAKE_RESULT(set_actor_enable_gravity(c.actor, c.enabled)); },
3920 [=](
auto,
const C::SetAutopilot &c) {
MAKE_RESULT(set_actor_autopilot(c.actor, c.enabled)); },
3921 [=](
auto,
const C::ShowDebugTelemetry &c) {
MAKE_RESULT(show_vehicle_debug_telemetry(c.actor, c.enabled)); },
3922 [=](
auto,
const C::SetVehicleLightState &c) {
MAKE_RESULT(set_vehicle_light_state(c.actor, c.light_state)); },
3925 [=](
auto,
const C::ApplyWalkerState &c) {
MAKE_RESULT(set_walker_state(c.actor, c.transform, c.speed)); },
3926 [=](
auto,
const C::ConsoleCommand& c) -> CR {
return console_command(c.cmd); },
3927 [=](
auto,
const C::SetTrafficLightState& c) {
MAKE_RESULT(set_traffic_light_state(c.actor, c.traffic_light_state)); },
3928 [=](
auto,
const C::ApplyLocation& c) {
MAKE_RESULT(set_actor_location(c.actor, c.location)); }
3934 const std::vector<cr::Command> &commands,
3937 std::vector<CR> result;
3938 result.reserve(commands.size());
3939 for (
const auto &command : commands)
3941 result.emplace_back(std::visit(command_visitor, command.command));
3952 BIND_SYNC(query_lights_state) << [
this](std::string client) ->
R<std::vector<cr::LightState>>
3955 std::vector<cr::LightState> result;
3956 auto *World =
Episode->GetWorld();
3959 result = CarlaLightSubsystem->
GetLights(FString(client.c_str()));
3964 BIND_SYNC(update_lights_state) << [
this]
3965 (std::string client,
const std::vector<cr::LightState>& lights,
bool discard_client) ->
R<void>
3969 auto *World =
Episode->GetWorld();
3972 CarlaLightSubsystem->
SetLights(FString(client.c_str()), lights, discard_client);
3977 BIND_SYNC(update_day_night_cycle) << [
this]
3978 (std::string client,
const bool active) ->
R<void>
3982 auto *World =
Episode->GetWorld();
3994 (cr::Location
Location, cr::Vector3D Direction,
float SearchDistance)
3995 ->
R<std::pair<bool,cr::LabelledPoint>>
3998 auto *World =
Episode->GetWorld();
3999 constexpr float meter_to_centimeter = 100.0f;
4008 meter_to_centimeter * SearchDistance, World);
4012 (cr::Location StartLocation, cr::Location EndLocation)
4013 ->
R<std::vector<cr::LabelledPoint>>
4016 auto *World =
Episode->GetWorld();
4017 FVector UEStartLocation = StartLocation;
4018 FVector UEEndLocation = EndLocation;
4034 if (CarlaActor ==
nullptr)
4035 return std::string();
4036 auto Actor = CarlaActor->GetActor();
4037 if (Actor ==
nullptr)
4038 return std::string();
4039 auto Name = Actor->GetName();
4040 if (Name.Len() == 0)
4041 return std::string();
4042 auto NameStr = StringCast<UTF8CHAR>(*Name, Name.Len());
4043 return std::string((
const char*)NameStr.Get(), NameStr.Length());
4046 BIND_SYNC(get_actor_class_name) << [
this](
4051 if (CarlaActor ==
nullptr)
4052 return std::string();
4053 auto Actor = CarlaActor->GetActor();
4054 if (Actor ==
nullptr)
4055 return std::string();
4056 auto Class = Actor->GetClass();
4057 if (Class ==
nullptr)
4058 return std::string();
4059 auto Name = Class->GetName();
4060 if (Name.Len() == 0)
4061 return std::string();
4062 auto NameStr = StringCast<UTF8CHAR>(*Name, Name.Len());
4063 return std::string((
const char*)NameStr.Get(), NameStr.Length());