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