CARLA
 
载入中...
搜索中...
未找到
TriggerFactory.cpp
浏览该文件的文档.
1// Copyright (c) 2019 Computer Vision Center (CVC) at the Universitat Autonoma
2// de Barcelona (UAB).
3//
4// This work is licensed under the terms of the MIT license.
5// For a copy, see <https://opensource.org/licenses/MIT>.
6
7#include "Carla.h"
9
16
17// =============================================================================
18// -- ATriggerFactory -----------------------------------------------------------
19// =============================================================================
20
21TArray<FActorDefinition> ATriggerFactory::GetDefinitions()
22{
23 FActorDefinition TriggerDefinition = FActorDefinition();
24 TriggerDefinition.Class = AFrictionTrigger::StaticClass();
25
26 TArray<FActorDefinition> TriggerDefinitions;
27
28 bool Success;
29 UActorBlueprintFunctionLibrary::MakeTriggerDefinition(TEXT("friction"), Success, TriggerDefinition);
30 check(Success);
31 TriggerDefinitions.Add(TriggerDefinition);
32
33 return TriggerDefinitions;
34}
35
37 const FTransform &Transform,
38 const FActorDescription &Description)
39{
40 auto *World = GetWorld();
41 if (World == nullptr)
42 {
43 UE_LOG(LogCarla, Error, TEXT("ATriggerFactory: cannot spawn trigger into an empty world."));
44 return {};
45 }
46
48 if (GameInstance == nullptr)
49 {
50 UE_LOG(LogCarla, Error, TEXT("ATriggerFactory:: cannot spawn trigger, incompatible game instance."));
51 return {};
52 }
53
54 auto *Trigger = World->SpawnActorDeferred<AFrictionTrigger>(
55 Description.Class,
56 Transform,
57 this,
58 nullptr,
59 ESpawnActorCollisionHandlingMethod::AlwaysSpawn);
60
61 if (Trigger == nullptr)
62 {
63 UE_LOG(LogCarla, Error, TEXT("ATriggerFactory:: spawn trigger failed."));
64 }
65 else
66 {
67 // Retrieve Episode
68 auto *Episode = GameInstance->GetCarlaEpisode();
69 check(Episode != nullptr);
70 Trigger->SetEpisode(*Episode);
71
72 // Retrieve Friction
74 Description.Variations,
75 3.5f);
76 Trigger->SetFriction(Friction);
77
78 // Retrieve Extent
79 FVector Extent {100.0f, 100.0f, 100.0f};
80
82 Description.Variations,
83 Extent.X);
85 Description.Variations,
86 Extent.Y);
88 Description.Variations,
89 Extent.Z);
90
91 Trigger->SetBoxExtent(Extent);
92 }
93 UGameplayStatics::FinishSpawningActor(Trigger, Transform);
94 return FActorSpawnResult{Trigger};
95}
TArray< FActorDefinition > GetDefinitions() final
Retrieve the definitions of all the sensors registered in the SensorRegistry.
FActorSpawnResult SpawnActor(const FTransform &SpawnAtTransform, const FActorDescription &ActorDescription) final
Spawn an actor based on ActorDescription and Transform.
static void MakeTriggerDefinition(const FString &Id, bool &Success, FActorDefinition &Definition)
static float RetrieveActorAttributeToFloat(const FString &Id, const TMap< FString, FActorAttribute > &Attributes, float Default)
The game instance contains elements that must be kept alive in between levels.
UCarlaEpisode * GetCarlaEpisode()
static UCarlaGameInstance * GetGameInstance(const UObject *WorldContextObject)
A definition of a Carla Actor with all the variation and attributes.
TSubclassOf< AActor > Class
Class of the actor to be spawned (Optional).
A description of a Carla Actor with all its variation.
TMap< FString, FActorAttribute > Variations
User selected variations of the actor.
TSubclassOf< AActor > Class
Class of the actor to be spawned.
Result of an actor spawn function.