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