Cesium for Unreal 2.24.1
Loading...
Searching...
No Matches
CesiumVoxelMetadataComponent.h
Go to the documentation of this file.
1// Copyright 2020-2026 CesiumGS, Inc. and Contributors
2
3#pragma once
4
7#include "Templates/UniquePtr.h"
8
9#if WITH_EDITOR
10#include "Materials/MaterialFunctionMaterialLayer.h"
11#endif
12
13#include "CesiumVoxelMetadataComponent.generated.h"
14
15class UTexture;
16
17/**
18 * @brief Description of the metadata properties available in the class used by
19 * the 3DTILES_content_voxels extension. Exposes what properties are available
20 * to use in a custom shader in Unreal materials.
21 */
22USTRUCT() struct CESIUMRUNTIME_API FCesiumVoxelClassDescription {
23 GENERATED_USTRUCT_BODY()
24
25 /**
26 * @brief The ID of the class in the tileset's metadata schema.
27 */
28 UPROPERTY(EditAnywhere, Category = "Cesium|Metadata")
29 FString ClassId;
30
31 /**
32 * @brief Descriptions of properties to pass to the Unreal material.
33 */
34 UPROPERTY(
35 EditAnywhere,
36 Category = "Cesium|Metadata",
37 Meta = (TitleProperty = "Name"))
38 TArray<FCesiumPropertyAttributePropertyDescription> Properties;
39
40 /**
41 * @brief Description of the statistics of the properties on the voxel class.
42 */
43 UPROPERTY(
44 EditAnywhere,
45 Category = "Cesium|Metadata|Statistics",
46 Meta = (TitleProperty = "Id"))
47 TArray<FCesiumMetadataPropertyStatisticsDescription> Statistics;
48};
49
50/**
51 * @brief A component that can be added to Cesium3DTileset actors to
52 * view and style metadata embedded in voxel content. "Build Shader" allows
53 * users to view the voxel metadata properties available in the tileset and
54 * write custom code to style them. Then, the boiler-plate material code to
55 * access the selected properties and apply custom shaders can be auto-generated
56 * using the "Generate Material" button.
57 */
58UCLASS(ClassGroup = (Cesium), Meta = (BlueprintSpawnableComponent))
59class CESIUMRUNTIME_API UCesiumVoxelMetadataComponent
61 GENERATED_BODY()
62
63public:
64 UCesiumVoxelMetadataComponent();
65
66#if WITH_EDITOR
67 /**
68 * Opens a window to build a custom shader for the tileset using its available
69 * voxel properties.
70 */
71 UFUNCTION(
72 CallInEditor,
73 Category = "Cesium",
74 Meta = (DisplayName = "Build Shader"))
75 void BuildShader();
76
77 /**
78 * Creates or overwrites a boiler-plate material that exposes the requested
79 * metadata properties in the current description and writes out the custom
80 * shader. The changes will be applied to TargetMaterial if it is already
81 * specified. Otherwise a new material layer will be created in the /Content/
82 * folder and TargetMaterial will be set to the new material.
83 */
84 UFUNCTION(
85 CallInEditor,
86 Category = "Cesium",
87 Meta = (DisplayName = "Generate Material"))
88 void GenerateMaterial();
89#endif
90
91#if WITH_EDITORONLY_DATA
92 /**
93 * This is the target UMaterial that the boiler-plate material generation will
94 * use. When pressing "Generate Material", nodes will be added to this
95 * material to enable access to the requested metadata. If this is left blank,
96 * a new material will be created in the /Content/ folder.
97 */
98 UPROPERTY(EditAnywhere, Category = "Cesium")
99 UMaterial* TargetMaterial = nullptr;
100
101 /**
102 * The custom shader code to apply to each voxel that is raymarched.
103 */
104 UPROPERTY(
105 EditAnywhere,
106 Category = "Cesium",
107 Meta =
108 (TitleProperty = "Custom Shader",
109 DisplayAfter = "TargetMaterialLayer",
110 MultiLine = true))
111 FString CustomShader = TEXT("return float4(1, 1, 1, 0.02);");
112
113 /**
114 * Any additional functions to include for use in the custom shader. The HLSL
115 * code provided here is included verbatim in the generated material.
116 */
117 UPROPERTY(
118 EditAnywhere,
119 Category = "Cesium",
120 Meta =
121 (TitleProperty = "Additional Functions",
122 DisplayAfter = "CustomShader",
123 MultiLine = true))
124 FString AdditionalFunctions;
125#endif
126
127 /**
128 * A description of the class used by the 3DTILES_content_voxel extension in
129 * the tileset.
130 */
131 UPROPERTY(
132 EditAnywhere,
133 Category = "Cesium",
134 Meta =
135 (TitleProperty = "Voxel Class", DisplayAfter = "AdditionalFunctions"))
136 FCesiumVoxelClassDescription Description;
137
138 /**
139 * Gets a preview of the generated custom shader.
140 */
141 FString getCustomShaderPreview() const;
142
143protected:
144 virtual void OnFetchMetadata(
145 ACesium3DTileset* pActor,
147 virtual void ClearStatistics();
148
149private:
150 TObjectPtr<UTexture> _pDefaultVolumeTexture;
151#if WITH_EDITOR
152 static const FString _shaderPreviewTemplate;
153#endif
154};
USTRUCT() struct FCesiumVoxelClassDescription
Description of the metadata properties available in the class used by the 3DTILES_content_voxels exte...
A base component interface for interacting with metadata in a Cesium3DTileset.
virtual void ClearStatistics()
Called during various parts of the sync process.
virtual void OnFetchMetadata(ACesium3DTileset *pActor, const Cesium3DTilesSelection::TilesetMetadata *pMetadata)
Event that occurs once metadata is successfully synced from the tileset during SyncStatistics.