Skip to content

Commit

Permalink
Add RequestHeaders property to Cesium3DTileset
Browse files Browse the repository at this point in the history
  • Loading branch information
azrogers committed Jan 9, 2025
1 parent 31c9dce commit ede6c52
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Change Log

### ? - ?

##### Additions :tada:
- Added `RequestHeaders` property to `Cesium3DTileset`, allowing per-tileset headers to be specified.

### v2.12.0 - 2025-01-02

##### Breaking Changes :mega:
Expand Down
33 changes: 33 additions & 0 deletions Source/CesiumRuntime/Private/Cesium3DTileset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,31 @@ void ACesium3DTileset::SetTilesetSource(ETilesetSource InSource) {
}
}

bool CompareMaps(
const TMap<FString, FString>& Lhs,
const TMap<FString, FString>& Rhs) {
if (Lhs.Num() != Rhs.Num()) {
return false;
}

for (auto& [Key, Value] : Lhs) {
const FString* RhsVal = Rhs.Find(Key);
if (!RhsVal || *RhsVal != Value) {
return false;
}
}

return true;
}

void ACesium3DTileset::SetRequestHeaders(
const TMap<FString, FString>& InRequestHeaders) {
if (!CompareMaps(InRequestHeaders, this->RequestHeaders)) {
this->DestroyTileset();
this->RequestHeaders = RequestHeaders;
}
}

void ACesium3DTileset::SetUrl(const FString& InUrl) {
if (InUrl != this->Url) {
if (this->TilesetSource == ETilesetSource::FromUrl) {
Expand Down Expand Up @@ -1287,6 +1312,14 @@ void ACesium3DTileset::LoadTileset() {

options.contentOptions.applyTextureTransform = false;

options.requestHeaders.reserve(this->RequestHeaders.Num());

for (auto& [Key, Value] : this->RequestHeaders) {
options.requestHeaders.emplace_back(CesiumAsync::IAssetAccessor::THeader{
std::string(TCHAR_TO_UTF8(*Key)),
std::string(TCHAR_TO_UTF8(*Value))});
}

switch (this->TilesetSource) {
case ETilesetSource::FromEllipsoid:
UE_LOG(LogCesium, Log, TEXT("Loading tileset from ellipsoid"));
Expand Down
16 changes: 16 additions & 0 deletions Source/CesiumRuntime/Public/Cesium3DTileset.h
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,16 @@ class CESIUMRUNTIME_API ACesium3DTileset : public AActor {
meta = (EditCondition = "TilesetSource==ETilesetSource::FromCesiumIon"))
UCesiumIonServer* CesiumIonServer;

/**
* Headers to be attached to each request made for this tileset.
*/
UPROPERTY(
EditAnywhere,
BlueprintGetter = GetRequestHeaders,
BlueprintSetter = SetRequestHeaders,
Category = "Cesium")
TMap<FString, FString> RequestHeaders;

/**
* Check if the Cesium ion token used to access this tileset is working
* correctly, and fix it if necessary.
Expand Down Expand Up @@ -972,6 +982,12 @@ class CESIUMRUNTIME_API ACesium3DTileset : public AActor {
UFUNCTION(BlueprintSetter, Category = "Cesium")
void SetUrl(const FString& InUrl);

UFUNCTION(BlueprintGetter, Category = "Cesium")
TMap<FString, FString> GetRequestHeaders() const { return RequestHeaders; }

UFUNCTION(BlueprintSetter, Category = "Cesium")
void SetRequestHeaders(const TMap<FString, FString>& InRequestHeaders);

UFUNCTION(BlueprintGetter, Category = "Cesium")
int64 GetIonAssetID() const { return IonAssetID; }

Expand Down

0 comments on commit ede6c52

Please sign in to comment.