Added support for recast build from server-side

This commit is contained in:
Marc Garcia Puig 2020-03-04 18:47:30 +01:00
parent 930b6ec115
commit ee343dbe9b
3 changed files with 80 additions and 3 deletions

View File

@ -57,6 +57,7 @@ namespace sensor {
std::pair<AObstacleDetectionSensor *, s11n::ObstacleDetectionEventSerializer>, std::pair<AObstacleDetectionSensor *, s11n::ObstacleDetectionEventSerializer>,
std::pair<ARadar *, s11n::RadarSerializer>, std::pair<ARadar *, s11n::RadarSerializer>,
std::pair<ARayCastLidar *, s11n::LidarSerializer>, std::pair<ARayCastLidar *, s11n::LidarSerializer>,
std::pair<ARssSensor *, s11n::NoopSerializer>,
std::pair<ASceneCaptureCamera *, s11n::ImageSerializer>, std::pair<ASceneCaptureCamera *, s11n::ImageSerializer>,
std::pair<ASemanticSegmentationCamera *, s11n::ImageSerializer>, std::pair<ASemanticSegmentationCamera *, s11n::ImageSerializer>,
std::pair<FWorldObserver *, s11n::EpisodeStateSerializer> std::pair<FWorldObserver *, s11n::EpisodeStateSerializer>
@ -78,6 +79,7 @@ namespace sensor {
#include "Carla/Sensor/ObstacleDetectionSensor.h" #include "Carla/Sensor/ObstacleDetectionSensor.h"
#include "Carla/Sensor/Radar.h" #include "Carla/Sensor/Radar.h"
#include "Carla/Sensor/RayCastLidar.h" #include "Carla/Sensor/RayCastLidar.h"
#include "Carla/Sensor/RssSensor.h"
#include "Carla/Sensor/SceneCaptureCamera.h" #include "Carla/Sensor/SceneCaptureCamera.h"
#include "Carla/Sensor/SemanticSegmentationCamera.h" #include "Carla/Sensor/SemanticSegmentationCamera.h"
#include "Carla/Sensor/WorldObserver.h" #include "Carla/Sensor/WorldObserver.h"

View File

@ -7,14 +7,20 @@
#include "Carla.h" #include "Carla.h"
#include "Carla/Game/CarlaEpisode.h" #include "Carla/Game/CarlaEpisode.h"
#include <compiler/disable-ue4-macros.h>
#include <carla/opendrive/OpenDriveParser.h>
#include <carla/rpc/String.h>
#include <compiler/enable-ue4-macros.h>
#include "Carla/Sensor/Sensor.h" #include "Carla/Sensor/Sensor.h"
#include "Carla/Util/BoundingBoxCalculator.h" #include "Carla/Util/BoundingBoxCalculator.h"
#include "Carla/Util/RandomEngine.h" #include "Carla/Util/RandomEngine.h"
#include "Carla/Vehicle/VehicleSpawnPoint.h" #include "Carla/Vehicle/VehicleSpawnPoint.h"
#include "EngineUtils.h"
#include "Engine/StaticMeshActor.h" #include "Engine/StaticMeshActor.h"
#include "EngineUtils.h"
#include "GameFramework/SpectatorPawn.h" #include "GameFramework/SpectatorPawn.h"
#include "GenericPlatform/GenericPlatformProcess.h"
#include "Kismet/GameplayStatics.h" #include "Kismet/GameplayStatics.h"
#include "Misc/FileHelper.h" #include "Misc/FileHelper.h"
#include "Misc/Paths.h" #include "Misc/Paths.h"
@ -102,20 +108,89 @@ bool UCarlaEpisode::LoadNewEpisode(const FString &MapString)
return bIsFileFound; return bIsFileFound;
} }
static FString BuildRecastBuilderFile()
{
// Define filename with extension depending on if we are on Windows or not
#if PLATFORM_WINDOWS
const FString RecastToolName = "RecastBuilder.exe";
#else
const FString RecastToolName = "RecastBuilder";
#endif // PLATFORM_WINDOWS
// Define path depending on the UE4 build type (Package or Editor)
#if UE_BUILD_SHIPPING
const FString AbsoluteRecastBuilderPath = FPaths::ConvertRelativePathToFull(
FPaths::ProjectDir() + "Tools/" + RecastToolName);
#else
const FString AbsoluteRecastBuilderPath = FPaths::ConvertRelativePathToFull(
FPaths::ProjectDir() + "../../Util/DockerUtils/dist/" + RecastToolName);
#endif
return AbsoluteRecastBuilderPath;
}
bool UCarlaEpisode::LoadNewOpendriveEpisode(const FString &OpenDriveString) bool UCarlaEpisode::LoadNewOpendriveEpisode(const FString &OpenDriveString)
{ {
if (OpenDriveString.IsEmpty()) if (OpenDriveString.IsEmpty())
{ {
UE_LOG(LogCarla, Error, TEXT("The OpenDrive string is empty."));
return false; return false;
} }
// Build the Map from the OpenDRIVE data
const auto CarlaMap = carla::opendrive::OpenDriveParser::Load(
carla::rpc::FromFString(OpenDriveString));
// Check the Map is correclty generated
if (!CarlaMap.has_value())
{
UE_LOG(LogCarla, Error, TEXT("The OpenDrive string is invalid or not supported"));
return false;
}
// Generate the OBJ (as string)
const auto RecastOBJ = CarlaMap->GenerateGeometry(2).GenerateOBJForRecast();
const FString AbsoluteOBJPath = FPaths::ConvertRelativePathToFull(
FPaths::ProjectContentDir() + "Carla/Maps/Nav/OpenDriveMap.obj");
// Store the OBJ string to a file in order to that RecastBuilder can load it
FFileHelper::SaveStringToFile(
carla::rpc::ToFString(RecastOBJ),
*AbsoluteOBJPath,
FFileHelper::EEncodingOptions::ForceUTF8,
&IFileManager::Get());
const FString AbsoluteXODRPath = FPaths::ConvertRelativePathToFull(
FPaths::ProjectContentDir() + "Carla/Maps/OpenDrive/OpenDriveMap.xodr");
// Copy the OpenDrive as a file in the serverside // Copy the OpenDrive as a file in the serverside
FFileHelper::SaveStringToFile( FFileHelper::SaveStringToFile(
OpenDriveString, OpenDriveString,
*(FPaths::ProjectContentDir() + "/Carla/Maps/OpenDrive/OpenDriveMap.xodr"), *AbsoluteXODRPath,
FFileHelper::EEncodingOptions::ForceUTF8, FFileHelper::EEncodingOptions::ForceUTF8,
&IFileManager::Get()); &IFileManager::Get());
if (!FPaths::FileExists(AbsoluteXODRPath))
{
UE_LOG(LogCarla, Error, TEXT("ERROR: XODR not copied!"));
return false;
}
const FString AbsoluteRecastBuilderPath = BuildRecastBuilderFile();
if (FPaths::FileExists(AbsoluteRecastBuilderPath))
{
FPlatformProcess::CreateProc(
*AbsoluteRecastBuilderPath, *AbsoluteOBJPath,
true, false, false, nullptr, 0, nullptr, nullptr);
}
else
{
UE_LOG(LogCarla, Warning, TEXT("'RecastBuilder' not present under '%s', "
"the binaries for pedestrian navigation will not be created."),
*AbsoluteRecastBuilderPath);
}
return true; return true;
} }

View File

@ -12,7 +12,7 @@ launch-only:
import: CarlaUE4Editor PythonAPI build.utils import: CarlaUE4Editor PythonAPI build.utils
@${CARLA_BUILD_TOOLS_FOLDER}/Import.py $(ARGS) @${CARLA_BUILD_TOOLS_FOLDER}/Import.py $(ARGS)
package: CarlaUE4Editor PythonAPI package: CarlaUE4Editor PythonAPI build.utils
@${CARLA_BUILD_TOOLS_FOLDER}/Package.sh $(ARGS) @${CARLA_BUILD_TOOLS_FOLDER}/Package.sh $(ARGS)
docs: docs: