9 #include "Engine/StaticMeshActor.h" 10 #include "Components/InstancedStaticMeshComponent.h" 11 #include "Engine/StaticMesh.h" 15 #include "Kismet/KismetSystemLibrary.h" 18 using tag_size_t = std::underlying_type<ECityMapMeshTag>::type;
27 : Super(ObjectInitializer)
29 PrimaryActorTick.bCanEverTick =
false;
32 ObjectInitializer.CreateDefaultSubobject<USceneComponent>(
this, TEXT(
"SceneComponent"));
52 Super::OnConstruction(Transform);
58 Super::PostInitializeComponents();
60 if(
IsValid(GetLevel())&&!GetLevel()->IsPendingKill())
62 TArray<AActor*> roadpieces;
63 GetAttachedActors(roadpieces);
64 if(roadpieces.Num()==0)
66 UE_LOG(LogCarla, Error, TEXT(
"Please regenerate the road in edit mode for '%s' actor"), *UKismetSystemLibrary::GetDisplayName(
this));
75 void ACityMapMeshHolder::PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent)
77 Super::PostEditChangeProperty(PropertyChangedEvent);
78 if (PropertyChangedEvent.Property)
99 if (Mesh !=
nullptr) {
117 return (Tag !=
nullptr ? *Tag : ECityMapMeshTag::INVALID);
127 const FQuat rotation(FVector(0.0f, 0.0f, 1.0f), Angle);
134 FActorSpawnParameters params;
135 params.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
136 FVector location = Transform.GetLocation();
137 FRotator rotation = Transform.Rotator();
138 AStaticMeshActor* StaticMeshActor = Cast<AStaticMeshActor>(GetWorld()->SpawnActor(AStaticMeshActor::StaticClass(),&location,&rotation,params));
139 StaticMeshActor->AttachToActor(
this,FAttachmentTransformRules::KeepRelativeTransform);
140 StaticMeshActor->SetMobility(EComponentMobility::Static);
141 UStaticMeshComponent* staticmeshcomponent = StaticMeshActor->GetStaticMeshComponent();
142 staticmeshcomponent->SetMobility(EComponentMobility::Static);
145 StaticMeshActor->bEnableAutoLODGeneration =
true;
157 TArray<UInstancedStaticMeshComponent*> oldcomponents;
158 GetComponents(oldcomponents);
159 for(int32 i=0;i<oldcomponents.Num();i++)
161 oldcomponents[i]->DestroyComponent();
164 TArray<AActor*> roadpieces;
165 GetAttachedActors(roadpieces);
167 for(int32 i=roadpieces.Num()-1; i>=0; i--)
171 roadpieces[i]->Destroy();
181 if (mesh ==
nullptr) {
185 TEXT(
"Cannot find mesh \"%s\" for computing tile size"),
189 FVector size = mesh->GetBoundingBox().GetSize();
void AddInstance(ECityMapMeshTag Tag, uint32 X, uint32 Y)
Add an instance of a mesh with a given tile location.
static FString ToString(ECityMapMeshTag Tag)
Get Tag name as FString.
static constexpr uint8 GetNumberOfTags()
Return the number of tags.
void DeletePieces()
Clear all instances of the static mesh actors.
virtual void OnConstruction(const FTransform &Transform) override
Initializes the instantiators.
static ECityMapMeshTag FromUInt(uint8 Value)
Convert an unsigned integer to a ECityMapMeshTag.
std::underlying_type< ECityMapMeshTag >::type tag_size_t
ECityMapMeshTag
Tag to identify the meshes used by the ProceduralMapGenerator.
static bool IsValid(const ACarlaWheeledVehicle *Vehicle)
void SetStaticMesh(ECityMapMeshTag Tag, UStaticMesh *Mesh)
Set the static mesh associated with Tag.
FVector GetTileLocation(uint32 X, uint32 Y) const
Return the 3D world location (relative to this actor) of the given 2D tile.
UStaticMesh * GetStaticMesh(ECityMapMeshTag Tag)
Return the static mesh corresponding to Tag.
TMap< UStaticMesh *, ECityMapMeshTag > TagMap
virtual void PostInitializeComponents() override
static constexpr tag_size_t NUMBER_OF_TAGS
static ECityMapMeshTag GetBaseMeshTag()
Return the base mesh. The base mesh defines the unit tile for map scaling.
ECityMapMeshTag GetTag(const UStaticMesh &StaticMesh) const
Return the tag corresponding to StaticMesh.
ACityMapMeshHolder(const FObjectInitializer &ObjectInitializer)
Initializes the mesh holders.
void UpdateMapScale()
Set the scale to the dimensions of the base mesh.
static const FName CARLA_ROAD_TAG
CARLA_ROAD name to tag road mesh actors.
USceneComponent * SceneRootComponent
TMap< ECityMapMeshTag, UStaticMesh * > StaticMeshes
geom::Transform Transform
virtual void UpdateMap()
Here does nothing, implement in derived classes.