Cesium for Unreal 2.13.2
Loading...
Searching...
No Matches
CesiumFeaturesMetadataComponent.h
Go to the documentation of this file.
1// Copyright 2020-2024 CesiumGS, Inc. and Contributors
2
3#pragma once
4
8#include "Components/ActorComponent.h"
9#include "Containers/Array.h"
10#include "Containers/UnrealString.h"
11#include "Misc/Guid.h"
12
13#if WITH_EDITOR
14#include "Materials/MaterialFunctionMaterialLayer.h"
15#endif
16
17#include "CesiumFeaturesMetadataComponent.generated.h"
18
19#pragma region Features descriptions
20
21/**
22 * @brief Description of a feature ID set from EXT_mesh_features.
23 */
24USTRUCT()
25struct CESIUMRUNTIME_API FCesiumFeatureIdSetDescription {
26 GENERATED_USTRUCT_BODY()
27
28 /**
29 * The display name of the feature ID set. If the feature ID set already has a
30 * label, this will use the label. Otherwise, if the feature ID set is
31 * unlabeled, a name will be generated like so:
32 *
33 * - If the feature ID set is an attribute, this will appear as
34 * "_FEATURE_ID_<index>", where <index> is the set index specified in
35 * the attribute.
36 * - If the feature ID set is a texture, this will appear as
37 * "_FEATURE_ID_TEXTURE_<index>", where <index> increments with the number
38 * of feature ID textures seen in an individual primitive.
39 * - If the feature ID set is an implicit set, this will appear as
40 * "_IMPLICIT_FEATURE_ID". Implicit feature ID sets don't vary in definition,
41 * so any additional implicit feature ID sets across the primitives are
42 * counted by this one.
43 *
44 * This name will also be used to represent the feature ID set in the
45 * generated material.
46 */
47 UPROPERTY(EditAnywhere, Category = "Cesium")
48 FString Name;
49
50 /**
51 * The type of the feature ID set.
52 */
53 UPROPERTY(EditAnywhere, Category = "Cesium")
55
56 /**
57 * Whether this feature ID set contains a KHR_texture_transform glTF
58 * extension. Only applicable if the feature ID set is a feature ID texture.
59 */
60 UPROPERTY(
61 EditAnywhere,
62 Category = "Cesium",
63 Meta = (EditCondition = "Type == ECesiumFeatureIdSetType::Texture"))
64 bool bHasKhrTextureTransform = false;
65
66 /**
67 * The name of the property table that this feature ID set corresponds to.
68 */
69 UPROPERTY(EditAnywhere, Category = "Cesium")
70 FString PropertyTableName;
71
72 /**
73 * The null feature ID for the feature ID set. This value indicates that no
74 * feature is associated with the vertex or texel containing the value. If no
75 * such value is specified, this defaults to -1, which prevents it from being
76 * unnecessarily included in the generated material.
77 */
78 UPROPERTY(EditAnywhere, Category = "Cesium")
79 bool bHasNullFeatureId = false;
80};
81
82/**
83 * @brief Description of the feature ID sets available from the
84 * EXT_mesh_features on a glTF's primitives.
85 *
86 * This aggregates the feature ID sets of all visible glTF primitives in the
87 * model. This describes the feature IDs that can be made accessible
88 * to Unreal Engine materials.
89 */
90USTRUCT()
91struct CESIUMRUNTIME_API FCesiumPrimitiveFeaturesDescription {
92 GENERATED_USTRUCT_BODY()
93
94 /**
95 * @brief The feature ID sets to make accessible to the material. Note that
96 * the order of feature ID sets in this array does not necessarily
97 * correspond to the order of these feature ID sets in a glTF
98 * primitive.
99 */
100 UPROPERTY(
101 EditAnywhere,
102 Category = "Features",
103 Meta = (TitleProperty = "Name"))
104 TArray<FCesiumFeatureIdSetDescription> FeatureIdSets;
105};
106#pragma endregion
107
108#pragma region Metadata descriptions
109
110// These don't exhaustively cover the possibilities of glTF metadata
111// classes, they only cover the subset that can be encoded into textures. The
112// following types are excluded:
113// - enums
114// - strings that cannot be parsed as numbers or colors
115// - matrices
116// - variable length arrays
117// - arrays of non-scalar, non-boolean elements
118//
119// Additionally, if a property contains fixed-length arrays, only the first four
120// elements can be encoded.
121
122/**
123 * @brief Description of a property table property that should be encoded for
124 * access on the GPU.
125 */
126USTRUCT()
128 GENERATED_USTRUCT_BODY()
129
130 /**
131 * The name of this property. This will be how it is referenced in the
132 * material.
133 */
134 UPROPERTY(EditAnywhere, Category = "Cesium")
135 FString Name;
136
137 /**
138 * Describes the underlying type of this property and other relevant
139 * information from its EXT_structural_metadata definition. Not all types of
140 * properties can be encoded to the GPU, or coerced to GPU-compatible types.
141 */
142 UPROPERTY(EditAnywhere, Category = "Cesium")
144
145 /**
146 * Describes how the property will be encoded as data on the GPU, if possible.
147 */
148 UPROPERTY(EditAnywhere, Category = "Cesium")
150};
151
152/**
153 * @brief Description of a property table containing properties to be encoded
154 * for access in Unreal materials.
155 */
156USTRUCT()
157struct CESIUMRUNTIME_API FCesiumPropertyTableDescription {
158 GENERATED_USTRUCT_BODY()
159
160 /**
161 * @brief The name of this property table. If this property table has no name
162 * in the EXT_structural_metadata extension, then its class name is used
163 * instead.
164 */
165 UPROPERTY(EditAnywhere, Category = "Cesium")
166 FString Name;
167
168 /**
169 * @brief Descriptions of the properties to upload to the GPU.
170 */
171 UPROPERTY(EditAnywhere, Category = "Cesium", Meta = (TitleProperty = "Name"))
173};
174
175/**
176 * @brief Description of a property texture property that should be made
177 * accessible to Unreal materials. A property texture property's data is
178 * already available through a texture, so no additional encoding details need
179 * to be specified.
180 */
181USTRUCT()
183 GENERATED_USTRUCT_BODY()
184
185 /**
186 * The name of this property. This will be how it is referenced in the
187 * material.
188 */
189 UPROPERTY(EditAnywhere, Category = "Cesium")
190 FString Name;
191
192 /**
193 * Describes the underlying type of this property and other relevant
194 * information from its EXT_structural_metadata definition.
195 */
196 UPROPERTY(EditAnywhere, Category = "Cesium")
198
199 /**
200 * Whether this property texture property contains a KHR_texture_transform
201 * glTF extension.
202 */
203 UPROPERTY(EditAnywhere, Category = "Cesium")
204 bool bHasKhrTextureTransform = false;
205};
206
207/**
208 * @brief Description of a property texture with properties that should be
209 * made accessible to Unreal materials.
210 */
211USTRUCT()
212struct CESIUMRUNTIME_API FCesiumPropertyTextureDescription {
213 GENERATED_USTRUCT_BODY()
214
215 /**
216 * @brief The name of this property texture.
217 */
218 UPROPERTY(EditAnywhere, Category = "Cesium")
219 FString Name;
220
221 /**
222 * @brief Descriptions of the properties to upload to the GPU.
223 */
224 UPROPERTY(EditAnywhere, Category = "Cesium", Meta = (TitleProperty = "Name"))
226};
227
228/**
229 * @brief Names of the metadata entities referenced by the
230 * EXT_structural_metadata on a glTF's primitives.
231 *
232 * This aggregates the metadata of all visible glTF primitives in the model.
233 * This lists the names of the property textures actually used by the glTF
234 * primitive, indicating it can be sampled with the primitive's texture
235 * coordinates in the Unreal material.
236 */
237USTRUCT()
238struct CESIUMRUNTIME_API FCesiumPrimitiveMetadataDescription {
239 GENERATED_USTRUCT_BODY()
240
241 /**
242 * @brief The names of the property textures used by the glTF primitives
243 * across the tileset.
244 *
245 * This should be a subset of the property textures listed in the model
246 * metadata. Property textures can be passed to the material even if they are
247 * not explicitly used by a glTF primitive, but the primitive may lack the
248 * corresponding sets of texture coordinates intended to sample them.
249 */
250 UPROPERTY(
251 EditAnywhere,
252 Category = "Metadata",
253 Meta = (TitleProperty = "Name"))
254 TSet<FString> PropertyTextureNames;
255};
256
257/**
258 * @brief Description of metadata from a glTF's EXT_structural_metadata
259 * extension that should be uploaded to the GPU for access in Unreal materials.
260 */
261USTRUCT()
262struct CESIUMRUNTIME_API FCesiumModelMetadataDescription {
263 GENERATED_USTRUCT_BODY()
264
265 /**
266 * @brief Descriptions of property tables to encode for access in Unreal
267 * materials.
268 */
269 UPROPERTY(
270 EditAnywhere,
271 Category = "Metadata",
272 Meta = (TitleProperty = "Name"))
273 TArray<FCesiumPropertyTableDescription> PropertyTables;
274
275 /**
276 * @brief Descriptions of property textures to make accessible to Unreal
277 * materials.
278 */
279 UPROPERTY(
280 EditAnywhere,
281 Category = "Metadata",
282 Meta = (TitleProperty = "Name"))
283 TArray<FCesiumPropertyTextureDescription> PropertyTextures;
284};
285
286#pragma endregion
287
288/**
289 * @brief Description of both feature IDs and metadata from a glTF via the
290 * EXT_mesh_Features and EXT_structural_metadata extensions. Indicates what
291 * parts of the extension should be uploaded to the GPU for access in Unreal
292 * materials.
293 */
294USTRUCT()
295struct CESIUMRUNTIME_API FCesiumFeaturesMetadataDescription {
296 GENERATED_USTRUCT_BODY()
297
298public:
299 /**
300 * @brief Description of the feature ID sets available from the
301 * EXT_mesh_features on a glTF's primitives.
302 */
304
305 /**
306 * @brief Description of the metadata used by the EXT_structural_metadata on a
307 * glTF's primitives.
308 */
310
311 /**
312 * @brief Description of metadata from a glTF's EXT_structural_metadata
313 * extension.
314 */
316};
317
318/**
319 * @brief A component that can be added to Cesium3DTileset actors to
320 * dictate what metadata to encode for access on the GPU. The selection can be
321 * automatically populated based on available metadata by clicking the
322 * "Auto Fill" button. Once a selection of desired metadata is made, the
323 * boiler-plate material code to access the selected properties can be
324 * auto-generated using the "Generate Material" button.
325 */
326UCLASS(ClassGroup = Cesium, Meta = (BlueprintSpawnableComponent))
327class CESIUMRUNTIME_API UCesiumFeaturesMetadataComponent
328 : public UActorComponent {
329 GENERATED_BODY()
330
331public:
332#if WITH_EDITOR
333 /**
334 * Populate the description of metadata and feature IDs using the current view
335 * of the tileset. This determines what to encode to the GPU based on the
336 * existing metadata.
337 *
338 * Warning: Using Auto Fill may populate the description with a large amount
339 * of metadata. Make sure to delete the properties that aren't relevant.
340 */
341 UFUNCTION(CallInEditor, Category = "Cesium")
342 void AutoFill();
343
344 /**
345 * This button can be used to create a boiler-plate material layer that
346 * exposes the requested metadata properties in the current description. The
347 * nodes to access the metadata will be added to TargetMaterialLayer if it
348 * exists. Otherwise a new material layer will be created in the /Content/
349 * folder and TargetMaterialLayer will be set to the new material layer.
350 */
351 UFUNCTION(CallInEditor, Category = "Cesium")
352 void GenerateMaterial();
353#endif
354
355#if WITH_EDITORONLY_DATA
356 /**
357 * This is the target UMaterialFunctionMaterialLayer that the
358 * boiler-plate material generation will use. When pressing
359 * "Generate Material", nodes will be added to this material to enable access
360 * to the requested metadata. If this is left blank, a new material layer
361 * will be created in the /Game/ folder.
362 */
363 UPROPERTY(EditAnywhere, Category = "Cesium")
364 UMaterialFunctionMaterialLayer* TargetMaterialLayer = nullptr;
365#endif
366
367 // Using the FCesiumPrimitiveFeaturesDescription and
368 // FCesiumModelMetadataDescription structs makes the UI less readable, so the
369 // component uses arrays directly to help flatten the UI.
370
371 /**
372 * Description of the feature ID sets in the visible glTF primitives across
373 * the tileset.
374 */
375 UPROPERTY(
376 EditAnywhere,
377 Category = "Cesium|Primitive Features",
378 Meta = (TitleProperty = "Name"))
379 TArray<FCesiumFeatureIdSetDescription> FeatureIdSets;
380
381 /**
382 * Names of the property textures used by the glTF primitives across the
383 * tileset.
384 *
385 * This should be a subset of the property textures listed in the model
386 * metadata. Property textures can be passed to the material even if they are
387 * not explicitly used by a glTF primitive, but the primitive may lack the
388 * corresponding sets of texture coordinates intended to sample them.
389 */
390 UPROPERTY(
391 EditAnywhere,
392 Category = "Cesium|Primitive Metadata",
393 Meta = (TitleProperty = "Name"))
394 TSet<FString> PropertyTextureNames;
395
396 /**
397 * Descriptions of the property tables in the visible glTF
398 * models across the tileset.
399 */
400 UPROPERTY(
401 EditAnywhere,
402 Category = "Cesium|Model Metadata",
403 Meta = (TitleProperty = "Name"))
404 TArray<FCesiumPropertyTableDescription> PropertyTables;
405
406 /**
407 * Descriptions of property textures in the visible glTF models across
408 * the tileset.
409 */
410 UPROPERTY(
411 EditAnywhere,
412 Category = "Cesium|Model Metadata",
413 Meta = (TitleProperty = "Name"))
414 TArray<FCesiumPropertyTextureDescription> PropertyTextures;
415};
ECesiumFeatureIdSetType
The type of a feature ID set.
A component that can be added to Cesium3DTileset actors to dictate what metadata to encode for access...
Description of a feature ID set from EXT_mesh_features.
Description of both feature IDs and metadata from a glTF via the EXT_mesh_Features and EXT_structural...
FCesiumPrimitiveFeaturesDescription Features
Description of the feature ID sets available from the EXT_mesh_features on a glTF's primitives.
FCesiumPrimitiveMetadataDescription PrimitiveMetadata
Description of the metadata used by the EXT_structural_metadata on a glTF's primitives.
FCesiumModelMetadataDescription ModelMetadata
Description of metadata from a glTF's EXT_structural_metadata extension.
Describes how a property from EXT_structural_metadata will be encoded for access in Unreal materials.
Represents information about a metadata property according to how the property is defined in EXT_stru...
Description of metadata from a glTF's EXT_structural_metadata extension that should be uploaded to th...
Description of the feature ID sets available from the EXT_mesh_features on a glTF's primitives.
Names of the metadata entities referenced by the EXT_structural_metadata on a glTF's primitives.
Description of a property table containing properties to be encoded for access in Unreal materials.
Description of a property table property that should be encoded for access on the GPU.
Description of a property texture with properties that should be made accessible to Unreal materials.
Description of a property texture property that should be made accessible to Unreal materials.