diff --git a/Cesium3DTilesSelection/include/Cesium3DTilesSelection/Tileset.h b/Cesium3DTilesSelection/include/Cesium3DTilesSelection/Tileset.h index 09dbe01ac..b8f9699bf 100644 --- a/Cesium3DTilesSelection/include/Cesium3DTilesSelection/Tileset.h +++ b/Cesium3DTilesSelection/include/Cesium3DTilesSelection/Tileset.h @@ -184,10 +184,11 @@ class CESIUM3DTILESSELECTION_API Tileset final { /** * @brief Returns the {@link SharedAssetDepot} of this tileset. */ - CesiumGltf::SharedAssetSystem& getSharedAssetSystem() noexcept; + CesiumGltfReader::GltfSharedAssetSystem& getSharedAssetSystem() noexcept; /** @copydoc Tileset::getSharedAssetSystem() */ - const CesiumGltf::SharedAssetSystem& getSharedAssetSystem() const noexcept; + const CesiumGltfReader::GltfSharedAssetSystem& + getSharedAssetSystem() const noexcept; /** * @brief Updates this view but waits for all tiles that meet sse to finish diff --git a/Cesium3DTilesSelection/src/TileContentLoadInfo.cpp b/Cesium3DTilesSelection/src/TileContentLoadInfo.cpp index b09c988cb..f643f71e4 100644 --- a/Cesium3DTilesSelection/src/TileContentLoadInfo.cpp +++ b/Cesium3DTilesSelection/src/TileContentLoadInfo.cpp @@ -9,8 +9,8 @@ TileContentLoadInfo::TileContentLoadInfo( const std::shared_ptr& pPrepareRendererResources_, const std::shared_ptr& pLogger_, - const CesiumUtility::IntrusivePointer - pAssetDepot_, + const CesiumUtility::IntrusivePointer< + CesiumGltfReader::GltfSharedAssetSystem> pAssetDepot_, const TilesetContentOptions& contentOptions_, const Tile& tile) : asyncSystem(asyncSystem_), diff --git a/Cesium3DTilesSelection/src/TileContentLoadInfo.h b/Cesium3DTilesSelection/src/TileContentLoadInfo.h index a887d1c60..4c9d89e3e 100644 --- a/Cesium3DTilesSelection/src/TileContentLoadInfo.h +++ b/Cesium3DTilesSelection/src/TileContentLoadInfo.h @@ -9,7 +9,7 @@ #include #include #include -#include +#include #include #include @@ -25,8 +25,8 @@ struct TileContentLoadInfo { const std::shared_ptr& pPrepareRendererResources, const std::shared_ptr& pLogger, - const CesiumUtility::IntrusivePointer - maybeAssetDepot, + const CesiumUtility::IntrusivePointer< + CesiumGltfReader::GltfSharedAssetSystem> maybeAssetDepot, const TilesetContentOptions& contentOptions, const Tile& tile); @@ -43,7 +43,8 @@ struct TileContentLoadInfo { BoundingVolume tileBoundingVolume; std::optional tileContentBoundingVolume; - CesiumUtility::IntrusivePointer pAssetDepot; + CesiumUtility::IntrusivePointer + pAssetDepot; TileRefine tileRefine; diff --git a/Cesium3DTilesSelection/src/Tileset.cpp b/Cesium3DTilesSelection/src/Tileset.cpp index f5b1b7b5c..a98af5d23 100644 --- a/Cesium3DTilesSelection/src/Tileset.cpp +++ b/Cesium3DTilesSelection/src/Tileset.cpp @@ -149,11 +149,12 @@ const RasterOverlayCollection& Tileset::getOverlays() const noexcept { return this->_pTilesetContentManager->getRasterOverlayCollection(); } -CesiumGltf::SharedAssetSystem& Tileset::getSharedAssetSystem() noexcept { +CesiumGltfReader::GltfSharedAssetSystem& +Tileset::getSharedAssetSystem() noexcept { return *this->_pTilesetContentManager->getSharedAssetSystem(); } -const CesiumGltf::SharedAssetSystem& +const CesiumGltfReader::GltfSharedAssetSystem& Tileset::getSharedAssetSystem() const noexcept { return *this->_pTilesetContentManager->getSharedAssetSystem(); } diff --git a/Cesium3DTilesSelection/src/TilesetContentManager.cpp b/Cesium3DTilesSelection/src/TilesetContentManager.cpp index cf0a8f223..ec4bc45e3 100644 --- a/Cesium3DTilesSelection/src/TilesetContentManager.cpp +++ b/Cesium3DTilesSelection/src/TilesetContentManager.cpp @@ -666,7 +666,7 @@ TilesetContentManager::TilesetContentManager( _tileLoadsInProgress{0}, _loadedTilesCount{0}, _tilesDataUsed{0}, - _pAssetDepot(new CesiumGltf::SharedAssetSystem()), + _pSharedAssets(CesiumGltfReader::GltfSharedAssetSystem::default()), _destructionCompletePromise{externals.asyncSystem.createPromise()}, _destructionCompleteFuture{ this->_destructionCompletePromise.getFuture().share()}, @@ -696,7 +696,7 @@ TilesetContentManager::TilesetContentManager( _tileLoadsInProgress{0}, _loadedTilesCount{0}, _tilesDataUsed{0}, - _pAssetDepot(new CesiumGltf::SharedAssetSystem()), + _pSharedAssets(CesiumGltfReader::GltfSharedAssetSystem::default()), _destructionCompletePromise{externals.asyncSystem.createPromise()}, _destructionCompleteFuture{ this->_destructionCompletePromise.getFuture().share()}, @@ -848,7 +848,7 @@ TilesetContentManager::TilesetContentManager( _tileLoadsInProgress{0}, _loadedTilesCount{0}, _tilesDataUsed{0}, - _pAssetDepot(new CesiumGltf::SharedAssetSystem()), + _pSharedAssets(CesiumGltfReader::GltfSharedAssetSystem::default()), _destructionCompletePromise{externals.asyncSystem.createPromise()}, _destructionCompleteFuture{ this->_destructionCompletePromise.getFuture().share()}, @@ -994,7 +994,7 @@ void TilesetContentManager::loadTileContent( this->_externals.pAssetAccessor, this->_externals.pPrepareRendererResources, this->_externals.pLogger, - this->_pAssetDepot, + this->_pSharedAssets, tilesetOptions.contentOptions, tile}; @@ -1237,9 +1237,9 @@ TilesetContentManager::getTilesetCredits() const noexcept { return this->_tilesetCredits; } -const CesiumUtility::IntrusivePointer& +const CesiumUtility::IntrusivePointer& TilesetContentManager::getSharedAssetSystem() const noexcept { - return this->_pAssetDepot; + return this->_pSharedAssets; } int32_t TilesetContentManager::getNumberOfTilesLoading() const noexcept { diff --git a/Cesium3DTilesSelection/src/TilesetContentManager.h b/Cesium3DTilesSelection/src/TilesetContentManager.h index 4a4ec286f..12bd65484 100644 --- a/Cesium3DTilesSelection/src/TilesetContentManager.h +++ b/Cesium3DTilesSelection/src/TilesetContentManager.h @@ -115,7 +115,8 @@ class TilesetContentManager const std::vector& getTilesetCredits() const noexcept; - const CesiumUtility::IntrusivePointer& + const CesiumUtility::IntrusivePointer< + CesiumGltfReader::GltfSharedAssetSystem>& getSharedAssetSystem() const noexcept; int32_t getNumberOfTilesLoading() const noexcept; @@ -171,7 +172,8 @@ class TilesetContentManager int64_t _tilesDataUsed; // Stores assets that might be shared between tiles. - CesiumUtility::IntrusivePointer _pAssetDepot; + CesiumUtility::IntrusivePointer + _pSharedAssets; CesiumAsync::Promise _destructionCompletePromise; CesiumAsync::SharedFuture _destructionCompleteFuture; diff --git a/Cesium3DTilesSelection/src/TilesetJsonLoader.h b/Cesium3DTilesSelection/src/TilesetJsonLoader.h index 0039edc6e..fa590bdd6 100644 --- a/Cesium3DTilesSelection/src/TilesetJsonLoader.h +++ b/Cesium3DTilesSelection/src/TilesetJsonLoader.h @@ -6,7 +6,7 @@ #include #include #include -#include +#include #include @@ -56,7 +56,8 @@ class TilesetJsonLoader : public TilesetContentLoader { private: std::string _baseUrl; CesiumGeospatial::Ellipsoid _ellipsoid; - CesiumUtility::IntrusivePointer _pAssetDepot; + CesiumUtility::IntrusivePointer + _pSharedAssets; /** * @brief The axis that was declared as the "up-axis" for glTF content. diff --git a/Cesium3DTilesSelection/test/TestTilesetContentManager.cpp b/Cesium3DTilesSelection/test/TestTilesetContentManager.cpp index f297c54d4..af048b2ea 100644 --- a/Cesium3DTilesSelection/test/TestTilesetContentManager.cpp +++ b/Cesium3DTilesSelection/test/TestTilesetContentManager.cpp @@ -1682,7 +1682,7 @@ TEST_CASE("Test the tileset content manager's post processing for gltf") { CHECK(images.size() == 1); } - CHECK(pManager->getSharedAssetSystem()->image().getDistinctCount() == 2); + CHECK(pManager->getSharedAssetSystem()->pImage->getDistinctCount() == 2); // unload the tile content for (auto& child : containerTile.getChildren()) { diff --git a/CesiumGltf/include/CesiumGltf/SharedAssetSystem.h b/CesiumGltf/include/CesiumGltf/SharedAssetSystem.h deleted file mode 100644 index b8abb23ec..000000000 --- a/CesiumGltf/include/CesiumGltf/SharedAssetSystem.h +++ /dev/null @@ -1,47 +0,0 @@ -#pragma once - -#include -#include - -namespace CesiumGltf { - -struct ImageCesium; - -/** - * @brief Contains assets that are potentially shared across multiple glTF - * models. - */ -class SharedAssetSystem - : public CesiumUtility::ReferenceCountedThreadSafe { -public: - SharedAssetSystem() noexcept; - ~SharedAssetSystem() noexcept; - - SharedAssetSystem(const SharedAssetSystem&) = delete; - void operator=(const SharedAssetSystem& other) = delete; - - /** - * Obtains an existing {@link ImageCesium} or constructs a new one using the provided factory. - */ - template - CesiumAsync::SharedFuture< - CesiumUtility::IntrusivePointer> - getOrFetch( - const CesiumAsync::AsyncSystem& asyncSystem, - const std::shared_ptr& pAssetAccessor, - const Factory& factory, - const std::string& uri, - const std::vector& headers) { - return this->_pImages - ->getOrFetch(asyncSystem, pAssetAccessor, factory, uri, headers); - } - - const CesiumAsync::SharedAssetDepot& image(); - -private: - CesiumUtility::IntrusivePointer< - CesiumAsync::SharedAssetDepot> - _pImages; -}; - -} // namespace CesiumGltf diff --git a/CesiumGltf/src/SharedAssetSystem.cpp b/CesiumGltf/src/SharedAssetSystem.cpp deleted file mode 100644 index aac4114ac..000000000 --- a/CesiumGltf/src/SharedAssetSystem.cpp +++ /dev/null @@ -1,16 +0,0 @@ -#include -#include - -namespace CesiumGltf { - -SharedAssetSystem::SharedAssetSystem() noexcept - : _pImages(new CesiumAsync::SharedAssetDepot()) {} - -SharedAssetSystem::~SharedAssetSystem() noexcept = default; - -const CesiumAsync::SharedAssetDepot& -SharedAssetSystem::image() { - return *this->_pImages; -} - -} // namespace CesiumGltf diff --git a/CesiumGltfReader/include/CesiumGltfReader/GltfReader.h b/CesiumGltfReader/include/CesiumGltfReader/GltfReader.h index a1e941bd7..d8f086429 100644 --- a/CesiumGltfReader/include/CesiumGltfReader/GltfReader.h +++ b/CesiumGltfReader/include/CesiumGltfReader/GltfReader.h @@ -10,7 +10,7 @@ #include #include #include -#include +#include #include #include @@ -111,12 +111,11 @@ struct CESIUMGLTFREADER_API GltfReaderOptions { CesiumGltf::Ktx2TranscodeTargets ktx2TranscodeTargets; /** - * The depot that will be used to store all of the shared assets that might - * appear in this glTF. If not present, assets will not be shared between - * glTFs, even if they're loaded from the same URL. + * The shared asset system that will be used to store all of the shared assets + * that might appear in this glTF. */ - CesiumUtility::IntrusivePointer pSharedAssets = - nullptr; + CesiumUtility::IntrusivePointer pSharedAssets = + GltfSharedAssetSystem::default(); }; /** diff --git a/CesiumGltfReader/include/CesiumGltfReader/GltfSharedAssetSystem.h b/CesiumGltfReader/include/CesiumGltfReader/GltfSharedAssetSystem.h new file mode 100644 index 000000000..71d6c2536 --- /dev/null +++ b/CesiumGltfReader/include/CesiumGltfReader/GltfSharedAssetSystem.h @@ -0,0 +1,26 @@ +#pragma once + +#include +#include + +namespace CesiumGltf { +struct ImageCesium; +} + +namespace CesiumGltfReader { + +/** + * @brief Contains assets that are potentially shared across multiple glTF + * models. + */ +class GltfSharedAssetSystem + : public CesiumUtility::ReferenceCountedThreadSafe { +public: + static CesiumUtility::IntrusivePointer default(); + + CesiumUtility::IntrusivePointer< + CesiumAsync::SharedAssetDepot> + pImage; +}; + +} // namespace CesiumGltfReader diff --git a/CesiumGltfReader/src/GltfReader.cpp b/CesiumGltfReader/src/GltfReader.cpp index 5914cc980..495ea5a37 100644 --- a/CesiumGltfReader/src/GltfReader.cpp +++ b/CesiumGltfReader/src/GltfReader.cpp @@ -555,7 +555,8 @@ void CesiumGltfReader::GltfReader::postprocessGltf( const std::shared_ptr& pAssetAccessor, const std::string& uri, const std::vector& headers) { - if (options.pSharedAssets == nullptr) { + if (options.pSharedAssets == nullptr || + options.pSharedAssets->pImage == nullptr) { // We don't have a depot, we have to fetch this the old way. return pAssetAccessor->get(asyncSystem, uri, headers) .thenInWorkerThread( @@ -580,7 +581,7 @@ void CesiumGltfReader::GltfReader::postprocessGltf( .share(); } else { // We have a depot, this is easy! - return options.pSharedAssets->getOrFetch( + return options.pSharedAssets->pImage->getOrFetch( asyncSystem, pAssetAccessor, ImageAssetFactory(options.ktx2TranscodeTargets), diff --git a/CesiumGltfReader/src/GltfSharedAssetSystem.cpp b/CesiumGltfReader/src/GltfSharedAssetSystem.cpp new file mode 100644 index 000000000..0f98f38df --- /dev/null +++ b/CesiumGltfReader/src/GltfSharedAssetSystem.cpp @@ -0,0 +1,26 @@ +#include +#include + +namespace CesiumGltfReader { + +namespace { + +CesiumUtility::IntrusivePointer createDefault() { + CesiumUtility::IntrusivePointer p = + new GltfSharedAssetSystem(); + + p->pImage.emplace(); + + return p; +} + +} // namespace + +/*static*/ CesiumUtility::IntrusivePointer + GltfSharedAssetSystem::default() { + static CesiumUtility::IntrusivePointer pDefault = + createDefault(); + return pDefault; +} + +} // namespace CesiumGltfReader