Skip to content

Commit 8c2fd03

Browse files
committed
Add TArray constructor for CesiumPropertyArray
1 parent bf5b3ff commit 8c2fd03

File tree

5 files changed

+217
-136
lines changed

5 files changed

+217
-136
lines changed

Source/CesiumRuntime/Private/CesiumGoogleMapTilesRasterOverlay.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Copyright 2020-2025 CesiumGS, Inc. and Contributors
22

33
#include "CesiumGoogleMapTilesRasterOverlay.h"
4+
#include "CesiumRuntime.h"
5+
46
#include <Cesium3DTilesSelection/Tileset.h>
57
#include <CesiumJsonReader/JsonObjectJsonHandler.h>
68
#include <CesiumJsonReader/JsonReader.h>

Source/CesiumRuntime/Private/CesiumPropertyArray.cpp

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Copyright 2020-2024 CesiumGS, Inc. and Contributors
22

33
#include "CesiumPropertyArray.h"
4+
#include "CesiumMetadataValue.h"
5+
46
#include <CesiumGltf/PropertyTypeTraits.h>
57

68
FCesiumPropertyArray::FCesiumPropertyArray(FCesiumPropertyArray&& rhs) =
@@ -9,21 +11,52 @@ FCesiumPropertyArray::FCesiumPropertyArray(FCesiumPropertyArray&& rhs) =
911
FCesiumPropertyArray&
1012
FCesiumPropertyArray::operator=(FCesiumPropertyArray&& rhs) = default;
1113

14+
FCesiumPropertyArray::FCesiumPropertyArray(
15+
const TArray<FCesiumMetadataValue>&& values,
16+
TSharedPtr<FCesiumMetadataEnum> pEnumDefinition)
17+
: _valueView(),
18+
_valueArray(),
19+
_elementType(),
20+
_pEnumDefinition(pEnumDefinition) {
21+
if (values.Num() == 0) {
22+
return;
23+
}
24+
25+
FCesiumMetadataValueType valueType =
26+
UCesiumMetadataValueBlueprintLibrary::GetValueType(values[0]);
27+
28+
// Verify that all other elements in the array have the same type. If any of
29+
// them differ, consider this array invalid.
30+
for (int32 i = 1; i < values.Num(); i++) {
31+
FCesiumMetadataValueType otherValueType =
32+
UCesiumMetadataValueBlueprintLibrary::GetValueType(values[i]);
33+
if (valueType != otherValueType) {
34+
return;
35+
}
36+
}
37+
38+
_elementType = valueType;
39+
_valueArray = std::move(values);
40+
}
41+
1242
FCesiumPropertyArray::FCesiumPropertyArray(const FCesiumPropertyArray& rhs)
13-
: _value(), _elementType(rhs._elementType), _storage(rhs._storage) {
43+
: _valueView(),
44+
_valueArray(),
45+
_elementType(rhs._elementType),
46+
_storage(rhs._storage) {
1447
swl::visit(
1548
[this](const auto& value) {
1649
if constexpr (CesiumGltf::IsMetadataArray<decltype(value)>::value) {
1750
if (!this->_storage.empty()) {
18-
this->_value = decltype(value)(this->_storage);
51+
this->_valueView = decltype(value)(this->_storage);
1952
} else {
20-
this->_value = value;
53+
this->_valueView = value;
2154
}
2255
} else {
23-
this->_value = value;
56+
this->_valueView = value;
2457
}
2558
},
26-
rhs._value);
59+
rhs._valueView);
2760
}
2861

2962
FCesiumPropertyArray&

Source/CesiumRuntime/Private/CesiumPropertyArrayBlueprintLibrary.cpp

Lines changed: 63 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -6,54 +6,67 @@
66

77
ECesiumMetadataBlueprintType
88
UCesiumPropertyArrayBlueprintLibrary::GetElementBlueprintType(
9-
UPARAM(ref) const FCesiumPropertyArray& array) {
10-
return CesiumMetadataValueTypeToBlueprintType(array._elementType);
9+
UPARAM(ref) const FCesiumPropertyArray& Array) {
10+
return CesiumMetadataValueTypeToBlueprintType(Array._elementType);
1111
}
1212

1313
ECesiumMetadataBlueprintType
1414
UCesiumPropertyArrayBlueprintLibrary::GetBlueprintComponentType(
15-
UPARAM(ref) const FCesiumPropertyArray& array) {
16-
return CesiumMetadataValueTypeToBlueprintType(array._elementType);
15+
UPARAM(ref) const FCesiumPropertyArray& Array) {
16+
return CesiumMetadataValueTypeToBlueprintType(Array._elementType);
1717
}
1818

1919
FCesiumMetadataValueType
2020
UCesiumPropertyArrayBlueprintLibrary::GetElementValueType(
21-
UPARAM(ref) const FCesiumPropertyArray& array) {
22-
return array._elementType;
21+
UPARAM(ref) const FCesiumPropertyArray& Array) {
22+
return Array._elementType;
2323
}
2424

