Skip to content

Commit c37df6a

Browse files
committed
Refresh when server property changes, fill API URL.
1 parent 425820b commit c37df6a

7 files changed

+124
-11
lines changed

Source/CesiumEditor/Private/CesiumIonServerManager.cpp

+41
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@
22

33
#include "CesiumIonServerManager.h"
44
#include "AssetRegistry/AssetRegistryModule.h"
5+
#include "Cesium3DTileset.h"
56
#include "CesiumEditorSettings.h"
7+
#include "CesiumIonRasterOverlay.h"
68
#include "CesiumIonServer.h"
79
#include "CesiumIonSession.h"
810
#include "CesiumRuntime.h"
911
#include "CesiumRuntimeSettings.h"
1012
#include "CesiumSourceControl.h"
13+
#include "Editor.h"
14+
#include "EngineUtils.h"
1115
#include "FileHelpers.h"
1216

1317
CesiumIonServerManager::CesiumIonServerManager() noexcept {
@@ -19,6 +23,9 @@ CesiumIonServerManager::CesiumIonServerManager() noexcept {
1923
AssetRegistryModule.GetRegistry().OnAssetRemoved().AddRaw(
2024
this,
2125
&CesiumIonServerManager::OnAssetRemoved);
26+
AssetRegistryModule.GetRegistry().OnAssetUpdated().AddRaw(
27+
this,
28+
&CesiumIonServerManager::OnAssetUpdated);
2229
}
2330

2431
CesiumIonServerManager::~CesiumIonServerManager() noexcept {
@@ -27,6 +34,7 @@ CesiumIonServerManager::~CesiumIonServerManager() noexcept {
2734
if (pAssetRegistryModule) {
2835
pAssetRegistryModule->GetRegistry().OnAssetAdded().RemoveAll(this);
2936
pAssetRegistryModule->GetRegistry().OnAssetRemoved().RemoveAll(this);
37+
pAssetRegistryModule->GetRegistry().OnAssetUpdated().RemoveAll(this);
3038
}
3139
}
3240

@@ -194,3 +202,36 @@ void CesiumIonServerManager::OnAssetRemoved(const FAssetData& asset) {
194202
}
195203
}
196204
}
205+
206+
void CesiumIonServerManager::OnAssetUpdated(const FAssetData& asset) {
207+
if (!GEditor)
208+
return;
209+
210+
if (asset.AssetClassPath !=
211+
UCesiumIonServer::StaticClass()->GetClassPathName())
212+
return;
213+
214+
// When a Cesium ion Server definition changes, refresh any objects that use
215+
// it.
216+
UCesiumIonServer* pServer = Cast<UCesiumIonServer>(asset.GetAsset());
217+
if (!pServer)
218+
return;
219+
220+
UWorld* pCurrentWorld = GEditor->GetEditorWorldContext().World();
221+
if (!pCurrentWorld)
222+
return;
223+
224+
for (TActorIterator<ACesium3DTileset> it(pCurrentWorld); it; ++it) {
225+
if (it->GetCesiumIonServer() == pServer) {
226+
it->RefreshTileset();
227+
} else {
228+
TArray<UCesiumIonRasterOverlay*> rasterOverlays;
229+
it->GetComponents<UCesiumIonRasterOverlay>(rasterOverlays);
230+
231+
for (UCesiumIonRasterOverlay* pOverlay : rasterOverlays) {
232+
if (pOverlay->CesiumIonServer == pServer)
233+
pOverlay->Refresh();
234+
}
235+
}
236+
}
237+
}

