Skip to content

Commit 5c26b8c

Browse files
authored
Merge pull request CesiumGS#1309 from CesiumGS/multiple-cesium-ions
Add support for multiple Cesium ion servers
2 parents bdbfb17 + 43f9e95 commit 5c26b8c

35 files changed

+1894
-505
lines changed

CHANGES.md

+10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# Change Log
22

3+
### ? - ?
4+
5+
##### Breaking Changes :mega:
6+
7+
- Deprecated `IonAssetEndpointUrl` on `Cesium3DTileset` and `CesiumIonRasterOverlay`. Use the new `CesiumIonServer` property instead.
8+
9+
##### Additions :tada:
10+
11+
- Added support for multiple Cesium ion servers by creating `CesiumIonServer` data assets.
12+
313
### v2.1.0 - 2023-12-01
414

515
##### Additions :tada:

Source/CesiumEditor/Private/CesiumEditor.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "CesiumGlobeAnchorCustomization.h"
1111
#include "CesiumIonPanel.h"
1212
#include "CesiumIonRasterOverlay.h"
13+
#include "CesiumIonServer.h"
1314
#include "CesiumIonTokenTroubleshooting.h"
1415
#include "CesiumPanel.h"
1516
#include "CesiumRuntime.h"
@@ -268,9 +269,7 @@ void FCesiumEditorModule::StartupModule() {
268269

269270
registerDetailCustomization();
270271

271-
this->_pIonSession =
272-
std::make_shared<CesiumIonSession>(getAsyncSystem(), getAssetAccessor());
273-
this->_pIonSession->resume();
272+
this->_serverManager.Initialize();
274273

275274
// Only register style once
276275
if (!StyleSet.IsValid()) {

Source/CesiumEditor/Private/CesiumEditor.h

+5-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include "CesiumEditorReparentHandler.h"
66
#include "CesiumEditorSubLevelMutex.h"
7+
#include "CesiumIonServerManager.h"
78
#include "CesiumIonSession.h"
89
#include "CoreMinimal.h"
910
#include "Modules/ModuleManager.h"
@@ -17,6 +18,7 @@ class UCesiumRasterOverlay;
1718
class UCesiumIonRasterOverlay;
1819
struct FCesium3DTilesetLoadFailureDetails;
1920
struct FCesiumRasterOverlayLoadFailureDetails;
21+
class UCesiumIonServer;
2022

2123
DECLARE_LOG_CATEGORY_EXTERN(LogCesiumEditor, Log, All);
2224

@@ -34,9 +36,9 @@ class FCesiumEditorModule : public IModuleInterface {
3436

3537
static FCesiumEditorModule* get() { return _pModule; }
3638

37-
static CesiumIonSession& ion() {
39+
static CesiumIonServerManager& serverManager() {
3840
assert(_pModule);
39-
return *_pModule->_pIonSession;
41+
return get()->_serverManager;
4042
}
4143

4244
static ACesium3DTileset* FindFirstTilesetSupportingOverlays();
@@ -109,7 +111,7 @@ class FCesiumEditorModule : public IModuleInterface {
109111
void OnTilesetIonTroubleshooting(ACesium3DTileset* pTileset);
110112
void OnRasterOverlayIonTroubleshooting(UCesiumRasterOverlay* pOverlay);
111113

112-
std::shared_ptr<CesiumIonSession> _pIonSession;
114+
CesiumIonServerManager _serverManager;
113115
FDelegateHandle _tilesetLoadFailureSubscription;
114116
FDelegateHandle _rasterOverlayLoadFailureSubscription;
115117
FDelegateHandle _tilesetIonTroubleshootingSubscription;
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
// Copyright 2020-2021 CesiumGS, Inc. and Contributors
22

33
#include "CesiumEditorSettings.h"
4+
#include "CesiumSourceControl.h"
45

56
UCesiumEditorSettings::UCesiumEditorSettings(
67
const FObjectInitializer& ObjectInitializer)
78
: Super(ObjectInitializer) {}
9+
10+
void UCesiumEditorSettings::Save() {
11+
CesiumSourceControl::PromptToCheckoutConfigFile(
12+
this->GetClass()->GetConfigName());
13+
this->Modify();
14+
this->SaveConfig();
15+
}

Source/CesiumEditor/Private/CesiumEditorSettings.h

+20-6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#pragma once
44

5+
#include "CesiumIonServer.h"
56
#include "CoreMinimal.h"
67
#include "Engine/DeveloperSettings.h"
78
#include "CesiumEditorSettings.generated.h"
@@ -14,16 +15,29 @@ class UCesiumEditorSettings : public UDeveloperSettings {
1415
GENERATED_UCLASS_BODY()
1516

1617
public:
18+
UPROPERTY(
19+
Config,
20+
meta =
21+
(DeprecatedProperty,
22+
DeprecationMessage = "Set UserAccessTokenMap instead."))
23+
FString UserAccessToken_DEPRECATED;
24+
1725
/**
18-
* The token representing the signed-in user to Cesium ion. If this is blank
19-
* or invalid, the Cesium panel will prompt you to log in to Cesium ion with
20-
* OAuth2. This is set automatically by logging in with the UI; it is not
21-
* usually necessary to set it directly.
26+
* The Cesium ion server that is currently selected in the user interface.
2227
*/
2328
UPROPERTY(
2429
Config,
2530
EditAnywhere,
2631
Category = "Cesium ion",
27-
meta = (DisplayName = "User Access Token"))
28-
FString UserAccessToken;
32+
meta = (DisplayName = "Current Cesium ion Server"))
33+
TSoftObjectPtr<UCesiumIonServer> CurrentCesiumIonServer;
34+
35+
UPROPERTY(
36+
Config,
37+
EditAnywhere,
38+
Category = "Cesium ion",
39+
meta = (DisplayName = "Token Map"))
40+
TMap<TSoftObjectPtr<UCesiumIonServer>, FString> UserAccessTokenMap;
41+
42+
void Save();
2943
};

Source/CesiumEditor/Private/CesiumIonPanel.cpp

+56-21
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#include "CesiumCommands.h"
88
#include "CesiumEditor.h"
99
#include "CesiumIonRasterOverlay.h"
10+
#include "CesiumIonServerSelector.h"
11+
#include "CesiumRuntime.h"
1012
#include "Editor.h"
1113
#include "EditorModeManager.h"
1214
#include "EngineUtils.h"
@@ -30,31 +32,28 @@ static FName ColumnName_Type = "Type";
3032
static FName ColumnName_DateAdded = "DateAdded";
3133

3234
CesiumIonPanel::CesiumIonPanel()
33-
: _connectionUpdatedDelegateHandle(),
34-
_assetsUpdatedDelegateHandle(),
35-
_pListView(nullptr),
35+
: _pListView(nullptr),
3636
_assets(),
37-
_pSelection(nullptr) {
38-
this->_connectionUpdatedDelegateHandle =
39-
FCesiumEditorModule::ion().ConnectionUpdated.AddRaw(
37+
_pSelection(nullptr),
38+
_pLastServer(nullptr) {
39+
this->_serverChangedDelegateHandle =
40+
FCesiumEditorModule::serverManager().CurrentServerChanged.AddRaw(
4041
this,
41-
&CesiumIonPanel::Refresh);
42-
this->_assetsUpdatedDelegateHandle =
43-
FCesiumEditorModule::ion().AssetsUpdated.AddRaw(
44-
this,
45-
&CesiumIonPanel::Refresh);
42+
&CesiumIonPanel::OnServerChanged);
4643
this->_sortColumnName = ColumnName_DateAdded;
4744
this->_sortMode = EColumnSortMode::Type::Descending;
45+
this->OnServerChanged();
4846
}
4947

5048
CesiumIonPanel::~CesiumIonPanel() {
51-
FCesiumEditorModule::ion().AssetsUpdated.Remove(
52-
this->_assetsUpdatedDelegateHandle);
53-
FCesiumEditorModule::ion().ConnectionUpdated.Remove(
54-
this->_connectionUpdatedDelegateHandle);
49+
this->Subscribe(nullptr);
50+
FCesiumEditorModule::serverManager().CurrentServerChanged.Remove(
51+
this->_serverChangedDelegateHandle);
5552
}
5653

5754
void CesiumIonPanel::Construct(const FArguments& InArgs) {
55+
this->Subscribe(FCesiumEditorModule::serverManager().GetCurrentServer());
56+
5857
// A function that returns the lambda that is used for rendering
5958
// the sort mode indicator of the header column: If sorting is
6059
// currently done based on the given name, then this will
@@ -111,6 +110,7 @@ void CesiumIonPanel::Construct(const FArguments& InArgs) {
111110
SVerticalBox::Slot().AutoHeight()
112111
[
113112
SNew(SHorizontalBox) +
113+
SHorizontalBox::Slot().Padding(5.0f)[SNew(CesiumIonServerSelector)] +
114114
// Add the refresh button at the upper left
115115
SHorizontalBox::Slot().HAlign(HAlign_Left).Padding(5.0f)
116116
[
@@ -123,7 +123,7 @@ void CesiumIonPanel::Construct(const FArguments& InArgs) {
123123
.Text(FText::FromString(TEXT("Refresh")))
124124
.ToolTipText(FText::FromString(TEXT("Refresh the asset list")))
125125
.OnClicked_Lambda([this]() {
126-
FCesiumEditorModule::ion().refreshAssets();
126+
FCesiumEditorModule::serverManager().GetCurrentSession()->refreshAssets();
127127
Refresh();
128128
return FReply::Handled();
129129
})
@@ -156,7 +156,7 @@ void CesiumIonPanel::Construct(const FArguments& InArgs) {
156156
];
157157
// clang-format on
158158

159-
FCesiumEditorModule::ion().refreshAssets();
159+
FCesiumEditorModule::serverManager().GetCurrentSession()->refreshAssets();
160160
}
161161

162162
void CesiumIonPanel::OnSortChange(
@@ -402,7 +402,11 @@ void CesiumIonPanel::ApplySorting() {
402402
}
403403

404404
void CesiumIonPanel::Refresh() {
405-
const Assets& assets = FCesiumEditorModule::ion().getAssets();
405+
if (!this->_pListView)
406+
return;
407+
408+
const Assets& assets =
409+
FCesiumEditorModule::serverManager().GetCurrentSession()->getAssets();
406410

407411
this->_assets.SetNum(assets.items.size());
408412

@@ -418,7 +422,7 @@ void CesiumIonPanel::Tick(
418422
const FGeometry& AllottedGeometry,
419423
const double InCurrentTime,
420424
const float InDeltaTime) {
421-
FCesiumEditorModule::ion().getAsyncSystem().dispatchMainThreadTasks();
425+
getAsyncSystem().dispatchMainThreadTasks();
422426
SCompoundWidget::Tick(AllottedGeometry, InCurrentTime, InDeltaTime);
423427
}
424428

@@ -428,6 +432,33 @@ void CesiumIonPanel::AssetSelected(
428432
this->_pSelection = item;
429433
}
430434

435+
void CesiumIonPanel::Subscribe(UCesiumIonServer* pNewServer) {
436+
if (this->_pLastServer) {
437+
std::shared_ptr<CesiumIonSession> pLastSession =
438+
FCesiumEditorModule::serverManager().GetSession(this->_pLastServer);
439+
if (pLastSession) {
440+
pLastSession->ConnectionUpdated.RemoveAll(this);
441+
pLastSession->AssetsUpdated.RemoveAll(this);
442+
}
443+
}
444+
445+
this->_pLastServer = pNewServer;
446+
447+
if (pNewServer) {
448+
std::shared_ptr<CesiumIonSession> pSession =
449+
FCesiumEditorModule::serverManager().GetSession(pNewServer);
450+
pSession->ConnectionUpdated.AddRaw(this, &CesiumIonPanel::Refresh);
451+
pSession->AssetsUpdated.AddRaw(this, &CesiumIonPanel::Refresh);
452+
}
453+
}
454+
455+
void CesiumIonPanel::OnServerChanged() {
456+
UCesiumIonServer* pNewServer =
457+
FCesiumEditorModule::serverManager().GetCurrentServer();
458+
this->Subscribe(pNewServer);
459+
this->Refresh();
460+
}
461+
431462
void CesiumIonPanel::AddAsset(TSharedPtr<CesiumIonClient::Asset> item) {
432463

433464
if (isSupportedImagery(item)) {
@@ -445,7 +476,9 @@ void CesiumIonPanel::AddAsset(TSharedPtr<CesiumIonClient::Asset> item) {
445476
}
446477

447478
void CesiumIonPanel::AddAssetToLevel(TSharedPtr<CesiumIonClient::Asset> item) {
448-
SelectCesiumIonToken::SelectAndAuthorizeToken({item->id})
479+
SelectCesiumIonToken::SelectAndAuthorizeToken(
480+
FCesiumEditorModule::serverManager().GetCurrentServer(),
481+
{item->id})
449482
.thenInMainThread([item](const std::optional<Token>& /*maybeToken*/) {
450483
// If token selection was canceled, or if an error occurred while
451484
// selecting the token, ignore it and create the tileset anyway. It's
@@ -462,7 +495,9 @@ void CesiumIonPanel::AddAssetToLevel(TSharedPtr<CesiumIonClient::Asset> item) {
462495
void CesiumIonPanel::AddOverlayToTerrain(
463496
TSharedPtr<CesiumIonClient::Asset> item,
464497
bool useAsBaseLayer) {
465-
SelectCesiumIonToken::SelectAndAuthorizeToken({item->id})
498+
SelectCesiumIonToken::SelectAndAuthorizeToken(
499+
FCesiumEditorModule::serverManager().GetCurrentServer(),
500+
{item->id})
466501
.thenInMainThread([useAsBaseLayer, item](const std::optional<Token>&) {
467502
UWorld* pCurrentWorld = GEditor->GetEditorWorldContext().World();
468503
ULevel* pCurrentLevel = pCurrentWorld->GetCurrentLevel();

Source/CesiumEditor/Private/CesiumIonPanel.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
class FArguments;
1212
class ITableRow;
1313
class STableViewBase;
14+
class UCesiumIonServer;
1415

1516
template <typename ItemType> class SListView;
1617

@@ -43,6 +44,8 @@ class CesiumIonPanel : public SCompoundWidget {
4344
void AssetSelected(
4445
TSharedPtr<CesiumIonClient::Asset> item,
4546
ESelectInfo::Type selectionType);
47+
void Subscribe(UCesiumIonServer* pNewServer);
48+
void OnServerChanged();
4649

4750
/**
4851
* Filter the current _assets array, based on the current _searchString.
@@ -73,11 +76,11 @@ class CesiumIonPanel : public SCompoundWidget {
7376
*/
7477
void OnSearchTextChange(const FText& SearchText);
7578

76-
FDelegateHandle _connectionUpdatedDelegateHandle;
77-
FDelegateHandle _assetsUpdatedDelegateHandle;
79+
FDelegateHandle _serverChangedDelegateHandle;
7880
TSharedPtr<SListView<TSharedPtr<CesiumIonClient::Asset>>> _pListView;
7981
TArray<TSharedPtr<CesiumIonClient::Asset>> _assets;
8082
TSharedPtr<CesiumIonClient::Asset> _pSelection;
83+
TObjectPtr<UCesiumIonServer> _pLastServer;
8184

8285
/**
8386
* The column name based on which the main assets list view is currently
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright 2020-2023 CesiumGS, Inc. and Contributors
2+
3+
#include "CesiumIonServerDisplay.h"
4+
#include "CesiumEditor.h"
5+
#include "CesiumIonServer.h"
6+
#include "Editor.h"
7+
#include "PropertyCustomizationHelpers.h"
8+
#include "Widgets/Input/SEditableTextBox.h"
9+
10+
void CesiumIonServerDisplay::Construct(const FArguments& InArgs) {
11+
UCesiumIonServer* pServer = InArgs._Server;
12+
13+
ChildSlot
14+
[SNew(SHorizontalBox) +
15+
SHorizontalBox::Slot()
16+
.AutoWidth()
17+
.VAlign(EVerticalAlignment::VAlign_Center)
18+
.Padding(5.0f)[SNew(STextBlock)
19+
.Text(FText::FromString("Cesium ion Server:"))] +
20+
SHorizontalBox::Slot()
21+
.AutoWidth()
22+
.VAlign(EVerticalAlignment::VAlign_Center)
23+
.Padding(5.0f)[SNew(SEditableTextBox)
24+
.IsEnabled(false)
25+
.Padding(5.0f)
26+
.Text(FText::FromString(pServer->DisplayName))] +
27+
SHorizontalBox::Slot()
28+
.AutoWidth()
29+
.VAlign(EVerticalAlignment::VAlign_Center)
30+
.Padding(5.0f)[PropertyCustomizationHelpers::MakeBrowseButton(
31+
FSimpleDelegate::
32+
CreateSP(this, &CesiumIonServerDisplay::OnBrowseForServer),
33+
FText::FromString(
34+
"Show this Cesium ion Server in the Content Browser."),
35+
true,
36+
false)]];
37+
}
38+
39+
void CesiumIonServerDisplay::OnBrowseForServer() {
40+
TArray<UObject*> Objects;
41+
Objects.Add(FCesiumEditorModule::serverManager().GetCurrentServer());
42+
GEditor->SyncBrowserToObjects(Objects);
43+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2020-2023 CesiumGS, Inc. and Contributors
2+
3+
#pragma once
4+
5+
#include "Widgets/SCompoundWidget.h"
6+
7+
class FArguments;
8+
class UCesiumIonServer;
9+
10+
class CesiumIonServerDisplay : public SCompoundWidget {
11+
SLATE_BEGIN_ARGS(CesiumIonServerDisplay) {}
12+
SLATE_ARGUMENT(UCesiumIonServer*, Server)
13+
SLATE_END_ARGS()
14+
15+
void Construct(const FArguments& InArgs);
16+
17+
private:
18+
void OnBrowseForServer();
19+
};

0 commit comments

Comments
 (0)