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(
false);
240 result.second->GetActor()->SetActorEnableCollision(
true);
243 return std::make_pair(result.first, result.second->GetActorId());
245 return std::make_pair(result.first, 0);
253 if (CarlaActor ==
nullptr)
255 UE_LOG(LogCarla, Log, TEXT(
"Actor %d not found to destroy"), DatabaseId);
270 UE_LOG(LogCarla, Log, TEXT(
"Parenting Child actors not found"));
275 UE_LOG(LogCarla, Log, TEXT(
"Parenting Parent actors not found"));
312 Rotation = FRotator::MakeFromEuler(Pos1.
Rotation);
317 Location = FMath::Lerp(FVector(Pos1.
Location), FVector(Pos2.
Location), Per);
318 Rotation = FMath::Lerp(FRotator::MakeFromEuler(Pos1.
Rotation), FRotator::MakeFromEuler(Pos2.
Rotation), Per);
321 FTransform Trans(Rotation, Location, FVector(1, 1, 1));
332 if (CarlaActor ==
nullptr)
337 check(CarlaVehicle !=
nullptr)
338 USkeletalMeshComponent* SkeletalMesh = CarlaVehicle->GetMesh();
339 check(SkeletalMesh !=
nullptr)
340 UVehicleAnimInstance* VehicleAnim = Cast<UVehicleAnimInstance>(SkeletalMesh->GetAnimInstance());
341 check(VehicleAnim !=
nullptr)
343 for (uint32_t i = 0; i < VehicleAnimWheels.
WheelValues.size(); ++i)
371 FQuat ActorRot = ActorTransform.GetRotation();
372 FVector Pos = ActorTransform.GetTranslation() + (ActorRot.RotateVector(Offset));
434 UWorld* World =
Episode->GetWorld();
438 if (!CarlaLightSubsystem)
445 CarlaLight->SetLightIntensity(LightScene.
Intensity);
446 CarlaLight->SetLightColor(LightScene.
Color);
447 CarlaLight->SetLightOn(LightScene.
bOn);
448 CarlaLight->SetLightType(static_cast<ELightType>(LightScene.
Type));
463 if (CarlaActor ==
nullptr)
466 check(CarlaVehicle !=
nullptr)
477 if (!CarlaActor)
return;
480 auto Walker = Cast<APawn>(
Actor);
483 AWalkerController *Controller = Cast<AWalkerController>(Walker->GetController());
484 if (!Controller)
return;
488 for (
const auto &Bone : WalkerBones.
Bones)
490 FTransform Trans(FRotator::MakeFromEuler(Bone.Rotation), Bone.Location, FVector(1, 1, 1));
504 for (
auto& It : Registry)
515 if (!(bIgnoreHero && IsHero[CarlaActor->
GetActorId()]))
522 Control.
Steer = 0.0f;
523 Control.
Brake = 0.0f;
561 Control.
Speed = Speed;
568 auto World =
Episode->GetWorld();
569 for (TActorIterator<AStaticMeshActor> It(World); It; ++It)
572 check(
Actor !=
nullptr);
573 auto MeshComponent =
Actor->GetStaticMeshComponent();
574 check(MeshComponent !=
nullptr);
575 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 &)
void ProcessReplayerAnimBiker(CarlaRecorderAnimBiker Biker)
void BlendPose(float Blend)
auto end() const noexcept
A registry of all the Carla actors.
void SetSpeedAnim(float Speed)
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 ProcessReplayerAnimVehicleWheels(CarlaRecorderAnimWheels Vehicle)
std::pair< int, uint32_t > ProcessReplayerEventAdd(FVector Location, FVector Rotation, CarlaRecorderActorDescription Description, uint32_t DesiredId, bool bIgnoreHero, bool bIgnoreSpectator, bool ReplaySensors)
void ProcessReplayerWalkerBones(const CarlaRecorderWalkerBones &Walker)
void PutActorToSleep(carla::rpc::ActorId ActorId)
void OnActorSpawned(const FCarlaActor &CarlaActor)
virtual ECarlaServerResponse ApplyControlToVehicle(const FVehicleControl &, const EVehicleInputPriority &)
EVehicleWheelLocation Location
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)
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)
TMap< FString, FTransform > BoneTransforms
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)
void SetRotationAnim(float Rotation)
void SetBonesTransform(const FWalkerBoneControlIn &WalkerBones)
std::pair< int, FCarlaActor * > TryToCreateReplayerActor(FVector &Location, FVector &Rotation, FActorDescription &ActorDesc, uint32_t DesiredId, bool SpawnSensors)
ATrafficLightGroup * GetGroup()
std::vector< WheelInfo > WheelValues
Base class for CARLA wheeled vehicles.
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)
std::vector< CarlaRecorderWalkerBone > Bones
FVector GetActorGlobalLocation() const
ActorType GetActorType() const
A view over an actor and its properties.
void ProcessReplayerAnimWalker(CarlaRecorderAnimWalker Walker)