29 if (bIncludeActorsAgain)
35 for (
auto It = Registry.begin(); It != Registry.end(); ++It)
81 UCarlaEpisode *ThisEpisode,
82 std::unordered_map<uint32_t, uint32_t>& MappedId)
92 uint32_t OldId =
EventAdd.DatabaseId;
94 auto Result = ProcessReplayerEventAdd(
102 switch (Result.first)
106 UE_LOG(LogCarla, Log, TEXT(
"actor could not be created"));
112 MappedId[OldId] = Result.second;
113 UE_LOG(LogCarla, Log, TEXT(
"actor created"));
119 MappedId[OldId] = Result.second;
120 UE_LOG(LogCarla, Log, TEXT(
"actor reused"));
127 ProcessReplayerEventDel(MappedId[
EventDel.DatabaseId]);
128 MappedId.erase(
EventDel.DatabaseId);
135 if (NewId != MappedId.end())
138 ProcessReplayerPosition(Pos, Pos, 0.0, 0.0);
146 ProcessReplayerStateTrafficLight(StateTrafficLight);
153 ProcessReplayerAnimVehicle(
Vehicle);
160 ProcessReplayerAnimVehicleWheels(Wheels);
167 ProcessReplayerAnimWalker(Walker);
174 ProcessReplayerAnimBiker(Biker);
181 ProcessReplayerLightVehicle(Light);
186 ProcessReplayerLightScene(Light);
234 while(!InStream.eof())
237 ReadValue<char>(InStream, header.
Id);
238 ReadValue<uint32_t>(InStream, header.
Size);
303 InStream.seekg(header.
Size, std::ios::cur);
313 const FTransform &Transform,
315 bool bAddOtherRelatedInfo)
318 Description.
UId = ActorDescription.
UId;
319 Description.
Id = ActorDescription.
Id;
323 for (
const auto &item : ActorDescription.
Variations)
326 Attr.
Type =
static_cast<uint8_t
>(item.Value.Type);
327 Attr.
Id = item.Value.Id;
328 Attr.
Value = item.Value.Value;
330 if (!Attr.
Id.IsEmpty())
332 Description.
Attributes.emplace_back(std::move(Attr));
341 Transform.GetTranslation(),
342 Transform.GetRotation().Euler(),
343 std::move(Description)
347 if (!bAddOtherRelatedInfo)
388 check(CarlaActor !=
nullptr);
395 Transform.GetLocation(),
396 Transform.GetRotation().Euler()
402 check(CarlaActor !=
nullptr);
425 check(CarlaActor !=
nullptr)
432 if (CarlaVehicle ==
nullptr)
435 USkeletalMeshComponent* SkeletalMesh = CarlaVehicle->GetMesh();
436 if (SkeletalMesh ==
nullptr)
439 UVehicleAnimInstance* VehicleAnim = Cast<UVehicleAnimInstance>(SkeletalMesh->GetAnimInstance());
440 if (VehicleAnim ==
nullptr)
443 const UWheeledVehicleMovementComponent* WheeledVehicleMovementComponent = VehicleAnim->GetWheeledVehicleMovementComponent();
444 if (WheeledVehicleMovementComponent ==
nullptr)
449 Record.
WheelValues.reserve(WheeledVehicleMovementComponent->Wheels.Num());
452 for (
auto Wheel : WheeledVehicleMovementComponent->Wheels)
457 Info.TireRotation = Wheel->GetRotationAngle();
469 WheeledVehicleMovementComponent->GetForwardSpeed(),
470 WheeledVehicleMovementComponent->GetEngineRotationSpeed() / WheeledVehicleMovementComponent->GetEngineMaxRotationSpeed()
477 check(CarlaActor !=
nullptr);
493 check(CarlaActor !=
nullptr);
515 check(CarlaActor !=
nullptr);
527 check(CarlaActor !=
nullptr);
529 FVector Velocity, AngularVelocity;
530 constexpr float TO_METERS = 1e-2;
544 check(CarlaActor !=
nullptr);
550 {Box.Origin, Box.Extent}
563 UBoxComponent* Trigger = Triggers.Top();
564 auto VolumeOrigin = Trigger->GetComponentLocation();
565 auto VolumeExtent = Trigger->GetScaledBoxExtent();
568 Episode->GetActorRegistry().FindCarlaActor(&TrafficSign)->GetActorId(),
569 {VolumeOrigin, VolumeExtent}
578 Control.VehiclePhysicsControl =
Vehicle.GetVehiclePhysicsControl();
691 Light->GetLightIntensity(),
692 Light->GetLightColor(),
694 static_cast<uint8
>(Light->GetLightType())
722 std::unordered_map<uint32_t, uint32_t>& MappedId)
727 if (ActorDesc.
Id.StartsWith(
"traffic."))
730 if (CarlaActor !=
nullptr)
733 UE_LOG(LogCarla, Log, TEXT(
"TrafficLight found"));
734 return std::pair<int, FCarlaActor*>(2, CarlaActor);
739 UE_LOG(LogCarla, Log, TEXT(
"TrafficLight not found"));
740 return std::pair<int, FCarlaActor*>(0,
nullptr);
743 else if (SpawnSensors || !ActorDesc.
Id.StartsWith(
"sensor."))
746 if (
Episode->GetActorRegistry().Contains(DesiredId))
748 auto* CarlaActor =
Episode->FindCarlaActor(DesiredId);
750 if (desc->
Id == ActorDesc.
Id)
754 FRotator Rot = FRotator::MakeFromEuler(Rotation);
755 FTransform Trans2(Rot, Location, FVector(1, 1, 1));
756 CarlaActor->SetActorGlobalTransform(Trans2);
757 return std::pair<int, FCarlaActor*>(2, CarlaActor);
760 else if (MappedId.find(DesiredId) != MappedId.end() &&
Episode->GetActorRegistry().Contains(MappedId[DesiredId]))
762 auto* CarlaActor =
Episode->FindCarlaActor(MappedId[DesiredId]);
764 if (desc->
Id == ActorDesc.
Id)
768 FRotator Rot = FRotator::MakeFromEuler(Rotation);
769 FTransform Trans2(Rot, Location, FVector(1, 1, 1));
770 CarlaActor->SetActorGlobalTransform(Trans2);
771 return std::pair<int, FCarlaActor*>(2, CarlaActor);
776 FRotator Rot = FRotator::MakeFromEuler(Rotation);
777 FTransform Trans(Rot, FVector(0, 0, 100000), FVector(1, 1, 1));
779 TPair<EActorSpawnResultStatus, FCarlaActor*> Result =
Episode->SpawnActorWithInfo(Trans, ActorDesc, DesiredId);
780 if (Result.Key == EActorSpawnResultStatus::Success)
783 FTransform Trans2(Rot, Location, FVector(1, 1, 1));
784 Result.Value->SetActorGlobalTransform(Trans2);
790 return std::pair<int, FCarlaActor*>(1, Result.Value);
794 UE_LOG(LogCarla, Log, TEXT(
"Actor could't be created"));
795 return std::pair<int, FCarlaActor*>(0, Result.Value);
801 return std::pair<int, FCarlaActor*>(0,
nullptr);
813 std::unordered_map<uint32_t, uint32_t>& MappedId)
820 ActorDesc.
UId = Description.
UId;
821 ActorDesc.
Id = Description.
Id;
822 for (
const auto &Item : Description.
Attributes)
827 Attr.
Value = Item.Value;
830 if (Item.Id ==
"role_name" && Item.Value ==
"hero")
842 if (result.first != 0)
848 if (!(bIgnoreHero && IsHero))
861 return std::make_pair(result.first, result.second->GetActorId());
863 return std::make_pair(result.first, 0);
871 if (CarlaActor ==
nullptr)
873 UE_LOG(LogCarla, Log, TEXT(
"Actor %d not found to destroy"), DatabaseId);
888 UE_LOG(LogCarla, Log, TEXT(
"Parenting Child actors not found"));
893 UE_LOG(LogCarla, Log, TEXT(
"Parenting Parent actors not found"));
930 Rotation = FRotator::MakeFromEuler(Pos1.
Rotation);
935 Location = FMath::Lerp(FVector(Pos1.
Location), FVector(Pos2.
Location), Per);
936 Rotation = FMath::Lerp(FRotator::MakeFromEuler(Pos1.
Rotation), FRotator::MakeFromEuler(Pos2.
Rotation), Per);
939 FTransform Trans(Rotation, Location, FVector(1, 1, 1));
966 FQuat ActorRot = ActorTransform.GetRotation();
967 FVector Pos = ActorTransform.GetTranslation() + (ActorRot.RotateVector(Offset));
1018 if (CarlaActor ==
nullptr)
1023 check(CarlaVehicle !=
nullptr)
1024 USkeletalMeshComponent* SkeletalMesh = CarlaVehicle->GetMesh();
1025 check(SkeletalMesh !=
nullptr)
1026 UVehicleAnimInstance* VehicleAnim = Cast<UVehicleAnimInstance>(SkeletalMesh->GetAnimInstance());
1027 check(VehicleAnim !=
nullptr)
1029 for (uint32_t i = 0; i < VehicleAnimWheels.
WheelValues.size(); ++i)
1056 if (!CarlaLightSubsystem)
1063 CarlaLight->SetLightIntensity(LightScene.
Intensity);
1064 CarlaLight->SetLightColor(LightScene.
Color);
1065 CarlaLight->SetLightOn(LightScene.
bOn);
1066 CarlaLight->SetLightType(
static_cast<ELightType>(LightScene.
Type));
1081 if (CarlaActor ==
nullptr)
1084 check(CarlaVehicle !=
nullptr)
1095 for (
auto& It : Registry)
1106 if (!(bIgnoreHero && IsHero[CarlaActor->
GetActorId()]))
1181 check(
World !=
nullptr);
1184 int x =
static_cast<int>(Location.X);
1185 int y =
static_cast<int>(Location.Y);
1186 int z =
static_cast<int>(Location.Z);
1190 for (
auto It = Registry.begin(); It != Registry.end(); ++It)
1196 int x2 =
static_cast<int>(vec.X);
1197 int y2 =
static_cast<int>(vec.Y);
1198 int z2 =
static_cast<int>(vec.Z);
1199 if ((x2 == x) && (y2 == y) && (z2 == z))
1214 for (
auto& It : Registry)
1217 if (CarlaActor !=
nullptr)
FVehicleLightState LightState
UE_LOG(LogCarla, Log, TEXT("UActorDispatcher::Destroying actor: '%s' %x"), *Id, Actor)
TSharedPtr< const FActorInfo > carla::rpc::ActorState UWorld * World
EActorAttributeType
List of valid types for actor attributes.(角色属性有效类型的列表)
Base class for CARLA wheeled vehicles.
bool IsTwoWheeledVehicle()
float GetWheelSteerAngle(EVehicleWheelLocation WheelLocation)
void SetRotationAnim(float Rotation)
void SetSpeedAnim(float Speed)
void OnActorSpawned(const FCarlaActor &CarlaActor)
如果你的类继承自UObject,你的类名上方需要加入 UCLASS() 宏 实现交通信号灯状态改变的类
void SetFrozenGroup(bool InFreeze)
TArray< UBoxComponent * > GetTriggerVolumes() const
void Add(const CarlaRecorderActorBoundingBox &InObj)
void Add(const CarlaRecorderActorBoundingBox &InObj)
void Add(const CarlaRecorderKinematics &InObj)
void Write(std::ostream &OutFile) const
void Add(const CarlaRecorderAnimBiker &InObj)
void Read(std::istream &InFile)
void Write(std::ostream &OutFile)
void Add(const CarlaRecorderAnimWheels &InObj)
void Read(std::istream &InFile)
void Write(std::ostream &OutFile)
void Read(std::istream &InFile)
void Add(const CarlaRecorderAnimVehicle &InObj)
void Add(const CarlaRecorderAnimWalker &InObj)
void Read(std::istream &InFile)
void Write(std::ostream &OutFile)
void Add(const CarlaRecorderCollision &Collision)
void Add(const CarlaRecorderEventAdd &Event)
void Read(std::istream &InFile)
void Write(std::ostream &OutFile)
void Add(const CarlaRecorderEventDel &Event)
void Write(std::ostream &OutFile)
void Read(std::istream &InFile)
void Write(std::ostream &OutFile)
void Read(std::istream &InFile)
void Add(const CarlaRecorderEventParent &Event)
void Add(const CarlaRecorderPhysicsControl &InObj)
void Add(const CarlaRecorderPosition &InObj)
void Read(std::istream &InFile)
void Write(std::ostream &OutFile)
void Write(std::ostream &OutFile)
void Add(const CarlaRecorderStateTrafficLight &State)
void Read(std::istream &InFile)
void Add(const CarlaRecorderTrafficLightTime &InObj)
void Write(std::ostream &OutFile)
ActorType GetActorType() const
virtual ECarlaServerResponse SetVehicleLightState(const FVehicleLightState &)
virtual ECarlaServerResponse ApplyControlToVehicle(const FVehicleControl &, const EVehicleInputPriority &)
FVector GetActorAngularVelocity() const
void SetParent(IdType InParentId)
void SetAttachmentType(carla::rpc::AttachmentType InAttachmentType)
virtual ECarlaServerResponse GetVehicleLightState(FVehicleLightState &)
FTransform GetActorGlobalTransform() const
FVector GetActorVelocity() const
void SetActorGlobalTransform(const FTransform &Transform, ETeleportType Teleport=ETeleportType::TeleportPhysics)
virtual ECarlaServerResponse ApplyControlToWalker(const FWalkerControl &)
virtual ECarlaServerResponse GetVehicleControl(FVehicleControl &)
FVector GetActorGlobalLocation() const
bool IsPendingKill() const
void AddChildren(IdType ChildId)
virtual ETrafficLightState GetTrafficLightState() const
virtual UTrafficLightController * GetTrafficLightController()
virtual ECarlaServerResponse GetWalkerControl(FWalkerControl &)
const FActorInfo * GetActorInfo() const
IdType GetActorId() const
ECarlaServerResponse SetActorTargetVelocity(const FVector &Velocity)
virtual ECarlaServerResponse SetActorSimulatePhysics(bool bEnabled)
virtual ECarlaServerResponse SetTrafficLightState(const ETrafficLightState &)
static uint64_t GetFrameCounter()
static void ResetFrameCounter(uint64_t Value=0)
void AddPhysicsControl(const ACarlaWheeledVehicle &Vehicle)
void AddAnimVehicle(const CarlaRecorderAnimVehicle &Vehicle)
CarlaRecorderEventsDel EventsDel
void ProcessReplayerLightVehicle(CarlaRecorderLightVehicle LightVehicle)
bool ProcessReplayerEventDel(uint32_t DatabaseId)
CarlaRecorderLightVehicles LightVehicles
void GetFrameData(UCarlaEpisode *ThisEpisode, bool bAdditionalData=false, bool bIncludeActorsAgain=false)
CarlaRecorderCollisions Collisions
std::pair< int, FCarlaActor * > CreateOrReuseActor(FVector &Location, FVector &Rotation, FActorDescription &ActorDesc, uint32_t DesiredId, bool SpawnSensors, std::unordered_map< uint32_t, uint32_t > &MappedId)
void SetActorVelocity(FCarlaActor *CarlaActor, FVector Velocity)
void Read(std::istream &InStream)
bool ProcessReplayerStateTrafficLight(CarlaRecorderStateTrafficLight State)
CarlaRecorderEventsParent EventsParent
bool ProcessReplayerPosition(CarlaRecorderPosition Pos1, CarlaRecorderPosition Pos2, double Per, double DeltaTime)
void AddActorBoundingBox(FCarlaActor *CarlaActor)
bool ProcessReplayerFinish(bool bApplyAutopilot, bool bIgnoreHero, std::unordered_map< uint32_t, bool > &IsHero)
void Write(std::ostream &OutStream)
void ProcessReplayerLightScene(CarlaRecorderLightScene LightScene)
void AddExistingActors(void)
void AddAnimBiker(const CarlaRecorderAnimBiker &Biker)
CarlaRecorderLightScenes LightScenes
CarlaRecorderActorTriggerVolumes TriggerVolumes
FCarlaActor * FindTrafficLightAt(FVector Location)
void ProcessReplayerAnimVehicleWheels(CarlaRecorderAnimWheels Vehicle)
void AddVehicleWheelsAnimation(FCarlaActor *CarlaActor)
CarlaRecorderAnimBikers Bikers
bool SetActorSimulatePhysics(FCarlaActor *CarlaActor, bool bEnabled)
void AddState(const CarlaRecorderStateTrafficLight &State)
void ProcessReplayerAnimVehicle(CarlaRecorderAnimVehicle Vehicle)
CarlaRecorderActorBoundingBoxes BoundingBoxes
void AddCollision(AActor *Actor1, AActor *Actor2)
void AddLightVehicle(const CarlaRecorderLightVehicle &LightVehicle)
void AddVehicleAnimation(FCarlaActor *CarlaActor)
void AddVehicleLight(FCarlaActor *CarlaActor)
CarlaRecorderTrafficLightTimes TrafficLightTimes
void AddTriggerVolume(const ATrafficSignBase &TrafficSign)
CarlaRecorderAnimVehicles Vehicles
void ProcessReplayerAnimBiker(CarlaRecorderAnimBiker Biker)
CarlaRecorderFrameCounter FrameCounter
CarlaRecorderAnimVehicleWheels Wheels
CarlaRecorderEventsAdd EventsAdd
void AddActorPosition(FCarlaActor *CarlaActor)
void AddWalkerAnimation(FCarlaActor *CarlaActor)
bool SetCameraPosition(uint32_t Id, FVector Offset, FQuat Rotation)
void AddTrafficLightTime(const ATrafficLightBase &TrafficLight)
void AddPosition(const CarlaRecorderPosition &Position)
void SetWalkerSpeed(uint32_t ActorId, float Speed)
void PlayFrameData(UCarlaEpisode *ThisEpisode, std::unordered_map< uint32_t, uint32_t > &MappedId)
CarlaRecorderPositions Positions
void AddActorKinematics(FCarlaActor *CarlaActor)
CarlaRecorderPhysicsControls PhysicsControls
CarlaRecorderStates States
void AddAnimVehicleWheels(const CarlaRecorderAnimWheels &VehicleWheels)
void ProcessReplayerAnimWalker(CarlaRecorderAnimWalker Walker)
CarlaRecorderActorsKinematics Kinematics
void AddEvent(const CarlaRecorderEventAdd &Event)
CarlaRecorderAnimWalkers Walkers
void CreateRecorderEventAdd(uint32_t DatabaseId, uint8_t Type, const FTransform &Transform, FActorDescription ActorDescription, bool bAddOtherRelatedInfo=true)
std::pair< int, uint32_t > ProcessReplayerEventAdd(FVector Location, FVector Rotation, CarlaRecorderActorDescription Description, uint32_t DesiredId, bool bIgnoreHero, bool ReplaySensors, std::unordered_map< uint32_t, uint32_t > &MappedId)
void AddEventLightSceneChanged(const UCarlaLight *Light)
bool ProcessReplayerEventParent(uint32_t ChildId, uint32_t ParentId)
void AddAnimWalker(const CarlaRecorderAnimWalker &Walker)
void AddKinematics(const CarlaRecorderKinematics &ActorKinematics)
void AddTrafficLightState(FCarlaActor *CarlaActor)
void AddBoundingBox(const CarlaRecorderActorBoundingBox &ActorBoundingBox)
UCarlaLight * GetLight(int Id)
static ALargeMapManager * GetLargeMapManager(const UObject *WorldContextObject)
从 OpenDrive 映射一个控制器。控制相关交通信号灯并包含其循环
void SetElapsedTime(float InElapsedTime)
ATrafficLightGroup * GetGroup()
float GetElapsedTime() const
flag_type light_state
灯光状态标志,默认情况下全部关闭
std::vector< CarlaRecorderActorAttribute > Attributes
std::vector< WheelInfo > WheelValues
void Write(std::ostream &OutFile)
void Read(std::istream &InFile)
void Read(std::istream &InFile)
void Write(std::ostream &OutFile)
void Add(const CarlaRecorderLightScene &InObj)
VehicleLightStateType State
void Read(std::istream &InFile)
void Write(std::ostream &OutFile)
void Add(const CarlaRecorderLightVehicle &InObj)
An actor attribute, may be an intrinsic (non-modifiable) attribute of the actor or an user-defined ac...
TMap< FString, FActorAttribute > Variations
用户选择了参与者的变化版本。请注意,此时是 由不可修改的属性表示
FActorDescription Description
EVehicleWheelLocation Location