Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update cesium native to 0.38.0 #726

Merged
merged 16 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,9 @@ if(MSVC)
_UNICODE # tell Windows to use the unicode version of string functions, as opposed to ASCII (https://docs.microsoft.com/en-us/windows/win32/learnwin32/working-with-strings)
WIN32_LEAN_AND_MEAN # ignore some unnecessary Windows APIs
NOMINMAX # don't let Windows create macros for MIN and MAX
_SILENCE_CXX17_RESULT_OF_DEPRECATION_WARNING)
_SILENCE_CXX17_RESULT_OF_DEPRECATION_WARNING
_DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR # See https://developercommunity.visualstudio.com/t/Visual-Studio-17100-Update-leads-to-Pr/10669759?sort=newest
)
endif()

if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
Expand Down Expand Up @@ -364,6 +366,7 @@ set(CESIUM_OMNI_CXX_DEFINES
GLM_FORCE_XYZW_ONLY # Disable .rgba and .stpq to make it easier to view values from debugger
GLM_FORCE_EXPLICIT_CTOR # Disallow implicit conversions between dvec3 <-> dvec4, dvec3 <-> fvec3, etc
GLM_FORCE_SIZE_T_LENGTH # Make vec.length() and vec[idx] use size_t instead of int
GLM_ENABLE_EXPERIMENTAL
)

# Boost is a dependency of USD. It is dynamically linked so we need to set this flag.
Expand Down
4 changes: 3 additions & 1 deletion cmake/conan-0.17.0.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ function(_get_msvc_ide_version result)
set(${result} 15 PARENT_SCOPE)
elseif(NOT MSVC_VERSION VERSION_LESS 1920 AND MSVC_VERSION VERSION_LESS 1930)
set(${result} 16 PARENT_SCOPE)
elseif(NOT MSVC_VERSION VERSION_LESS 1930 AND MSVC_VERSION VERSION_LESS 1940)
# Omniverse modification - 1940 was changed to 1945
# This version of the conan-cmake script does not properly account for newer versions of MSVC
elseif(NOT MSVC_VERSION VERSION_LESS 1930 AND MSVC_VERSION VERSION_LESS 1945)
set(${result} 17 PARENT_SCOPE)
else()
message(FATAL_ERROR "Conan: Unknown MSVC compiler version [${MSVC_VERSION}]")
Expand Down
2 changes: 1 addition & 1 deletion extern/cesium-native
Submodule cesium-native updated 255 files
15 changes: 15 additions & 0 deletions src/core/include/cesium/omniverse/CesiumIonSession.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#pragma once

#include "cesium/omniverse/OmniIonServer.h"

#include <CesiumAsync/AsyncSystem.h>
#include <CesiumAsync/SharedFuture.h>
#include <CesiumIonClient/ApplicationData.h>
#include <CesiumIonClient/Connection.h>

