Skip to content

Commit

Permalink
GltfSharedAssetSystem
Browse files Browse the repository at this point in the history
  • Loading branch information
kring committed Oct 10, 2024
1 parent a9516a0 commit 7f79837
Show file tree
Hide file tree
Showing 14 changed files with 87 additions and 92 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions Cesium3DTilesSelection/src/TileContentLoadInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ TileContentLoadInfo::TileContentLoadInfo(
const std::shared_ptr<IPrepareRendererResources>&
pPrepareRendererResources_,
const std::shared_ptr<spdlog::logger>& pLogger_,
const CesiumUtility::IntrusivePointer<CesiumGltf::SharedAssetSystem>
pAssetDepot_,
const CesiumUtility::IntrusivePointer<
CesiumGltfReader::GltfSharedAssetSystem> pAssetDepot_,
const TilesetContentOptions& contentOptions_,
const Tile& tile)
: asyncSystem(asyncSystem_),
Expand Down
9 changes: 5 additions & 4 deletions Cesium3DTilesSelection/src/TileContentLoadInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <CesiumAsync/AsyncSystem.h>
#include <CesiumAsync/IAssetAccessor.h>
#include <CesiumGeometry/Axis.h>
#include <CesiumGltf/SharedAssetSystem.h>
#include <CesiumGltfReader/GltfSharedAssetSystem.h>

#include <gsl/span>
#include <spdlog/fwd.h>
Expand All @@ -25,8 +25,8 @@ struct TileContentLoadInfo {
const std::shared_ptr<IPrepareRendererResources>&
pPrepareRendererResources,
const std::shared_ptr<spdlog::logger>& pLogger,
const CesiumUtility::IntrusivePointer<CesiumGltf::SharedAssetSystem>
maybeAssetDepot,
const CesiumUtility::IntrusivePointer<
CesiumGltfReader::GltfSharedAssetSystem> maybeAssetDepot,
const TilesetContentOptions& contentOptions,
const Tile& tile);

