CARLA
Loading...
Searching...
No Matches
MapGenFunctionLibrary.h
Go to the documentation of this file.
1// Copyright (c) 2026 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
10
11#include <util/ue-header-guard-begin.h>
12#include "CoreMinimal.h"
13#include "Kismet/BlueprintFunctionLibrary.h"
14#include "MeshDescription.h"
15#include "ProceduralMeshComponent.h"
16#include <util/ue-header-guard-end.h>
17
18#include "MapGenFunctionLibrary.generated.h"
19
20
21DECLARE_LOG_CATEGORY_EXTERN(LogCarlaMapGenFunctionLibrary, Log, All);
22
23UCLASS(BlueprintType)
25{
26 GENERATED_BODY()
27public:
28 UFUNCTION(BlueprintCallable)
29 static UStaticMesh* CreateMesh(
30 const FProceduralCustomMesh& Data,
31 const TArray<FProcMeshTangent>& ParamTangents,
32 UMaterialInstance* MaterialInstance,
33 FString MapName,
34 FString FolderName,
35 FName MeshName);
36
37 static FMeshDescription BuildMeshDescriptionFromData(
38 const FProceduralCustomMesh& Data,
39 const TArray<FProcMeshTangent>& ParamTangents,
40 UMaterialInstance* MaterialInstance );
41
42 UFUNCTION(BlueprintCallable)
43 static FVector2D GetTransversemercProjection(float lat, float lon, float lat0, float lon0);
44
45 UFUNCTION(BlueprintCallable)
46 static void SetThreadToSleep(float seconds);
47
48 UFUNCTION(BlueprintCallable)
49 static void FlushRenderingCommandsInBlueprint();
50
51 UFUNCTION(BlueprintCallable)
52 static void CleanupGEngine();
53
54 // This function will count instances of each static mesh in the level, if there are > MinNumOfInstancesToBeChanged they will be changed by instanced static meshes
55 // to reduce draw calls
56 UFUNCTION(BlueprintCallable)
57 static TArray<class AInstancedStaticMeshActor*> ChangeStaticMeshesInTheLevelForInstancedStaticMeshes(UWorld* World, TArray<UStaticMesh*> Filter, int MinNumOfInstancesToBeChanged = 20);
58
59 // This function will removed instanced static meshes in the level and place static mesh actors instead
60 UFUNCTION(BlueprintCallable)
61 static TArray<AStaticMeshActor*> RevertStaticMeshesInTheLevelForInstancedStaticMeshes(UWorld* World, TArray<UStaticMesh*> Filter);
62
63 // Ported from carla-digitaltwins' CarlaMeshGeneration module so its building-generator
64 // blueprints (redirected here via CoreRedirects) can run against stock CARLA.
65 UFUNCTION(BlueprintCallable)
66 static UInstancedStaticMeshComponent* AddInstancedStaticMeshComponentToActor(AActor* TargetActor);
67
68 UFUNCTION(BlueprintCallable)
69 static UStaticMeshComponent* AddStaticMeshComponentToActor(AActor* TargetActor);
70
71 // Ported from carla-mesh-generation (MIT) for the carla-digitaltwins tooling.
72 UFUNCTION(BlueprintCallable)
73 static FVector2D InverseTransverseMercatorProjection(float x, float y, float lat0, float lon0);
74
75 UFUNCTION(BlueprintCallable)
76 static USceneComponent* AddSceneComponentToActor(AActor* TargetActor);
77
78 UFUNCTION(BlueprintCallable)
79 static void SmoothVerticesDeep(
80 TArray<FVector>& Vertices,
81 const TArray<int32>& Indices,
82 int Depth = 3, // Number of neighbor levels
83 int NumIterations = 1,
84 float SmoothingFactor = 1.0f // Blend between original and averaged
85 );
86
87 static uint16 GetPixelG16(const TArrayView64<const uint16>& Pixels, int Width, int Height, int X, int Y)
88 {
89 X = FMath::Clamp(X, 0, Width - 1);
90 Y = FMath::Clamp(Y, 0, Height - 1);
91 return Pixels[Y * Width + X];
92 }
93
94 static float CubicHermite(float A, float B, float C, float D, float T)
95 {
96 float a = -0.5f*A + 1.5f*B - 1.5f*C + 0.5f*D;
97 float b = A - 2.5f*B + 2.0f*C - 0.5f*D;
98 float c = -0.5f*A + 0.5f*C;
99 float d = B;
100 return ((a * T + b) * T + c) * T + d;
101 }
102
103 static float BicubicSampleG16(const TArrayView64<const uint16>& Pixels, int Width, int Height, float X, float Y);
104};
float y
float x
DECLARE_LOG_CATEGORY_EXTERN(LogCarlaMapGenFunctionLibrary, Log, All)
static float CubicHermite(float A, float B, float C, float D, float T)
static uint16 GetPixelG16(const TArrayView64< const uint16 > &Pixels, int Width, int Height, int X, int Y)
A definition of a Carla Mesh.