#include <memory>
Expand Down Expand Up @@ -37,6 +40,9 @@ class CesiumIonSession {
CesiumAsync::AsyncSystem& getAsyncSystem() {
return this->_asyncSystem;
}
[[nodiscard]] const std::optional<CesiumIonClient::ApplicationData>& getApplicationData() const {
return this->_appData;
}

[[nodiscard]] bool isConnected() const {
return this->_connection.has_value();
Expand Down Expand Up @@ -107,10 +113,19 @@ class CesiumIonSession {
[[nodiscard]] CesiumAsync::Future<CesiumIonClient::Response<CesiumIonClient::Token>>
findToken(const std::string& token) const;

/**
* If the {@link _appData} field has no value, this method will request the
* ion server's /appData endpoint to obtain its data.
* @returns A future that resolves to true if _appData is present or false if
* it couldn't be fetched.
*/
CesiumAsync::Future<bool> ensureAppDataLoaded();

private:
CesiumAsync::AsyncSystem _asyncSystem;
std::shared_ptr<CesiumAsync::IAssetAccessor> _pAssetAccessor;

std::optional<CesiumIonClient::ApplicationData> _appData;
std::optional<CesiumIonClient::Connection> _connection;
std::optional<CesiumIonClient::Profile> _profile;
std::optional<CesiumIonClient::Assets> _assets;
Expand Down
29 changes: 29 additions & 0 deletions src/core/include/cesium/omniverse/CesiumIonSessionManager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#pragma once

#include <memory>
#include <string>
#include <unordered_map>

namespace cesium::omniverse {

class CesiumIonSession;
class Context;

class CesiumIonSessionManager {
public:
CesiumIonSessionManager(Context* pContext);
~CesiumIonSessionManager() = default;
CesiumIonSessionManager(const CesiumIonSessionManager&) = delete;
CesiumIonSessionManager& operator=(const CesiumIonSessionManager&) = delete;
CesiumIonSessionManager(CesiumIonSessionManager&&) noexcept = delete;
CesiumIonSessionManager& operator=(CesiumIonSessionManager&&) noexcept = delete;

std::shared_ptr<CesiumIonSession>
getOrCreateSession(const std::string& ionServerUrl, const std::string& ionServerApiUrl, int64_t applicationId);

private:
std::unordered_map<std::string, std::shared_ptr<CesiumIonSession>> _sessions;
Context* _pContext;
};

} // namespace cesium::omniverse
4 changes: 4 additions & 0 deletions src/core/include/cesium/omniverse/Context.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ namespace cesium::omniverse {

class AssetRegistry;
class CesiumIonServerManager;
class CesiumIonSessionManager;
class FabricResourceManager;
class Logger;
class TaskProcessor;
Expand Down Expand Up @@ -55,6 +56,8 @@ class Context {
[[nodiscard]] AssetRegistry& getAssetRegistry();
[[nodiscard]] const FabricResourceManager& getFabricResourceManager() const;
[[nodiscard]] FabricResourceManager& getFabricResourceManager();
[[nodiscard]] const CesiumIonSessionManager& getCesiumIonSessionManager() const;
[[nodiscard]] CesiumIonSessionManager& getCesiumIonSessionManager();
[[nodiscard]] const CesiumIonServerManager& getCesiumIonServerManager() const;
[[nodiscard]] CesiumIonServerManager& getCesiumIonServerManager();

Expand Down Expand Up @@ -88,6 +91,7 @@ class Context {
std::shared_ptr<CesiumUtility::CreditSystem> _pCreditSystem;
std::unique_ptr<AssetRegistry> _pAssetRegistry;
std::unique_ptr<FabricResourceManager> _pFabricResourceManager;
std::unique_ptr<CesiumIonSessionManager> _pCesiumIonSessionManager;
std::unique_ptr<CesiumIonServerManager> _pCesiumIonServerManager;
std::unique_ptr<UsdNotificationHandler> _pUsdNotificationHandler;

Expand Down
11 changes: 6 additions & 5 deletions src/core/include/cesium/omniverse/MetadataUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,13 +227,14 @@ void forEachPropertyTableProperty(

for (uint64_t i = 0; i < pMeshFeatures->featureIds.size(); ++i) {
const auto featureIdSetIndex = i;
const auto& featureId = pMeshFeatures->featureIds[featureIdSetIndex];
if (featureId.propertyTable.has_value()) {
const auto pPropertyTable = model.getSafe(
&pStructuralMetadataModel->propertyTables, static_cast<int32_t>(featureId.propertyTable.value()));
const CesiumGltf::FeatureId& featureId = pMeshFeatures->featureIds[featureIdSetIndex];

if (featureId.propertyTable != -1) {
const auto pPropertyTable =
model.getSafe(&pStructuralMetadataModel->propertyTables, static_cast<int32_t>(featureId.propertyTable));
if (!pPropertyTable) {
context.getLogger()->warn(
fmt::format("Property table index {} is out of range.", featureId.propertyTable.value()));
fmt::format("Property table index {} is out of range.", featureId.propertyTable));
continue;
}

Expand Down
1 change: 0 additions & 1 deletion src/core/include/cesium/omniverse/OmniIonServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,5 @@ class OmniIonServer {
private:
Context* _pContext;
pxr::SdfPath _path;
std::shared_ptr<CesiumIonSession> _session;
};
} // namespace cesium::omniverse
4 changes: 2 additions & 2 deletions src/core/src/CesiumIonServerManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ void CesiumIonServerManager::updateTokenTroubleshootingDetails(

details.showDetails = true;

const auto pConnection =
std::make_shared<CesiumIonClient::Connection>(pSession->getAsyncSystem(), pSession->getAssetAccessor(), token);
const auto pConnection = std::make_shared<CesiumIonClient::Connection>(
pSession->getAsyncSystem(), pSession->getAssetAccessor(), token, pSession->getApplicationData().value());

pConnection->me()
.thenInMainThread(
Expand Down
117 changes: 95 additions & 22 deletions src/core/src/CesiumIonSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "cesium/omniverse/Broadcast.h"
#include "cesium/omniverse/SettingsWrapper.h"

#include <CesiumAsync/SharedFuture.h>
#include <CesiumUtility/Uri.h>

#include <utility>
Expand Down Expand Up @@ -46,19 +47,51 @@ void CesiumIonSession::connect() {

this->_isConnecting = true;

Connection::authorize(
this->_asyncSystem,
this->_pAssetAccessor,
"Cesium for Omniverse",
_ionApplicationId,
"/cesium-for-omniverse/oauth2/callback",
{"assets:list", "assets:read", "profile:read", "tokens:read", "tokens:write", "geocode"},
[this](const std::string& url) {
// NOTE: We open the browser in the Python code. Check in the sign in widget's on_update_frame function.
this->_authorizeUrl = url;
},
_ionApiUrl,
CesiumUtility::Uri::resolve(_ionServerUrl, "oauth"))
CesiumAsync::Future<std::optional<std::string>> futureApiUrl =
!_ionApiUrl.empty()
? this->_asyncSystem.createResolvedFuture<std::optional<std::string>>(_ionApiUrl)
: CesiumIonClient::Connection::getApiUrl(this->_asyncSystem, this->_pAssetAccessor, _ionServerUrl);

std::move(futureApiUrl)
.thenInMainThread([this](std::optional<std::string>&& ionApiUrl) {
CesiumAsync::Promise<bool> promise = this->_asyncSystem.createPromise<bool>();

if (_ionApiUrl.empty()) {
_ionApiUrl = ionApiUrl.value();
}

// Make request to /appData to learn the server's authentication mode
return this->ensureAppDataLoaded();
})
.thenInMainThread([this](bool loadedAppData) {
if (!loadedAppData || !this->_appData.has_value()) {
CesiumAsync::Promise<CesiumIonClient::Connection> promise =
this->_asyncSystem.createPromise<CesiumIonClient::Connection>();

promise.reject(std::runtime_error("Failed to load _appData, can't create connection"));
return promise.getFuture();
}

if (this->_appData->needsOauthAuthentication()) {
return CesiumIonClient::Connection::authorize(
this->_asyncSystem,
this->_pAssetAccessor,
"Cesium for Omniverse",
_ionApplicationId,
"/cesium-for-omniverse/oauth2/callback",
{"assets:list", "assets:read", "profile:read", "tokens:read", "tokens:write", "geocode"},
[this](const std::string& url) {
// NOTE: We open the browser in the Python code. Check in the sign in widget's on_update_frame function.
this->_authorizeUrl = url;
},
this->_appData.value(),
_ionApiUrl,
CesiumUtility::Uri::resolve(_ionServerUrl, "oauth"));
}

return this->_asyncSystem.createResolvedFuture<CesiumIonClient::Connection>(CesiumIonClient::Connection(
this->_asyncSystem, this->_pAssetAccessor, "", this->_appData.value(), _ionServerUrl));
})
.thenInMainThread([this](CesiumIonClient::Connection&& connection) {
this->_isConnecting = false;
this->_connection = std::move(connection);
Expand Down Expand Up @@ -105,17 +138,38 @@ void CesiumIonSession::resume() {

this->_isResuming = true;

this->_connection = Connection(this->_asyncSystem, this->_pAssetAccessor, accessToken);

// Verify that the connection actually works.
this->_connection.value()
.me()
.thenInMainThread([this](Response<Profile>&& response) {
if (!response.value.has_value()) {
this->_connection.reset();
this->ensureAppDataLoaded()
.thenInMainThread([this, accessToken](bool loadedAppData) {
CesiumAsync::Promise<void> promise = this->_asyncSystem.createPromise<void>();

if (!loadedAppData || !this->_appData.has_value()) {
promise.reject(std::runtime_error("Failed to obtain _appData, can't resume connection"));
return promise.getFuture();
}
this->_isResuming = false;
Broadcast::connectionUpdated();

if (this->_appData->needsOauthAuthentication() && accessToken.empty()) {
// No user access token was stored, so there's no existing session to resume.
promise.resolve();
this->_isResuming = false;
return promise.getFuture();
}

std::shared_ptr<CesiumIonClient::Connection> pConnection = std::make_shared<CesiumIonClient::Connection>(
this->_asyncSystem, this->_pAssetAccessor, accessToken, this->_appData.value(), _ionApiUrl);

return pConnection->me().thenInMainThread(
[this, pConnection](CesiumIonClient::Response<CesiumIonClient::Profile>&& response) {
if (!response.value.has_value()) {
this->_connection.reset();
}
this->_isResuming = false;
Broadcast::connectionUpdated();
// logResponseErrors(response);
if (response.value.has_value()) {
this->_connection = std::move(*pConnection);
}
});
})
.catchInMainThread([this]([[maybe_unused]] std::exception&& e) {
this->_isResuming = false;
Expand Down Expand Up @@ -280,3 +334,22 @@ Future<Response<Token>> CesiumIonSession::findToken(const std::string& token) co

return this->_connection->token(*maybeTokenID);
}

CesiumAsync::Future<bool> CesiumIonSession::ensureAppDataLoaded() {

return CesiumIonClient::Connection::appData(this->_asyncSystem, this->_pAssetAccessor, this->_ionApiUrl)
.thenInMainThread([this](CesiumIonClient::Response<CesiumIonClient::ApplicationData>&& applicationData) {
CesiumAsync::Promise<bool> promise = this->_asyncSystem.createPromise<bool>();

this->_appData = applicationData.value;
if (!applicationData.value.has_value()) {
promise.resolve(false);
} else {
promise.resolve(true);
}

return promise.getFuture();
})
.catchInMainThread(
[this]([[maybe_unused]] std::exception&& e) { return this->_asyncSystem.createResolvedFuture(false); });
}
29 changes: 29 additions & 0 deletions src/core/src/CesiumIonSessionManager.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include "cesium/omniverse/CesiumIonSessionManager.h"

#include "cesium/omniverse/CesiumIonSession.h"
#include "cesium/omniverse/Context.h"

namespace cesium::omniverse {

CesiumIonSessionManager::CesiumIonSessionManager(Context* pContext)
: _pContext(pContext) {}

std::shared_ptr<CesiumIonSession> CesiumIonSessionManager::getOrCreateSession(
const std::string& ionServerUrl,
const std::string& ionServerApiUrl,
int64_t applicationId) {
const auto key = ionServerUrl + ionServerApiUrl + std::to_string(applicationId);
const auto foundIter = _sessions.find(key);
if (foundIter != _sessions.end()) {
return foundIter->second;
}

auto pSession = std::make_shared<CesiumIonSession>(
_pContext->getAsyncSystem(), _pContext->getAssetAccessor(), ionServerUrl, ionServerApiUrl, applicationId);

_sessions.emplace(key, pSession);

return pSession;
}

} // namespace cesium::omniverse
10 changes: 10 additions & 0 deletions src/core/src/Context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "cesium/omniverse/AssetRegistry.h"
#include "cesium/omniverse/CesiumIonServerManager.h"
#include "cesium/omniverse/CesiumIonSessionManager.h"
#include "cesium/omniverse/FabricResourceManager.h"
#include "cesium/omniverse/FabricStatistics.h"
#include "cesium/omniverse/FabricUtil.h"
Expand Down Expand Up @@ -78,6 +79,7 @@ Context::Context(const std::filesystem::path& cesiumExtensionLocation)
, _pCreditSystem(std::make_shared<CesiumUtility::CreditSystem>())
, _pAssetRegistry(std::make_unique<AssetRegistry>(this))
, _pFabricResourceManager(std::make_unique<FabricResourceManager>(this))
, _pCesiumIonSessionManager(std::make_unique<CesiumIonSessionManager>(this))
, _pCesiumIonServerManager(std::make_unique<CesiumIonServerManager>(this))
, _pUsdNotificationHandler(std::make_unique<UsdNotificationHandler>(this))
, _contextId(static_cast<int64_t>(getSecondsSinceEpoch())) {
Expand Down Expand Up @@ -152,6 +154,14 @@ FabricResourceManager& Context::getFabricResourceManager() {
return *_pFabricResourceManager.get();
}

const CesiumIonSessionManager& Context::getCesiumIonSessionManager() const {
return *_pCesiumIonSessionManager.get();
}

CesiumIonSessionManager& Context::getCesiumIonSessionManager() {
return *_pCesiumIonSessionManager.get();
}

const CesiumIonServerManager& Context::getCesiumIonServerManager() const {
return *_pCesiumIonServerManager.get();
}
Expand Down
Loading
Loading