Expand All @@ -43,7 +43,8 @@ struct TileContentLoadInfo {
BoundingVolume tileBoundingVolume;

std::optional<BoundingVolume> tileContentBoundingVolume;
CesiumUtility::IntrusivePointer<CesiumGltf::SharedAssetSystem> pAssetDepot;
CesiumUtility::IntrusivePointer<CesiumGltfReader::GltfSharedAssetSystem>
pAssetDepot;

TileRefine tileRefine;

Expand Down
5 changes: 3 additions & 2 deletions Cesium3DTilesSelection/src/Tileset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
12 changes: 6 additions & 6 deletions Cesium3DTilesSelection/src/TilesetContentManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@ TilesetContentManager::TilesetContentManager(
_tileLoadsInProgress{0},
_loadedTilesCount{0},
_tilesDataUsed{0},
_pAssetDepot(new CesiumGltf::SharedAssetSystem()),
_pSharedAssets(CesiumGltfReader::GltfSharedAssetSystem::default()),
_destructionCompletePromise{externals.asyncSystem.createPromise<void>()},
_destructionCompleteFuture{
this->_destructionCompletePromise.getFuture().share()},
Expand Down Expand Up @@ -696,7 +696,7 @@ TilesetContentManager::TilesetContentManager(
_tileLoadsInProgress{0},
_loadedTilesCount{0},
_tilesDataUsed{0},
_pAssetDepot(new CesiumGltf::SharedAssetSystem()),
_pSharedAssets(CesiumGltfReader::GltfSharedAssetSystem::default()),
_destructionCompletePromise{externals.asyncSystem.createPromise<void>()},
_destructionCompleteFuture{
this->_destructionCompletePromise.getFuture().share()},
Expand Down Expand Up @@ -848,7 +848,7 @@ TilesetContentManager::TilesetContentManager(
_tileLoadsInProgress{0},
_loadedTilesCount{0},
_tilesDataUsed{0},
_pAssetDepot(new CesiumGltf::SharedAssetSystem()),
_pSharedAssets(CesiumGltfReader::GltfSharedAssetSystem::default()),
_destructionCompletePromise{externals.asyncSystem.createPromise<void>()},
_destructionCompleteFuture{
this->_destructionCompletePromise.getFuture().share()},
Expand Down Expand Up @@ -994,7 +994,7 @@ void TilesetContentManager::loadTileContent(
this->_externals.pAssetAccessor,
this->_externals.pPrepareRendererResources,
this->_externals.pLogger,
this->_pAssetDepot,
this->_pSharedAssets,
tilesetOptions.contentOptions,
tile};

Expand Down Expand Up @@ -1237,9 +1237,9 @@ TilesetContentManager::getTilesetCredits() const noexcept {
return this->_tilesetCredits;
}

const CesiumUtility::IntrusivePointer<CesiumGltf::SharedAssetSystem>&
const CesiumUtility::IntrusivePointer<CesiumGltfReader::GltfSharedAssetSystem>&
TilesetContentManager::getSharedAssetSystem() const noexcept {
return this->_pAssetDepot;
return this->_pSharedAssets;
}

int32_t TilesetContentManager::getNumberOfTilesLoading() const noexcept {
Expand Down
6 changes: 4 additions & 2 deletions Cesium3DTilesSelection/src/TilesetContentManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ class TilesetContentManager

const std::vector<CesiumUtility::Credit>& getTilesetCredits() const noexcept;

const CesiumUtility::IntrusivePointer<CesiumGltf::SharedAssetSystem>&
const CesiumUtility::IntrusivePointer<
CesiumGltfReader::GltfSharedAssetSystem>&
getSharedAssetSystem() const noexcept;

int32_t getNumberOfTilesLoading() const noexcept;
Expand Down Expand Up @@ -171,7 +172,8 @@ class TilesetContentManager
int64_t _tilesDataUsed;

// Stores assets that might be shared between tiles.
CesiumUtility::IntrusivePointer<CesiumGltf::SharedAssetSystem> _pAssetDepot;
CesiumUtility::IntrusivePointer<CesiumGltfReader::GltfSharedAssetSystem>
_pSharedAssets;

CesiumAsync::Promise<void> _destructionCompletePromise;
CesiumAsync::SharedFuture<void> _destructionCompleteFuture;
Expand Down
5 changes: 3 additions & 2 deletions Cesium3DTilesSelection/src/TilesetJsonLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <Cesium3DTilesSelection/TilesetExternals.h>
#include <CesiumAsync/Future.h>
#include <CesiumAsync/IAssetAccessor.h>
#include <CesiumGltf/SharedAssetSystem.h>
#include <CesiumGltfReader/GltfSharedAssetSystem.h>

#include <rapidjson/fwd.h>

Expand Down Expand Up @@ -56,7 +56,8 @@ class TilesetJsonLoader : public TilesetContentLoader {
private:
std::string _baseUrl;
CesiumGeospatial::Ellipsoid _ellipsoid;
CesiumUtility::IntrusivePointer<CesiumGltf::SharedAssetSystem> _pAssetDepot;
CesiumUtility::IntrusivePointer<CesiumGltfReader::GltfSharedAssetSystem>
_pSharedAssets;

/**
* @brief The axis that was declared as the "up-axis" for glTF content.
Expand Down
2 changes: 1 addition & 1 deletion Cesium3DTilesSelection/test/TestTilesetContentManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
47 changes: 0 additions & 47 deletions CesiumGltf/include/CesiumGltf/SharedAssetSystem.h

This file was deleted.

16 changes: 0 additions & 16 deletions CesiumGltf/src/SharedAssetSystem.cpp

This file was deleted.

11 changes: 5 additions & 6 deletions CesiumGltfReader/include/CesiumGltfReader/GltfReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <CesiumGltf/ImageCesium.h>
#include <CesiumGltf/Ktx2TranscodeTargets.h>
#include <CesiumGltf/Model.h>
#include <CesiumGltf/SharedAssetSystem.h>
#include <CesiumGltfReader/GltfSharedAssetSystem.h>
#include <CesiumJsonReader/IExtensionJsonHandler.h>
#include <CesiumJsonReader/JsonReaderOptions.h>

Expand Down Expand Up @@ -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<CesiumGltf::SharedAssetSystem> pSharedAssets =
nullptr;
CesiumUtility::IntrusivePointer<GltfSharedAssetSystem> pSharedAssets =
GltfSharedAssetSystem::default();
};

/**
Expand Down
26 changes: 26 additions & 0 deletions CesiumGltfReader/include/CesiumGltfReader/GltfSharedAssetSystem.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#pragma once

#include <CesiumAsync/SharedAssetDepot.h>
#include <CesiumAsync/SharedFuture.h>

namespace CesiumGltf {
struct ImageCesium;
}

namespace CesiumGltfReader {

/**
* @brief Contains assets that are potentially shared across multiple glTF
* models.
*/
class GltfSharedAssetSystem
: public CesiumUtility::ReferenceCountedThreadSafe<GltfSharedAssetSystem> {
public:
static CesiumUtility::IntrusivePointer<GltfSharedAssetSystem> default();

CesiumUtility::IntrusivePointer<
CesiumAsync::SharedAssetDepot<CesiumGltf::ImageCesium>>
pImage;
};

} // namespace CesiumGltfReader
5 changes: 3 additions & 2 deletions CesiumGltfReader/src/GltfReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,8 @@ void CesiumGltfReader::GltfReader::postprocessGltf(
const std::shared_ptr<IAssetAccessor>& pAssetAccessor,
const std::string& uri,
const std::vector<IAssetAccessor::THeader>& 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(
Expand All @@ -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),
Expand Down
26 changes: 26 additions & 0 deletions CesiumGltfReader/src/GltfSharedAssetSystem.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include <CesiumGltf/ImageCesium.h>
#include <CesiumGltfReader/GltfSharedAssetSystem.h>

namespace CesiumGltfReader {

namespace {

CesiumUtility::IntrusivePointer<GltfSharedAssetSystem> createDefault() {
CesiumUtility::IntrusivePointer<GltfSharedAssetSystem> p =
new GltfSharedAssetSystem();

p->pImage.emplace();

return p;
}

} // namespace

/*static*/ CesiumUtility::IntrusivePointer<GltfSharedAssetSystem>
GltfSharedAssetSystem::default() {
static CesiumUtility::IntrusivePointer<GltfSharedAssetSystem> pDefault =
createDefault();
return pDefault;
}

} // namespace CesiumGltfReader

0 comments on commit 7f79837

Please sign in to comment.