Cesium for Unreal 2.15.0
Loading...
Searching...
No Matches
CesiumMetadataValueType.h
Go to the documentation of this file.
1// Copyright 2020-2024 CesiumGS, Inc. and Contributors
2
3#pragma once
4
5#include "CesiumGltf/Enum.h"
6#include "CesiumGltf/PropertyArrayView.h"
7#include "CesiumGltf/PropertyType.h"
8#include "CesiumGltf/PropertyTypeTraits.h"
10#include "CesiumMetadataValueType.generated.h"
11
12/**
13 * The Blueprint type that can losslessly represent values of a given property.
14 */
15UENUM(BlueprintType)
16enum class ECesiumMetadataBlueprintType : uint8 {
17 /* Indicates a value cannot be represented in Blueprints. */
19 /* Indicates a value is best represented as a Boolean. */
21 /* Indicates a value is best represented as a Byte (8-bit unsigned integer).
22 */
24 /* Indicates a value is best represented as a Integer (32-bit signed). */
26 /* Indicates a value is best represented as a Integer64 (64-bit signed). */
28 /* Indicates a value is best represented as a Float (32-bit). */
30 /* Indicates a value is best represented as a Float64 (64-bit). */
32 /* Indicates a value is best represented as a FVector2D (2-dimensional
33 integer vector). */
35 /* Indicates a value is best represented as a FVector2D (2-dimensional
36 double-precision vector). */
38 /* Indicates a value is best represented as a FIntVector (3-dimensional
39 integer vector). */
41 /* Indicates a value is best represented as a FVector3f (3-dimensional
42 single-precision vector). */
44 /* Indicates a value is best represented as a FVector3 (3-dimensional
45 double-precision vector). */
47 /* Indicates a value is best represented as a FVector4 (4-dimensional
48 double-precision vector). */
50 /* Indicates a value is best represented as a FMatrix (4-by-4 double-precision
51 matrix). */
53 /* Indicates a value is best represented as a FString. This can be used as a
54 fallback for types with no proper Blueprints representation. */
56 /* Indicates a value is best represented as a CesiumPropertyArray. */
58};
59
60// UE requires us to have an enum with the value 0.
61// Invalid / None should have that value, but just make sure.
62static_assert(int(CesiumGltf::PropertyType::Invalid) == 0);
63static_assert(int(CesiumGltf::PropertyComponentType::None) == 0);
64
65/**
66 * The type of a metadata property in EXT_feature_metadata. This has been
67 * deprecated; use FCesiumMetadataValueType to get the complete type information
68 * of a metadata property instead.
69 */
70UENUM(BlueprintType)
88
89// True types are cast, reintepreted, or parsed before being packed into gpu
90// types when encoding into a texture.
96
97/**
98 * The type of a metadata property in EXT_structural_metadata.
99 */
100UENUM(BlueprintType)
101enum class ECesiumMetadataType : uint8 {
103 Scalar = int(CesiumGltf::PropertyType::Scalar),
104 Vec2 = int(CesiumGltf::PropertyType::Vec2),
105 Vec3 = int(CesiumGltf::PropertyType::Vec3),
106 Vec4 = int(CesiumGltf::PropertyType::Vec4),
107 Mat2 = int(CesiumGltf::PropertyType::Mat2),
108 Mat3 = int(CesiumGltf::PropertyType::Mat3),
109 Mat4 = int(CesiumGltf::PropertyType::Mat4),
110 Boolean = int(CesiumGltf::PropertyType::Boolean),
111 String = int(CesiumGltf::PropertyType::String),
112 Enum = int(CesiumGltf::PropertyType::Enum)
113};
114
115/**
116 * The component type of a metadata property in EXT_structural_metadata. Only
117 * applicable if the property has a Scalar, VecN, or MatN type.
118 */
119UENUM(BlueprintType)
121 None = 0,
122 Int8 = int(CesiumGltf::PropertyComponentType::Int8),
123 Uint8 = int(CesiumGltf::PropertyComponentType::Uint8),
124 Int16 = int(CesiumGltf::PropertyComponentType::Int16),
125 Uint16 = int(CesiumGltf::PropertyComponentType::Uint16),
126 Int32 = int(CesiumGltf::PropertyComponentType::Int32),
127 Uint32 = int(CesiumGltf::PropertyComponentType::Uint32),
128 Int64 = int(CesiumGltf::PropertyComponentType::Int64),
129 Uint64 = int(CesiumGltf::PropertyComponentType::Uint64),
130 Float32 = int(CesiumGltf::PropertyComponentType::Float32),
131 Float64 = int(CesiumGltf::PropertyComponentType::Float64),
132};
133
134/**
135 * Represents the true value type of a metadata value, akin to the property
136 * types in EXT_structural_metadata.
137 */
138USTRUCT(BlueprintType)
139struct CESIUMRUNTIME_API FCesiumMetadataValueType {
140 GENERATED_USTRUCT_BODY()
141
146
148 ECesiumMetadataType InType,
149 ECesiumMetadataComponentType InComponentType,
150 bool IsArray = false)
151 : Type(InType), ComponentType(InComponentType), bIsArray(IsArray) {}
152
153 /**
154 * The type of the metadata property or value.
155 */
156 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Cesium")
158
159 /**
160 * The component type of the metadata property or value. Only applies when the
161 * type is an Enum, Scalar, VecN, or MatN type. For Enum types, the component
162 * type applies to the underlying scalars used to represent the enum values.
163 */
164 UPROPERTY(
165 EditAnywhere,
166 BlueprintReadWrite,
167 Category = "Cesium",
168 Meta =
169 (EditCondition =
170 "Type != ECesiumMetadataType::Invalid && Type != ECesiumMetadataType::Boolean && Type != ECesiumMetadataType::String"))
172
173 /**
174 * Whether or not this represents an array containing elements of the
175 * specified types.
176 */
177 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Cesium")
179
180 inline bool operator==(const FCesiumMetadataValueType& ValueType) const {
181 return Type == ValueType.Type && ComponentType == ValueType.ComponentType &&
182 bIsArray == ValueType.bIsArray;
183 }
184
185 inline bool operator!=(const FCesiumMetadataValueType& ValueType) const {
186 return Type != ValueType.Type || ComponentType != ValueType.ComponentType ||
187 bIsArray != ValueType.bIsArray;
188 }
189};
190
191template <typename T>
193TypeToMetadataValueType(TSharedPtr<FCesiumMetadataEnum> pEnumDefinition) {
195 ECesiumMetadataComponentType componentType;
196 bool isArray;
197
199 using ArrayType = typename CesiumGltf::MetadataArrayType<T>::type;
201 pEnumDefinition != nullptr) {
203 } else {
204 type =
206 }
207 componentType = ECesiumMetadataComponentType(
209 isArray = true;
210 } else {
211 if (CesiumGltf::IsMetadataInteger<T>::value && pEnumDefinition.IsValid()) {
213 } else {
215 }
216 componentType = ECesiumMetadataComponentType(
218 isArray = false;
219 }
220
221 return {type, componentType, isArray};
222}
223
224/**
225 * Gets the size in bytes of the represented metadata type. Returns 0 for enums
226 * and strings.
227 */
228static size_t GetMetadataTypeByteSize(
230 ECesiumMetadataComponentType ComponentType) {
231 size_t componentByteSize = 0;
232 if (ComponentType != ECesiumMetadataComponentType::None)
233 componentByteSize = CesiumGltf::getSizeOfComponentType(
234 CesiumGltf::PropertyComponentType(ComponentType));
235
236 size_t byteSize = componentByteSize;
237 switch (Type) {
239 byteSize = sizeof(bool);
240 break;
242 break;
244 byteSize *= 2;
245 break;
247 byteSize *= 3;
248 break;
250 byteSize *= 4;
251 break;
253 byteSize *= 4;
254 break;
256 byteSize *= 9;
257 break;
259 byteSize *= 16;
260 break;
261 default:
262 return 0;
263 }
264
265 return byteSize;
266}
267
268static FString MetadataTypeToString(ECesiumMetadataType type) {
269 const UEnum* pEnum = StaticEnum<ECesiumMetadataType>();
270 return pEnum ? pEnum->GetNameByValue((int64)type).ToString() : FString();
271}
272
273static FString
274MetadataComponentTypeToString(ECesiumMetadataComponentType type) {
275 const UEnum* pEnum = StaticEnum<ECesiumMetadataComponentType>();
276 return pEnum ? pEnum->GetNameByValue((int64)type).ToString() : FString();
277}
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.
FCesiumMetadataValueType(ECesiumMetadataType InType, ECesiumMetadataComponentType InComponentType, bool IsArray=false)
ECesiumMetadataComponentType ComponentType
The component type of the metadata property or value.