Source/CesiumEditor/Private/CesiumIonServerManager.h

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class CESIUMEDITOR_API CesiumIonServerManager {
3333
private:
3434
void OnAssetAdded(const FAssetData& asset);
3535
void OnAssetRemoved(const FAssetData& asset);
36+
void OnAssetUpdated(const FAssetData& asset);
3637

3738
struct ServerSession {
3839
TWeakObjectPtr<UCesiumIonServer> Server;

Source/CesiumEditor/Private/CesiumIonSession.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "CesiumRuntimeSettings.h"
88
#include "CesiumSourceControl.h"
99
#include "CesiumUtility/Uri.h"
10+
#include "FileHelpers.h"
1011
#include "HAL/PlatformProcess.h"
1112
#include "Misc/App.h"
1213

@@ -121,6 +122,9 @@ void CesiumIonSession::connect() {
121122
if (pServer->ApiUrl.IsEmpty()) {
122123
pServer->ApiUrl = UTF8_TO_TCHAR(ionApiUrl->c_str());
123124
pServer->Modify();
125+
UEditorLoadingAndSavingUtils::SavePackages(
126+
{pServer->GetPackage()},
127+
true);
124128
}
125129

126130
int64_t clientID = pServer->OAuth2ApplicationID;

Source/CesiumRuntime/Private/Cesium3DTileset.cpp

+15-9
Original file line numberDiff line numberDiff line change
@@ -1152,19 +1152,25 @@ void ACesium3DTileset::LoadTileset() {
11521152
? this->CesiumIonServer->DefaultIonAccessToken
11531153
: this->IonAccessToken;
11541154

1155+
#if WITH_EDITOR
1156+
this->CesiumIonServer->ResolveApiUrl();
1157+
#endif
1158+
11551159
std::string ionAssetEndpointUrl =
11561160
TCHAR_TO_UTF8(*this->CesiumIonServer->ApiUrl);
11571161

1158-
// Make sure the URL ends with a slash
1159-
if (!ionAssetEndpointUrl.empty() && *ionAssetEndpointUrl.rbegin() != '/')
1160-
ionAssetEndpointUrl += '/';
1162+
if (!ionAssetEndpointUrl.empty()) {
1163+
// Make sure the URL ends with a slash
1164+
if (!ionAssetEndpointUrl.empty() && *ionAssetEndpointUrl.rbegin() != '/')
1165+
ionAssetEndpointUrl += '/';
11611166

1162-
this->_pTileset = MakeUnique<Cesium3DTilesSelection::Tileset>(
1163-
externals,
1164-
static_cast<uint32_t>(this->IonAssetID),
1165-
TCHAR_TO_UTF8(*token),
1166-
options,
1167-
ionAssetEndpointUrl);
1167+
this->_pTileset = MakeUnique<Cesium3DTilesSelection::Tileset>(
1168+
externals,
1169+
static_cast<uint32_t>(this->IonAssetID),
1170+
TCHAR_TO_UTF8(*token),
1171+
options,
1172+
ionAssetEndpointUrl);
1173+
}
11681174
break;
11691175
}
11701176

Source/CesiumRuntime/Private/CesiumIonRasterOverlay.cpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,16 @@ UCesiumIonRasterOverlay::CreateOverlay(
3434
? this->CesiumIonServer->DefaultIonAccessToken
3535
: this->IonAccessToken;
3636

37+
#if WITH_EDITOR
38+
this->CesiumIonServer->ResolveApiUrl();
39+
#endif
40+
3741
// Make sure the URL ends with a slash
3842
std::string apiUrl = TCHAR_TO_UTF8(*this->CesiumIonServer->ApiUrl);
39-
if (!apiUrl.empty() && *apiUrl.rbegin() != '/')
43+
if (apiUrl.empty())
44+
return nullptr;
45+
46+
if (*apiUrl.rbegin() != '/')
4047
apiUrl += '/';
4148

4249
return std::make_unique<CesiumRasterOverlays::IonRasterOverlay>(

Source/CesiumRuntime/Private/CesiumIonServer.cpp

+34
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
// Copyright 2020-2023 CesiumGS, Inc. and Contributors
22

33
#include "CesiumIonServer.h"
4+
#include "CesiumAsync/AsyncSystem.h"
5+
#include "CesiumIonClient/Connection.h"
6+
#include "CesiumRuntime.h"
47
#include "CesiumRuntimeSettings.h"
58
#include "UObject/Package.h"
69
#include "UObject/UObjectGlobals.h"
710

811
#if WITH_EDITOR
912
#include "AssetRegistry/AssetRegistryModule.h"
13+
#include "CesiumIonClient/Connection.h"
1014
#include "Factories/DataAssetFactory.h"
1115
#include "FileHelpers.h"
1216
#endif
@@ -142,4 +146,34 @@ UCesiumIonServer::GetBackwardCompatibleServer(const FString& apiUrl) {
142146

143147
return Server;
144148
}
149+
150+
CesiumAsync::Future<void> UCesiumIonServer::ResolveApiUrl() {
151+
if (!this->ApiUrl.IsEmpty())
152+
return getAsyncSystem().createResolvedFuture();
153+
154+
if (this->ServerUrl.IsEmpty()) {
155+
// We don't even have a server URL, so use the SaaS defaults.
156+
this->ServerUrl = TEXT("https://ion.cesium.com/");
157+
this->ApiUrl = TEXT("https://api.cesium.com/");
158+
this->Modify();
159+
UEditorLoadingAndSavingUtils::SavePackages({this->GetPackage()}, true);
160+
return getAsyncSystem().createResolvedFuture();
161+
}
162+
163+
TObjectPtr<UCesiumIonServer> pServer = this;
164+
165+
return CesiumIonClient::Connection::getApiUrl(
166+
getAsyncSystem(),
167+
getAssetAccessor(),
168+
TCHAR_TO_UTF8(*this->ServerUrl))
169+
.thenInMainThread([pServer](std::optional<std::string>&& apiUrl) {
170+
if (pServer && pServer->ApiUrl.IsEmpty()) {
171+
pServer->ApiUrl = UTF8_TO_TCHAR(apiUrl->c_str());
172+
pServer->Modify();
173+
UEditorLoadingAndSavingUtils::SavePackages(
174+
{pServer->GetPackage()},
175+
true);
176+
}
177+
});
178+
}
145179
#endif

Source/CesiumRuntime/Public/CesiumIonServer.h

+21-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
#include "UObject/Object.h"
77
#include "CesiumIonServer.generated.h"
88

9+
namespace CesiumAsync {
10+
template <typename T> class Future;
11+
}
12+
913
/**
1014
* Defines a Cesium ion Server. This may be the public (SaaS) Cesium ion server
1115
* at ion.cesium.com, or it may be a self-hosted instance.
@@ -65,6 +69,7 @@ class CESIUMRUNTIME_API UCesiumIonServer : public UDataAsset {
6569
*/
6670
UPROPERTY(
6771
EditAnywhere,
72+
AssetRegistrySearchable,
6873
Category = "Cesium",
6974
meta = (DisplayName = "Server URL"))
7075
FString ServerUrl = "https://ion.cesium.com";
@@ -74,7 +79,11 @@ class CESIUMRUNTIME_API UCesiumIonServer : public UDataAsset {
7479
* the default, public Cesium ion server, this is `https://api.cesium.com`. If
7580
* left blank, the API URL is automatically inferred from the Server URL.
7681
*/
77-
UPROPERTY(EditAnywhere, Category = "Cesium", meta = (DisplayName = "API URL"))
82+
UPROPERTY(
83+
EditAnywhere,
84+
AssetRegistrySearchable,
85+
Category = "Cesium",
86+
meta = (DisplayName = "API URL"))
7887
FString ApiUrl = "https://api.cesium.com";
7988

8089
/**
@@ -84,6 +93,7 @@ class CESIUMRUNTIME_API UCesiumIonServer : public UDataAsset {
8493
*/
8594
UPROPERTY(
8695
EditAnywhere,
96+
AssetRegistrySearchable,
8797
Category = "Cesium",
8898
meta = (DisplayName = "OAuth Application ID"))
8999
int64 OAuth2ApplicationID = 190;
@@ -106,10 +116,20 @@ class CESIUMRUNTIME_API UCesiumIonServer : public UDataAsset {
106116
*/
107117
UPROPERTY(
108118
EditAnywhere,
119+
AssetRegistrySearchable,
109120
Category = "Cesium",
110121
meta = (DisplayName = "Default Cesium ion Access Token"))
111122
FString DefaultIonAccessToken;
112123

124+
#if WITH_EDITOR
125+
/**
126+
* If the `ApiUrl` property is blank, this method asynchronously resolves it
127+
* by consulting with the `ServerUrl`. If the `ApiUrl` is not blank, this
128+
* method returns an already-resolved future.
129+
*/
130+
CesiumAsync::Future<void> ResolveApiUrl();
131+
#endif
132+
113133
private:
114134
static UCesiumIonServer* _pDefaultForNewObjects;
115135
};

0 commit comments

Comments
 (0)