NVIDIA DeepLearning Dataset Synthesizer (NDDS)
 All Classes Namespaces Functions Variables Typedefs Pages
GroupActorManager.h
1 /*
2 * Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved.
3 *
4 * NVIDIA CORPORATION and its licensors retain all intellectual property
5 * and proprietary rights in and to this software, related documentation
6 * and any modifications thereto. Any use, reproduction, disclosure or
7 * distribution of this software and related documentation without an express
8 * license agreement from NVIDIA CORPORATION is strictly prohibited.
9 */
10 
11 #pragma once
12 
13 #include "GameFramework/Actor.h"
14 #include "DomainRandomizationDNNPCH.h"
15 #include "GroupActorManager.generated.h"
16 
18 
19 USTRUCT(Blueprintable)
20 struct DOMAINRANDOMIZATIONDNN_API FNVActorTemplateConfig
21 {
22  GENERATED_BODY()
23 
24  FNVActorTemplateConfig();
25 
26 public:
27  // The class to be used to spawn the new actor
28  UPROPERTY(EditAnywhere)
29  TSubclassOf<AActor> ActorClass;
30 
31  // The mesh to be used by the new actor
32  UPROPERTY(EditAnywhere)
33  class UStaticMesh* ActorOverrideMesh;
34 };
35 
36 /**
37 * Manages array of actors to spawn with mesh and spatial randomization control.
38 */
39 UCLASS(Blueprintable)
40 class DOMAINRANDOMIZATIONDNN_API AGroupActorManager : public AActor
41 {
42  GENERATED_BODY()
43 
44 public:
45  AGroupActorManager(const FObjectInitializer& ObjectInitializer);
46 
47  void SpawnActors();
48  void SpawnTemplateActors();
49 
50 protected:
51  virtual void BeginPlay() override;
52  virtual void BeginDestroy() override;
53  virtual void PostLoad() override;
54 
55  virtual void Tick(float DeltaTime) override;
56 
57  bool ShouldSpawnRepeatively() const;
58 
59  AActor* CreateActorFromTemplate(const FNVActorTemplateConfig& ActorTemplate, const FTransform& ActorTransform);
60 
61 public: // Editor properties
62  UPROPERTY(EditAnywhere, Category = GroupActorManager)
63  bool bAutoActive;
64 
65  // The list of actor classes to spawn and manage
66  UPROPERTY(EditAnywhere, Category = GroupActorManager)
67  TArray<TSubclassOf<AActor>> ActorClassesToSpawn;
68 
69  // The list of meshes to used for managed actors
70  // NOTE: If there are meshes in this list, the system will only use the first class in
71  UPROPERTY(EditAnywhere, Category = GroupActorManager)
72  TArray<class UStaticMesh*> OverrideActorMeshes;
73 
74  // How many instances of each actors do we need to spawn
75  UPROPERTY(EditAnywhere, Category = GroupActorManager)
76  FInt32Interval CountPerActor;
77 
78  // Total number of actors to spawn
79  UPROPERTY(EditAnywhere, Category = GroupActorManager)
80  FInt32Interval TotalNumberOfActorsToSpawn;
81 
82  // The layout for these managed actors
83  UPROPERTY(EditAnywhere, Instanced, SimpleDisplay, Category = GroupActorManager)
84  USpatialLayoutGenerator* LayoutGenerator;
85 
86  // The volume to choose the location where those managed actor can be in
87  UPROPERTY(EditAnywhere, BlueprintReadWrite)
88  AVolume* RandomLocationVolume;
89 
90  // How long to wait until we spawn a new group of actors again
91  // NOTE: If SpawnDuration <= 0 then we only spawn the actors once
92  UPROPERTY(EditAnywhere, Category = GroupActorManager)
93  float SpawnDuration;
94 
95 protected: // Transient
96  UPROPERTY(Transient)
97  TArray<AActor*> ManagedActors;
98 
99  UPROPERTY(Transient)
100  TArray<AActor*> TemplateActors;
101  UPROPERTY(Transient)
102  float CountdownUntilNextSpawn;
103 
104 #if WITH_EDITORONLY_DATA
105  virtual void PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent) override;
106  static void AddReferencedObjects(UObject* InThis, FReferenceCollector& Collector);
107 
108 protected:
109  // List of the proxy meshes used to show where actors should be on the level
110  TArray<class UStaticMeshComponent*> ProxyMeshComponents;
111 
112  void UpdateProxyMeshes();
113  void UpdateProxyMeshesVisibility();
114 
115 #endif // WITH_EDITORONLY_DATA
116 
117  void DestroyManagedActors();
118 };