CARLA
Loading...
Searching...
No Matches
PrepareAssetsForCookingCommandlet.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 "Commandlets/Commandlet.h"
13#include "Engine/ObjectLibrary.h"
14#include "Engine/StaticMeshActor.h"
15#include "AssetRegistry/AssetRegistryModule.h"
16#include "Materials/MaterialInterface.h"
17#include <util/ue-header-guard-end.h>
18
19#include "PrepareAssetsForCookingCommandlet.generated.h"
20
21// undef this API to avoid conflict with UE 4.26
22// (see UE_4.26\Engine\Source\Runtime\Core\Public\Windows\HideWindowsPlatformAtomics.h)
23#undef InterlockedCompareExchange
24#undef _InterlockedCompareExchange
25
26/// Struct containing Package with @a Name and @a bOnlyPrepareMaps flag used to
27/// separate the cooking of maps and props across the different stages (Maps
28/// will be imported during make import command and Props will be imported
29/// during make package command)
30USTRUCT()
31struct CARLA_API FPackageParams
32{
33 GENERATED_USTRUCT_BODY()
34
35 FString Name;
36
38};
39
40/// Struct containing map data read from .Package.json file.
41USTRUCT()
42struct CARLA_API FMapData
43{
44 GENERATED_USTRUCT_BODY()
45
46 FString Name;
47
48 FString Path;
49
51
52 /// Build one map out of a tiled .fbx set instead of a sublevel per tile.
53 bool bMergeTiles = false;
54};
55
56/// Struct containing all assets data read from .Package.json file.
57USTRUCT()
58struct CARLA_API FAssetsPaths
59{
60 GENERATED_USTRUCT_BODY()
61
63
64 TArray<FString> PropsPaths;
65};
66
67UCLASS()
69 : public UCommandlet
70{
71 GENERATED_BODY()
72
73public:
74
75 /// Default constructor.
77#if WITH_EDITORONLY_DATA
78
79 /// Parses the command line parameters provided through @a InParams
80 FPackageParams ParseParams(const FString &InParams) const;
81
82 /// Loads a UWorld object contained in Carla BaseMap into @a AssetData data
83 /// structure.
84 void LoadWorld(FAssetData &AssetData);
85
86 /// Loads a UWorld object contained in Carla BaseTile into @a AssetData data
87 /// structure.
88 void LoadWorldTile(FAssetData &AssetData);
89
90 void LoadLargeMapWorld(FAssetData &AssetData);
91
92 /// Spawns all the static meshes located in @a AssetsPaths inside the World.
93 /// There is an option to use Carla materials by setting @a bUseCarlaMaterials
94 /// to true, otherwise it will use RoadRunner materials.
95 /// If meshes are been added to a PropsMap, set @a bIsPropMap to true.
96 ///
97 /// @pre World is expected to be previously loaded
98 TArray<AStaticMeshActor *> SpawnMeshesToWorld(
99 const TArray<FString> &AssetsPaths,
100 bool bUseCarlaMaterials,
101 int i = -1,
102 int j = -1);
103
104 /// Saves the current World, contained in @a AssetData, into @a DestPath
105 /// composed of @a PackageName and with @a WorldName.
106 bool SaveWorld(
107 FAssetData &AssetData,
108 const FString &PackageName,
109 const FString &DestPath,
110 const FString &WorldName,
111 bool bGenerateSpawnPoints = true);
112
113 /// Destroys all the previously spawned actors stored in @a SpawnedActors
114 void DestroySpawnedActorsInWorld(TArray<AStaticMeshActor *> &SpawnedActors);
115
116 /// Gets the Path of all the Assets contained in the package to cook with name
117 /// @a PackageName
118 FAssetsPaths GetAssetsPathFromPackage(const FString &PackageName) const;
119
120 /// Generates the MapPaths file provided @a AssetsPaths and @a PropsMapPath
121 void GenerateMapPathsFile(const FAssetsPaths &AssetsPaths, const FString &PropsMapPath);
122
123 /// Generates the PackagePat file that contains the path of a package with @a
124 /// PackageName
125 void GeneratePackagePathFile(const FString &PackageName);
126
127 /// For each Map data contained in @MapsPaths, it creates a World, spawn its
128 /// actors inside the world and saves it in .umap format
129 /// in a destination path built from @a PackageName.
130 void PrepareMapsForCooking(const FString &PackageName, const TArray<FMapData> &MapsPaths);
131
132 /// For all the props inside @a PropsPaths, it creates a single World, spawn
133 /// all the props inside the world and saves it in .umap format
134 /// in a destination path built from @a PackageName and @a MapDestPath.
135 void PreparePropsForCooking(FString &PackageName, const TArray<FString> &PropsPaths, FString &MapDestPath);
136
137 /// Return if there is any tile between the assets to cook
138 bool IsMapInTiles(const TArray<FString> &AssetsPaths);
139
140public:
141
142 /// Main method and entry of the commandlet, taking as input parameters @a
143 /// Params.
144 virtual int32 Main(const FString &Params) override;
145
146#endif // WITH_EDITORONLY_DATA
147
148private:
149
150 /// Loaded assets from any object library
151 UPROPERTY()
152 TArray<FAssetData> AssetDatas;
153
154 /// Loaded map content from any object library
155 UPROPERTY()
156 TArray<FAssetData> MapContents;
157
158 /// Used for loading maps in object library. Loaded Data is stored in
159 /// AssetDatas.
160 UPROPERTY()
161 UObjectLibrary *MapObjectLibrary;
162
163 /// Used for loading assets in object library. Loaded Data is stored in
164 /// AssetDatas.
165 UPROPERTY()
166 UObjectLibrary *AssetsObjectLibrary;
167
168 /// Base map world loaded from Carla Content
169 UPROPERTY()
170 UWorld *World;
171
172 /// Workaround material for the RoadNode mesh
173 UPROPERTY()
174 UMaterialInstance *RoadNodeMaterial;
175
176 /// Material to apply to curbs on the road
177 UPROPERTY()
178 UMaterialInstance *CurbNodeMaterialInstance;
179
180 /// Material to apply to gutters on the road
181 UPROPERTY()
182 UMaterialInstance *GutterNodeMaterialInstance;
183
184 /// Workaround material for the center lane markings
185 UPROPERTY()
186 UMaterialInstance *MarkingNodeYellow;
187
188 /// Workaround material for exterior lane markings
189 UPROPERTY()
190 UMaterialInstance *MarkingNodeWhite;
191
192 /// Workaround material for the TerrainNodes
193 UPROPERTY()
194 UMaterialInstance *TerrainNodeMaterialInstance;
195
196 /// Workaround material for the SidewalkNodes
197 UPROPERTY()
199
200 /// Saves @a Package in .umap format in path @a PackagePath inside Unreal
201 /// Content folder
202 bool SavePackage(const FString &PackagePath, UPackage *Package) const;
203
204 /// Gets the first .Package.json file found in Unreal Content Directory with
205 /// @a PackageName
206 FString GetFirstPackagePath(const FString &PackageName) const;
207
208};
UMaterialInstance * RoadNodeMaterial
Workaround material for the RoadNode mesh.
UMaterialInstance * CurbNodeMaterialInstance
Material to apply to curbs on the road.
FString GetFirstPackagePath(const FString &PackageName) const
Gets the first .Package.json file found in Unreal Content Directory with PackageName.
UObjectLibrary * AssetsObjectLibrary
Used for loading assets in object library.
UWorld * World
Base map world loaded from Carla Content.
UObjectLibrary * MapObjectLibrary
Used for loading maps in object library.
UMaterialInstance * GutterNodeMaterialInstance
Material to apply to gutters on the road.
UMaterialInstance * MarkingNodeYellow
Workaround material for the center lane markings.
UMaterialInstance * MarkingNodeWhite
Workaround material for exterior lane markings.
TArray< FAssetData > AssetDatas
Loaded assets from any object library.
UMaterialInstance * SidewalkNodeMaterialInstance
Workaround material for the SidewalkNodes.
bool SavePackage(const FString &PackagePath, UPackage *Package) const
Saves Package in .umap format in path PackagePath inside Unreal Content folder.
TArray< FAssetData > MapContents
Loaded map content from any object library.
UMaterialInstance * TerrainNodeMaterialInstance
Workaround material for the TerrainNodes.
Struct containing all assets data read from .Package.json file.
Struct containing map data read from .Package.json file.
bool bMergeTiles
Build one map out of a tiled .fbx set instead of a sublevel per tile.
Struct containing Package with Name and bOnlyPrepareMaps flag used to separate the cooking of maps an...