Cesium for Unreal 2.16.0
Loading...
Searching...
No Matches
CesiumMetadataValue.h
Go to the documentation of this file.
1// Copyright 2020-2024 CesiumGS, Inc. and Contributors
2
3#pragma once
4
8#include "Kismet/BlueprintFunctionLibrary.h"
9#include "UObject/ObjectMacros.h"
10
11#include <CesiumGltf/PropertyTypeTraits.h>
12#include <glm/glm.hpp>
13#include <optional>
14#include <swl/variant.hpp>
15
16#include "CesiumMetadataValue.generated.h"
17
18/**
19 * A Blueprint-accessible wrapper for a glTF metadata value.
20 */
21USTRUCT(BlueprintType)
22struct CESIUMRUNTIME_API FCesiumMetadataValue {
23 GENERATED_USTRUCT_BODY()
24
25private:
26#pragma region ValueType declaration
27 template <typename T> using ArrayView = CesiumGltf::PropertyArrayView<T>;
28 using ValueType = swl::variant<
29 swl::monostate,
30 int8_t,
31 uint8_t,
32 int16_t,
33 uint16_t,
34 int32_t,
35 uint32_t,
36 int64_t,
37 uint64_t,
38 float,
39 double,
40 bool,
41 std::string_view,
42 glm::vec<2, int8_t>,
43 glm::vec<2, uint8_t>,
44 glm::vec<2, int16_t>,
45 glm::vec<2, uint16_t>,
46 glm::vec<2, int32_t>,
47 glm::vec<2, uint32_t>,
48 glm::vec<2, int64_t>,
49 glm::vec<2, uint64_t>,
50 glm::vec<2, float>,
51 glm::vec<2, double>,
52 glm::vec<3, int8_t>,
53 glm::vec<3, uint8_t>,
54 glm::vec<3, int16_t>,
55 glm::vec<3, uint16_t>,
56 glm::vec<3, int32_t>,
57 glm::vec<3, uint32_t>,
58 glm::vec<3, int64_t>,
59 glm::vec<3, uint64_t>,
60 glm::vec<3, float>,
61 glm::vec<3, double>,
62 glm::vec<4, int8_t>,
63 glm::vec<4, uint8_t>,
64 glm::vec<4, int16_t>,
65 glm::vec<4, uint16_t>,
66 glm::vec<4, int32_t>,
67 glm::vec<4, uint32_t>,
68 glm::vec<4, int64_t>,
69 glm::vec<4, uint64_t>,
70 glm::vec<4, float>,
71 glm::vec<4, double>,
72 glm::mat<2, 2, int8_t>,
73 glm::mat<2, 2, uint8_t>,
74 glm::mat<2, 2, int16_t>,
75 glm::mat<2, 2, uint16_t>,
76 glm::mat<2, 2, int32_t>,
77 glm::mat<2, 2, uint32_t>,
78 glm::mat<2, 2, int64_t>,
79 glm::mat<2, 2, uint64_t>,
80 glm::mat<2, 2, float>,
81 glm::mat<2, 2, double>,
82 glm::mat<3, 3, int8_t>,
83 glm::mat<3, 3, uint8_t>,
84 glm::mat<3, 3, int16_t>,
85 glm::mat<3, 3, uint16_t>,
86 glm::mat<3, 3, int32_t>,
87 glm::mat<3, 3, uint32_t>,
88 glm::mat<3, 3, int64_t>,
89 glm::mat<3, 3, uint64_t>,
90 glm::mat<3, 3, float>,
91 glm::mat<3, 3, double>,
92 glm::mat<4, 4, int8_t>,
93 glm::mat<4, 4, uint8_t>,
94 glm::mat<4, 4, int16_t>,
95 glm::mat<4, 4, uint16_t>,
96 glm::mat<4, 4, int32_t>,
97 glm::mat<4, 4, uint32_t>,
98 glm::mat<4, 4, int64_t>,
99 glm::mat<4, 4, uint64_t>,
100 glm::mat<4, 4, float>,
101 glm::mat<4, 4, double>,
102 ArrayView<int8_t>,
103 ArrayView<uint8_t>,
104 ArrayView<int16_t>,
105 ArrayView<uint16_t>,
106 ArrayView<int32_t>,
107 ArrayView<uint32_t>,
108 ArrayView<int64_t>,
109 ArrayView<uint64_t>,
110 ArrayView<float>,
111 ArrayView<double>,
112 ArrayView<bool>,
113 ArrayView<std::string_view>,
114 ArrayView<glm::vec<2, int8_t>>,
115 ArrayView<glm::vec<2, uint8_t>>,
116 ArrayView<glm::vec<2, int16_t>>,
117 ArrayView<glm::vec<2, uint16_t>>,
118 ArrayView<glm::vec<2, int32_t>>,
119 ArrayView<glm::vec<2, uint32_t>>,
120 ArrayView<glm::vec<2, int64_t>>,
121 ArrayView<glm::vec<2, uint64_t>>,
122 ArrayView<glm::vec<2, float>>,
123 ArrayView<glm::vec<2, double>>,
124 ArrayView<glm::vec<3, int8_t>>,
125 ArrayView<glm::vec<3, uint8_t>>,
126 ArrayView<glm::vec<3, int16_t>>,
127 ArrayView<glm::vec<3, uint16_t>>,
128 ArrayView<glm::vec<3, int32_t>>,
129 ArrayView<glm::vec<3, uint32_t>>,
130 ArrayView<glm::vec<3, int64_t>>,
131 ArrayView<glm::vec<3, uint64_t>>,
132 ArrayView<glm::vec<3, float>>,
133 ArrayView<glm::vec<3, double>>,
134 ArrayView<glm::vec<4, int8_t>>,
135 ArrayView<glm::vec<4, uint8_t>>,
136 ArrayView<glm::vec<4, int16_t>>,
137 ArrayView<glm::vec<4, uint16_t>>,
138 ArrayView<glm::vec<4, int32_t>>,
139 ArrayView<glm::vec<4, uint32_t>>,
140 ArrayView<glm::vec<4, int64_t>>,
141 ArrayView<glm::vec<4, uint64_t>>,
142 ArrayView<glm::vec<4, float>>,
143 ArrayView<glm::vec<4, double>>,
144 ArrayView<glm::mat<2, 2, int8_t>>,
145 ArrayView<glm::mat<2, 2, uint8_t>>,
146 ArrayView<glm::mat<2, 2, int16_t>>,
147 ArrayView<glm::mat<2, 2, uint16_t>>,
148 ArrayView<glm::mat<2, 2, int32_t>>,
149 ArrayView<glm::mat<2, 2, uint32_t>>,
150 ArrayView<glm::mat<2, 2, int64_t>>,
151 ArrayView<glm::mat<2, 2, uint64_t>>,
152 ArrayView<glm::mat<2, 2, float>>,
153 ArrayView<glm::mat<2, 2, double>>,
154 ArrayView<glm::mat<3, 3, int8_t>>,
155 ArrayView<glm::mat<3, 3, uint8_t>>,
156 ArrayView<glm::mat<3, 3, int16_t>>,
157 ArrayView<glm::mat<3, 3, uint16_t>>,
158 ArrayView<glm::mat<3, 3, int32_t>>,
159 ArrayView<glm::mat<3, 3, uint32_t>>,
160 ArrayView<glm::mat<3, 3, int64_t>>,
161 ArrayView<glm::mat<3, 3, uint64_t>>,
162 ArrayView<glm::mat<3, 3, float>>,
163 ArrayView<glm::mat<3, 3, double>>,
164 ArrayView<glm::mat<4, 4, int8_t>>,
165 ArrayView<glm::mat<4, 4, uint8_t>>,
166 ArrayView<glm::mat<4, 4, int16_t>>,
167 ArrayView<glm::mat<4, 4, uint16_t>>,
168 ArrayView<glm::mat<4, 4, int32_t>>,
169 ArrayView<glm::mat<4, 4, uint32_t>>,
170 ArrayView<glm::mat<4, 4, int64_t>>,
171 ArrayView<glm::mat<4, 4, uint64_t>>,
172 ArrayView<glm::mat<4, 4, float>>,
173 ArrayView<glm::mat<4, 4, double>>>;
174#pragma endregion
175
176public:
177 /**
178 * Constructs an empty metadata value with unknown type.
179 */
181 : _value(swl::monostate{}),
182 _valueType(),
183 _storage(),
184 _pEnumDefinition() {}
185
186 /**
187 * Constructs a metadata value with the given input.
188 *
189 * @param Value The value to be stored in this struct.
190 * @param pEnumDefinition The enum definition for this metadata value, or
191 * nullptr if not an enum.
192 */
193 template <typename T>
195 const T& Value,
196 const TSharedPtr<FCesiumMetadataEnum>& pEnumDefinition)
197 : _value(Value),
198 _valueType(TypeToMetadataValueType<T>(pEnumDefinition)),
199 _storage(),
200 _pEnumDefinition(pEnumDefinition) {}
201
202 /**
203 * Constructs a metadata value with the given input.
204 *
205 * @param Value The value to be stored in this struct.
206 */
207 template <typename T>
208 explicit FCesiumMetadataValue(const T& Value)
210 std::move(Value),
211 TSharedPtr<FCesiumMetadataEnum>(nullptr)) {}
212
213 template <typename ArrayType>
216 const TSharedPtr<FCesiumMetadataEnum>& pEnumDefinition = nullptr)
218 CesiumGltf::PropertyArrayCopy<ArrayType>(Copy),
219 pEnumDefinition) {}
220
221 template <typename ArrayType>
224 const TSharedPtr<FCesiumMetadataEnum>& pEnumDefinition = nullptr)
225 : _value(),
226 _valueType(
227 TypeToMetadataValueType<CesiumGltf::PropertyArrayView<ArrayType>>(
228 pEnumDefinition)),
229 _storage(),
230 _pEnumDefinition(pEnumDefinition) {
231 this->_value = std::move(Copy).toViewAndExternalBuffer(this->_storage);
232 }
233
234 /**
235 * Constructs a metadata value with the given optional input.
236 *
237 * @param MaybeValue The optional value to be stored in this struct.
238 * @param pEnumDefinition The enum definition for this metadata value, or
239 * nullptr if not an enum.
240 */
241 template <typename T>
243 const std::optional<T>& MaybeValue,
244 const TSharedPtr<FCesiumMetadataEnum>& pEnumDefinition = nullptr)
245 : _value(), _valueType(), _storage(), _pEnumDefinition(pEnumDefinition) {
246 if (!MaybeValue) {
247 return;
248 }
249
250 FCesiumMetadataValue temp(*MaybeValue);
251 this->_value = std::move(temp._value);
252 this->_valueType = std::move(temp._valueType);
253 this->_storage = std::move(temp._storage);
254 }
255
260
261private:
262 ValueType _value;
263 FCesiumMetadataValueType _valueType;
264 std::vector<std::byte> _storage;
265 TSharedPtr<FCesiumMetadataEnum> _pEnumDefinition;
266
269};
270
271UCLASS()
273 : public UBlueprintFunctionLibrary {
274 GENERATED_BODY()
275
276public:
277 /**
278 * Gets the best-fitting Blueprints type for this value. For the most precise
279 * representation of the value possible from Blueprints, you should retrieve
280 * it using this type.
281 */
282 UFUNCTION(
283 BlueprintCallable,
284 BlueprintPure,
285 Category = "Cesium|Metadata|Value")
287 GetBlueprintType(UPARAM(ref) const FCesiumMetadataValue& Value);
288
289 /**
290 * Gets the best-fitting Blueprints type for the elements of this array value.
291 * If the given value is not of an array type, this returns None.
292 */
293 UFUNCTION(
294 BlueprintCallable,
295 BlueprintPure,
296 Category = "Cesium|Metadata|Value")
299
300 /**
301 * Gets the type of the metadata value as defined in the
302 * EXT_structural_metadata extension. Many of these types are not accessible
303 * from Blueprints, but can be converted to a Blueprint-accessible type.
304 */
305 UFUNCTION(
306 BlueprintCallable,
307 BlueprintPure,
308 Category = "Cesium|Metadata|Value")
310 GetValueType(UPARAM(ref) const FCesiumMetadataValue& Value);
311
312 PRAGMA_DISABLE_DEPRECATION_WARNINGS
313 /**
314 * Gets true type of the value. Many of these types are not accessible
315 * from Blueprints, but can be converted to a Blueprint-accessible type.
316 */
317 UFUNCTION(
318 BlueprintCallable,
319 BlueprintPure,
320 Meta =
321 (DeprecatedFunction,
322 DeprecationMessage =
323 "CesiumMetadataTrueType is deprecated. Use GetValueType to get the CesiumMetadataValueType instead."))
325 GetTrueType(UPARAM(ref) const FCesiumMetadataValue& Value);
326
327 /**
328 * Gets true type of the elements in the array. If this value is not an array,
329 * the component type will be None. Many of these types are not accessible
330 * from Blueprints, but can be converted to a Blueprint-accessible type.
331 */
332 UFUNCTION(
333 BlueprintCallable,
334 BlueprintPure,
335 Meta =
336 (DeprecatedFunction,
337 DeprecationMessage =
338 "CesiumMetadataTrueType is deprecated. Use GetValueType to get the CesiumMetadataValueType instead."))
341
342 PRAGMA_ENABLE_DEPRECATION_WARNINGS
343
344 /**
345 * Attempts to retrieve the value as a boolean.
346 *
347 * If the value is a boolean, it is returned as-is.
348 *
349 * If the value is a scalar, zero is converted to false, while any other
350 * value is converted to true.
351 *
352 * If the value is a string, "0", "false", and "no" (case-insensitive) are
353 * converted to false, while "1", "true", and "yes" are converted to true.
354 * All other strings, including strings that can be converted to numbers,
355 * will return the default value.
356 *
357 * All other types return the default value.
358 *
359 * @param value The metadata value to retrieve.
360 * @param DefaultValue The default value to use if the given value cannot
361 * be converted to a Boolean.
362 * @return The value as a Boolean.
363 */
364 UFUNCTION(
365 BlueprintCallable,
366 BlueprintPure,
367 Category = "Cesium|Metadata|Value")
368 static bool
369 GetBoolean(UPARAM(ref) const FCesiumMetadataValue& value, bool DefaultValue);
370
371 /**
372 * Attempts to retrieve the value as an unsigned 8-bit integer.
373 *
374 * If the value is an integer between 0 and 255, it is returned
375 * as-is.
376 *
377 * If the value is a floating-point number in the aforementioned range, it is
378 * truncated (rounded toward zero) and returned.
379 *
380 * If the value is a boolean, 1 is returned for true and 0 for false.
381 *
382 * If the value is a string and the entire string can be parsed as an
383 * integer between 0 and 255, the parsed value is returned. The string is
384 * parsed in a locale-independent way and does not support the use of commas
385 * or other delimiters to group digits together.
386 *
387 * In all other cases, the default value is returned.
388 *
389 * @param Value The metadata value to retrieve.
390 * @param DefaultValue The default value to use if the given value cannot
391 * be converted to a Byte.
392 * @return The value as a Byte.
393 */
394 UFUNCTION(
395 BlueprintCallable,
396 BlueprintPure,
397 Category = "Cesium|Metadata|Value")
398 static uint8
399 GetByte(UPARAM(ref) const FCesiumMetadataValue& Value, uint8 DefaultValue);
400
401 /**
402 * Attempts to retrieve the value as a signed 32-bit integer.
403 *
404 * If the value is an integer between -2,147,483,648 and 2,147,483,647,
405 * it is returned as-is.
406 *
407 * If the value is a floating-point number in the aforementioned range, it is
408 * truncated (rounded toward zero) and returned;
409 *
410 * If the value is a boolean, 1 is returned for true and 0 for false.
411 *
412 * If the value is a string and the entire string can be parsed as an
413 * integer in the valid range, the parsed value is returned. If it can be
414 * parsed as a floating-point number, the parsed value is truncated (rounded
415 * toward zero). In either case, the string is parsed in a locale-independent
416 * way and does not support the use of commas or other delimiters to group
417 * digits together.
418 *
419 * In all other cases, the default value is returned.
420 *
421 * @param Value The metadata value to retrieve.
422 * @param DefaultValue The default value to use if the given value cannot
423 * be converted to an Integer.
424 * @return The value as an Integer.
425 */
426 UFUNCTION(
427 BlueprintCallable,
428 BlueprintPure,
429 Category = "Cesium|Metadata|Value")
430 static int32
431 GetInteger(UPARAM(ref) const FCesiumMetadataValue& Value, int32 DefaultValue);
432
433 /**
434 * Attempts to retrieve the value as a signed 64-bit integer.
435 *
436 * If the value is an integer and between -2^63 and (2^63 - 1),
437 * it is returned as-is.
438 *
439 * If the value is a floating-point number in the aforementioned range, it
440 * is truncated (rounded toward zero) and returned;
441 *
442 * If the value is a boolean, 1 is returned for true and 0 for false.
443 *
444 * If the value is a string and the entire string can be parsed as an
445 * integer in the valid range, the parsed value is returned. If it can be
446 * parsed as a floating-point number, the parsed value is truncated (rounded
447 * toward zero). In either case, the string is parsed in a locale-independent
448 * way and does not support the use of commas or other delimiters to group
449 * digits together.
450 *
451 * In all other cases, the default value is returned.
452 *
453 * @param Value The metadata value to retrieve.
454 * @param DefaultValue The default value to use if the given value cannot
455 * be converted to an Integer64.
456 * @return The value as an Integer64.
457 */
458 UFUNCTION(
459 BlueprintCallable,
460 BlueprintPure,
461 Category = "Cesium|Metadata|Value")
462 static int64 GetInteger64(
463 UPARAM(ref) const FCesiumMetadataValue& Value,
464 int64 DefaultValue);
465
466 /**
467 * Attempts to retrieve the value as a single-precision floating-point number.
468 *
469 * If the value is already a single-precision floating-point number, it is
470 * returned as-is.
471 *
472 * If the value is a scalar of any other type within the range of values that
473 * a single-precision float can represent, it is converted to its closest
474 * representation as a single-precision float and returned.
475 *
476 * If the value is a boolean, 1.0f is returned for true and 0.0f for false.
477 *
478 * If the value is a string, and the entire string can be parsed as a
479 * number, the parsed value is returned. The string is parsed in a
480 * locale-independent way and does not support the use of a comma or other
481 * delimiter to group digits togther.
482 *
483 * In all other cases, the default value is returned.
484 *
485 * @param Value The metadata value to retrieve.
486 * @param DefaultValue The default value to use if the given value cannot
487 * be converted to a Float.
488 * @return The value as a Float.
489 */
490 UFUNCTION(
491 BlueprintCallable,
492 BlueprintPure,
493 Category = "Cesium|Metadata|Value")
494 static float
495 GetFloat(UPARAM(ref) const FCesiumMetadataValue& Value, float DefaultValue);
496
497 /**
498 * Attempts to retrieve the value as a double-precision floating-point number.
499 *
500 * If the value is a single- or double-precision floating-point number, it is
501 * returned as-is.
502 *
503 * If the value is an integer, it is converted to the closest representable
504 * double-precision floating-point number.
505 *
506 * If the value is a boolean, 1.0 is returned for true and 0.0 for false.
507 *
508 * If the value is a string and the entire string can be parsed as a
509 * number, the parsed value is returned. The string is parsed in a
510 * locale-independent way and does not support the use of commas or other
511 * delimiters to group digits together.
512 *
513 * In all other cases, the default value is returned.
514 *
515 * @param Value The metadata value to retrieve.
516 * @param DefaultValue The default value to use if the given value cannot
517 * be converted to a Float64.
518 * @return The value as a Float64.
519 */
520 UFUNCTION(
521 BlueprintCallable,
522 BlueprintPure,
523 Category = "Cesium|Metadata|Value")
524 static double GetFloat64(
525 UPARAM(ref) const FCesiumMetadataValue& Value,
526 double DefaultValue);
527
528 /**
529 * Attempts to retrieve the value as a FIntPoint.
530 *
531 * If the value is a 2-dimensional vector, its components will be converted to
532 * 32-bit signed integers if possible.
533 *
534 * If the value is a 3- or 4-dimensional vector, it will use the first two
535 * components to construct the FIntPoint.
536 *
537 * If the value is a scalar that can be converted to a 32-bit signed integer,
538 * the resulting FIntPoint will have this value in both of its components.
539 *
540 * If the value is a boolean, (1, 1) is returned for true, while (0, 0) is
541 * returned for false.
542 *
543 * If the value is a string that can be parsed as a FIntPoint, the parsed
544 * value is returned. The string must be formatted as "X=... Y=...".
545 *
546 * In all other cases, the default value is returned. In all vector cases, if
547 * any of the relevant components cannot be represented as a 32-bit signed,
548 * the default value is returned.
549 *
550 * @param Value The metadata value to retrieve.
551 * @param DefaultValue The default value to use if the given value cannot
552 * be converted to a FIntPoint.
553 * @return The value as a FIntPoint.
554 */
555 UFUNCTION(
556 BlueprintCallable,
557 BlueprintPure,
558 Category = "Cesium|Metadata|Value")
559 static FIntPoint GetIntPoint(
560 UPARAM(ref) const FCesiumMetadataValue& Value,
561 const FIntPoint& DefaultValue);
562
563 /**
564 * Attempts to retrieve the value as a FVector2D.
565 *
566 * If the value is a 2-dimensional vector, its components will be converted to
567 * double-precision floating-point numbers.
568 *
569 * If the value is a 3- or 4-dimensional vector, it will use the first two
570 * components to construct the FVector2D.
571 *
572 * If the value is a scalar, the resulting FVector2D will have this value in
573 * both of its components.
574 *
575 * If the value is a boolean, (1.0, 1.0) is returned for true, while (0.0,
576 * 0.0) is returned for false.
577 *
578 * If the value is a string that can be parsed as a FVector2D, the parsed
579 * value is returned. The string must be formatted as "X=... Y=...".
580 *
581 * In all other cases, the default value is returned.
582 *
583 * @param Value The metadata value to retrieve.
584 * @param DefaultValue The default value to use if the given value cannot
585 * be converted to a FIntPoint.
586 * @return The value as a FIntPoint.
587 */
588 UFUNCTION(
589 BlueprintCallable,
590 BlueprintPure,
591 Category = "Cesium|Metadata|Value")
592 static FVector2D GetVector2D(
593 UPARAM(ref) const FCesiumMetadataValue& Value,
594 const FVector2D& DefaultValue);
595
596 /**
597 * Attempts to retrieve the value as a FIntVector.
598 *
599 * If the value is a 3-dimensional vector, its components will be converted to
600 * 32-bit signed integers if possible.
601 *
602 * If the value is a 4-dimensional vector, it will use the first three
603 * components to construct the FIntVector.
604 *
605 * If the value is a 2-dimensional vector, it will become the XY-components of
606 * the FIntVector. The Z component will be set to zero.
607 *
608 * If the value is a scalar that can be converted to a 32-bit signed integer,
609 * the resulting FIntVector will have this value in all of its components.
610 *
611 * If the value is a boolean, (1, 1, 1) is returned for true, while (0, 0, 0)
612 * is returned for false.
613 *
614 * If the value is a string that can be parsed as a FIntVector, the parsed
615 * value is returned. The string must be formatted as "X=... Y=... Z=".
616 *
617 * In all other cases, the default value is returned. In all vector cases, if
618 * any of the relevant components cannot be represented as a 32-bit signed
619 * integer, the default value is returned.
620 *
621 * @param Value The metadata value to retrieve.
622 * @param DefaultValue The default value to use if the given value cannot
623 * be converted to a FIntVector.
624 * @return The value as a FIntVector.
625 */
626 UFUNCTION(
627 BlueprintCallable,
628 BlueprintPure,
629 Category = "Cesium|Metadata|Value")
630 static FIntVector GetIntVector(
631 UPARAM(ref) const FCesiumMetadataValue& Value,
632 const FIntVector& DefaultValue);
633
634 /**
635 * Attempts to retrieve the value as a FVector3f.
636 *
637 * If the value is a 3-dimensional vector, its components will be converted to
638 * the closest representable single-precision floats, if possible.
639 *
640 * If the value is a 4-dimensional vector, a FVector3f containing the first
641 * three components will be returned.
642 *
643 * If the value is a 2-dimensional vector, it will become the XY-components of
644 * the FVector3f. The Z-component will be set to zero.
645 *
646 * If the value is a scalar that can be converted to a single-precision
647 * floating-point number, then the resulting FVector3f will have this value in
648 * all of its components.
649 *
650 * If the value is a boolean, (1.0f, 1.0f, 1.0f) is returned for true, while
651 * (0.0f, 0.0f, 0.0f) is returned for false.
652 *
653 * If the value is a string that can be parsed as a FVector3f, the parsed
654 * value is returned. The string must be formatted as "X=... Y=... Z=".
655 *
656 * In all other cases, the default value is returned. In all vector cases, if
657 * any of the relevant components cannot be represented as a single-precision
658 * float, the default value is returned.
659 *
660 * @param Value The metadata value to retrieve.
661 * @param DefaultValue The default value to use if the given value cannot
662 * be converted to a FVector3f.
663 * @return The value as a FVector3f.
664 */
665 UFUNCTION(
666 BlueprintCallable,
667 BlueprintPure,
668 Category = "Cesium|Metadata|Value")
669 static FVector3f GetVector3f(
670 UPARAM(ref) const FCesiumMetadataValue& Value,
671 const FVector3f& DefaultValue);
672
673 /**
674 * Attempts to retrieve the value as a FVector.
675 *
676 * If the value is a 3-dimensional vector, its components will be converted to
677 * double-precision floating-point numbers.
678 *
679 * If the value is a 4-dimensional vector, a FVector containing the first
680 * three components will be returned.
681 *
682 * If the value is a 2-dimensional vector, it will become the XY-components of
683 * the FVector. The Z-component will be set to zero.
684 *
685 * If the value is a scalar, then the resulting FVector will have this value
686 * as a double-precision floating-point number in all of its components.
687 *
688 * If the value is a boolean, (1.0, 1.0, 1.0) is returned for true, while
689 * (0.0, 0.0, 0.0) is returned for false.
690 *
691 * If the value is a string that can be parsed as a FVector, the parsed
692 * value is returned. The string must be formatted as "X=... Y=... Z=".
693 *
694 * In all other cases, the default value is returned.
695 *
696 * @param Value The metadata value to retrieve.
697 * @param DefaultValue The default value to use if the given value cannot
698 * be converted to a FVector.
699 * @return The value as a FVector.
700 */
701 UFUNCTION(
702 BlueprintCallable,
703 BlueprintPure,
704 Category = "Cesium|Metadata|Value")
705 static FVector GetVector(
706 UPARAM(ref) const FCesiumMetadataValue& Value,
707 const FVector& DefaultValue);
708
709 /**
710 * Attempts to retrieve the value as a FVector4.
711 *
712 * If the value is a 4-dimensional vector, its components will be converted to
713 * double-precision floating-point numbers.
714 *
715 * If the value is a 3-dimensional vector, it will become the XYZ-components
716 * of the FVector4. The W-component will be set to zero.
717 *
718 * If the value is a 2-dimensional vector, it will become the XY-components of
719 * the FVector4. The Z- and W-components will be set to zero.
720 *
721 * If the value is a scalar, then the resulting FVector4 will have this value
722 * as a double-precision floating-point number in all of its components.
723 *
724 * If the value is a boolean, (1.0, 1.0, 1.0, 1.0) is returned for true, while
725 * (0.0, 0.0, 0.0, 0.0) is returned for false.
726 *
727 * If the value is a string that can be parsed as a FVector4, the parsed
728 * value is returned. This follows the rules of FVector4::InitFromString. The
729 * string must be formatted as "X=... Y=... Z=... W=...". The W-component is
730 * optional; if absent, it will be set to 1.0.
731 *
732 * In all other cases, the default value is returned.
733 *
734 * @param Value The metadata value to retrieve.
735 * @param DefaultValue The default value to use if the given value cannot
736 * be converted to a FVector4.
737 * @return The value as a FVector4.
738 */
739 UFUNCTION(
740 BlueprintCallable,
741 BlueprintPure,
742 Category = "Cesium|Metadata|Value")
743 static FVector4 GetVector4(
744 UPARAM(ref) const FCesiumMetadataValue& Value,
745 const FVector4& DefaultValue);
746
747 /**
748 * Attempts to retrieve the value as a FMatrix.
749 *
750 * If the value is a 4-by-4 matrix, its components will be converted to
751 * double-precision floating-point numbers.
752 *
753 * If the value is a 3-by-3 matrix, it will initialize the corresponding
754 * entries of the FMatrix, while all other entries are set to zero. In other
755 * words, the 3-by-3 matrix is returned in an FMatrix where the fourth row and
756 * column are filled with zeroes.
757 *
758 * If the value is a 2-by-2 matrix, it will initialize the corresponding
759 * entries of the FMatrix, while all other entries are set to zero. In other
760 * words, the 2-by-2 matrix is returned in an FMatrix where the third and
761 * fourth rows / columns are filled with zeroes.
762 *
763 * If the value is a scalar, then the resulting FMatrix will have this value
764 * along its diagonal, including the very last component. All other entries
765 * will be zero.
766 *
767 * If the value is a boolean, it is converted to 1.0 for true and 0.0 for
768 * false. Then, the resulting FMatrix will have this value along its diagonal,
769 * including the very last component. All other entries will be zero.
770 *
771 * In all other cases, the default value is returned.
772 *
773 * @param Value The metadata value to retrieve.
774 * @param DefaultValue The default value to use if the given value cannot
775 * be converted to a FMatrix.
776 * @return The value as a FMatrix.
777 */
778 UFUNCTION(
779 BlueprintCallable,
780 BlueprintPure,
781 Category = "Cesium|Metadata|Value")
782 static FMatrix GetMatrix(
783 UPARAM(ref) const FCesiumMetadataValue& Value,
784 const FMatrix& DefaultValue);
785
786 /**
787 * Attempts to retrieve the value as a FString.
788 *
789 * String properties are returned as-is.
790 *
791 * Scalar values are converted to a string with `std::to_string`.
792 *
793 * Boolean properties are converted to "true" or "false".
794 *
795 * Vector properties are returned as strings in the format "X=... Y=... Z=...
796 * W=..." depending on how many components they have.
797 *
798 * Matrix properties are returned as strings row-by-row, where each row's
799 * values are printed between square brackets. For example, a 2-by-2 matrix
800 * will be printed out as "[A B] [C D]".
801 *
802 * Array properties return the default value.
803 *
804 * @param Value The metadata value to retrieve.
805 * @param DefaultValue The default value to use if the given value cannot
806 * be converted to a FString.
807 * @return The value as a FString.
808 */
809 UFUNCTION(
810 BlueprintCallable,
811 BlueprintPure,
812 Category = "Cesium|Metadata|Value")
813 static FString GetString(
814 UPARAM(ref) const FCesiumMetadataValue& Value,
815 const FString& DefaultValue);
816
817 /**
818 * Attempts to retrieve the value as a FCesiumPropertyArray. If the property
819 * is not an array type, this returns an empty array.
820 *
821 * @param Value The metadata value to retrieve.
822 * @return The value as a FCesiumPropertyArray.
823 */
824 UFUNCTION(
825 BlueprintCallable,
826 BlueprintPure,
827 Category = "Cesium|Metadata|Value")
829 const FCesiumMetadataValue& Value);
830
831 /**
832 * Whether the value is empty, i.e., whether it does not actually represent
833 * any data. An empty value functions as a null value, and can be compared to
834 * a std::nullopt in C++. For example, when the raw value of a property
835 * matches the property's specified "no data" value, it will return an empty
836 * FCesiumMetadataValue.
837 *
838 * @param Value The metadata value to retrieve.
839 * @return Whether the value is empty.
840 */
841 UFUNCTION(
842 BlueprintCallable,
843 BlueprintPure,
844 Category = "Cesium|Metadata|Value")
845 static bool IsEmpty(UPARAM(ref) const FCesiumMetadataValue& Value);
846
847 /**
848 * Gets the given map of metadata values as a new map of strings, mapped by
849 * name. This is useful for displaying the values from a property table or
850 * property texture as strings in a user interface.
851 *
852 * Array properties cannot be converted to strings, so empty strings
853 * will be returned for their values.
854 */
855 UFUNCTION(
856 BlueprintCallable,
857 BlueprintPure,
858 Category = "Cesium|Metadata|Value")
859 static TMap<FString, FString>
860 GetValuesAsStrings(const TMap<FString, FCesiumMetadataValue>& Values);
861};
862
863/**
864 * Grants access to metadata value types that are not currently supported in
865 * Blueprints. This can be useful in C++ code.
866 *
867 * These should be moved to UCesiumMetadataValueBlueprintLibrary if those types
868 * become compatible with Blueprints in the future.
869 */
870class CESIUMRUNTIME_API CesiumMetadataValueAccess {
871
872public:
873 /**
874 * Attempts to retrieve the value as an unsigned 64-bit integer.
875 *
876 * If the value is an integer and between 0 and (2^64 - 1),
877 * it is returned as-is.
878 *
879 * If the value is a floating-point number in the aforementioned range, it
880 * is truncated (rounded toward zero) and returned;
881 *
882 * If the value is a boolean, 1 is returned for true and 0 for false.
883 *
884 * If the value is a string and the entire string can be parsed as an
885 * integer in the valid range, the parsed value is returned. If it can be
886 * parsed as a floating-point number, the parsed value is truncated (rounded
887 * toward zero). In either case, the string is parsed in a locale-independent
888 * way and does not support the use of commas or other delimiters to group
889 * digits together.
890 *
891 * In all other cases, the default value is returned.
892 *
893 * @param DefaultValue The default value to use if the given value cannot
894 * be converted to an uint64.
895 * @return The value as an unsigned 64-bit integer.
896 */
897 static uint64
898 GetUnsignedInteger64(const FCesiumMetadataValue& Value, uint64 DefaultValue);
899};
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.
Grants access to metadata value types that are not currently supported in Blueprints.
static uint64 GetUnsignedInteger64(const FCesiumMetadataValue &Value, uint64 DefaultValue)
Attempts to retrieve the value as an unsigned 64-bit integer.
static PRAGMA_DISABLE_DEPRECATION_WARNINGS ECesiumMetadataTrueType_DEPRECATED GetTrueType(UPARAM(ref) const FCesiumMetadataValue &Value)
Gets true type of the value.
static FVector3f GetVector3f(UPARAM(ref) const FCesiumMetadataValue &Value, const FVector3f &DefaultValue)
Attempts to retrieve the value as a FVector3f.
static double GetFloat64(UPARAM(ref) const FCesiumMetadataValue &Value, double DefaultValue)
Attempts to retrieve the value as a double-precision floating-point number.
static FVector4 GetVector4(UPARAM(ref) const FCesiumMetadataValue &Value, const FVector4 &DefaultValue)
Attempts to retrieve the value as a FVector4.
static bool IsEmpty(UPARAM(ref) const FCesiumMetadataValue &Value)
Whether the value is empty, i.e., whether it does not actually represent any data.
static FIntVector GetIntVector(UPARAM(ref) const FCesiumMetadataValue &Value, const FIntVector &DefaultValue)
Attempts to retrieve the value as a FIntVector.
static ECesiumMetadataBlueprintType GetBlueprintType(UPARAM(ref) const FCesiumMetadataValue &Value)
Gets the best-fitting Blueprints type for this value.
static int64 GetInteger64(UPARAM(ref) const FCesiumMetadataValue &Value, int64 DefaultValue)
Attempts to retrieve the value as a signed 64-bit integer.
static int32 GetInteger(UPARAM(ref) const FCesiumMetadataValue &Value, int32 DefaultValue)
Attempts to retrieve the value as a signed 32-bit integer.
static FMatrix GetMatrix(UPARAM(ref) const FCesiumMetadataValue &Value, const FMatrix &DefaultValue)
Attempts to retrieve the value as a FMatrix.
static TMap< FString, FString > GetValuesAsStrings(const TMap< FString, FCesiumMetadataValue > &Values)
Gets the given map of metadata values as a new map of strings, mapped by name.
static FString GetString(UPARAM(ref) const FCesiumMetadataValue &Value, const FString &DefaultValue)
Attempts to retrieve the value as a FString.
static ECesiumMetadataTrueType_DEPRECATED GetTrueComponentType(UPARAM(ref) const FCesiumMetadataValue &Value)
Gets true type of the elements in the array.
static FVector GetVector(UPARAM(ref) const FCesiumMetadataValue &Value, const FVector &DefaultValue)
Attempts to retrieve the value as a FVector.
static FVector2D GetVector2D(UPARAM(ref) const FCesiumMetadataValue &Value, const FVector2D &DefaultValue)
Attempts to retrieve the value as a FVector2D.
static float GetFloat(UPARAM(ref) const FCesiumMetadataValue &Value, float DefaultValue)
Attempts to retrieve the value as a single-precision floating-point number.
static ECesiumMetadataBlueprintType GetArrayElementBlueprintType(UPARAM(ref) const FCesiumMetadataValue &Value)
Gets the best-fitting Blueprints type for the elements of this array value.
static FIntPoint GetIntPoint(UPARAM(ref) const FCesiumMetadataValue &Value, const FIntPoint &DefaultValue)
Attempts to retrieve the value as a FIntPoint.
static FCesiumMetadataValueType GetValueType(UPARAM(ref) const FCesiumMetadataValue &Value)
Gets the type of the metadata value as defined in the EXT_structural_metadata extension.
static PRAGMA_ENABLE_DEPRECATION_WARNINGS bool GetBoolean(UPARAM(ref) const FCesiumMetadataValue &value, bool DefaultValue)
Attempts to retrieve the value as a boolean.
static FCesiumPropertyArray GetArray(UPARAM(ref) const FCesiumMetadataValue &Value)
Attempts to retrieve the value as a FCesiumPropertyArray.
static uint8 GetByte(UPARAM(ref) const FCesiumMetadataValue &Value, uint8 DefaultValue)
Attempts to retrieve the value as an unsigned 8-bit integer.
STL namespace.
Stores information on the values of an enum and the corresponding names of those values.
Represents the true value type of a metadata value, akin to the property types in EXT_structural_meta...
A Blueprint-accessible wrapper for a glTF metadata value.
FCesiumMetadataValue(const std::optional< T > &MaybeValue, const TSharedPtr< FCesiumMetadataEnum > &pEnumDefinition=nullptr)
Constructs a metadata value with the given optional input.
FCesiumMetadataValue()
Constructs an empty metadata value with unknown type.
friend class CesiumMetadataValueAccess
FCesiumMetadataValue & operator=(FCesiumMetadataValue &&rhs)
FCesiumMetadataValue & operator=(const FCesiumMetadataValue &rhs)
friend class UCesiumMetadataValueBlueprintLibrary
FCesiumMetadataValue(const FCesiumMetadataValue &rhs)
FCesiumMetadataValue(const T &Value, const TSharedPtr< FCesiumMetadataEnum > &pEnumDefinition)
Constructs a metadata value with the given input.
FCesiumMetadataValue(const T &Value)
Constructs a metadata value with the given input.
FCesiumMetadataValue(CesiumGltf::PropertyArrayCopy< ArrayType > &&Copy, const TSharedPtr< FCesiumMetadataEnum > &pEnumDefinition=nullptr)
FCesiumMetadataValue(const CesiumGltf::PropertyArrayCopy< ArrayType > &Copy, const TSharedPtr< FCesiumMetadataEnum > &pEnumDefinition=nullptr)
FCesiumMetadataValue(FCesiumMetadataValue &&rhs)
A Blueprint-accessible wrapper for an array property in glTF metadata.