27#include "Components/BoxComponent.h"
28#include "Engine/StaticMeshActor.h"
35#include "EngineUtils.h"
48 if (ActorDesc.
Id.StartsWith(
"traffic."))
51 if (CarlaActor !=
nullptr)
54 return std::pair<int, FCarlaActor*>(2, CarlaActor);
59 UE_LOG(LogCarla, Log, TEXT(
"TrafficLight not found"));
60 return std::pair<int, FCarlaActor*>(0,
nullptr);
63 else if (SpawnSensors || !ActorDesc.
Id.StartsWith(
"sensor."))
70 if (desc->
Id == ActorDesc.
Id)
74 FRotator Rot = FRotator::MakeFromEuler(Rotation);
75 FTransform Trans2(Rot, Location, FVector(1, 1, 1));
76 CarlaActor->SetActorGlobalTransform(Trans2);
77 return std::pair<int, FCarlaActor*>(2, CarlaActor);
81 FRotator Rot = FRotator::MakeFromEuler(Rotation);
82 FTransform Trans(Rot, FVector(0, 0, 100000), FVector(1, 1, 1));
85 if (Result.Key == EActorSpawnResultStatus::Success)
88 FTransform Trans2(Rot, Location, FVector(1, 1, 1));
89 Result.Value->SetActorGlobalTransform(Trans2);
95 return std::pair<int, FCarlaActor*>(1, Result.Value);
99 UE_LOG(LogCarla, Log, TEXT(
"Actor could't be created by replayer"));
100 return std::pair<int, FCarlaActor*>(0, Result.Value);
106 return std::pair<int, FCarlaActor*>(0,
nullptr);
113 auto World =
Episode->GetWorld();
114 check(World !=
nullptr);
117 int x =
static_cast<int>(Location.X);
118 int y =
static_cast<int>(Location.Y);
119 int z =
static_cast<int>(Location.Z);
123 for (
auto It = Registry.
begin(); It != Registry.
end(); ++It)
129 int x2 =
static_cast<int>(vec.X);
130 int y2 =
static_cast<int>(vec.Y);
131 int z2 =
static_cast<int>(vec.Z);
132 if ((x2 == x) && (y2 == y) && (z2 == z))
182 bool bIgnoreSpectator,
190 ActorDesc.
UId = Description.
UId;
191 ActorDesc.
Id = Description.
Id;
192 for (
const auto &Item : Description.
Attributes)
197 Attr.
Value = Item.Value;
200 if (Item.Id ==
"role_name" && Item.Value ==
"hero")
205 if ((bIgnoreHero && IsHero) ||
206 (bIgnoreSpectator && ActorDesc.
Id.StartsWith(
"spectator")))
208 return std::make_pair(3, 0);
218 if (result.first != 0)
225 if (!(bIgnoreHero && IsHero))
230 result.second->GetActor()->SetActorEnableCollision(
true);
231 auto RootComponent = Cast<UPrimitiveComponent>(
232 result.second->GetActor()->GetRootComponent());
233 RootComponent->SetSimulatePhysics(
false);
234 RootComponent->SetCollisionEnabled(ECollisionEnabled::NoCollision);
244 result.second->GetActor()->SetActorEnableCollision(
true);
247 return std::make_pair(result.first, result.second->GetActorId());
249 return std::make_pair(result.first, 0);
257 if (CarlaActor ==
nullptr)
259 UE_LOG(LogCarla, Log, TEXT(
"Actor %d not found to destroy"), DatabaseId);
274 UE_LOG(LogCarla, Log, TEXT(
"Parenting Child actors not found"));
279 UE_LOG(LogCarla, Log, TEXT(
"Parenting Parent actors not found"));
312 if(bIgnoreSpectator && CarlaActor->
GetActor()->GetClass()->GetFName().ToString().Contains(
"Spectator"))
321 Rotation = FRotator::MakeFromEuler(Pos1.
Rotation);
326 Location = FMath::Lerp(FVector(Pos1.
Location), FVector(Pos2.
Location), Per);
327 Rotation = FMath::Lerp(FRotator::MakeFromEuler(Pos1.
Rotation), FRotator::MakeFromEuler(Pos2.
Rotation), Per);
330 FTransform Trans(Rotation, Location, FVector(1, 1, 1));
341 if (CarlaActor ==
nullptr)
346 check(CarlaVehicle !=
nullptr)
347 USkeletalMeshComponent* SkeletalMesh = CarlaVehicle->GetMesh();
348 check(SkeletalMesh !=
nullptr)
349 UVehicleAnimInstance* VehicleAnim = Cast<UVehicleAnimInstance>(SkeletalMesh->GetAnimInstance());
350 check(VehicleAnim !=
nullptr)
352 for (uint32_t i = 0; i < VehicleAnimWheels.
WheelValues.size(); ++i)
380 FQuat ActorRot = ActorTransform.GetRotation();
381 FVector Pos = ActorTransform.GetTranslation() + (ActorRot.RotateVector(Offset));
461 UWorld* World =
Episode->GetWorld();
465 if (!CarlaLightSubsystem)
472 CarlaLight->SetLightIntensity(LightScene.
Intensity);
473 CarlaLight->SetLightColor(LightScene.
Color);
474 CarlaLight->SetLightOn(LightScene.
bOn);
475 CarlaLight->SetLightType(
static_cast<ELightType>(LightScene.
Type));
490 if (CarlaActor ==
nullptr)
493 check(CarlaVehicle !=
nullptr)
504 if (!CarlaActor)
return;
507 auto Walker = Cast<APawn>(Actor);
510 AWalkerController *Controller = Cast<AWalkerController>(Walker->GetController());
511 if (!Controller)
return;
517 FTransform Trans(FRotator::MakeFromEuler(Bone.Rotation), Bone.Location, FVector(1, 1, 1));
531 for (
auto& It : Registry)
542 if (!(bIgnoreHero && IsHero[CarlaActor->
GetActorId()]))
549 Control.
Steer = 0.0f;
550 Control.
Brake = 0.0f;
588 Control.
Speed = Speed;
595 auto World =
Episode->GetWorld();
596 for (TActorIterator<AStaticMeshActor> It(World); It; ++It)
599 check(Actor !=
nullptr);
600 auto MeshComponent = Actor->GetStaticMeshComponent();
601 check(MeshComponent !=
nullptr);
602 if (MeshComponent->Mobility == EComponentMobility::Movable)
EVehicleDoor
Type of door to open/close
EActorAttributeType
List of valid types for actor attributes.
Base class for CARLA wheeled vehicles.
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)
void BlendPose(float Blend)
void SetBonesTransform(const FWalkerBoneControlIn &WalkerBones)
void SetWalkerSpeed(uint32_t ActorId, float Speed)
std::pair< int, FCarlaActor * > TryToCreateReplayerActor(FVector &Location, FVector &Rotation, FActorDescription &ActorDesc, uint32_t DesiredId, bool SpawnSensors)
void ProcessReplayerWalkerBones(const CarlaRecorderWalkerBones &Walker)
bool ProcessReplayerFinish(bool bApplyAutopilot, bool bIgnoreHero, std::unordered_map< uint32_t, bool > &IsHero)
void SetActorVelocity(FCarlaActor *CarlaActor, FVector Velocity)
void ProcessReplayerAnimVehicleWheels(CarlaRecorderAnimWheels Vehicle)
void ProcessReplayerLightScene(CarlaRecorderLightScene LightScene)
void ProcessReplayerDoorVehicle(CarlaRecorderDoorVehicle DoorVehicle)
void ProcessReplayerAnimWalker(CarlaRecorderAnimWalker Walker)
bool ProcessReplayerStateTrafficLight(CarlaRecorderStateTrafficLight State)
FCarlaActor * FindTrafficLightAt(FVector Location)
bool ProcessReplayerEventParent(uint32_t ChildId, uint32_t ParentId)
bool SetActorSimulatePhysics(FCarlaActor *CarlaActor, bool bEnabled)
void ProcessReplayerAnimVehicle(CarlaRecorderAnimVehicle Vehicle)
bool ProcessReplayerPosition(CarlaRecorderPosition Pos1, CarlaRecorderPosition Pos2, double Per, double DeltaTime, bool bIgnoreSpectator)
bool SetActorAutopilot(FCarlaActor *CarlaActor, bool bEnabled, bool bKeepState=false)
bool ProcessReplayerEventDel(uint32_t DatabaseId)
void ProcessReplayerLightVehicle(CarlaRecorderLightVehicle LightVehicle)
std::pair< int, uint32_t > ProcessReplayerEventAdd(FVector Location, FVector Rotation, CarlaRecorderActorDescription Description, uint32_t DesiredId, bool bIgnoreHero, bool bIgnoreSpectator, bool ReplaySensors)
void ProcessReplayerAnimBiker(CarlaRecorderAnimBiker Biker)
bool SetCameraPosition(uint32_t Id, FVector Offset, FQuat Rotation)
A registry of all the Carla actors.
bool Contains(uint32 Id) const
auto begin() const noexcept
auto end() const noexcept
A view over an actor and its properties.
ActorType GetActorType() const
virtual ECarlaServerResponse SetActorAutopilot(bool, bool bKeepState=false)
virtual ECarlaServerResponse SetVehicleLightState(const FVehicleLightState &)
virtual ECarlaServerResponse ApplyControlToVehicle(const FVehicleControl &, const EVehicleInputPriority &)
void SetParent(IdType InParentId)
void SetAttachmentType(carla::rpc::AttachmentType InAttachmentType)
FTransform GetActorGlobalTransform() const
void SetActorGlobalTransform(const FTransform &Transform, ETeleportType Teleport=ETeleportType::TeleportPhysics)
virtual ECarlaServerResponse ApplyControlToWalker(const FWalkerControl &)
FVector GetActorGlobalLocation() const
void AddChildren(IdType ChildId)
virtual UTrafficLightController * GetTrafficLightController()
IdType GetActorId() const
ECarlaServerResponse SetActorTargetVelocity(const FVector &Velocity)
virtual ECarlaServerResponse SetActorSimulatePhysics(bool bEnabled)
virtual ECarlaServerResponse SetTrafficLightState(const ETrafficLightState &)
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()
Defines the physical appearance of a vehicle whitch is obtained by the sensors.
std::vector< CarlaRecorderActorAttribute > Attributes
std::vector< WheelInfo > WheelValues
VehicleLightStateType State
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.
TMap< FString, FTransform > BoneTransforms
EVehicleWheelLocation Location