CARLA
CityMapMeshHolder.h
Go to the documentation of this file.
1 // Copyright (c) 2017 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 #pragma once
8 
9 #include "GameFramework/Actor.h"
10 #include "CityMapMeshTag.h"
11 #include "CityMapMeshHolder.generated.h"
12 
13 class IDetailLayoutBuilder;
14 class UInstancedStaticMeshComponent;
15 class AStaticMeshActor;
16 
17 
18 /// Holds the static meshes and instances necessary for building a city map.
19 UCLASS(Abstract)
20 class CARLA_API ACityMapMeshHolder : public AActor
21 {
22  GENERATED_BODY()
23 
24  // ===========================================================================
25  // -- Construction and update related methods --------------------------------
26  // ===========================================================================
27 public:
28 
29  /// Initializes the mesh holders. It is safe to call SetStaticMesh after this.
30  /// However, instances cannot be added until OnConstruction is called.
31  ACityMapMeshHolder(const FObjectInitializer& ObjectInitializer);
32  //void LayoutDetails( IDetailLayoutBuilder& DetailLayout );
33 protected:
34 
35  /// Initializes the instantiators.
36  virtual void OnConstruction(const FTransform &Transform) override;
37  virtual void PostInitializeComponents() override;
38 
39 #if WITH_EDITOR
40  /// Clears and updates the instantiators.
41  virtual void PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent) override;
42 #endif // WITH_EDITOR
43 
44  // ===========================================================================
45  // -- Other protected methods ------------------------------------------------
46  // ===========================================================================
47 protected:
48 
49  float GetMapScale() const
50  {
51 
52  return MapScale;
53  }
54 
55  /// Return the 3D world location (relative to this actor) of the given 2D
56  /// tile.
57  FVector GetTileLocation(uint32 X, uint32 Y) const;
58 
59  /// Set the static mesh associated with @a Tag.
60  void SetStaticMesh(ECityMapMeshTag Tag, UStaticMesh *Mesh);
61 
62  /// Return the static mesh corresponding to @a Tag.
63  UStaticMesh *GetStaticMesh(ECityMapMeshTag Tag);
64 
65  /// Return the static mesh corresponding to @a Tag.
66  const UStaticMesh *GetStaticMesh(ECityMapMeshTag Tag) const;
67 
68  /// Return the tag corresponding to @a StaticMesh.
69  ECityMapMeshTag GetTag(const UStaticMesh &StaticMesh) const;
70 
71  /// Add an instance of a mesh with a given tile location.
72  /// @param Tag The mesh' tag
73  /// @param X Tile coordinate X
74  /// @param Y Tile coordinate Y
75  void AddInstance(ECityMapMeshTag Tag, uint32 X, uint32 Y);
76 
77  /// Add an instance of a mesh with a given tile location and rotation.
78  /// @param Tag The mesh' tag
79  /// @param X Tile coordinate X
80  /// @param Y Tile coordinate Y
81  /// @param Angle Rotation around Z axis
82  void AddInstance(ECityMapMeshTag Tag, uint32 X, uint32 Y, float Angle);
83 
84  /// Add an instance of a mesh with a given transform.
85  /// @param Tag The mesh' tag
86  /// @param Transform Transform that will be applied to the mesh
87  void AddInstance(ECityMapMeshTag Tag, FTransform Transform);
88 
89  // ===========================================================================
90  // -- Private methods and members --------------------------------------------
91  // ===========================================================================
92 private:
93 
94  /// Here does nothing, implement in derived classes.
95  virtual void UpdateMap();
96 
97  /// Clear all instances of the static mesh actors.
98  void DeletePieces();
99 
100  /// Set the scale to the dimensions of the base mesh.
101  void UpdateMapScale();
102 
103  private:
104 
105 
106  UPROPERTY()
107  USceneComponent *SceneRootComponent;
108 
109  UPROPERTY(Category = "Map Generation", VisibleAnywhere)
110  float MapScale = 1.0f;
111 
112  UPROPERTY(Category = "Meshes", EditAnywhere)
113  TMap<ECityMapMeshTag, UStaticMesh *> StaticMeshes;
114 
115  UPROPERTY()
116  TMap<UStaticMesh *, ECityMapMeshTag> TagMap;
117 
118 
119 };
ECityMapMeshTag
Tag to identify the meshes used by the ProceduralMapGenerator.
Holds the static meshes and instances necessary for building a city map.
float GetMapScale() const
geom::Transform Transform
Definition: rpc/Transform.h:16