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))
137 if (Actor ==
nullptr)
141 Actor->SetActorEnableCollision(
true);
142 TArray<UPrimitiveComponent *> Primitives;
143 Actor->GetComponents<UPrimitiveComponent>(Primitives);
144 for (UPrimitiveComponent *Primitive : Primitives)
146 const ECollisionEnabled::Type Enabled = Primitive->BodyInstance.GetCollisionEnabled(
false);
147 const bool bOverlaps = Primitive->GetGenerateOverlapEvents();
149 const bool bSensorVisible = Primitive == Actor->GetRootComponent() ||
150 Primitive->GetCollisionResponseToChannel(ECC_GameTraceChannel2 ) == ECR_Block;
151 const ECollisionEnabled::Type Replayed =
152 Enabled == ECollisionEnabled::NoCollision || !bSensorVisible ? ECollisionEnabled::NoCollision : ECollisionEnabled::QueryOnly;
153 if (Replayed == Enabled && !bOverlaps)
158 Primitive->SetGenerateOverlapEvents(
false);
159 Primitive->SetCollisionEnabled(Replayed);
202 bool bIgnoreSpectator,
210 ActorDesc.
UId = Description.
UId;
211 ActorDesc.
Id = Description.
Id;
212 for (
const auto &Item : Description.
Attributes)
217 Attr.
Value = Item.Value;
220 if (Item.Id ==
"role_name" && Item.Value ==
"hero")
225 if ((bIgnoreHero && IsHero) ||
226 (bIgnoreSpectator && ActorDesc.
Id.StartsWith(
"spectator")))
228 return std::make_pair(3, 0);
238 if (result.first != 0)
245 if (!(bIgnoreHero && IsHero))
260 result.second->GetActor()->SetActorEnableCollision(
true);
263 return std::make_pair(result.first, result.second->GetActorId());
265 return std::make_pair(result.first, 0);
273 if (CarlaActor ==
nullptr)
275 UE_LOG(LogCarla, Log, TEXT(
"Actor %d not found to destroy"), DatabaseId);
290 UE_LOG(LogCarla, Log, TEXT(
"Parenting Child actors not found"));
295 UE_LOG(LogCarla, Log, TEXT(
"Parenting Parent actors not found"));
352 const float Delta = FMath::UnwindDegrees(Spin2 - Spin1);
353 if (Radius <= UE_KINDA_SMALL_NUMBER)
357 const float Expected = -FMath::RadiansToDegrees(Travel / Radius);
358 return Delta + 360.0f * FMath::RoundToFloat((Expected - Delta) / 360.0f);
369 if (CarlaActor ==
nullptr)
374 check(CarlaVehicle !=
nullptr)
381 const float Alpha =
static_cast<float>(Per);
383 for (
size_t i = 0; i < Wheels2.
WheelValues.size(); ++i)
387 const int32 WheelIndex =
static_cast<int32
>(Element2.
Location);
388 if (!CarlaVehicle->
HasWheel(WheelIndex))
418 FQuat ActorRot = ActorTransform.GetRotation();
419 FVector Pos = ActorTransform.GetTranslation() + (ActorRot.RotateVector(Offset));
501 if (WeatherActor !=
nullptr)
525 UWorld* World =
Episode->GetWorld();
529 if (!CarlaLightSubsystem)
536 CarlaLight->SetLightIntensity(LightScene.
Intensity);
537 CarlaLight->SetLightColor(LightScene.
Color);
538 CarlaLight->SetLightOn(LightScene.
bOn);
539 CarlaLight->SetLightType(
static_cast<ELightType>(LightScene.
Type));
558 if (CarlaActor ==
nullptr)
561 check(CarlaVehicle !=
nullptr)
572 if (!CarlaActor)
return;
575 auto Walker = Cast<APawn>(Actor);
578 AWalkerController *Controller = Cast<AWalkerController>(Walker->GetController());
579 if (!Controller)
return;
585 FTransform Trans(FRotator::MakeFromEuler(Bone.Rotation), Bone.Location, FVector(1, 1, 1));
600 if (Replayed.Primitive.IsValid())
602 Replayed.Primitive->SetCollisionEnabled(
static_cast<ECollisionEnabled::Type
>(Replayed.CollisionEnabled));
603 Replayed.Primitive->SetGenerateOverlapEvents(Replayed.bGenerateOverlapEvents);
610 for (
auto& It : Registry)
621 if (!(bIgnoreHero && IsHero[CarlaActor->
GetActorId()]))
625 if (
auto* CarlaVehicle = Cast<ACarlaWheeledVehicle>(CarlaActor->
GetActor()))
627 CarlaVehicle->SetWheelAnimationOverride(
false);
632 Control.
Steer = 0.0f;
633 Control.
Brake = 0.0f;
672 Control.
Speed = Speed;
679 auto World =
Episode->GetWorld();
680 for (TActorIterator<AStaticMeshActor> It(World); It; ++It)
683 check(Actor !=
nullptr);
684 auto MeshComponent = Actor->GetStaticMeshComponent();
685 check(MeshComponent !=
nullptr);
686 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)
void MakeReplayedActorQueryOnly(AActor *Actor)
bool ProcessReplayerStateTrafficLight(CarlaRecorderStateTrafficLight State)
TArray< FReplayedPrimitive > ReplayedPrimitives
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 &)
Euler angles of a rotation in CARLA's / Unreal's left-handed frame: x forward, y right,...
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