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"));
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())
170 const auto MinRoadId = *std::min_element(
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);