12 #include "UObject/ConstructorHelpers.h" 13 #include "DrawDebugHelpers.h" 15 #include "ConstructorHelpers.h" 16 #include "Materials/MaterialExpressionTextureSample.h" 18 #include "DrawDebugHelpers.h" 28 #include <unordered_set> 31 : Super(ObjectInitializer)
33 PrimaryActorTick.bCanEverTick =
false;
36 static struct FConstructorStatics
40 ConstructorHelpers::FObjectFinderOptional<UTexture2D> TextureObject;
45 : TextureObject(TEXT(
"/Carla/Icons/OpenDriveActorIcon")),
46 Category(TEXT(
"OpenDriveActor")),
47 Name(NSLOCTEXT(
"SpriteCategory",
"OpenDriveActor",
"OpenDriveActor"))
52 USceneComponent *SceneComponent =
53 ObjectInitializer.CreateDefaultSubobject<USceneComponent>(
this, TEXT(
"SceneComp"));
54 RootComponent = SceneComponent;
55 RootComponent->Mobility = EComponentMobility::Static;
57 #if WITH_EDITORONLY_DATA 59 ObjectInitializer.CreateEditorOnlyDefaultSubobject<UBillboardComponent>(
this, TEXT(
"Sprite"));
73 #endif // WITH_EDITORONLY_DATA 77 void AOpenDriveActor::PostEditChangeProperty(
struct FPropertyChangedEvent &Event)
79 Super::PostEditChangeProperty(Event);
81 const FName PropertyName = (Event.Property != NULL ? Event.Property->GetFName() : NAME_None);
82 if (PropertyName == GET_MEMBER_NAME_CHECKED(
AOpenDriveActor, bGenerateRoutes))
86 bGenerateRoutes =
false;
102 if (PropertyName == GET_MEMBER_NAME_CHECKED(
AOpenDriveActor, bRemoveRoutes))
106 bRemoveRoutes =
false;
113 if (PropertyName == GET_MEMBER_NAME_CHECKED(
AOpenDriveActor, bShowDebug))
124 if (PropertyName == GET_MEMBER_NAME_CHECKED(
AOpenDriveActor, bRemoveCurrentSpawners))
126 if (bRemoveCurrentSpawners)
128 bRemoveCurrentSpawners =
false;
134 #endif // WITH_EDITOR 151 if (!map.has_value())
153 UE_LOG(LogCarla, Error, TEXT(
"Failed to parse OpenDrive file."));
158 const std::vector<Waypoint> LaneWaypoints =
159 map->GenerateWaypointsOnRoadEntries();
161 std::unordered_map<Waypoint, std::vector<Waypoint>> PredecessorMap;
163 for (
auto &Wp : LaneWaypoints)
165 const auto PredecessorsList = map->GetPredecessors(Wp);
166 if (PredecessorsList.empty())
171 PredecessorsList.begin(),
172 PredecessorsList.end(),
173 [](
const auto &WaypointA,
const auto &WaypointB) {
174 return WaypointA.road_id < WaypointB.road_id;
176 PredecessorMap[MinRoadId].emplace_back(Wp);
179 for (
auto &&PredecessorWp : PredecessorMap)
183 for (
auto &&Wp : PredecessorWp.second)
185 std::vector<Waypoint> Waypoints;
190 Waypoints.emplace_back(CurrentWp);
191 const auto Successors = map->GetNext(CurrentWp,
RoadAccuracy);
192 if (Successors.empty())
196 if (Successors.front().road_id != Wp.road_id)
200 CurrentWp = Successors.front();
201 }
while (CurrentWp.road_id == Wp.road_id);
204 const auto FollowingWp = map->GetSuccessors(CurrentWp);
205 if (!FollowingWp.empty())
207 Waypoints.emplace_back(FollowingWp.front());
210 if (Waypoints.size() >= 2)
212 TArray<FVector> Positions;
213 Positions.Reserve(Waypoints.size());
214 for (
int i = 0; i < Waypoints.size(); ++i)
218 Positions.Add(map->ComputeTransform(Waypoints[i]).location +
223 if (RoutePlanner ==
nullptr )
225 const auto WpTransform = map->ComputeTransform(Wp);
229 RoutePlanner->SetActorRotation(WpTransform.rotation);
230 RoutePlanner->SetActorLocation(WpTransform.location +
234 if (RoutePlanner !=
nullptr)
236 RoutePlanner->
AddRoute(1.f, Positions);
247 for (
int i = 0; i < rp_num; i++)
271 FlushPersistentDebugLines(GetWorld());
272 #endif // WITH_EDITOR 289 Spawner->SetActorRotation(Trans.GetRotation());
290 Spawner->SetActorLocation(Trans.GetTranslation() + FVector(0.f, 0.f,
SpawnersHeight));
300 for (
int i = 0; i < vs_num; i++)
TArray< AVehicleSpawnPoint * > VehicleSpawners
static FString LoadXODR(const FString &MapName)
Base class for spawner locations for walkers.
UBillboardComponent * SpriteComponent
A UBillboardComponent to hold Icon sprite.
TArray< ARoutePlanner * > RoutePlanners
Assign a random route to every ACarlaWheeledVehicle entering the trigger volume.
void RemoveRoutes()
Remove all the existing ARoutePlanner and VehicleSpawners previously generated by this class to avoid...
static boost::optional< road::Map > Load(const std::string &opendrive)
I min_element(I begin, I end, const Pred &pred)
bool bAddSpawners
If true, spawners will be placed when generating the routes.
void RemoveDebugRoutes() const
void AddRoute(float probability, const TArray< FVector > &routePoints)
float RoadAccuracy
Distance between waypoints where the cars will drive.
bool bOnIntersections
If true, spawners will be placed on junctions too.
void SetBoxExtent(const FVector &Extent)
float TriggersHeight
Trigger elevantion.
float SpawnersHeight
Determine the height where the spawners will be placed, relative to each RoutePlanner.
AOpenDriveActor(const FObjectInitializer &ObjectInitializer)