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