Cesium for Unreal 2.22.0
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
13/**
14 * The Blueprint type that can losslessly represent values of a given property.
15 */
16UENUM(BlueprintType)
17enum class ECesiumMetadataBlueprintType : uint8 {
18 /* Indicates a value cannot be represented in Blueprints. */
20 /* Indicates a value is best represented as a Boolean. */
22 /* Indicates a value is best represented as a Byte (8-bit unsigned integer).
23 */
25 /* Indicates a value is best represented as a Integer (32-bit signed). */
27 /* Indicates a value is best represented as a Integer64 (64-bit signed). */
29 /* Indicates a value is best represented as a Float (32-bit). */
31 /* Indicates a value is best represented as a Float64 (64-bit). */
33 /* Indicates a value is best represented as a FVector2D (2-dimensional
34 integer vector). */
36 /* Indicates a value is best represented as a FVector2D (2-dimensional
37 double-precision vector). */
39 /* Indicates a value is best represented as a FIntVector (3-dimensional
40 integer vector). */
42 /* Indicates a value is best represented as a FVector3f (3-dimensional
43 single-precision vector). */
45 /* Indicates a value is best represented as a FVector3 (3-dimensional
46 double-precision vector). */
48 /* Indicates a value is best represented as a FVector4 (4-dimensional
49 double-precision vector). */
51 /* Indicates a value is best represented as a FMatrix (4-by-4 double-precision
52 matrix). */
54 /* Indicates a value is best represented as a FString. This can be used as a
55 fallback for types with no proper Blueprints representation. */
57 /* Indicates a value is best represented as a CesiumPropertyArray. */
59};
60
61// UE requires us to have an enum with the value 0.
62// Invalid / None should have that value, but just make sure.
63static_assert(int(CesiumGltf::PropertyType::Invalid) == 0);
64static_assert(int(CesiumGltf::PropertyComponentType::None) == 0);
65
66/**
67 * The type of a metadata property in EXT_feature_metadata. This has been
68 * deprecated; use FCesiumMetadataValueType to get the complete type information
69 * of a metadata property instead.
70 */
71UENUM(BlueprintType)
89
90// True types are cast, reintepreted, or parsed before being packed into gpu
91// types when encoding into a texture.
97
98/**
99 * The type of a metadata property in EXT_structural_metadata.
100 */
101UENUM(BlueprintType)
102enum class ECesiumMetadataType : uint8 {
104 Scalar = int(CesiumGltf::PropertyType::Scalar),
105 Vec2 = int(CesiumGltf::PropertyType::Vec2),
106 Vec3 = int(CesiumGltf::PropertyType::Vec3),
107 Vec4 = int(CesiumGltf::PropertyType::Vec4),
108 Mat2 = int(CesiumGltf::PropertyType::Mat2),
109 Mat3 = int(CesiumGltf::PropertyType::Mat3),
110 Mat4 = int(CesiumGltf::PropertyType::Mat4),
111 Boolean = int(CesiumGltf::PropertyType::Boolean),
112 String = int(CesiumGltf::PropertyType::String),
113 Enum = int(CesiumGltf::PropertyType::Enum)
114};
115
116/**
117 * The component type of a metadata property in EXT_structural_metadata. Only
118 * applicable if the property has a Scalar, VecN, or MatN type.
119 */
120UENUM(BlueprintType)
122 None = 0,
123 Int8 = int(CesiumGltf::PropertyComponentType::Int8),
124 Uint8 = int(CesiumGltf::PropertyComponentType::Uint8),
125 Int16 = int(CesiumGltf::PropertyComponentType::Int16),
126 Uint16 = int(CesiumGltf::PropertyComponentType::Uint16),
127 Int32 = int(CesiumGltf::PropertyComponentType::Int32),
128 Uint32 = int(CesiumGltf::PropertyComponentType::Uint32),
129 Int64 = int(CesiumGltf::PropertyComponentType::Int64),
130 Uint64 = int(CesiumGltf::PropertyComponentType::Uint64),
131 Float32 = int(CesiumGltf::PropertyComponentType::Float32),
132 Float64 = int(CesiumGltf::PropertyComponentType::Float64),
133};
134
135/**
136 * Represents the true value type of a metadata value, akin to the property
137 * types in EXT_structural_metadata.
138 */
139USTRUCT(BlueprintType)
140struct CESIUMRUNTIME_API FCesiumMetadataValueType {
141 GENERATED_USTRUCT_BODY()
142
144
146 ECesiumMetadataType InType,
147 ECesiumMetadataComponentType InComponentType,
148 bool IsArray = false);
149
150 /**
151 * The type of the metadata property or value.
152 */
153 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Cesium")
155
156 /**
157 * The component type of the metadata property or value. Only applies when the
158 * type is an Enum, Scalar, VecN, or MatN type. For Enum types, the component
159 * type applies to the underlying scalars used to represent the enum values.
160 */
161 UPROPERTY(
162 EditAnywhere,
163 BlueprintReadWrite,
164 Category = "Cesium",
165 Meta =
166 (EditCondition =
167 "Type != ECesiumMetadataType::Invalid && Type != ECesiumMetadataType::Boolean && Type != ECesiumMetadataType::String"))
169
170 /**
171 * Whether or not this represents an array containing elements of the
172 * specified types.
173 */
174 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Cesium")
176
177 inline bool operator==(const FCesiumMetadataValueType& ValueType) const {
178 return Type == ValueType.Type && ComponentType == ValueType.ComponentType &&
179 bIsArray == ValueType.bIsArray;
180 }
181
182 inline bool operator!=(const FCesiumMetadataValueType& ValueType) const {
183 return Type != ValueType.Type || ComponentType != ValueType.ComponentType ||
184 bIsArray != ValueType.bIsArray;
185 }
186
187 /**
188 * Prints this value type in the format "(Component Type) (Type) (Array)".
189 * For example, "Int16 Scalar", "Float32 Mat4 Array", "String Array".
190 */
191 FString ToString() const;
192};
193
194template <typename T>
196TypeToMetadataValueType(TSharedPtr<FCesiumMetadataEnum> pEnumDefinition) {
198 ECesiumMetadataComponentType componentType;
199 bool isArray;
200
202 using ArrayType = typename CesiumGltf::MetadataArrayType<T>::type;
204 pEnumDefinition != nullptr) {
206 } else {
207 type =
209 }
210 componentType = ECesiumMetadataComponentType(
212 isArray = true;
213 } else {
214 if (CesiumGltf::IsMetadataInteger<T>::value && pEnumDefinition.IsValid()) {
216 } else {
218 }
219 componentType = ECesiumMetadataComponentType(
221 isArray = false;
222 }
223
224 return {type, componentType, isArray};
225}
226
227/**
228 * Gets the size in bytes of the represented metadata type. Returns 0 for enums
229 * and strings.
230 */
231static size_t GetMetadataTypeByteSize(
233 ECesiumMetadataComponentType ComponentType) {
234 size_t componentByteSize = 0;
235 if (ComponentType != ECesiumMetadataComponentType::None)
236 componentByteSize = CesiumGltf::getSizeOfComponentType(
237 CesiumGltf::PropertyComponentType(ComponentType));
238
239 size_t byteSize = componentByteSize;
240 switch (Type) {
242 byteSize = sizeof(bool);
243 break;
245 break;
247 byteSize *= 2;
248 break;
250 byteSize *= 3;
251 break;
253 byteSize *= 4;
254 break;
256 byteSize *= 4;
257 break;
259 byteSize *= 9;
260 break;
262 byteSize *= 16;
263 break;
264 default:
265 return 0;
266 }
267
268 return byteSize;
269}
@ 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.
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.