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