2525
int64 UCesiumPropertyArrayBlueprintLibrary::GetArraySize(
26-
UPARAM(ref) const FCesiumPropertyArray& array) {
27-
return swl::visit([](const auto& view) { return view.size(); }, array._value);
26+
UPARAM(ref) const FCesiumPropertyArray& Array) {
27+
if (Array._valueArray.IsSet()) {
28+
return Array._valueArray->Num();
29+
}
30+
31+
return swl::visit(
32+
[](const auto& view) { return view.size(); },
33+
Array._valueView);
2834
}
2935

3036
int64 UCesiumPropertyArrayBlueprintLibrary::GetSize(
31-
UPARAM(ref) const FCesiumPropertyArray& array) {
32-
return swl::visit([](const auto& view) { return view.size(); }, array._value);
37+
UPARAM(ref) const FCesiumPropertyArray& Array) {
38+
return UCesiumPropertyArrayBlueprintLibrary::GetArraySize(Array);
3339
}
3440

3541
FCesiumMetadataValue UCesiumPropertyArrayBlueprintLibrary::GetValue(
36-
UPARAM(ref) const FCesiumPropertyArray& array,
37-
int64 index) {
42+
UPARAM(ref) const FCesiumPropertyArray& Array,
43+
int64 Index) {
44+
int64 arraySize = UCesiumPropertyArrayBlueprintLibrary::GetArraySize(Array);
45+
if (Index < 0 || Index >= arraySize) {
46+
FFrame::KismetExecutionMessage(
47+
*FString::Printf(
48+
TEXT(
49+
"Attempted to access index %d from CesiumPropertyArray of length %d!"),
50+
Index,
51+
arraySize),
52+
ELogVerbosity::Warning,
53+
FName("CesiumPropertyArrayOutOfBoundsWarning"));
54+
return FCesiumMetadataValue();
55+
}
56+
57+
if (Array._valueArray.IsSet()) {
58+
return (*Array._valueArray)[Index];
59+
}
60+
3861
return swl::visit(
39-
[index, &pEnumDefinition = array._pEnumDefinition](
62+
[Index, &pEnumDefinition = Array._pEnumDefinition](
4063
const auto& v) -> FCesiumMetadataValue {
41-
if (index < 0 || index >= v.size()) {
42-
FFrame::KismetExecutionMessage(
43-
*FString::Printf(
44-
TEXT(
45-
"Attempted to access index %d from CesiumPropertyArray of length %d!"),
46-
index,
47-
v.size()),
48-
ELogVerbosity::Warning,
49-
FName("CesiumPropertyArrayOutOfBoundsWarning"));
50-
return FCesiumMetadataValue();
51-
}
52-
return FCesiumMetadataValue(v[index], pEnumDefinition);
64+
return FCesiumMetadataValue(v[Index], pEnumDefinition);
5365
},
54-
array._value);
66+
Array._valueView);
5567
}
5668

