Added OpenDriveActor custom path

This commit is contained in:
glopezdiest 2025-01-23 11:48:51 +01:00 committed by Blyron
parent 159a4fea47
commit cef475396d
4 changed files with 34 additions and 2 deletions

View File

@ -122,6 +122,26 @@ FString UOpenDrive::LoadXODR(const FString &MapName)
return Content;
}
FString UOpenDrive::LoadXODRFullPath(const FString &FullPath)
{
FString Content;
if (FullPath.IsEmpty())
{
UE_LOG(LogTemp, Error, TEXT("Failed to find OpenDrive file for map '%s'"), *FullPath);
}
else if (FFileHelper::LoadFileToString(Content, *FullPath))
{
UE_LOG(LogTemp, Log, TEXT("Loaded OpenDrive file '%s'"), *FullPath);
}
else
{
UE_LOG(LogTemp, Error, TEXT("Failed to load OpenDrive file '%s'"), *FullPath);
}
return Content;
}
FString UOpenDrive::GetXODRByPath(FString XODRPath, FString MapName){
// When playing in editor the map name gets an extra prefix, here we

View File

@ -37,6 +37,9 @@ public:
UFUNCTION(BlueprintCallable, Category="CARLA|OpenDrive")
static FString LoadXODR(const FString &MapName);
UFUNCTION(BlueprintCallable, Category="CARLA|OpenDrive")
static FString LoadXODRFullPath(const FString &FullPath);
/// Load OpenDriveMap associated to the given MapName. Return nullptr if no
/// XODR can be found with same MapName.
UFUNCTION(BlueprintCallable, Category="CARLA|OpenDrive")

View File

@ -143,7 +143,12 @@ void AOpenDriveActor::BuildRoutes(FString MapName)
// As the OpenDrive file has the same name as level, build the path to the
// xodr file using the lavel name and the game content directory.
const FString XodrContent = UOpenDrive::LoadXODR(MapName);
static FString XodrContent;
if (CustomPath.IsEmpty()){
XodrContent = UOpenDrive::LoadXODR(MapName);
} else {
XodrContent = UOpenDrive::LoadXODRFullPath(CustomPath);
}
auto map = carla::opendrive::OpenDriveParser::Load(carla::rpc::FromLongFString(XodrContent));

View File

@ -38,11 +38,15 @@ private:
#if WITH_EDITORONLY_DATA
/// Generate the road network using an OpenDrive file (named as the current
/// .umap)
/// .umap, or the custom one)
UPROPERTY(Category = "Generate", EditAnywhere)
bool bGenerateRoutes = false;
#endif // WITH_EDITORONLY_DATA
/// Specify a custom path. Expected a full path to the xodr.
UPROPERTY(Category = "Generate", EditAnywhere)
FString CustomPath = "";
/// Distance between waypoints where the cars will drive
UPROPERTY(Category = "Generate", EditAnywhere, meta = (ClampMin = "0.01", UIMin = "0.01"))
float RoadAccuracy = 2.f;