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),
710 MakeVectorFromTArray<cg::Transform>(SpawnPoints)};
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);
768 const FString SavedDir = FPaths::ConvertRelativePathToFull(FPaths::ProjectSavedDir()) / TEXT(
"");
771 const FString Folder = UTF8_TO_TCHAR(folder.c_str());
772 const bool bWantXODR = Folder.IsEmpty() || Folder.StartsWith(TEXT(
"OpenDrive"), ESearchCase::IgnoreCase);
773 const bool bWantNav = Folder.IsEmpty() || Folder.StartsWith(TEXT(
"Nav"), ESearchCase::IgnoreCase);
783 const FString SavedNav = SavedDir / TEXT(
"Nav") / (
Episode->
GetMapName() + TEXT(
".bin"));
784 if (bWantXODR && IFileManager::Get().FileExists(*SavedXODR)) Files.Add(SavedXODR);
785 if (bWantNav && !
bIsSecondaryServer && IFileManager::Get().FileExists(*SavedNav)) Files.Add(SavedNav);
797 const FString ContentDir = FPaths::ConvertRelativePathToFull(FPaths::ProjectContentDir()) / TEXT(
"");
799 std::vector<std::string> result;
800 for (
auto File : Files) {
801 File = FPaths::ConvertRelativePathToFull(File);
802 if (File.StartsWith(SavedDir) && File.EndsWith(TEXT(
".xodr")))
805 File = TEXT(
"Carla/Maps/OpenDrive") / FPaths::GetCleanFilename(File);
807 else if (File.StartsWith(SavedDir))
809 File.RemoveFromStart(SavedDir);
810 File = TEXT(
"Carla/Maps") / File;
812 else if (File.StartsWith(ContentDir))
814 File.RemoveFromStart(ContentDir);
816 else if (ContentPacks !=
nullptr)
820 const FString PackContentDir = Pack.ContentDir / TEXT(
"");
821 if (Pack.bMounted && File.StartsWith(PackContentDir))
823 File.RemoveFromStart(PackContentDir);
824 File = FString::Printf(TEXT(
"Packs/%s"), *Pack.GetName()) / File;
829 result.emplace_back(TCHAR_TO_UTF8(*File));
834 BIND_SYNC(request_file) << [
this](std::string name) ->
R<std::vector<uint8_t>>
841 const FString ContentDir = FPaths::ConvertRelativePathToFull(FPaths::ProjectContentDir());
842 FString path = ContentDir;
843 path.Append(name.c_str());
844 path = FPaths::ConvertRelativePathToFull(path);
845 if (!path.StartsWith(ContentDir))
857 Rest.RemoveFromStart(ContentDir);
858 FString PackName, PackRelative;
859 FString SavedRelative = Rest;
860 if (Rest.RemoveFromStart(TEXT(
"Packs/")) && Rest.Split(TEXT(
"/"), &PackName, &PackRelative))
864 if (Pack !=
nullptr && Pack->
bMounted)
866 const FString PackContentDir = Pack->
ContentDir / TEXT(
"");
867 const FString PackPath = FPaths::ConvertRelativePathToFull(PackContentDir / PackRelative);
868 if (!PackPath.StartsWith(PackContentDir))
870 RESPOND_ERROR(
"file requested outside the content pack folder");
875 else if (SavedRelative.RemoveFromStart(TEXT(
"Carla/Maps/")) &&
876 (SavedRelative.StartsWith(TEXT(
"OpenDrive/")) || SavedRelative.StartsWith(TEXT(
"Nav/"))))
878 const FString SavedDir = FPaths::ConvertRelativePathToFull(FPaths::ProjectSavedDir()) / TEXT(
"");
883 (FPaths::GetPath(SavedRelative) == TEXT(
"OpenDrive")) &&
884 FPaths::GetExtension(SavedRelative).Equals(TEXT(
"xodr"), ESearchCase::IgnoreCase);
885 const FString SavedPath = bOwnXODR ?
887 FPaths::ConvertRelativePathToFull(SavedDir / SavedRelative);
888 if (SavedPath.StartsWith(SavedDir) && IFileManager::Get().FileExists(*SavedPath) &&
897 TArray<uint8_t> Content;
898 FFileHelper::LoadFileToArray(Content, *path, 0);
899 std::vector<uint8_t> Result(Content.Num());
900 memcpy(&Result[0], Content.GetData(), Content.Num());
911 BIND_SYNC(set_episode_settings) << [
this](
912 const cr::EpisodeSettings &settings) ->
R<uint64_t>
932 TrafficLightManager->SetAdjustSignsHeightToGround(
933 settings.adjust_signs_height_to_ground);
939 BIND_SYNC(get_actor_definitions) << [
this]() ->
R<std::vector<cr::ActorDefinition>>
956 BIND_SYNC(get_all_level_BBs) << [
this](uint8 QueriedTag) ->
R<std::vector<cg::BoundingBox>>
959 TArray<FBoundingBox> Result;
969 for(
auto& Box : Result)
974 return MakeVectorFromTArray<cg::BoundingBox>(Result);
977 BIND_SYNC(get_environment_objects) << [
this](uint8 QueriedTag) ->
R<std::vector<cr::EnvironmentObject>>
989 for(
auto& Object : Result)
994 return MakeVectorFromTArray<cr::EnvironmentObject>(Result);
997 BIND_SYNC(enable_environment_objects) << [
this](std::vector<uint64_t> EnvObjectIds,
bool Enable) ->
R<void>
1007 TSet<uint64> EnvObjectIdsSet;
1008 for(uint64 Id : EnvObjectIds)
1010 EnvObjectIdsSet.Emplace(Id);
1025 UE_LOG(LogCarla, Log, TEXT(
"internal error: unable to find weather:: weather is disabled"));
1026 return cr::WeatherParameters();
1028 return Weather->GetCurrentWeather();
1031 BIND_SYNC(set_weather_parameters) << [
this](
1032 const cr::WeatherParameters &weather) ->
R<void>
1039 RESPOND_ERROR(
"set_weather_parameters internal error: unable to find weather:: weather is disabled");
1041 Weather->ApplyWeather(weather);
1050 const cr::TextureFloatColor &panorama,
float intensity, int32_t face_size) ->
R<void>
1054 if (panorama.GetWidth() < 2 || panorama.GetHeight() < 2)
1056 RESPOND_ERROR(
"set_sky_light_map: panorama must be at least 2x2");
1058 static_assert(
sizeof(cr::FloatColor) == 4 *
sizeof(
float),
"FloatColor must be 4 packed floats");
1060 reinterpret_cast<const float*
>(panorama.GetDataPtr()),
1061 int32(panorama.GetWidth()), int32(panorama.GetHeight()),
1062 face_size > 0 ? face_size : 512);
1063 if (Cubemap ==
nullptr)
1065 RESPOND_ERROR(
"set_sky_light_map: could not build the cubemap");
1069 RESPOND_ERROR(
"set_sky_light_map: no sky rig (ASkyBase) in the level");
1094 return GameMode->IMUSensorGravity;
1102 GameMode->IMUSensorGravity = new_imu_gravity;
1121 #if defined(WITH_ROS2)
1125 if (ROS2 && ROS2->IsEnabled()) {
1126 ROS2->SetPublishTF(publish_tf);
1131 RESPOND_ERROR(
"set_publish_tf: Server was compiled without ROS2 support");
1137 #if defined(WITH_ROS2)
1140 if (ROS2 && ROS2->IsEnabled()) {
1141 return ROS2->GetPublishTF();
1149 BIND_SYNC(get_ego_spawn_points) << [
this]() ->
R<std::vector<carla::geom::Transform>>
1153 auto result = MakeVectorFromTArray<cg::Transform>(SpawnPoints);
1160 const std::vector<FCarlaActor::IdType> &ids) ->
R<std::vector<cr::Actor>>
1163 std::vector<cr::Actor> Result;
1164 Result.reserve(ids.size());
1165 for (
auto &&Id : ids)
1177 cr::ActorDescription Description,
1185 if (Result.Key != EActorSpawnResultStatus::Success)
1187 UE_LOG(LogCarla, Error, TEXT(
"Actor not Spawned"));
1200 BIND_SYNC(spawn_actor_with_parent) << [
this](
1201 cr::ActorDescription Description,
1202 const cr::Transform &Transform,
1203 cr::ActorId ParentId,
1210 if (Result.Key != EActorSpawnResultStatus::Success)
1218 RESPOND_ERROR(
"internal error: actor could not be spawned");
1223 if (!ParentCarlaActor)
1225 RESPOND_ERROR(
"unable to attach actor: parent actor not found");
1260 UE_LOG(LogCarla, Log, TEXT(
"CarlaServer destroy_actor %d"), ActorId);
1261 std::optional<carla::streaming::detail::stream_id_type> SensorStreamId;
1285 APlayerController* PController= UGameplayStatics::GetPlayerController(
Episode->GetWorld(), 0);
1288 auto result = PController->ConsoleCommand(UTF8_TO_TCHAR(cmd.c_str()),
true);
1290 result.Contains(FString(TEXT(
"Command not recognized"))) ||
1291 result.Contains(FString(TEXT(
"Error")))
1294 bool success =
false;
1296 success = GEngine->Exec(
Episode->GetWorld(), UTF8_TO_TCHAR(cmd.c_str()));
1305 bool ForceInPrimary =
false;
1310 ForceInPrimary =
true;
1316 const bool bOwnWorldObserver = (sensor_id ==
1318 if (!bOwnWorldObserver)
1325 if (Desc ==
"" || Desc ==
"sensor.other.collision")
1327 ForceInPrimary =
true;
1332 if (Desc ==
"sensor.other.v2x" || Desc ==
"sensor.other.v2x_custom")
1334 ForceInPrimary =
true;
1340 UE_LOG(LogCarla, Log, TEXT(
"Sensor %d '%s' created in secondary server"), sensor_id, *Desc);
1342 if (SensorActor ==
nullptr)
1349 RESPOND_ERROR(
"no secondary server could provide a token for this sensor");
1358 UE_LOG(LogCarla, Warning,
1359 TEXT(
"Sensor %d '%s' refused: this server cannot render (-nullrhi) and no secondary server is connected"),
1361 RESPOND_ERROR(
"this server cannot render (-nullrhi) and no rendering secondary server is connected to own this camera sensor");
1363 UE_LOG(LogCarla, Log, TEXT(
"Sensor %d '%s' created in primary server"), sensor_id, *Desc);
1373 bool ForceInPrimary =
false;
1378 ForceInPrimary =
true;
1383 if (Desc ==
"" || Desc ==
"sensor.other.collision")
1385 ForceInPrimary =
true;
1392 if (SensorActor ==
nullptr)
1398 RESPOND_ERROR(
"no secondary server could enable ROS for this sensor");
1406 UE_LOG(LogCarla, Warning,
1407 TEXT(
"ROS 2 for sensor %d '%s' refused: this server cannot render (-nullrhi) and no secondary server is connected"),
1409 RESPOND_ERROR(
"this server cannot render (-nullrhi) and no rendering secondary server is connected to publish this camera sensor");
1421 bool ForceInPrimary =
false;
1426 ForceInPrimary =
true;
1431 if (Desc ==
"" || Desc ==
"sensor.other.collision")
1433 ForceInPrimary =
true;
1453 bool ForceInPrimary =
false;
1458 ForceInPrimary =
true;
1463 if (Desc ==
"" || Desc ==
"sensor.other.collision")
1465 ForceInPrimary =
true;
1481 cr::ActorId ActorId,
1482 cr::CustomV2XBytes Data) ->
R<void>
1492 " Actor Id: " + FString::FromInt(ActorId));
1500 " Actor Id: " + FString::FromInt(ActorId));
1508 " Actor Id: " + FString::FromInt(ActorId));
1517 BIND_SYNC(set_actor_location) << [
this](
1518 cr::ActorId ActorId,
1519 cr::Location Location) ->
R<void>
1527 "set_actor_location",
1529 " Actor Id: " + FString::FromInt(ActorId));
1533 Location, ETeleportType::TeleportPhysics);
1537 BIND_SYNC(set_actor_transform) << [
this](
1538 cr::ActorId ActorId,
1539 cr::Transform Transform) ->
R<void>
1547 "set_actor_transform",
1549 " Actor Id: " + FString::FromInt(ActorId));
1553 Transform, ETeleportType::TeleportPhysics);
1558 cr::ActorId ActorId,
1559 cr::Transform Transform,
1570 " Actor Id: " + FString::FromInt(ActorId));
1584 " Actor Id: " + FString::FromInt(ActorId));
1589 BIND_SYNC(set_actor_target_velocity) << [
this](
1590 cr::ActorId ActorId,
1591 cr::Vector3D vector) ->
R<void>
1599 "set_actor_target_velocity",
1601 " Actor Id: " + FString::FromInt(ActorId));
1608 "set_actor_target_velocity",
1610 " Actor Id: " + FString::FromInt(ActorId));
1615 BIND_SYNC(set_actor_target_angular_velocity) << [
this](
1616 cr::ActorId ActorId,
1617 cr::Vector3D vector) ->
R<void>
1625 "set_actor_target_angular_velocity",
1627 " Actor Id: " + FString::FromInt(ActorId));
1634 "set_actor_target_angular_velocity",
1636 " Actor Id: " + FString::FromInt(ActorId));
1641 BIND_SYNC(enable_actor_constant_velocity) << [
this](
1642 cr::ActorId ActorId,
1643 cr::Vector3D vector) ->
R<void>
1651 "enable_actor_constant_velocity",
1653 " Actor Id: " + FString::FromInt(ActorId));
1661 "enable_actor_constant_velocity",
1663 " Actor Id: " + FString::FromInt(ActorId));
1669 BIND_SYNC(disable_actor_constant_velocity) << [
this](
1670 cr::ActorId ActorId) ->
R<void>
1678 "disable_actor_constant_velocity",
1680 " Actor Id: " + FString::FromInt(ActorId));
1688 "disable_actor_constant_velocity",
1690 " Actor Id: " + FString::FromInt(ActorId));
1696 BIND_SYNC(enable_actor_constant_acceleration) << [
this](
1697 cr::ActorId ActorId,
1698 cr::Vector3D vector) ->
R<void>
1706 "enable_actor_constant_acceleration",
1708 " Actor Id: " + FString::FromInt(ActorId));
1716 "enable_actor_constant_acceleration",
1718 " Actor Id: " + FString::FromInt(ActorId));
1724 BIND_SYNC(disable_actor_constant_acceleration) << [
this](
1725 cr::ActorId ActorId) ->
R<void>
1733 "disable_actor_constant_acceleration",
1735 " Actor Id: " + FString::FromInt(ActorId));
1743 "disable_actor_constant_acceleration",
1745 " Actor Id: " + FString::FromInt(ActorId));
1752 cr::ActorId ActorId,
1753 cr::Vector3D vector) ->
R<void>
1761 "add_actor_impulse",
1763 " Actor Id: " + FString::FromInt(ActorId));
1771 "add_actor_impulse",
1773 " Actor Id: " + FString::FromInt(ActorId));
1778 BIND_SYNC(add_actor_impulse_at_location) << [
this](
1779 cr::ActorId ActorId,
1780 cr::Vector3D impulse,
1781 cr::Vector3D location) ->
R<void>
1789 "add_actor_impulse_at_location",
1791 " Actor Id: " + FString::FromInt(ActorId));
1793 FVector UELocation = location.ToCentimeters().ToFVector();
1805 "add_actor_impulse_at_location",
1807 " Actor Id: " + FString::FromInt(ActorId));
1814 cr::ActorId ActorId,
1815 cr::Vector3D vector) ->
R<void>
1825 " Actor Id: " + FString::FromInt(ActorId));
1828 CarlaActor->
AddActorForce(vector.ToCentimeters().ToFVector());
1834 " Actor Id: " + FString::FromInt(ActorId));
1839 BIND_SYNC(add_actor_force_at_location) << [
this](
1840 cr::ActorId ActorId,
1842 cr::Vector3D location) ->
R<void>
1850 "add_actor_force_at_location",
1852 " Actor Id: " + FString::FromInt(ActorId));
1854 FVector UELocation = location.ToCentimeters().ToFVector();
1866 "add_actor_force_at_location",
1868 " Actor Id: " + FString::FromInt(ActorId));
1873 BIND_SYNC(add_actor_angular_impulse) << [
this](
1874 cr::ActorId ActorId,
1875 cr::Vector3D vector) ->
R<void>
1883 "add_actor_angular_impulse",
1885 " Actor Id: " + FString::FromInt(ActorId));
1892 "add_actor_angular_impulse",
1894 " Actor Id: " + FString::FromInt(ActorId));
1900 cr::ActorId ActorId,
1901 cr::Vector3D vector) ->
R<void>
1911 " Actor Id: " + FString::FromInt(ActorId));
1920 " Actor Id: " + FString::FromInt(ActorId));
1925 BIND_SYNC(get_actor_component_world_transform) << [
this](
1926 cr::ActorId ActorId,
1934 "get_actor_component_world_transform",
1936 " Actor Id: " + FString::FromInt(ActorId));
1939 const FString TargetName(UTF8_TO_TCHAR(component_name.c_str()));
1940 FTransform Transform;
1945 "get_actor_component_world_transform",
1947 " Component Name: " + TargetName);
1949 return cr::Transform(Transform);
1952 BIND_SYNC(get_actor_component_relative_transform) << [
this](
1953 cr::ActorId ActorId,
1961 "get_actor_component_relative_transform",
1963 " Actor Id: " + FString::FromInt(ActorId));
1966 const FString TargetName(UTF8_TO_TCHAR(component_name.c_str()));
1967 FTransform Transform;
1972 "get_actor_component_relative_transform",
1974 " Component Name: " + TargetName);
1976 return cr::Transform(Transform);
1979 BIND_SYNC(get_actor_bone_world_transforms) << [
this](
1980 cr::ActorId ActorId) ->
R<std::vector<cr::Transform>>
1987 "get_actor_bone_world_transforms",
1989 " Actor Id: " + FString::FromInt(ActorId));
1992 TArray<FTransform> Transforms;
1997 "get_actor_bone_world_transforms",
1999 " Actor Id: " + FString::FromInt(ActorId));
2001 return MakeVectorFromTArray<cr::Transform>(Transforms);
2004 BIND_SYNC(get_actor_bone_relative_transforms) << [
this](
2005 cr::ActorId ActorId) ->
R<std::vector<cr::Transform>>
2012 "get_actor_bone_relative_transforms",
2014 " Actor Id: " + FString::FromInt(ActorId));
2017 TArray<FTransform> Transforms;
2022 "get_actor_bone_relative_transforms",
2024 " Actor Id: " + FString::FromInt(ActorId));
2026 return MakeVectorFromTArray<cr::Transform>(Transforms);
2029 BIND_SYNC(get_actor_component_names) << [
this](
2030 cr::ActorId ActorId) ->
R<std::vector<std::string>>
2037 "get_actor_component_names",
2039 " Actor Id: " + FString::FromInt(ActorId));
2042 TArray<FString> Names;
2047 "get_actor_component_names",
2049 " Actor Id: " + FString::FromInt(ActorId));
2054 BIND_SYNC(get_actor_bone_names) << [
this](
2055 cr::ActorId ActorId) ->
R<std::vector<std::string>>
2062 "get_actor_bone_names",
2064 " Actor Id: " + FString::FromInt(ActorId));
2067 TArray<FString> Names;
2072 "get_actor_bone_names",
2074 " Actor Id: " + FString::FromInt(ActorId));
2079 BIND_SYNC(get_actor_socket_world_transforms) << [
this](
2080 cr::ActorId ActorId) ->
R<std::vector<cr::Transform>>
2087 "get_actor_socket_world_transforms",
2089 " Actor Id: " + FString::FromInt(ActorId));
2092 TArray<FTransform> Transforms;
2097 "get_actor_socket_world_transforms",
2099 " Actor Id: " + FString::FromInt(ActorId));
2101 return MakeVectorFromTArray<cr::Transform>(Transforms);
2104 BIND_SYNC(get_actor_socket_relative_transforms) << [
this](
2105 cr::ActorId ActorId) ->
R<std::vector<cr::Transform>>
2112 "get_actor_socket_relative_transforms",
2114 " Actor Id: " + FString::FromInt(ActorId));
2117 TArray<FTransform> Transforms;
2122 "get_actor_socket_relative_transforms",
2124 " Actor Id: " + FString::FromInt(ActorId));
2126 return MakeVectorFromTArray<cr::Transform>(Transforms);
2129 BIND_SYNC(get_actor_socket_names) << [
this](
2130 cr::ActorId ActorId) ->
R<std::vector<std::string>>
2137 "get_actor_socket_names",
2139 " Actor Id: " + FString::FromInt(ActorId));
2142 TArray<FString> Names;
2147 "get_actor_socket_names",
2149 " Actor Id: " + FString::FromInt(ActorId));
2154 BIND_SYNC(get_physics_control) << [
this](
2162 "get_physics_control",
2164 " Actor Id: " + FString::FromInt(ActorId));
2172 "get_physics_control",
2174 " Actor Id: " + FString::FromInt(ActorId));
2176 return cr::VehiclePhysicsControl::FromFVehiclePhysicsControl(
PhysicsControl);
2179 BIND_SYNC(get_telemetry_data) << [
this](
2188 "get_telemetry_data",
2190 " Actor Id: " + FString::FromInt(ActorId));
2198 "get_telemetry_data",
2200 " Actor Id: " + FString::FromInt(ActorId));
2202 return cr::VehicleTelemetryData(TelemetryData);
2205 BIND_SYNC(get_vehicle_light_state) << [
this](
2213 "get_vehicle_light_state",
2215 " Actor Id: " + FString::FromInt(ActorId));
2223 "get_vehicle_light_state",
2225 " Actor Id: " + FString::FromInt(ActorId));
2227 return cr::VehicleLightState(LightState);
2230 BIND_SYNC(apply_physics_control) << [
this](
2231 cr::ActorId ActorId,
2240 "apply_physics_control",
2242 " Actor Id: " + FString::FromInt(ActorId));
2249 "apply_physics_control",
2251 " Actor Id: " + FString::FromInt(ActorId));
2256 BIND_SYNC(set_vehicle_light_state) << [
this](
2257 cr::ActorId ActorId,
2258 cr::VehicleLightState LightState) ->
R<void>
2266 "set_vehicle_light_state",
2268 " Actor Id: " + FString::FromInt(ActorId));
2275 "set_vehicle_light_state",
2277 " Actor Id: " + FString::FromInt(ActorId));
2284 cr::ActorId ActorId,
2285 cr::VehicleDoor DoorIdx) ->
R<void>
2293 "open_vehicle_door",
2295 " Actor Id: " + FString::FromInt(ActorId));
2302 "open_vehicle_door",
2304 " Actor Id: " + FString::FromInt(ActorId));
2309 BIND_SYNC(close_vehicle_door) << [
this](
2310 cr::ActorId ActorId,
2311 cr::VehicleDoor DoorIdx) ->
R<void>
2319 "close_vehicle_door",
2321 " Actor Id: " + FString::FromInt(ActorId));
2328 "close_vehicle_door",
2330 " Actor Id: " + FString::FromInt(ActorId));
2335 BIND_SYNC(set_wheel_steer_direction) << [
this](
2336 cr::ActorId ActorId,
2337 cr::VehicleWheelLocation WheelLocation,
2345 "set_wheel_steer_direction",
2347 " Actor Id: " + FString::FromInt(ActorId));
2355 "set_wheel_steer_direction",
2357 " Actor Id: " + FString::FromInt(ActorId));
2362 BIND_SYNC(get_wheel_steer_angle) << [
this](
2363 const cr::ActorId ActorId,
2364 cr::VehicleWheelLocation WheelLocation) ->
R<float>
2370 "get_wheel_steer_angle",
2372 " Actor Id: " + FString::FromInt(ActorId));
2381 "get_wheel_steer_angle",
2383 " Actor Id: " + FString::FromInt(ActorId));
2388 BIND_SYNC(set_wheel_pitch_angle) << [
this](
2389 cr::ActorId ActorId,
2390 cr::VehicleWheelLocation WheelLocation,
2398 "set_wheel_pitch_angle",
2400 " Actor Id: " + FString::FromInt(ActorId));
2408 "set_wheel_pitch_angle",
2410 " Actor Id: " + FString::FromInt(ActorId));
2415 BIND_SYNC(get_wheel_pitch_angle) << [
this](
2416 const cr::ActorId ActorId,
2417 cr::VehicleWheelLocation WheelLocation) ->
R<float>
2423 "get_wheel_pitch_angle",
2425 " Actor Id: " + FString::FromInt(ActorId));
2434 "get_wheel_pitch_angle",
2436 " Actor Id: " + FString::FromInt(ActorId));
2441 BIND_SYNC(set_wheel_suspension_offset) << [
this](
2442 cr::ActorId ActorId,
2443 cr::VehicleWheelLocation WheelLocation,
2451 "set_wheel_suspension_offset",
2453 " Actor Id: " + FString::FromInt(ActorId));
2461 "set_wheel_suspension_offset",
2463 " Actor Id: " + FString::FromInt(ActorId));
2468 BIND_SYNC(get_wheel_suspension_offset) << [
this](
2469 const cr::ActorId ActorId,
2470 cr::VehicleWheelLocation WheelLocation) ->
R<float>
2476 "get_wheel_suspension_offset",
2478 " Actor Id: " + FString::FromInt(ActorId));
2487 "get_wheel_suspension_offset",
2489 " Actor Id: " + FString::FromInt(ActorId));
2494 BIND_SYNC(set_wheel_animation_override) << [
this](
2495 cr::ActorId ActorId,
2503 "set_wheel_animation_override",
2505 " Actor Id: " + FString::FromInt(ActorId));
2511 "set_wheel_animation_override",
2513 " Actor Id: " + FString::FromInt(ActorId));
2518 BIND_SYNC(set_actor_simulate_physics) << [
this](
2519 cr::ActorId ActorId,
2528 "set_actor_simulate_physics",
2530 " Actor Id: " + FString::FromInt(ActorId));
2537 "set_actor_simulate_physics",
2539 " Actor Id: " + FString::FromInt(ActorId));
2544 BIND_SYNC(set_actor_collisions) << [
this](
2545 cr::ActorId ActorId,
2554 "set_actor_collisions",
2556 " Actor Id: " + FString::FromInt(ActorId));
2563 "set_actor_collisions",
2565 " Actor Id: " + FString::FromInt(ActorId));
2571 cr::ActorId ActorId) ->
R<void>
2581 " Actor Id: " + FString::FromInt(ActorId));
2590 " Actor Id: " + FString::FromInt(ActorId));
2595 BIND_SYNC(set_actor_enable_gravity) << [
this](
2596 cr::ActorId ActorId,
2605 "set_actor_enable_gravity",
2607 " Actor Id: " + FString::FromInt(ActorId));
2614 "set_actor_enable_gravity",
2616 " Actor Id: " + FString::FromInt(ActorId));
2621 BIND_SYNC(get_vehicle_bone_world_transforms) << [
this](
2622 cr::ActorId ActorId) ->
R<std::vector<cr::Transform>>
2629 "get_vehicle_bone_world_transforms",
2631 " Actor Id: " + FString::FromInt(ActorId));
2633 TArray<FTransform> Transforms;
2638 "get_vehicle_bone_world_transforms",
2640 " Actor Id: " + FString::FromInt(ActorId));
2642 return MakeVectorFromTArray<cr::Transform>(Transforms);
2647 BIND_SYNC(apply_control_to_vehicle) << [
this](
2648 cr::ActorId ActorId,
2649 cr::VehicleControl Control) ->
R<void>
2657 "apply_control_to_vehicle",
2659 " Actor Id: " + FString::FromInt(ActorId));
2666 "apply_control_to_vehicle",
2668 " Actor Id: " + FString::FromInt(ActorId));
2673 BIND_SYNC(apply_ackermann_control_to_vehicle) << [
this](
2674 cr::ActorId ActorId,
2675 cr::VehicleAckermannControl Control) ->
R<void>
2683 "apply_ackermann_control_to_vehicle",
2685 " Actor Id: " + FString::FromInt(ActorId));
2692 "apply_ackermann_control_to_vehicle",
2694 " Actor Id: " + FString::FromInt(ActorId));
2699 BIND_SYNC(get_ackermann_controller_settings) << [
this](
2707 "get_ackermann_controller_settings",
2709 " Actor Id: " + FString::FromInt(ActorId));
2717 "get_ackermann_controller_settings",
2719 " Actor Id: " + FString::FromInt(ActorId));
2721 return cr::AckermannControllerSettings(Settings);
2724 BIND_SYNC(apply_ackermann_controller_settings) << [
this](
2725 cr::ActorId ActorId,
2726 cr::AckermannControllerSettings AckermannSettings) ->
R<void>
2734 "apply_ackermann_controller_settings",
2736 " Actor Id: " + FString::FromInt(ActorId));
2743 "apply_ackermann_controller_settings",
2745 " Actor Id: " + FString::FromInt(ActorId));
2750 BIND_SYNC(apply_control_to_walker) << [
this](
2751 cr::ActorId ActorId,
2752 cr::WalkerControl Control) ->
R<void>
2760 "apply_control_to_walker",
2762 " Actor Id: " + FString::FromInt(ActorId));
2769 "apply_control_to_walker",
2771 " Actor Id: " + FString::FromInt(ActorId));
2776 BIND_SYNC(get_bones_transform) << [
this](
2784 "get_bones_transform",
2786 " Actor Id: " + FString::FromInt(ActorId));
2794 "get_bones_transform",
2796 " Actor Id: " + FString::FromInt(ActorId));
2799 std::vector<carla::rpc::BoneTransformDataOut> BoneData;
2803 Data.
bone_name = std::string(TCHAR_TO_UTF8(*Bone.Get<0>()));
2808 BoneData.push_back(Data);
2813 BIND_SYNC(set_bones_transform) << [
this](
2814 cr::ActorId ActorId,
2823 "set_bones_transform",
2825 " Actor Id: " + FString::FromInt(ActorId));
2833 "set_bones_transform",
2835 " Actor Id: " + FString::FromInt(ActorId));
2847 return (NavSubsystem !=
nullptr) && NavSubsystem->HasServerSideNavigation();
2855 const cr::Location Sentinel{0.0f, 0.0f, -1e6f};
2857 if (NavSubsystem ==
nullptr)
2862 if (!NavSubsystem->GetRandomNavLocation(Location))
2872 return cr::Location(Location);
2878 const auto EnsureWalkerNavigationStarted =
2881 if (Controller ==
nullptr)
2885 if (Controller->IsNavigationActive())
2887 return Controller->StartNavigation();
2892 BIND_SYNC(walker_start_navigation) << [
this, EnsureWalkerNavigationStarted](
2893 cr::ActorId ActorId) ->
R<bool>
2898 return EnsureWalkerNavigationStarted(
Episode, Controller);
2901 BIND_SYNC(walker_go_to_location) << [
this, EnsureWalkerNavigationStarted](
2902 cr::ActorId ActorId,
2903 cr::Location Location) ->
R<bool>
2908 if (!EnsureWalkerNavigationStarted(
Episode, Controller))
2912 FVector UELocation = Location;
2919 return Controller->GoToNavLocation(UELocation);
2922 BIND_SYNC(walker_set_max_speed) << [
this](
2923 cr::ActorId ActorId,
2924 float SpeedMPerSec) ->
R<bool>
2929 constexpr float MeterToCentimeter = 100.0f;
2930 return (Controller !=
nullptr) &&
2931 Controller->SetNavMaxSpeed(MeterToCentimeter * SpeedMPerSec);
2934 BIND_SYNC(walker_stop_navigation) << [
this](cr::ActorId ActorId) ->
R<bool>
2939 return (Controller !=
nullptr) && Controller->StopNavigation();
2942 BIND_SYNC(set_pedestrians_cross_factor) << [
this](
float CrossFactor) ->
R<bool>
2961 cr::ActorId ActorId,
2972 " Actor Id: " + FString::FromInt(ActorId));
2981 " Actor Id: " + FString::FromInt(ActorId));
2987 BIND_SYNC(get_pose_from_animation) << [
this](
2988 cr::ActorId ActorId) ->
R<void>
2996 "get_pose_from_animation",
2998 " Actor Id: " + FString::FromInt(ActorId));
3005 "get_pose_from_animation",
3007 " Actor Id: " + FString::FromInt(ActorId));
3013 BIND_SYNC(set_actor_autopilot) << [
this](
3014 cr::ActorId ActorId,
3023 "set_actor_autopilot",
3025 " Actor Id: " + FString::FromInt(ActorId));
3032 "set_actor_autopilot",
3034 " Actor Id: " + FString::FromInt(ActorId));
3039 BIND_SYNC(show_vehicle_debug_telemetry) << [
this](
3040 cr::ActorId ActorId,
3049 "show_vehicle_debug_telemetry",
3051 " Actor Id: " + FString::FromInt(ActorId));
3058 "show_vehicle_debug_telemetry",
3060 " Actor Id: " + FString::FromInt(ActorId));
3066 cr::ActorId ActorId,
3067 std::string SimfilePath) ->
R<void>
3077 " Actor Id: " + FString::FromInt(ActorId));
3080 CarlaActor->
EnableCarSim(carla::rpc::ToFString(SimfilePath));
3086 " Actor Id: " + FString::FromInt(ActorId));
3092 cr::ActorId ActorId,
3103 " Actor Id: " + FString::FromInt(ActorId));
3112 " Actor Id: " + FString::FromInt(ActorId));
3117 BIND_SYNC(enable_chrono_physics) << [
this](
3118 cr::ActorId ActorId,
3119 uint64_t MaxSubsteps,
3120 float MaxSubstepDeltaTime,
3121 std::string VehicleJSON,
3122 std::string PowertrainJSON,
3123 std::string TireJSON,
3124 std::string BaseJSONPath) ->
R<void>
3132 "enable_chrono_physics",
3134 " Actor Id: " + FString::FromInt(ActorId));
3138 MaxSubsteps, MaxSubstepDeltaTime,
3139 cr::ToFString(VehicleJSON),
3140 cr::ToFString(PowertrainJSON),
3141 cr::ToFString(TireJSON),
3142 cr::ToFString(BaseJSONPath));
3146 "enable_chrono_physics",
3148 " Actor Id: " + FString::FromInt(ActorId));
3155 BIND_SYNC(set_traffic_light_state) << [
this](
3156 cr::ActorId ActorId,
3157 cr::TrafficLightState trafficLightState) ->
R<void>
3165 "set_traffic_light_state",
3167 " Actor Id: " + FString::FromInt(ActorId));
3175 "set_traffic_light_state",
3177 " Actor Id: " + FString::FromInt(ActorId));
3182 BIND_SYNC(set_traffic_light_green_time) << [
this](
3183 cr::ActorId ActorId,
3192 "set_traffic_light_green_time",
3194 " Actor Id: " + FString::FromInt(ActorId));
3201 "set_traffic_light_green_time",
3203 " Actor Id: " + FString::FromInt(ActorId));
3208 BIND_SYNC(set_traffic_light_yellow_time) << [
this](
3209 cr::ActorId ActorId,
3218 "set_traffic_light_yellow_time",
3220 " Actor Id: " + FString::FromInt(ActorId));
3227 "set_traffic_light_yellow_time",
3229 " Actor Id: " + FString::FromInt(ActorId));
3234 BIND_SYNC(set_traffic_light_red_time) << [
this](
3235 cr::ActorId ActorId,
3244 "set_traffic_light_red_time",
3246 " Actor Id: " + FString::FromInt(ActorId));
3253 "set_traffic_light_red_time",
3255 " Actor Id: " + FString::FromInt(ActorId));
3260 BIND_SYNC(freeze_traffic_light) << [
this](
3261 cr::ActorId ActorId,
3270 "freeze_traffic_light",
3272 " Actor Id: " + FString::FromInt(ActorId));
3279 "freeze_traffic_light",
3281 " Actor Id: " + FString::FromInt(ActorId));
3286 BIND_SYNC(reset_traffic_light_group) << [
this](
3287 cr::ActorId ActorId) ->
R<void>
3295 "reset_traffic_light_group",
3297 " Actor Id: " + FString::FromInt(ActorId));
3304 "reset_traffic_light_group",
3306 " Actor Id: " + FString::FromInt(ActorId));
3315 for (TActorIterator<ATrafficLightGroup> It(
Episode->GetWorld()); It; ++It)
3322 BIND_SYNC(freeze_all_traffic_lights) << [
this]
3332 auto* TraffiLightManager = GameMode->GetTrafficLightManager();
3333 TraffiLightManager->SetFrozen(frozen);
3340 cr::VehicleLightStateList List;
3360 cr::VehicleLightState(
Vehicle->GetVehicleLightState()).GetLightStateAsValue());
3368 BIND_SYNC(get_group_traffic_lights) << [
this](
3369 const cr::ActorId ActorId) ->
R<std::vector<cr::ActorId>>
3375 RESPOND_ERROR(
"unable to get group traffic lights: actor not found");
3380 return std::vector<cr::ActorId>();
3387 RESPOND_ERROR(
"unable to get group traffic lights: actor is not a traffic light");
3389 std::vector<cr::ActorId> Result;
3390 for (
auto* TLight :
TrafficLight->GetGroupTrafficLights())
3395 Result.push_back(View->GetActorId());
3403 const cr::ActorId ActorId) ->
R<std::vector<cg::BoundingBox>>
3412 " Actor Id: " + FString::FromInt(ActorId));
3419 " Actor Id: " + FString::FromInt(ActorId));
3429 " Actor Id: " + FString::FromInt(ActorId));
3431 TArray<FBoundingBox> Result;
3432 TArray<uint8> OutTag;
3436 return MakeVectorFromTArray<cg::BoundingBox>(Result);
3441 BIND_SYNC(get_gbuffer_token) << [
this](
const cr::ActorId ActorId, uint32_t GBufferId) ->
R<std::vector<unsigned char>>
3449 "get_gbuffer_token",
3451 " Actor Id: " + FString::FromInt(ActorId));
3456 "get_gbuffer_token",
3458 " Actor Id: " + FString::FromInt(ActorId));
3464 "get_gbuffer_token",
3466 " Actor Id: " + FString::FromInt(ActorId));
3468 if (!FApp::CanEverRender())
3471 "get_gbuffer_token",
3472 "this server cannot render (-nullrhi), GBuffer streams are not available",
3473 " Actor Id: " + FString::FromInt(ActorId));
3481 return std::vector<unsigned char>(std::begin(Token.data), std::end(Token.data));
3486 return std::vector<unsigned char>(std::begin(Token.data), std::end(Token.data));
3491 return std::vector<unsigned char>(std::begin(Token.data), std::end(Token.data));
3496 return std::vector<unsigned char>(std::begin(Token.data), std::end(Token.data));
3501 return std::vector<unsigned char>(std::begin(Token.data), std::end(Token.data));
3506 return std::vector<unsigned char>(std::begin(Token.data), std::end(Token.data));
3511 return std::vector<unsigned char>(std::begin(Token.data), std::end(Token.data));
3516 return std::vector<unsigned char>(std::begin(Token.data), std::end(Token.data));
3521 return std::vector<unsigned char>(std::begin(Token.data), std::end(Token.data));
3526 return std::vector<unsigned char>(std::begin(Token.data), std::end(Token.data));
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));
3544 UE_LOG(LogCarla, Error, TEXT(
"Requested invalid GBuffer ID %u"), GBufferId);
3551 BIND_SYNC(start_recorder) << [
this](std::string name,
bool AdditionalData,
bool StopReplayer) ->
R<std::string>
3566 BIND_SYNC(show_recorder_file_info) << [
this](
3576 BIND_SYNC(show_recorder_collisions) << [
this](
3588 BIND_SYNC(show_recorder_actors_blocked) << [
this](
3605 bool replay_sensors,
3606 bool replay_weather,
3607 const cr::Transform& offset,
3623 BIND_SYNC(set_replayer_time_factor) << [
this](
double time_factor) ->
R<void>
3639 BIND_SYNC(set_replayer_ignore_spectator) << [
this](
bool ignore_spectator) ->
R<void>
3657 BIND_SYNC(draw_debug_shape) << [
this](
const cr::DebugShape &shape) ->
R<void>
3661 auto *World =
Episode->GetWorld();
3662 check(World !=
nullptr);
3674 auto *World =
Episode->GetWorld();
3675 check(World !=
nullptr);
3684 std::vector<float> vertices,
3685 std::vector<uint32_t> triangles,
3686 std::string material) ->
R<void>
3690 auto *World =
Episode->GetWorld();
3691 check(World !=
nullptr);
3692 if (vertices.empty() || (vertices.size() % 3u) != 0u)
3694 RESPOND_ERROR(
"spawn_custom_mesh: vertices must be a non-empty flat (x, y, z) triple list");
3696 if (triangles.empty() || (triangles.size() % 3u) != 0u)
3698 RESPOND_ERROR(
"spawn_custom_mesh: triangles must be a non-empty index-triple list");
3700 const uint32_t NumVertices = vertices.size() / 3u;
3701 for (
const uint32_t Index : triangles)
3703 if (Index >= NumVertices)
3705 RESPOND_ERROR(
"spawn_custom_mesh: triangle index out of range");
3710 TArray<FVector> Verts;
3711 Verts.Reserve(NumVertices);
3712 for (uint32_t i = 0u; i < NumVertices; ++i)
3715 vertices[3u * i + 0u] * 100.0f,
3716 vertices[3u * i + 1u] * 100.0f,
3717 vertices[3u * i + 2u] * 100.0f));
3720 Tris.Reserve(triangles.size());
3721 for (
const uint32_t Index : triangles)
3723 Tris.Add(
static_cast<int32
>(Index));
3729 TArray<FVector> Normals;
3730 Normals.Init(FVector::ZeroVector, Verts.Num());
3731 for (int32 i = 0; i + 2 < Tris.Num(); i += 3)
3733 const FVector &V0 = Verts[Tris[i]];
3734 const FVector &V1 = Verts[Tris[i + 1]];
3735 const FVector &V2 = Verts[Tris[i + 2]];
3736 const FVector FaceNormal = FVector::CrossProduct(V2 - V0, V1 - V0);
3737 Normals[Tris[i]] += FaceNormal;
3738 Normals[Tris[i + 1]] += FaceNormal;
3739 Normals[Tris[i + 2]] += FaceNormal;
3741 for (FVector &Normal : Normals)
3743 Normal = Normal.GetSafeNormal(1e-8, FVector::UpVector);
3747 TArray<FVector2D> UV0;
3748 UV0.Reserve(Verts.Num());
3749 for (
const FVector &V : Verts)
3751 UV0.Add(FVector2D(V.X / 500.0f, V.Y / 500.0f));
3755 if (MeshActor ==
nullptr)
3757 RESPOND_ERROR(
"spawn_custom_mesh: failed to spawn mesh actor");
3760 PMC->bUseAsyncCooking =
true;
3761 PMC->bUseComplexAsSimpleCollision =
true;
3762 PMC->SetCollisionEnabled(ECollisionEnabled::QueryAndPhysics);
3763 PMC->CreateMeshSection_LinearColor(
3769 TArray<FLinearColor>(),
3770 TArray<FProcMeshTangent>(),
3773 static const TMap<FString, FString> MaterialHints = {
3774 {TEXT(
"grass"), TEXT(
"/Game/Carla/Static/GenericMaterials/Ground/MI_LargeLandscape_Grass.MI_LargeLandscape_Grass")},
3775 {TEXT(
"dirt"), TEXT(
"/Game/Carla/Static/GenericMaterials/Ground/MI_Dirt.MI_Dirt")},
3776 {TEXT(
"road"), TEXT(
"/Game/Carla/Static/GenericMaterials/Roads/MI_RoadAsphalt_Town15.MI_RoadAsphalt_Town15")},
3777 {TEXT(
"sidewalk"), TEXT(
"/Game/Carla/Static/GenericMaterials/Sidewalk/MI_Sidewalk_Apartment.MI_Sidewalk_Apartment")}};
3778 const FString MaterialName = cr::ToFString(material);
3779 const FString *MaterialPath = MaterialHints.Find(MaterialName.ToLower());
3780 const FString ResolvedPath = (MaterialPath !=
nullptr) ? *MaterialPath : MaterialName;
3781 if (UMaterialInterface *Material = LoadObject<UMaterialInterface>(
nullptr, *ResolvedPath))
3783 PMC->SetMaterial(0, Material);
3800 auto *World =
Episode->GetWorld();
3801 check(World !=
nullptr);
3802 APlayerController *PlayerController = World->GetFirstPlayerController();
3803 if (PlayerController !=
nullptr)
3805 ACarlaHUD *CarlaHUD = Cast<ACarlaHUD>(PlayerController->GetHUD());
3806 if (CarlaHUD !=
nullptr)
3811 if (GEngine !=
nullptr)
3813 GEngine->ClearOnScreenDebugMessages();
3820 using C = cr::Command;
3821 using CR = cr::CommandResponse;
3824 auto parse_result = [](ActorId id,
const auto &response) {
3825 return response.HasError() ? CR{response.GetError()} : CR{
id};
3828#define MAKE_RESULT(operation) return parse_result(c.actor, operation);
3831 [=](
auto self,
const C::SpawnActor &c) -> CR {
3832 auto result = c.parent.has_value() ?
3833 spawn_actor_with_parent(
3837 cr::AttachmentType::Rigid) :
3838 spawn_actor(c.description, c.transform);
3839 if (!result.HasError())
3841 ActorId
id = result.Get().id;
3843 [](C::SpawnActor &) {},
3844 [](C::ConsoleCommand &) {},
3845 [id](
auto &s) { s.actor = id; });
3846 for (
auto command : c.do_after)
3848 std::visit(set_id, command.command);
3849 std::visit(self, command.command);
3853 return result.GetError();
3855 [=](
auto,
const C::DestroyActor &c) {
MAKE_RESULT(destroy_actor(c.actor)); },
3856 [=](
auto,
const C::ApplyVehicleControl &c) {
MAKE_RESULT(apply_control_to_vehicle(c.actor, c.control)); },
3857 [=](
auto,
const C::ApplyVehicleAckermannControl &c) {
MAKE_RESULT(apply_ackermann_control_to_vehicle(c.actor, c.control)); },
3858 [=](
auto,
const C::ApplyWalkerControl &c) {
MAKE_RESULT(apply_control_to_walker(c.actor, c.control)); },
3859 [=](
auto,
const C::ApplyVehiclePhysicsControl &c) {
MAKE_RESULT(apply_physics_control(c.actor, c.physics_control)); },
3860 [=](
auto,
const C::ApplyTransform &c) {
MAKE_RESULT(set_actor_transform(c.actor, c.transform)); },
3861 [=](
auto,
const C::ApplyTargetVelocity &c) {
MAKE_RESULT(set_actor_target_velocity(c.actor, c.velocity)); },
3862 [=](
auto,
const C::ApplyTargetAngularVelocity &c) {
MAKE_RESULT(set_actor_target_angular_velocity(c.actor, c.angular_velocity)); },
3863 [=](
auto,
const C::ApplyImpulse &c) {
MAKE_RESULT(add_actor_impulse(c.actor, c.impulse)); },
3864 [=](
auto,
const C::ApplyForce &c) {
MAKE_RESULT(add_actor_force(c.actor, c.force)); },
3865 [=](
auto,
const C::ApplyAngularImpulse &c) {
MAKE_RESULT(add_actor_angular_impulse(c.actor, c.impulse)); },
3866 [=](
auto,
const C::ApplyTorque &c) {
MAKE_RESULT(add_actor_torque(c.actor, c.torque)); },
3867 [=](
auto,
const C::SetSimulatePhysics &c) {
MAKE_RESULT(set_actor_simulate_physics(c.actor, c.enabled)); },
3868 [=](
auto,
const C::SetEnableGravity &c) {
MAKE_RESULT(set_actor_enable_gravity(c.actor, c.enabled)); },
3870 [=](
auto,
const C::SetAutopilot &c) {
MAKE_RESULT(set_actor_autopilot(c.actor, c.enabled)); },
3871 [=](
auto,
const C::ShowDebugTelemetry &c) {
MAKE_RESULT(show_vehicle_debug_telemetry(c.actor, c.enabled)); },
3872 [=](
auto,
const C::SetVehicleLightState &c) {
MAKE_RESULT(set_vehicle_light_state(c.actor, c.light_state)); },
3875 [=](
auto,
const C::ApplyWalkerState &c) {
MAKE_RESULT(set_walker_state(c.actor, c.transform, c.speed)); },
3876 [=](
auto,
const C::ConsoleCommand& c) -> CR {
return console_command(c.cmd); },
3877 [=](
auto,
const C::SetTrafficLightState& c) {
MAKE_RESULT(set_traffic_light_state(c.actor, c.traffic_light_state)); },
3878 [=](
auto,
const C::ApplyLocation& c) {
MAKE_RESULT(set_actor_location(c.actor, c.location)); }
3884 const std::vector<cr::Command> &commands,
3887 std::vector<CR> result;
3888 result.reserve(commands.size());
3889 for (
const auto &command : commands)
3891 result.emplace_back(std::visit(command_visitor, command.command));
3902 BIND_SYNC(query_lights_state) << [
this](std::string client) ->
R<std::vector<cr::LightState>>
3905 std::vector<cr::LightState> result;
3906 auto *World =
Episode->GetWorld();
3909 result = CarlaLightSubsystem->
GetLights(FString(client.c_str()));
3914 BIND_SYNC(update_lights_state) << [
this]
3915 (std::string client,
const std::vector<cr::LightState>& lights,
bool discard_client) ->
R<void>
3919 auto *World =
Episode->GetWorld();
3922 CarlaLightSubsystem->
SetLights(FString(client.c_str()), lights, discard_client);
3927 BIND_SYNC(update_day_night_cycle) << [
this]
3928 (std::string client,
const bool active) ->
R<void>
3932 auto *World =
Episode->GetWorld();
3944 (cr::Location Location, cr::Vector3D Direction,
float SearchDistance)
3945 ->
R<std::pair<bool,cr::LabelledPoint>>
3948 auto *World =
Episode->GetWorld();
3949 constexpr float meter_to_centimeter = 100.0f;
3950 FVector UELocation = Location;
3958 meter_to_centimeter * SearchDistance, World);
3962 (cr::Location StartLocation, cr::Location EndLocation)
3963 ->
R<std::vector<cr::LabelledPoint>>
3966 auto *World =
Episode->GetWorld();
3967 FVector UEStartLocation = StartLocation;
3968 FVector UEEndLocation = EndLocation;
3984 if (CarlaActor ==
nullptr)
3985 return std::string();
3986 auto Actor = CarlaActor->GetActor();
3987 if (Actor ==
nullptr)
3988 return std::string();
3989 auto Name = Actor->GetName();
3990 if (Name.Len() == 0)
3991 return std::string();
3992 auto NameStr = StringCast<UTF8CHAR>(*Name, Name.Len());
3993 return std::string((
const char*)NameStr.Get(), NameStr.Length());
3996 BIND_SYNC(get_actor_class_name) << [
this](
4001 if (CarlaActor ==
nullptr)
4002 return std::string();
4003 auto Actor = CarlaActor->GetActor();
4004 if (Actor ==
nullptr)
4005 return std::string();
4006 auto Class = Actor->GetClass();
4007 if (Class ==
nullptr)
4008 return std::string();
4009 auto Name = Class->GetName();
4010 if (Name.Len() == 0)
4011 return std::string();
4012 auto NameStr = StringCast<UTF8CHAR>(*Name, Name.Len());
4013 return std::string((
const char*)NameStr.Get(), NameStr.Length());