Cesium for Unreal 2.24.1
Loading...
Searching...
No Matches
CesiumMetadataValueType.h
Go to the documentation of this file.
1// Copyright 2020-2025 CesiumGS, Inc. and Contributors
2
3#pragma once
4
6#include <CesiumGltf/Enum.h>
7#include <CesiumGltf/PropertyArrayView.h>
8#include <CesiumGltf/PropertyType.h>
9#include <CesiumGltf/PropertyTypeTraits.h>
10
11#include "CesiumMetadataValueType.generated.h"
12
13namespace Cesium3DTiles {
14struct ClassProperty;
15}
16
17/**
18 * The Blueprint type that can losslessly represent values of a given property.
19 */
20UENUM(BlueprintType)
21enum class ECesiumMetadataBlueprintType : uint8 {
22 /* Indicates a value cannot be represented in Blueprints. */
24 /* Indicates a value is best represented as a Boolean. */
26 /* Indicates a value is best represented as a Byte (8-bit unsigned integer).
27 */
29 /* Indicates a value is best represented as a Integer (32-bit signed). */
31 /* Indicates a value is best represented as a Integer64 (64-bit signed). */
33 /* Indicates a value is best represented as a Float (32-bit). */
35 /* Indicates a value is best represented as a Float64 (64-bit). */
37 /* Indicates a value is best represented as a FVector2D (2-dimensional
38 integer vector). */
40 /* Indicates a value is best represented as a FVector2D (2-dimensional
41 double-precision vector). */
43 /* Indicates a value is best represented as a FIntVector (3-dimensional
44 integer vector). */
46 /* Indicates a value is best represented as a FVector3f (3-dimensional
47 single-precision vector). */
49 /* Indicates a value is best represented as a FVector3 (3-dimensional
50 double-precision vector). */
52 /* Indicates a value is best represented as a FVector4 (4-dimensional
53 double-precision vector). */
55 /* Indicates a value is best represented as a FMatrix (4-by-4 double-precision
56 matrix). */
58 /* Indicates a value is best represented as a FString. This can be used as a
59 fallback for types with no proper Blueprints representation. */
61 /* Indicates a value is best represented as a CesiumPropertyArray. */
63};
64
65// UE requires us to have an enum with the value 0.
66// Invalid / None should have that value, but just make sure.
67static_assert(int(CesiumGltf::PropertyType::Invalid) == 0);
68static_assert(int(CesiumGltf::PropertyComponentType::None) == 0);
69
70/**
71 * The type of a metadata property in EXT_feature_metadata. This has been
72 * deprecated; use FCesiumMetadataValueType to get the complete type information
73 * of a metadata property instead.
74 */
75UENUM(BlueprintType)
93
94// True types are cast, reintepreted, or parsed before being packed into gpu
95// types when encoding into a texture.
101
102/**
103 * The type of a metadata property in EXT_structural_metadata.
104 */
105UENUM(BlueprintType)
106enum class ECesiumMetadataType : uint8 {
108 Scalar = int(CesiumGltf::PropertyType::Scalar),
109 Vec2 = int(CesiumGltf::PropertyType::Vec2),
110 Vec3 = int(CesiumGltf::PropertyType::Vec3),
111 Vec4 = int(CesiumGltf::PropertyType::Vec4),
112 Mat2 = int(CesiumGltf::PropertyType::Mat2),
113 Mat3 = int(CesiumGltf::PropertyType::Mat3),
114 Mat4 = int(CesiumGltf::PropertyType::Mat4),
115 Boolean = int(CesiumGltf::PropertyType::Boolean),
116 String = int(CesiumGltf::PropertyType::String),
117 Enum = int(CesiumGltf::PropertyType::Enum)
118};
119
120/**
121 * The component type of a metadata property in EXT_structural_metadata. Only
122 * applicable if the property has a Scalar, VecN, or MatN type.
123 */
124UENUM(BlueprintType)
126 None = 0,
127 Int8 = int(CesiumGltf::PropertyComponentType::Int8),
128 Uint8 = int(CesiumGltf::PropertyComponentType::Uint8),
129 Int16 = int(CesiumGltf::PropertyComponentType::Int16),
130 Uint16 = int(CesiumGltf::PropertyComponentType::Uint16),
131 Int32 = int(CesiumGltf::PropertyComponentType::Int32),
132 Uint32 = int(CesiumGltf::PropertyComponentType::Uint32),
133 Int64 = int(CesiumGltf::PropertyComponentType::Int64),
134 Uint64 = int(CesiumGltf::PropertyComponentType::Uint64),
135 Float32 = int(CesiumGltf::PropertyComponentType::Float32),
136 Float64 = int(CesiumGltf::PropertyComponentType::Float64),
137};
138
139/**
140 * Represents the true value type of a metadata value, akin to the property
141 * types in EXT_structural_metadata.
142 */
143USTRUCT(BlueprintType)
144struct CESIUMRUNTIME_API FCesiumMetadataValueType {
145 GENERATED_USTRUCT_BODY()
146
148
150 ECesiumMetadataType InType,
151 ECesiumMetadataComponentType InComponentType,
152 bool IsArray = false);
153
154 /**
155 * The type of the metadata property or value.
156 */
157 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Cesium")
159
160 /**
161 * The component type of the metadata property or value. Only applies when the
162 * type is an Enum, Scalar, VecN, or MatN type. For Enum types, the component
163 * type applies to the underlying scalars used to represent the enum values.
164 */
165 UPROPERTY(
166 EditAnywhere,
167 BlueprintReadWrite,
168 Category = "Cesium",
169 Meta =
170 (EditCondition =
171 "Type != ECesiumMetadataType::Invalid && Type != ECesiumMetadataType::Boolean && Type != ECesiumMetadataType::String"))
173
174 /**
175 * Whether or not this represents an array containing elements of the
176 * specified types.
177 */
178 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Cesium")
180
181 inline bool operator==(const FCesiumMetadataValueType& ValueType) const {
182 return Type == ValueType.Type && ComponentType == ValueType.ComponentType &&
183 bIsArray == ValueType.bIsArray;
184 }
185
186 inline bool operator!=(const FCesiumMetadataValueType& ValueType) const {
187 return Type != ValueType.Type || ComponentType != ValueType.ComponentType ||
188 bIsArray != ValueType.bIsArray;
189 }
190
191 /**
192 * Prints this value type in the format "(Component Type) (Type) (Array)".
193 * For example, "Int16 Scalar", "Float32 Mat4 Array", "String Array".
194 */
195 FString ToString() const;
196
197 /**
198 * Deduces the corresponding value type for a given
199 * Cesium3DTiles::ClassProperty.
200 */
203};
204
205template <typename T>
207TypeToMetadataValueType(TSharedPtr<FCesiumMetadataEnum> pEnumDefinition) {
209 ECesiumMetadataComponentType componentType;
210 bool isArray;
211
213 using ArrayType = typename CesiumGltf::MetadataArrayType<T>::type;
215 pEnumDefinition != nullptr) {
217 } else {
218 type =
220 }
221 componentType = ECesiumMetadataComponentType(
223 isArray = true;
224 } else {
225 if (CesiumGltf::IsMetadataInteger<T>::value && pEnumDefinition.IsValid()) {
227 } else {
229 }
230 componentType = ECesiumMetadataComponentType(
232 isArray = false;
233 }
234
235 return {type, componentType, isArray};
236}
237
238/**
239 * Gets the size in bytes of the represented metadata type. Returns 0 for enums
240 * and strings.
241 */
242static size_t GetMetadataTypeByteSize(
244 ECesiumMetadataComponentType ComponentType) {
245 size_t componentByteSize = 0;
246 if (ComponentType != ECesiumMetadataComponentType::None)
247 componentByteSize = CesiumGltf::getSizeOfComponentType(
248 CesiumGltf::PropertyComponentType(ComponentType));
249
250 size_t byteSize = componentByteSize;
251 switch (Type) {
253 byteSize = sizeof(bool);
254 break;
256 break;
258 byteSize *= 2;
259 break;
261 byteSize *= 3;
262 break;
264 byteSize *= 4;
265 break;
267 byteSize *= 4;
268 break;
270 byteSize *= 9;
271 break;
273 byteSize *= 16;
274 break;
275 default:
276 return 0;
277 }
278
279 return byteSize;
280}
@ String
The feature's ID is a string.
@ Integer
The feature's ID is an integer.
ECesiumMetadataComponentType
The component type of a metadata property in EXT_structural_metadata.
ECesiumMetadataTrueType_DEPRECATED
The type of a metadata property in EXT_feature_metadata.
ECesiumMetadataBlueprintType
The Blueprint type that can losslessly represent values of a given property.
ECesiumMetadataPackedGpuType_DEPRECATED
ECesiumMetadataType
The type of a metadata property in EXT_structural_metadata.
size_t getSizeOfComponentType(PropertyComponentType componentType)
Represents the true value type of a metadata value, akin to the property types in EXT_structural_meta...
bool operator!=(const FCesiumMetadataValueType &ValueType) const
ECesiumMetadataType Type
The type of the metadata property or value.
bool bIsArray
Whether or not this represents an array containing elements of the specified types.
static FCesiumMetadataValueType fromClassProperty(const Cesium3DTiles::ClassProperty &property)
Deduces the corresponding value type for a given Cesium3DTiles::ClassProperty.
FString ToString() const
Prints this value type in the format "(Component Type) (Type) (Array)".
ECesiumMetadataComponentType ComponentType
The component type of the metadata property or value.