29#include <util/ue-header-guard-begin.h>
30#include "Components/BoxComponent.h"
31#include "Engine/StaticMeshActor.h"
32#include <util/ue-header-guard-end.h>
40#include "EngineUtils.h"
53 if (ActorDesc.
Id.StartsWith(
"traffic."))
56 if (CarlaActor !=
nullptr)
59 return std::pair<int, FCarlaActor*>(2, CarlaActor);
64 UE_LOG(LogCarla, Log, TEXT(
"TrafficLight not found"));
65 return std::pair<int, FCarlaActor*>(0,
nullptr);
68 else if (SpawnSensors || !ActorDesc.
Id.StartsWith(
"sensor."))
71 FRotator Rot = FRotator::MakeFromEuler(Rotation);
72 FTransform Trans(Rot, FVector(0, 0, 100000), FVector(1, 1, 1));
75 if (Result.Key == EActorSpawnResultStatus::Success)
78 FTransform Trans2(Rot, Location, FVector(1, 1, 1));
79 Result.Value->SetActorGlobalTransform(Trans2);
85 return std::pair<int, FCarlaActor*>(1, Result.Value);
89 UE_LOG(LogCarla, Log, TEXT(
"Actor could't be created by replayer"));
90 return std::pair<int, FCarlaActor*>(0, Result.Value);
96 return std::pair<int, FCarlaActor*>(0,
nullptr);
103 auto World =
Episode->GetWorld();
104 check(World !=
nullptr);
107 int x =
static_cast<int>(Location.X);
108 int y =
static_cast<int>(Location.Y);
109 int z =
static_cast<int>(Location.Z);
113 for (
auto It = Registry.
begin(); It != Registry.
end(); ++It)
120 int x2 =
static_cast<int>(vec.X);
121 int y2 =
static_cast<int>(vec.Y);
122 int z2 =
static_cast<int>(vec.Z);
123 if ((x2 ==
x) && (y2 ==
y) && (z2 ==
z))
173 bool bIgnoreSpectator,
181 ActorDesc.
UId = Description.
UId;
182 ActorDesc.
Id = Description.
Id;
183 for (
const auto &Item : Description.
Attributes)
188 Attr.
Value = Item.Value;
191 if (Item.Id ==
"role_name" && Item.Value ==
"hero")
196 if ((bIgnoreHero && IsHero) ||
197 (bIgnoreSpectator && ActorDesc.
Id.StartsWith(
"spectator")))
199 return std::make_pair(3, 0);
209 if (result.first != 0)
216 if (!(bIgnoreHero && IsHero))
221 result.second->GetActor()->SetActorEnableCollision(
false);
231 result.second->GetActor()->SetActorEnableCollision(
true);
234 return std::make_pair(result.first, result.second->GetActorId());
236 return std::make_pair(result.first, 0);
244 if (CarlaActor ==
nullptr)
246 UE_LOG(LogCarla, Log, TEXT(
"Actor %d not found to destroy"), DatabaseId);
261 UE_LOG(LogCarla, Log, TEXT(
"Parenting Child actors not found"));
266 UE_LOG(LogCarla, Log, TEXT(
"Parenting Parent actors not found"));
303 Rotation = FRotator::MakeFromEuler(Pos1.
Rotation);
308 Location = FMath::Lerp(FVector(Pos1.
Location), FVector(Pos2.
Location), Per);
309 Rotation = FMath::Lerp(FRotator::MakeFromEuler(Pos1.
Rotation), FRotator::MakeFromEuler(Pos2.
Rotation), Per);
312 FTransform Trans(Rotation, Location, FVector(1, 1, 1));
323 const float Delta = FMath::UnwindDegrees(Spin2 - Spin1);
324 if (Radius <= UE_KINDA_SMALL_NUMBER)
328 const float Expected = -FMath::RadiansToDegrees(Travel / Radius);
329 return Delta + 360.0f * FMath::RoundToFloat((Expected - Delta) / 360.0f);
340 if (CarlaActor ==
nullptr)
345 check(CarlaVehicle !=
nullptr)
352 const float Alpha =
static_cast<float>(Per);
354 for (
size_t i = 0; i < Wheels2.
WheelValues.size(); ++i)
358 const int32 WheelIndex =
static_cast<int32
>(Element2.
Location);
359 if (!CarlaVehicle->
HasWheel(WheelIndex))
389 FQuat ActorRot = ActorTransform.GetRotation();
390 FVector Pos = ActorTransform.GetTranslation() + (ActorRot.RotateVector(Offset));
472 if (WeatherActor !=
nullptr)
496 UWorld* World =
Episode->GetWorld();
500 if (!CarlaLightSubsystem)
507 CarlaLight->SetLightIntensity(LightScene.
Intensity);
508 CarlaLight->SetLightColor(LightScene.
Color);
509 CarlaLight->SetLightOn(LightScene.
bOn);
510 CarlaLight->SetLightType(
static_cast<ELightType>(LightScene.
Type));
529 if (CarlaActor ==
nullptr)
532 check(CarlaVehicle !=
nullptr)
543 if (!CarlaActor)
return;
546 auto Walker = Cast<APawn>(Actor);
549 AWalkerController *Controller = Cast<AWalkerController>(Walker->GetController());
550 if (!Controller)
return;
556 FTransform Trans(FRotator::MakeFromEuler(Bone.Rotation), Bone.Location, FVector(1, 1, 1));
570 for (
auto& It : Registry)
581 if (!(bIgnoreHero && IsHero[CarlaActor->
GetActorId()]))
585 if (
auto* CarlaVehicle = Cast<ACarlaWheeledVehicle>(CarlaActor->
GetActor()))
587 CarlaVehicle->SetWheelAnimationOverride(
false);
594 CarlaActor->
GetActor()->SetActorEnableCollision(
true);
599 Control.
Steer = 0.0f;
600 Control.
Brake = 0.0f;
638 Control.
Speed = Speed;
645 auto World =
Episode->GetWorld();
646 for (TActorIterator<AStaticMeshActor> It(World); It; ++It)
649 check(Actor !=
nullptr);
650 auto MeshComponent = Actor->GetStaticMeshComponent();
651 check(MeshComponent !=
nullptr);
652 if (MeshComponent->Mobility == EComponentMobility::Movable)
static float GetWheelSpinDelta(float Spin1, float Spin2, float Travel, float Radius)
EVehicleDoor
Type of door to open/close.
EActorAttributeType
List of valid types for actor attributes.
Base class for CARLA wheeled vehicles.
float GetWheelRadius(int32 WheelIndex) const
Radius of the wheel at WheelIndex, in cm, as last applied through the physics control.
bool HasCarlaVehicleAnimation() const
Whether the animation blueprint derives from UCarlaVehicleAnimationInstance, which is what draws the ...
void SetWheelAnimationOverride(bool bEnabled)
While the wheel animation is overridden the wheels show only the values set through the wheel setters...
void SetWheelSteerDirection(EVehicleWheelLocation WheelLocation, float AngleInDeg)
Set the rotation of the car wheels indicated by the user 0 = FL_VehicleWheel, 1 = FR_VehicleWheel,...
bool HasWheel(int32 WheelIndex) const
void SetRotationAnim(float Rotation)
void SetSpeedAnim(float Speed)
void SetWheelPitchAngle(EVehicleWheelLocation WheelLocation, float AngleInDeg)
Spin angle of a wheel, in degrees. Purely visual, wheel animation override only.
void OnActorSpawned(const FCarlaActor &CarlaActor)
Class which implements the state changing of traffic lights.
void SetFrozenGroup(bool InFreeze)
Possesses every walker pawn.
void BlendPose(float Blend)
void SetBonesTransform(const FWalkerBoneControlIn &WalkerBones)
void ApplyWeather(const FWeatherParameters &WeatherParameters)
Update the weather parameters and notifies it to the blueprint's event.
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(const CarlaRecorderAnimWheels &Wheels1, const CarlaRecorderAnimWheels &Wheels2, double Per, float Travel)
void ProcessReplayerLightScene(CarlaRecorderLightScene LightScene)
FCarlaActor * FindTrafficSignAt(FVector Location)
void ProcessReplayerDoorVehicle(CarlaRecorderDoorVehicle DoorVehicle)
void ProcessReplayerAnimWalker(CarlaRecorderAnimWalker Walker)
bool ProcessReplayerStateTrafficLight(CarlaRecorderStateTrafficLight State)
bool ProcessReplayerEventParent(uint32_t ChildId, uint32_t ParentId)
bool SetActorSimulatePhysics(FCarlaActor *CarlaActor, bool bEnabled)
void ProcessReplayerAnimVehicle(CarlaRecorderAnimVehicle Vehicle)
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 ProcessReplayerPosition(CarlaRecorderPosition Pos1, CarlaRecorderPosition Pos2, double Per, double DeltaTime)
void ProcessReplayerWeather(const CarlaRecorderWeather &Weather)
bool SetCameraPosition(uint32_t Id, FVector Offset, FQuat Rotation)
A registry of all the Carla actors.
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.
AWeather * GetWeather() const
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)
Attach Child to Parent.
bool DestroyActor(AActor *Actor)
void SetClientStatesdirty(FString ClientThatUpdate)
Flag every registered client (except ClientThatUpdate) so their LightManager re-queries light states.
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
float RayleighScatteringScale
float PrecipitationDeposits
float ScatteringIntensity
EVehicleWheelLocation Location