22 #include "Engine/StaticMeshActor.h" 31 #include "EngineUtils.h" 44 if (ActorDesc.
Id.StartsWith(
"traffic."))
47 if (CarlaActor !=
nullptr)
50 return std::pair<int, FCarlaActor*>(2, CarlaActor);
55 UE_LOG(LogCarla, Log, TEXT(
"TrafficLight not found"));
56 return std::pair<int, FCarlaActor*>(0,
nullptr);
59 else if (SpawnSensors || !ActorDesc.
Id.StartsWith(
"sensor."))
66 if (desc->
Id == ActorDesc.
Id)
70 FRotator Rot = FRotator::MakeFromEuler(Rotation);
71 FTransform Trans2(Rot, Location, FVector(1, 1, 1));
72 CarlaActor->SetActorGlobalTransform(Trans2);
73 return std::pair<int, FCarlaActor*>(2, CarlaActor);
77 FRotator Rot = FRotator::MakeFromEuler(Rotation);
78 FTransform Trans(Rot, FVector(0, 0, 100000), FVector(1, 1, 1));
81 if (Result.Key == EActorSpawnResultStatus::Success)
84 FTransform Trans2(Rot, Location, FVector(1, 1, 1));
85 Result.Value->SetActorGlobalTransform(Trans2);
91 return std::pair<int, FCarlaActor*>(1, Result.Value);
95 UE_LOG(LogCarla, Log, TEXT(
"Actor could't be created by replayer"));
96 return std::pair<int, FCarlaActor*>(0, Result.Value);
102 return std::pair<int, FCarlaActor*>(0,
nullptr);
109 auto World =
Episode->GetWorld();
110 check(World !=
nullptr);
113 int x =
static_cast<int>(Location.X);
114 int y =
static_cast<int>(Location.Y);
115 int z =
static_cast<int>(Location.Z);
119 for (
auto It = Registry.
begin(); It != Registry.
end(); ++It)
125 int x2 =
static_cast<int>(vec.X);
126 int y2 =
static_cast<int>(vec.Y);
127 int z2 =
static_cast<int>(vec.Z);
128 if ((x2 == x) && (y2 == y) && (z2 == z))
185 ActorDesc.
UId = Description.
UId;
186 ActorDesc.
Id = Description.
Id;
187 for (
const auto &Item : Description.
Attributes)
192 Attr.
Value = Item.Value;
195 if (Item.Id ==
"role_name" && Item.Value ==
"hero")
206 if (result.first != 0)
212 if (!(bIgnoreHero && IsHero))
225 return std::make_pair(result.first, result.second->GetActorId());
227 return std::make_pair(result.first, 0);
235 if (CarlaActor ==
nullptr)
237 UE_LOG(LogCarla, Log, TEXT(
"Actor %d not found to destroy"), DatabaseId);
252 UE_LOG(LogCarla, Log, TEXT(
"Parenting Child actors not found"));
257 UE_LOG(LogCarla, Log, TEXT(
"Parenting Parent actors not found"));
294 Rotation = FRotator::MakeFromEuler(Pos1.
Rotation);
299 Location = FMath::Lerp(FVector(Pos1.
Location), FVector(Pos2.
Location), Per);
300 Rotation = FMath::Lerp(FRotator::MakeFromEuler(Pos1.
Rotation), FRotator::MakeFromEuler(Pos2.
Rotation), Per);
303 FTransform Trans(Rotation, Location, FVector(1, 1, 1));
330 FQuat ActorRot = ActorTransform.GetRotation();
331 FVector Pos = ActorTransform.GetTranslation() + (ActorRot.RotateVector(Offset));
393 UWorld* World =
Episode->GetWorld();
397 if (!CarlaLightSubsystem)
404 CarlaLight->SetLightIntensity(LightScene.
Intensity);
405 CarlaLight->SetLightColor(LightScene.
Color);
406 CarlaLight->SetLightOn(LightScene.
bOn);
407 CarlaLight->SetLightType(static_cast<ELightType>(LightScene.
Type));
423 for (
auto& It : Registry)
434 if (!(bIgnoreHero && IsHero[CarlaActor->
GetActorId()]))
441 Control.
Steer = 0.0f;
442 Control.
Brake = 0.0f;
480 Control.
Speed = Speed;
487 auto World =
Episode->GetWorld();
488 for (TActorIterator<AStaticMeshActor> It(World); It; ++It)
491 check(
Actor !=
nullptr);
492 auto MeshComponent =
Actor->GetStaticMeshComponent();
493 check(MeshComponent !=
nullptr);
494 if (MeshComponent->Mobility == EComponentMobility::Movable)
UCarlaLight * GetLight(int Id)
FCarlaActor * FindCarlaActor(FCarlaActor::IdType ActorId)
Find a Carla actor by id.
virtual ECarlaServerResponse SetVehicleLightState(const FVehicleLightState &)
auto end() const noexcept
A registry of all the Carla actors.
bool DestroyActor(AActor *Actor)
FCarlaActor * FindTrafficLightAt(FVector Location)
void SetActorVelocity(FCarlaActor *CarlaActor, FVector Velocity)
void ProcessReplayerLightVehicle(CarlaRecorderLightVehicle LightVehicle)
void ProcessReplayerAnimVehicle(CarlaRecorderAnimVehicle Vehicle)
void SetElapsedTime(float InElapsedTime)
EActorAttributeType
List of valid types for actor attributes.
bool SetActorSimulatePhysics(FCarlaActor *CarlaActor, bool bEnabled)
void SetWalkerSpeed(uint32_t ActorId, float Speed)
auto begin() const noexcept
bool ProcessReplayerStateTrafficLight(CarlaRecorderStateTrafficLight State)
Class which implements the state changing of traffic lights.
bool SetActorAutopilot(FCarlaActor *CarlaActor, bool bEnabled, bool bKeepState=false)
void PutActorToSleep(carla::rpc::ActorId ActorId)
void OnActorSpawned(const FCarlaActor &CarlaActor)
virtual ECarlaServerResponse ApplyControlToVehicle(const FVehicleControl &, const EVehicleInputPriority &)
virtual ECarlaServerResponse SetTrafficLightState(const ETrafficLightState &)
const FActorRegistry & GetActorRegistry() const
TMap< FString, FActorAttribute > Variations
User selected variations of the actor.
carla::SharedPtr< cc::Actor > Actor
void ProcessReplayerLightScene(CarlaRecorderLightScene LightScene)
TPair< EActorSpawnResultStatus, FCarlaActor * > SpawnActorWithInfo(const FTransform &Transform, FActorDescription thisActorDescription, FCarlaActor::IdType DesiredId=0)
Spawns an actor based on ActorDescription at Transform.
bool ProcessReplayerFinish(bool bApplyAutopilot, bool bIgnoreHero, std::unordered_map< uint32_t, bool > &IsHero)
void SetAttachmentType(carla::rpc::AttachmentType InAttachmentType)
std::pair< int, uint32_t > ProcessReplayerEventAdd(FVector Location, FVector Rotation, CarlaRecorderActorDescription Description, uint32_t DesiredId, bool bIgnoreHero, bool ReplaySensors)
virtual ECarlaServerResponse ApplyControlToWalker(const FWalkerControl &)
std::vector< CarlaRecorderActorAttribute > Attributes
bool Contains(uint32 Id) const
bool ProcessReplayerPosition(CarlaRecorderPosition Pos1, CarlaRecorderPosition Pos2, double Per, double DeltaTime)
FString Id
Display ID that identifies the actor.
A description of a Carla Actor with all its variation.
bool ProcessReplayerEventParent(uint32_t ChildId, uint32_t ParentId)
VehicleLightStateType State
virtual ECarlaServerResponse SetActorAutopilot(bool, bool bKeepState=false)
ECarlaServerResponse SetActorTargetVelocity(const FVector &Velocity)
APawn * GetSpectatorPawn() const
void AttachActors(AActor *Child, AActor *Parent, EAttachmentType InAttachmentType=EAttachmentType::Rigid)
Attach Child to Parent.
void AddChildren(IdType ChildId)
virtual UTrafficLightController * GetTrafficLightController()
static ALargeMapManager * GetLargeMapManager(const UObject *WorldContextObject)
FTransform GetActorGlobalTransform() const
uint32 UId
UId of the definition in which this description was based.
void SetFrozenGroup(bool InFreeze)
virtual ECarlaServerResponse SetActorSimulatePhysics(bool bEnabled)
void SetParent(IdType InParentId)
IdType GetActorId() const
bool ProcessReplayerEventDel(uint32_t DatabaseId)
std::pair< int, FCarlaActor * > TryToCreateReplayerActor(FVector &Location, FVector &Rotation, FActorDescription &ActorDesc, uint32_t DesiredId, bool SpawnSensors)
ATrafficLightGroup * GetGroup()
Maps a controller from OpenDrive.
Defines the physical appearance of a vehicle whitch is obtained by the sensors.
An actor attribute, may be an intrinsic (non-modifiable) attribute of the actor or an user-defined ac...
bool SetCameraPosition(uint32_t Id, FVector Offset, FQuat Rotation)
void SetActorGlobalTransform(const FTransform &Transform, ETeleportType Teleport=ETeleportType::TeleportPhysics)
FVector GetActorGlobalLocation() const
ActorType GetActorType() const
A view over an actor and its properties.
void ProcessReplayerAnimWalker(CarlaRecorderAnimWalker Walker)