69+
PRAGMA_DISABLE_DEPRECATION_WARNINGS
5770
ECesiumMetadataTrueType_DEPRECATED
5871
UCesiumPropertyArrayBlueprintLibrary::GetTrueComponentType(
5972
UPARAM(ref) const FCesiumPropertyArray& array) {
@@ -64,130 +77,64 @@ bool UCesiumPropertyArrayBlueprintLibrary::GetBoolean(
6477
UPARAM(ref) const FCesiumPropertyArray& array,
6578
int64 index,
6679
bool defaultValue) {
67-
return swl::visit(
68-
[index, defaultValue](const auto& v) -> bool {
69-
if (index < 0 || index >= v.size()) {
70-
return defaultValue;
71-
}
72-
auto value = v[index];
73-
return CesiumGltf::MetadataConversions<bool, decltype(value)>::convert(
74-
value)
75-
.value_or(defaultValue);
76-
},
77-
array._value);
80+
FCesiumMetadataValue value =
81+
UCesiumPropertyArrayBlueprintLibrary::GetValue(array, index);
82+
return UCesiumMetadataValueBlueprintLibrary::GetBoolean(value, defaultValue);
7883
}
7984

8085
uint8 UCesiumPropertyArrayBlueprintLibrary::GetByte(
8186
UPARAM(ref) const FCesiumPropertyArray& array,
8287
int64 index,
8388
uint8 defaultValue) {
84-
return swl::visit(
85-
[index, defaultValue](const auto& v) -> uint8 {
86-
if (index < 0 || index >= v.size()) {
87-
return defaultValue;
88-
}
89-
auto value = v[index];
90-
return CesiumGltf::MetadataConversions<uint8, decltype(value)>::convert(
91-
value)
92-
.value_or(defaultValue);
93-
},
94-
array._value);
89+
FCesiumMetadataValue value =
90+
UCesiumPropertyArrayBlueprintLibrary::GetValue(array, index);
91+
return UCesiumMetadataValueBlueprintLibrary::GetByte(value, defaultValue);
9592
}
9693

9794
int32 UCesiumPropertyArrayBlueprintLibrary::GetInteger(
9895
UPARAM(ref) const FCesiumPropertyArray& array,
9996
int64 index,
10097
int32 defaultValue) {
101-
return swl::visit(
102-
[index, defaultValue](const auto& v) -> int32 {
103-
if (index < 0 || index >= v.size()) {
104-
return defaultValue;
105-
}
106-
auto value = v[index];
107-
return CesiumGltf::MetadataConversions<int32, decltype(value)>::convert(
108-
value)
109-
.value_or(defaultValue);
110-
},
111-
array._value);
98+
FCesiumMetadataValue value =
99+
UCesiumPropertyArrayBlueprintLibrary::GetValue(array, index);
100+
return UCesiumMetadataValueBlueprintLibrary::GetInteger(value, defaultValue);
112101
}
113102

114103
int64 UCesiumPropertyArrayBlueprintLibrary::GetInteger64(
115104
UPARAM(ref) const FCesiumPropertyArray& array,
116105
int64 index,
117106
int64 defaultValue) {
118-
return swl::visit(
119-
[index, defaultValue](const auto& v) -> int64 {
120-
if (index < 0 || index >= v.size()) {
121-
return defaultValue;
122-
}
123-
auto value = v[index];
124-
return CesiumGltf::MetadataConversions<int64_t, decltype(value)>::
125-
convert(value)
126-
.value_or(defaultValue);
127-
},
128-
array._value);
107+
FCesiumMetadataValue value =
108+
UCesiumPropertyArrayBlueprintLibrary::GetValue(array, index);
109+
return UCesiumMetadataValueBlueprintLibrary::GetInteger64(
110+
value,
111+
defaultValue);
129112
}
130113

131114
float UCesiumPropertyArrayBlueprintLibrary::GetFloat(
132115
UPARAM(ref) const FCesiumPropertyArray& array,
133116
int64 index,
134117
float defaultValue) {
135-
return swl::visit(
136-
[index, defaultValue](const auto& v) -> float {
137-
if (index < 0 || index >= v.size()) {
138-
return defaultValue;
139-
}
140-
auto value = v[index];
141-
return CesiumGltf::MetadataConversions<float, decltype(value)>::convert(
142-
value)
143-
.value_or(defaultValue);
144-
},
145-
array._value);
118+
FCesiumMetadataValue value =
119+
UCesiumPropertyArrayBlueprintLibrary::GetValue(array, index);
120+
return UCesiumMetadataValueBlueprintLibrary::GetFloat(value, defaultValue);
146121
}
147122

148123
double UCesiumPropertyArrayBlueprintLibrary::GetFloat64(
149124
UPARAM(ref) const FCesiumPropertyArray& array,
150125
int64 index,
151126
double defaultValue) {
152-
return swl::visit(
153-
[index, defaultValue](const auto& v) -> double {
154-
auto value = v[index];
155-
return CesiumGltf::MetadataConversions<double, decltype(value)>::
156-
convert(value)
157-
.value_or(defaultValue);
158-
},
159-
array._value);
127+
FCesiumMetadataValue value =
128+
UCesiumPropertyArrayBlueprintLibrary::GetValue(array, index);
129+
return UCesiumMetadataValueBlueprintLibrary::GetFloat64(value, defaultValue);
160130
}
161131

162132
FString UCesiumPropertyArrayBlueprintLibrary::GetString(
163133
UPARAM(ref) const FCesiumPropertyArray& array,
164134
int64 index,
165135
const FString& defaultValue) {
166-
return swl::visit(
167-
[index, defaultValue, &EnumDefinition = array._pEnumDefinition](
168-
const auto& v) -> FString {
169-
if (index < 0 || index >= v.size()) {
170-
return defaultValue;
171-
}
172-
auto value = v[index];
173-
using ValueType = decltype(value);
174-
175-
if constexpr (CesiumGltf::IsMetadataInteger<ValueType>::value) {
176-
if (EnumDefinition.IsValid()) {
177-
TOptional<FString> MaybeName = EnumDefinition->GetName(value);
178-
if (MaybeName.IsSet()) {
179-
return MaybeName.GetValue();
180-
}
181-
}
182-
}
183-
184-
auto maybeString =
185-
CesiumGltf::MetadataConversions<std::string, ValueType>::convert(
186-
value);
187-
if (!maybeString) {
188-
return defaultValue;
189-
}
190-
return UnrealMetadataConversions::toString(*maybeString);
191-
},
192-
array._value);
136+
FCesiumMetadataValue value =
137+
UCesiumPropertyArrayBlueprintLibrary::GetValue(array, index);
138+
return UCesiumMetadataValueBlueprintLibrary::GetString(value, defaultValue);
193139
}
140+
PRAGMA_ENABLE_DEPRECATION_WARNINGS

0 commit comments

Comments
 (0)