30 : Super(ObjectInitializer)
32 PrimaryActorTick.bCanEverTick =
false;
35 static struct FConstructorStatics
39 ConstructorHelpers::FObjectFinderOptional<UTexture2D> TextureObject;
44 : TextureObject(TEXT(
"/Carla/Icons/OpenDriveActorIcon")),
45 Category(TEXT(
"OpenDriveActor")),
46 Name(NSLOCTEXT(
"SpriteCategory",
"OpenDriveActor",
"OpenDriveActor"))
51 USceneComponent *SceneComponent =
52 ObjectInitializer.CreateDefaultSubobject<USceneComponent>(
this, TEXT(
"SceneComp"));
53 RootComponent = SceneComponent;
54 RootComponent->Mobility = EComponentMobility::Static;
56#if WITH_EDITORONLY_DATA
58 ObjectInitializer.CreateEditorOnlyDefaultSubobject<UBillboardComponent>(
this, TEXT(
"Sprite"));
146 static FString XodrContent;
155 if (!map.has_value())
157 UE_LOG(LogCarla, Error, TEXT(
"Failed to parse OpenDrive file."));
162 const std::vector<Waypoint> LaneWaypoints =
163 map->GenerateWaypointsOnRoadEntries();
165 std::unordered_map<Waypoint, std::vector<Waypoint>> PredecessorMap;
167 for (
auto &Wp : LaneWaypoints)
169 const auto PredecessorsList = map->GetPredecessors(Wp);
170 if (PredecessorsList.empty())
174 const auto MinRoadId = *std::min_element(
175 PredecessorsList.begin(),
176 PredecessorsList.end(),
177 [](
const auto &WaypointA,
const auto &WaypointB) {
178 return WaypointA.road_id < WaypointB.road_id;
180 PredecessorMap[MinRoadId].emplace_back(Wp);
183 for (
auto &&PredecessorWp : PredecessorMap)
187 for (
auto &&Wp : PredecessorWp.second)
189 std::vector<Waypoint> Waypoints;
194 Waypoints.emplace_back(CurrentWp);
195 const auto Successors = map->GetNext(CurrentWp,
RoadAccuracy);
196 if (Successors.empty())
200 if (Successors.front().road_id != Wp.road_id)
204 CurrentWp = Successors.front();
205 }
while (CurrentWp.road_id == Wp.road_id);
208 const auto FollowingWp = map->GetSuccessors(CurrentWp);
209 if (!FollowingWp.empty())
211 Waypoints.emplace_back(FollowingWp.front());
214 if (Waypoints.size() >= 2)
216 TArray<FVector> Positions;
217 Positions.Reserve(Waypoints.size());
218 for (
int i = 0; i < Waypoints.size(); ++i)
222 Positions.Add(map->ComputeTransform(Waypoints[i]).location +
227 if (RoutePlanner ==
nullptr )
229 const auto WpTransform = map->ComputeTransform(Wp);
233 RoutePlanner->SetActorRotation(WpTransform.rotation);
234 RoutePlanner->SetActorLocation(WpTransform.location +
238 if (RoutePlanner !=
nullptr)
240 RoutePlanner->
AddRoute(1.f, Positions);