29 if (bIncludeActorsAgain)
35 for (
auto It = Registry.
begin(); It != Registry.
end(); ++It)
80 std::unordered_map<uint32_t, uint32_t>& MappedId)
85 uint32_t OldId =
EventAdd.DatabaseId;
99 UE_LOG(LogCarla, Log, TEXT(
"actor could not be created"));
105 MappedId[OldId] = Result.second;
106 UE_LOG(LogCarla, Log, TEXT(
"actor created"));
112 MappedId[OldId] = Result.second;
113 UE_LOG(LogCarla, Log, TEXT(
"actor reused"));
121 MappedId.erase(
EventDel.DatabaseId);
128 if (NewId != MappedId.end())
227 while(!InStream.eof())
230 ReadValue<char>(InStream, header.
Id);
231 ReadValue<uint32_t>(InStream, header.
Size);
296 InStream.seekg(header.
Size, std::ios::cur);
306 const FTransform &Transform,
308 bool bAddOtherRelatedInfo)
311 Description.
UId = ActorDescription.
UId;
312 Description.
Id = ActorDescription.
Id;
316 for (
const auto &item : ActorDescription.
Variations)
319 Attr.
Type =
static_cast<uint8_t
>(item.Value.Type);
320 Attr.
Id = item.Value.Id;
321 Attr.
Value = item.Value.Value;
323 if (!Attr.
Id.IsEmpty())
325 Description.
Attributes.emplace_back(std::move(Attr));
334 Transform.GetTranslation(),
335 Transform.GetRotation().Euler(),
336 std::move(Description)
340 if (!bAddOtherRelatedInfo)
381 check(CarlaActor !=
nullptr);
388 Transform.GetLocation(),
389 Transform.GetRotation().Euler()
395 check(CarlaActor !=
nullptr);
418 check(CarlaActor !=
nullptr)
425 if (CarlaVehicle ==
nullptr)
428 USkeletalMeshComponent* SkeletalMesh = CarlaVehicle->GetMesh();
429 if (SkeletalMesh ==
nullptr)
432 UVehicleAnimInstance* VehicleAnim = Cast<UVehicleAnimInstance>(SkeletalMesh->GetAnimInstance());
433 if (VehicleAnim ==
nullptr)
436 const UWheeledVehicleMovementComponent* WheeledVehicleMovementComponent = VehicleAnim->GetWheeledVehicleMovementComponent();
437 if (WheeledVehicleMovementComponent ==
nullptr)
442 Record.
WheelValues.reserve(WheeledVehicleMovementComponent->Wheels.Num());
445 for (
auto Wheel : WheeledVehicleMovementComponent->Wheels)
450 Info.TireRotation = Wheel->GetRotationAngle();
462 WheeledVehicleMovementComponent->GetForwardSpeed(),
463 WheeledVehicleMovementComponent->GetEngineRotationSpeed() / WheeledVehicleMovementComponent->GetEngineMaxRotationSpeed()
470 check(CarlaActor !=
nullptr);
486 check(CarlaActor !=
nullptr);
500 static_cast<char>(LightState)
508 check(CarlaActor !=
nullptr);
520 check(CarlaActor !=
nullptr);
522 FVector Velocity, AngularVelocity;
523 constexpr float TO_METERS = 1e-2;
537 check(CarlaActor !=
nullptr);
543 {Box.Origin, Box.Extent}
556 UBoxComponent* Trigger = Triggers.Top();
557 auto VolumeOrigin = Trigger->GetComponentLocation();
558 auto VolumeExtent = Trigger->GetScaledBoxExtent();
562 {VolumeOrigin, VolumeExtent}
684 Light->GetLightIntensity(),
685 Light->GetLightColor(),
687 static_cast<uint8
>(Light->GetLightType())
715 std::unordered_map<uint32_t, uint32_t>& MappedId)
720 if (ActorDesc.
Id.StartsWith(
"traffic."))
723 if (CarlaActor !=
nullptr)
726 UE_LOG(LogCarla, Log, TEXT(
"TrafficLight found"));
727 return std::pair<int, FCarlaActor*>(2, CarlaActor);
732 UE_LOG(LogCarla, Log, TEXT(
"TrafficLight not found"));
733 return std::pair<int, FCarlaActor*>(0,
nullptr);
736 else if (SpawnSensors || !ActorDesc.
Id.StartsWith(
"sensor."))
743 if (desc->
Id == ActorDesc.
Id)
747 FRotator Rot = FRotator::MakeFromEuler(Rotation);
748 FTransform Trans2(Rot, Location, FVector(1, 1, 1));
749 CarlaActor->SetActorGlobalTransform(Trans2);
750 return std::pair<int, FCarlaActor*>(2, CarlaActor);
757 if (desc->
Id == ActorDesc.
Id)
761 FRotator Rot = FRotator::MakeFromEuler(Rotation);
762 FTransform Trans2(Rot, Location, FVector(1, 1, 1));
763 CarlaActor->SetActorGlobalTransform(Trans2);
764 return std::pair<int, FCarlaActor*>(2, CarlaActor);
769 FRotator Rot = FRotator::MakeFromEuler(Rotation);
770 FTransform Trans(Rot, FVector(0, 0, 100000), FVector(1, 1, 1));
773 if (Result.Key == EActorSpawnResultStatus::Success)
776 FTransform Trans2(Rot, Location, FVector(1, 1, 1));
777 Result.Value->SetActorGlobalTransform(Trans2);
783 return std::pair<int, FCarlaActor*>(1, Result.Value);
787 UE_LOG(LogCarla, Log, TEXT(
"Actor could't be created"));
788 return std::pair<int, FCarlaActor*>(0, Result.Value);
794 return std::pair<int, FCarlaActor*>(0,
nullptr);
806 std::unordered_map<uint32_t, uint32_t>& MappedId)
813 ActorDesc.
UId = Description.
UId;
814 ActorDesc.
Id = Description.
Id;
815 for (
const auto &Item : Description.
Attributes)
820 Attr.
Value = Item.Value;
823 if (Item.Id ==
"role_name" && Item.Value ==
"hero")
835 if (result.first != 0)
841 if (!(bIgnoreHero && IsHero))
854 return std::make_pair(result.first, result.second->GetActorId());
856 return std::make_pair(result.first, 0);
864 if (CarlaActor ==
nullptr)
866 UE_LOG(LogCarla, Log, TEXT(
"Actor %d not found to destroy"), DatabaseId);
881 UE_LOG(LogCarla, Log, TEXT(
"Parenting Child actors not found"));
886 UE_LOG(LogCarla, Log, TEXT(
"Parenting Parent actors not found"));
923 Rotation = FRotator::MakeFromEuler(Pos1.
Rotation);
928 Location = FMath::Lerp(FVector(Pos1.
Location), FVector(Pos2.
Location), Per);
929 Rotation = FMath::Lerp(FRotator::MakeFromEuler(Pos1.
Rotation), FRotator::MakeFromEuler(Pos2.
Rotation), Per);
932 FTransform Trans(Rotation, Location, FVector(1, 1, 1));
959 FQuat ActorRot = ActorTransform.GetRotation();
960 FVector Pos = ActorTransform.GetTranslation() + (ActorRot.RotateVector(Offset));
1011 if (CarlaActor ==
nullptr)
1016 check(CarlaVehicle !=
nullptr)
1017 USkeletalMeshComponent* SkeletalMesh = CarlaVehicle->GetMesh();
1018 check(SkeletalMesh !=
nullptr)
1019 UVehicleAnimInstance* VehicleAnim = Cast<UVehicleAnimInstance>(SkeletalMesh->GetAnimInstance());
1020 check(VehicleAnim !=
nullptr)
1022 for (uint32_t i = 0; i < VehicleAnimWheels.
WheelValues.size(); ++i)
1045 UWorld* World =
Episode->GetWorld();
1049 if (!CarlaLightSubsystem)
1056 CarlaLight->SetLightIntensity(LightScene.
Intensity);
1057 CarlaLight->SetLightColor(LightScene.
Color);
1058 CarlaLight->SetLightOn(LightScene.
bOn);
1059 CarlaLight->SetLightType(
static_cast<ELightType>(LightScene.
Type));
1074 if (CarlaActor ==
nullptr)
1077 check(CarlaVehicle !=
nullptr)
1088 for (
auto& It : Registry)
1099 if (!(bIgnoreHero && IsHero[CarlaActor->
GetActorId()]))
1106 Control.
Steer = 0.0f;
1107 Control.
Brake = 0.0f;
1145 Control.
Speed = Speed;
1173 auto World =
Episode->GetWorld();
1174 check(World !=
nullptr);
1177 int x =
static_cast<int>(Location.X);
1178 int y =
static_cast<int>(Location.Y);
1179 int z =
static_cast<int>(Location.Z);
1183 for (
auto It = Registry.
begin(); It != Registry.
end(); ++It)
1189 int x2 =
static_cast<int>(vec.X);
1190 int y2 =
static_cast<int>(vec.Y);
1191 int z2 =
static_cast<int>(vec.Z);
1192 if ((x2 == x) && (y2 == y) && (z2 == z))
1207 for (
auto& It : Registry)
1210 if (CarlaActor !=
nullptr)
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)
Class which implements the state changing of traffic lights
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)
const std::vector< CarlaRecorderAnimBiker > & GetBikers()
void Read(std::istream &InFile)
void Write(std::ostream &OutFile)
void Add(const CarlaRecorderAnimWheels &InObj)
const std::vector< CarlaRecorderAnimWheels > & GetVehicleWheels()
void Read(std::istream &InFile)
const std::vector< CarlaRecorderAnimVehicle > & GetVehicles()
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)
const std::vector< CarlaRecorderAnimWalker > & GetWalkers()
void Add(const CarlaRecorderCollision &Collision)
void Add(const CarlaRecorderEventAdd &Event)
void Read(std::istream &InFile)
void Write(std::ostream &OutFile)
const std::vector< CarlaRecorderEventAdd > & GetEvents()
void Add(const CarlaRecorderEventDel &Event)
const std::vector< CarlaRecorderEventDel > & GetEvents()
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)
const std::vector< CarlaRecorderPosition > & GetPositions()
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)
const std::vector< CarlaRecorderStateTrafficLight > & GetStates()
void Add(const CarlaRecorderTrafficLightTime &InObj)
void Write(std::ostream &OutFile)
A registry of all the Carla actors.
bool Contains(uint32 Id) const
auto begin() const noexcept
FCarlaActor * FindCarlaActor(IdType Id)
auto end() const noexcept
A view over an actor and its properties.
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)
void PutActorToSleep(carla::rpc::ActorId ActorId)
FCarlaActor * FindCarlaActor(FCarlaActor::IdType ActorId)
Find a Carla actor by id.
TPair< EActorSpawnResultStatus, FCarlaActor * > SpawnActorWithInfo(const FTransform &Transform, FActorDescription thisActorDescription, FCarlaActor::IdType DesiredId=0)
Spawns an actor based on ActorDescription at Transform.
APawn * GetSpectatorPawn() const
const FActorRegistry & GetActorRegistry() const
void AttachActors(AActor *Child, AActor *Parent, EAttachmentType InAttachmentType=EAttachmentType::Rigid, const FString &SocketName="")
Attach Child to Parent.
bool DestroyActor(AActor *Actor)
UCarlaLight * GetLight(int Id)
static ALargeMapManager * GetLargeMapManager(const UObject *WorldContextObject)
Maps a controller from OpenDrive.
void SetElapsedTime(float InElapsedTime)
ATrafficLightGroup * GetGroup()
float GetElapsedTime() const
Defines the physical appearance of a vehicle whitch is obtained by the sensors.
flag_type light_state
Lights state flag, all turned off by default
std::vector< CarlaRecorderActorAttribute > Attributes
std::vector< WheelInfo > WheelValues
void Write(std::ostream &OutFile)
void Read(std::istream &InFile)
void Read(std::istream &InFile)
const std::vector< CarlaRecorderLightScene > & GetLights()
void Write(std::ostream &OutFile)
void Add(const CarlaRecorderLightScene &InObj)
VehicleLightStateType State
void Read(std::istream &InFile)
const std::vector< CarlaRecorderLightVehicle > & GetLightVehicles()
void Write(std::ostream &OutFile)
void Add(const CarlaRecorderLightVehicle &InObj)
FVehiclePhysicsControl VehiclePhysicsControl
An actor attribute, may be an intrinsic (non-modifiable) attribute of the actor or an user-defined ac...
A description of a Carla Actor with all its variation.
TMap< FString, FActorAttribute > Variations
User selected variations of the actor.
uint32 UId
UId of the definition in which this description was based.
FString Id
Display ID that identifies the actor.
FActorDescription Description
EVehicleWheelLocation Location