12#include <util/ue-header-guard-begin.h>
13#include "Engine/StaticMeshActor.h"
14#include "Engine/StaticMesh.h"
15#include "Engine/Level.h"
16#include "Components/InstancedStaticMeshComponent.h"
17#include "Kismet/KismetSystemLibrary.h"
18#include <util/ue-header-guard-end.h>
23using tag_size_t = std::underlying_type<ECityMapMeshTag>::type;
32 : Super(ObjectInitializer)
34 PrimaryActorTick.bCanEverTick =
false;
37 ObjectInitializer.CreateDefaultSubobject<USceneComponent>(
this, TEXT(
"SceneComponent"));
57 Super::OnConstruction(Transform);
63 Super::PostInitializeComponents();
65 if (
IsValid(GetLevel()) && IsValidChecked(GetLevel()))
67 TArray<AActor*> roadpieces;
68 GetAttachedActors(roadpieces);
69 if (roadpieces.Num()==0)
71 UE_LOG(LogCarla, Error, TEXT(
"Please regenerate the road in edit mode for '%s' actor"), *UKismetSystemLibrary::GetDisplayName(
this));
80void ACityMapMeshHolder::PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent)
82 Super::PostEditChangeProperty(PropertyChangedEvent);
83 if (PropertyChangedEvent.Property)
104 if (Mesh !=
nullptr) {
122 return (Tag !=
nullptr ? *Tag : ECityMapMeshTag::INVALID);
132 const FQuat rotation(FVector(0.0f, 0.0f, 1.0f), Angle);
139 FActorSpawnParameters params;
140 params.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
141 FVector location = Transform.GetLocation();
142 FRotator rotation = Transform.Rotator();
143 AStaticMeshActor* StaticMeshActor = Cast<AStaticMeshActor>(GetWorld()->SpawnActor(AStaticMeshActor::StaticClass(),&location,&rotation,params));
144 StaticMeshActor->AttachToActor(
this,FAttachmentTransformRules::KeepRelativeTransform);
145 StaticMeshActor->SetMobility(EComponentMobility::Static);
146 UStaticMeshComponent* staticmeshcomponent = StaticMeshActor->GetStaticMeshComponent();
147 staticmeshcomponent->SetMobility(EComponentMobility::Static);
150 StaticMeshActor->bEnableAutoLODGeneration =
true;
162 TArray<UInstancedStaticMeshComponent*> oldcomponents;
163 GetComponents(oldcomponents);
164 for (int32 i=0;i<oldcomponents.Num();i++)
166 oldcomponents[i]->DestroyComponent();
169 TArray<AActor*> roadpieces;
170 GetAttachedActors(roadpieces);
172 for (int32 i=roadpieces.Num()-1; i>=0; i--)
176 roadpieces[i]->Destroy();
186 if (mesh ==
nullptr) {
190 TEXT(
"Cannot find mesh \"%s\" for computing tile size"),
194 FVector size = mesh->GetBoundingBox().GetSize();
static constexpr tag_size_t NUMBER_OF_TAGS
std::underlying_type< ECityMapMeshTag >::type tag_size_t
ECityMapMeshTag
Tag to identify the meshes used by the ProceduralMapGenerator.
static bool IsValid(const ACarlaWheeledVehicle *Vehicle)
virtual void PostInitializeComponents() override
FVector GetTileLocation(uint32 X, uint32 Y) const
Return the 3D world location (relative to this actor) of the given 2D tile.
void SetStaticMesh(ECityMapMeshTag Tag, UStaticMesh *Mesh)
Set the static mesh associated with Tag.
TMap< TObjectPtr< UStaticMesh >, ECityMapMeshTag > TagMap
virtual void UpdateMap()
Here does nothing, implement in derived classes.
void AddInstance(ECityMapMeshTag Tag, uint32 X, uint32 Y)
Add an instance of a mesh with a given tile location.
TObjectPtr< USceneComponent > SceneRootComponent
ECityMapMeshTag GetTag(const UStaticMesh &StaticMesh) const
Return the tag corresponding to StaticMesh.
UStaticMesh * GetStaticMesh(ECityMapMeshTag Tag)
Return the static mesh corresponding to Tag.
void UpdateMapScale()
Set the scale to the dimensions of the base mesh.
TMap< ECityMapMeshTag, TObjectPtr< UStaticMesh > > StaticMeshes
void DeletePieces()
Clear all instances of the static mesh actors.
ACityMapMeshHolder(const FObjectInitializer &ObjectInitializer)
Initializes the mesh holders.
virtual void OnConstruction(const FTransform &Transform) override
Initializes the instantiators.
static ECityMapMeshTag FromUInt(uint8 Value)
Convert an unsigned integer to a ECityMapMeshTag.
static constexpr uint8 GetNumberOfTags()
Return the number of tags.
static FString ToString(ECityMapMeshTag Tag)
Get Tag name as FString.
static ECityMapMeshTag GetBaseMeshTag()
Return the base mesh. The base mesh defines the unit tile for map scaling.
static const FName CARLA_ROAD_TAG
CARLA_ROAD name to tag road mesh actors.