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);
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)
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);
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)
UCarlaLight * GetLight(int Id)
FCarlaActor * FindCarlaActor(FCarlaActor::IdType ActorId)
Find a Carla actor by id.
bool ProcessReplayerEventParent(uint32_t ChildId, uint32_t ParentId)
void Read(std::istream &InFile)
bool IsTwoWheeledVehicle()
void AddExistingActors(void)
void Add(const CarlaRecorderAnimVehicle &InObj)
virtual ECarlaServerResponse SetVehicleLightState(const FVehicleLightState &)
void Read(std::istream &InFile)
void Read(std::istream &InFile)
auto end() const noexcept
void AddVehicleAnimation(FCarlaActor *CarlaActor)
void Write(std::ostream &OutFile)
void Add(const CarlaRecorderAnimBiker &InObj)
A registry of all the Carla actors.
void SetSpeedAnim(float Speed)
void Add(const CarlaRecorderPosition &InObj)
bool DestroyActor(AActor *Actor)
CarlaRecorderPhysicsControls PhysicsControls
void Write(std::ostream &OutFile)
FVehiclePhysicsControl GetVehiclePhysicsControl() const
TArray< UBoxComponent * > GetTriggerVolumes() const
FVector GetActorAngularVelocity() const
const std::vector< CarlaRecorderEventAdd > & GetEvents()
void ProcessReplayerAnimVehicleWheels(CarlaRecorderAnimWheels Vehicle)
virtual ETrafficLightState GetTrafficLightState() const
void AddTriggerVolume(const ATrafficSignBase &TrafficSign)
virtual ECarlaServerResponse GetWalkerControl(FWalkerControl &)
void Write(std::ostream &OutFile)
const std::vector< CarlaRecorderEventDel > & GetEvents()
void SetElapsedTime(float InElapsedTime)
EActorAttributeType
List of valid types for actor attributes.
void Add(const CarlaRecorderCollision &Collision)
const std::vector< CarlaRecorderLightScene > & GetLights()
const std::vector< CarlaRecorderAnimWalker > & GetWalkers()
void AddAnimWalker(const CarlaRecorderAnimWalker &Walker)
void Read(std::istream &InFile)
void Add(const CarlaRecorderAnimWheels &InObj)
void AddEventLightSceneChanged(const UCarlaLight *Light)
void Add(const CarlaRecorderLightScene &InObj)
void Add(const CarlaRecorderTrafficLightTime &InObj)
auto begin() const noexcept
CarlaRecorderTrafficLightTimes TrafficLightTimes
void AddWalkerAnimation(FCarlaActor *CarlaActor)
Class which implements the state changing of traffic lights.
CarlaRecorderAnimBikers Bikers
void AddAnimVehicle(const CarlaRecorderAnimVehicle &Vehicle)
float GetGreenTime() const
void Add(const CarlaRecorderEventAdd &Event)
CarlaRecorderActorBoundingBoxes BoundingBoxes
void AddBoundingBox(const CarlaRecorderActorBoundingBox &ActorBoundingBox)
void Add(const CarlaRecorderStateTrafficLight &State)
void PutActorToSleep(carla::rpc::ActorId ActorId)
CarlaRecorderActorsKinematics Kinematics
const std::vector< CarlaRecorderAnimBiker > & GetBikers()
void OnActorSpawned(const FCarlaActor &CarlaActor)
virtual ECarlaServerResponse ApplyControlToVehicle(const FVehicleControl &, const EVehicleInputPriority &)
void ProcessReplayerAnimWalker(CarlaRecorderAnimWalker Walker)
void AddVehicleLight(FCarlaActor *CarlaActor)
EVehicleWheelLocation Location
CarlaRecorderAnimVehicleWheels Wheels
void AddAnimVehicleWheels(const CarlaRecorderAnimWheels &VehicleWheels)
void Write(std::ostream &OutFile)
const std::vector< CarlaRecorderPosition > & GetPositions()
void Write(std::ostream &OutStream)
bg::model::box< Point3D > Box
virtual ECarlaServerResponse SetTrafficLightState(const ETrafficLightState &)
static void ResetFrameCounter(uint64_t Value=0)
void AddActorPosition(FCarlaActor *CarlaActor)
void AddVehicleWheelsAnimation(FCarlaActor *CarlaActor)
static uint64_t GetFrameCounter()
void Add(const CarlaRecorderPhysicsControl &InObj)
void Write(std::ostream &OutFile)
void Add(const CarlaRecorderLightVehicle &InObj)
void Write(std::ostream &OutFile)
CarlaRecorderActorTriggerVolumes TriggerVolumes
const FActorRegistry & GetActorRegistry() const
TMap< FString, FActorAttribute > Variations
User selected variations of the actor.
void ProcessReplayerLightVehicle(CarlaRecorderLightVehicle LightVehicle)
void Add(const CarlaRecorderActorBoundingBox &InObj)
void Add(const CarlaRecorderKinematics &InObj)
void Write(std::ostream &OutFile)
void SetWalkerSpeed(uint32_t ActorId, float Speed)
void AddPosition(const CarlaRecorderPosition &Position)
void Write(std::ostream &OutFile)
CarlaRecorderEventsDel EventsDel
float GetElapsedTime() const
void AddLightVehicle(const CarlaRecorderLightVehicle &LightVehicle)
TPair< EActorSpawnResultStatus, FCarlaActor * > SpawnActorWithInfo(const FTransform &Transform, FActorDescription thisActorDescription, FCarlaActor::IdType DesiredId=0)
Spawns an actor based on ActorDescription at Transform.
bool SetActorSimulatePhysics(FCarlaActor *CarlaActor, bool bEnabled)
void Write(std::ostream &OutFile)
void SetAttachmentType(carla::rpc::AttachmentType InAttachmentType)
CarlaRecorderLightScenes LightScenes
FCarlaActor * FindTrafficLightAt(FVector Location)
void AddActorBoundingBox(FCarlaActor *CarlaActor)
const std::vector< CarlaRecorderStateTrafficLight > & GetStates()
void GetFrameData(UCarlaEpisode *ThisEpisode, bool bAdditionalData=false, bool bIncludeActorsAgain=false)
virtual ECarlaServerResponse ApplyControlToWalker(const FWalkerControl &)
std::vector< CarlaRecorderActorAttribute > Attributes
void ProcessReplayerAnimBiker(CarlaRecorderAnimBiker Biker)
bool Contains(uint32 Id) const
CarlaRecorderEventsAdd EventsAdd
bool ProcessReplayerEventDel(uint32_t DatabaseId)
FString Id
Display ID that identifies the actor.
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 Read(std::istream &InFile)
void Read(std::istream &InFile)
float GetWheelSteerAngle(EVehicleWheelLocation WheelLocation)
A description of a Carla Actor with all its variation.
void ProcessReplayerAnimVehicle(CarlaRecorderAnimVehicle Vehicle)
FVector GetActorVelocity() const
FActorDescription Description
void Write(std::ostream &OutFile)
CarlaRecorderLightVehicles LightVehicles
void AddKinematics(const CarlaRecorderKinematics &ActorKinematics)
const FActorInfo * GetActorInfo() const
bool IsPendingKill() const
CarlaRecorderPositions Positions
void AddTrafficLightTime(const ATrafficLightBase &TrafficLight)
bool ProcessReplayerPosition(CarlaRecorderPosition Pos1, CarlaRecorderPosition Pos2, double Per, double DeltaTime)
float GetYellowTime() const
VehicleLightStateType State
ECarlaServerResponse SetActorTargetVelocity(const FVector &Velocity)
void AddState(const CarlaRecorderStateTrafficLight &State)
void AddCollision(AActor *Actor1, AActor *Actor2)
CarlaRecorderEventsParent EventsParent
const std::vector< CarlaRecorderAnimVehicle > & GetVehicles()
bool ProcessReplayerStateTrafficLight(CarlaRecorderStateTrafficLight State)
CarlaRecorderAnimWalkers Walkers
CarlaRecorderCollisions Collisions
APawn * GetSpectatorPawn() const
void AttachActors(AActor *Child, AActor *Parent, EAttachmentType InAttachmentType=EAttachmentType::Rigid)
Attach Child to Parent.
void AddChildren(IdType ChildId)
void AddActorKinematics(FCarlaActor *CarlaActor)
void AddAnimBiker(const CarlaRecorderAnimBiker &Biker)
virtual UTrafficLightController * GetTrafficLightController()
void AddTrafficLightState(FCarlaActor *CarlaActor)
bool ProcessReplayerFinish(bool bApplyAutopilot, bool bIgnoreHero, std::unordered_map< uint32_t, bool > &IsHero)
static ALargeMapManager * GetLargeMapManager(const UObject *WorldContextObject)
void AddPhysicsControl(const ACarlaWheeledVehicle &Vehicle)
void Read(std::istream &InFile)
FTransform GetActorGlobalTransform() const
void Read(std::istream &InStream)
uint32 UId
UId of the definition in which this description was based.
void SetFrozenGroup(bool InFreeze)
const std::vector< CarlaRecorderLightVehicle > & GetLightVehicles()
CarlaRecorderStates States
virtual ECarlaServerResponse SetActorSimulatePhysics(bool bEnabled)
void Read(std::istream &InFile)
virtual ECarlaServerResponse GetVehicleLightState(FVehicleLightState &)
void SetParent(IdType InParentId)
virtual ECarlaServerResponse GetVehicleControl(FVehicleControl &)
IdType GetActorId() const
void PlayFrameData(UCarlaEpisode *ThisEpisode, std::unordered_map< uint32_t, uint32_t > &MappedId)
void Add(const CarlaRecorderEventParent &Event)
void Add(const CarlaRecorderAnimWalker &InObj)
FCarlaActor * FindCarlaActor(IdType Id)
void SetActorVelocity(FCarlaActor *CarlaActor, FVector Velocity)
void SetRotationAnim(float Rotation)
void ProcessReplayerLightScene(CarlaRecorderLightScene LightScene)
ATrafficLightGroup * GetGroup()
void Read(std::istream &InFile)
const std::vector< CarlaRecorderAnimWheels > & GetVehicleWheels()
std::vector< WheelInfo > WheelValues
void Read(std::istream &InFile)
void CreateRecorderEventAdd(uint32_t DatabaseId, uint8_t Type, const FTransform &Transform, FActorDescription ActorDescription, bool bAddOtherRelatedInfo=true)
void Add(const CarlaRecorderActorBoundingBox &InObj)
void Add(const CarlaRecorderEventDel &Event)
flag_type light_state
Lights state flag, all turned off by default.
void Read(std::istream &InFile)
Base class for CARLA wheeled vehicles.
Maps a controller from OpenDrive.
void Read(std::istream &InFile)
Defines the physical appearance of a vehicle whitch is obtained by the sensors.
CarlaRecorderAnimVehicles Vehicles
void Write(std::ostream &OutFile)
An actor attribute, may be an intrinsic (non-modifiable) attribute of the actor or an user-defined ac...
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 SetActorGlobalTransform(const FTransform &Transform, ETeleportType Teleport=ETeleportType::TeleportPhysics)
void Write(std::ostream &OutFile)
void AddEvent(const CarlaRecorderEventAdd &Event)
geom::Transform Transform
FVehiclePhysicsControl VehiclePhysicsControl
CarlaRecorderFrameCounter FrameCounter
FVector GetActorGlobalLocation() const
ActorType GetActorType() const
bool SetCameraPosition(uint32_t Id, FVector Offset, FQuat Rotation)
A view over an actor and its properties.
void Write(std::ostream &OutFile) const