Skip to content

Commit

Permalink
pass asset accessor and request headers to tile content loading
Browse files Browse the repository at this point in the history
  • Loading branch information
nithinp7 committed Sep 8, 2021
1 parent b68440a commit b762be0
Show file tree
Hide file tree
Showing 14 changed files with 52 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include "Cesium3DTilesSelection/TileContentLoadResult.h"
#include "Cesium3DTilesSelection/TileContentLoader.h"
#include "Cesium3DTilesSelection/TileRefine.h"
#include "CesiumAsync/AsyncSystem.h"
#include <cstddef>
#include <gsl/span>
#include <memory>
Expand All @@ -31,6 +30,8 @@ class CESIUM3DTILESSELECTION_API ExternalTilesetContent final
*/
CesiumAsync::Future<std::unique_ptr<TileContentLoadResult>> load(
const CesiumAsync::AsyncSystem& asyncSystem,
const std::shared_ptr<CesiumAsync::IAssetAccessor>& pAssetAccessor,
const std::vector<std::pair<std::string, std::string>>& requestHeaders,
const TileContentLoadInput& input) override;

private:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class CESIUM3DTILESSELECTION_API GltfContent final : public TileContentLoader {
*/
CesiumAsync::Future<std::unique_ptr<TileContentLoadResult>> load(
const CesiumAsync::AsyncSystem& asyncSystem,
const std::shared_ptr<CesiumAsync::IAssetAccessor>& pAssetAccessor,
const std::vector<std::pair<std::string, std::string>>& requestHeaders,
const TileContentLoadInput& input) override;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ class CESIUM3DTILESSELECTION_API TileContentFactory final {
* If a matching loader is found, it will be applied to the given
* input, and the result will be returned.
*
* @param asyncSystem The async system to use during the loading.
* @param pAssetAccessor The asset accessor to use if needed.
* @param requestHeaders The request headers to be used if needed.
* @param input The {@link TileContentLoadInput}.
* @return The {@link TileContentLoadResult}, or `nullptr` if there is
* no loader registered for the magic header of the given
Expand All @@ -101,6 +104,8 @@ class CESIUM3DTILESSELECTION_API TileContentFactory final {
static CesiumAsync::Future<std::unique_ptr<TileContentLoadResult>>
createContent(
const CesiumAsync::AsyncSystem& asyncSystem,
const std::shared_ptr<CesiumAsync::IAssetAccessor>& pAssetAccessor,
const std::vector<std::pair<std::string, std::string>>& requestHeaders,
const TileContentLoadInput& input);

private:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
#include "Cesium3DTilesSelection/TileContentLoadInput.h"
#include "Cesium3DTilesSelection/TileContentLoadResult.h"
#include "CesiumAsync/AsyncSystem.h"
#include "CesiumAsync/IAssetAccessor.h"
#include <string>
#include <utility>
#include <vector>

namespace Cesium3DTilesSelection {
/**
Expand All @@ -17,12 +21,17 @@ class CESIUM3DTILESSELECTION_API TileContentLoader {
/**
* @brief Loads the tile content from the given input.
*
* @param asyncSystem The async system to use during the loading.
* @param pAssetAccessor The asset accessor to use if needed.
* @param requestHeaders The request headers to be used if needed.
* @param input The {@link TileContentLoadInput}
* @return The {@link TileContentLoadResult}. This may be the `nullptr` if the
* tile content could not be loaded.
*/
virtual CesiumAsync::Future<std::unique_ptr<TileContentLoadResult>> load(
const CesiumAsync::AsyncSystem& asyncSystem,
const std::shared_ptr<CesiumAsync::IAssetAccessor>& pAssetAccessor,
const std::vector<std::pair<std::string, std::string>>& requestHeaders,
const TileContentLoadInput& input) = 0;
};
} // namespace Cesium3DTilesSelection
2 changes: 2 additions & 0 deletions Cesium3DTilesSelection/src/Batched3DModelContent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ rapidjson::Document parseFeatureTableJsonData(
CesiumAsync::Future<std::unique_ptr<TileContentLoadResult>>
Batched3DModelContent::load(
const CesiumAsync::AsyncSystem& asyncSystem,
const std::shared_ptr<CesiumAsync::IAssetAccessor>& /*pAssetAccessor*/,
const std::vector<std::pair<std::string, std::string>>& /*requestHeaders*/,
const TileContentLoadInput& input) {
return asyncSystem.createResolvedFuture(
load(input.pLogger, input.url, input.data));
Expand Down
3 changes: 2 additions & 1 deletion Cesium3DTilesSelection/src/Batched3DModelContent.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include "Cesium3DTilesSelection/TileContentLoader.h"
#include "Cesium3DTilesSelection/TileID.h"
#include "Cesium3DTilesSelection/TileRefine.h"
#include "CesiumAsync/AsyncSystem.h"
#include <cstddef>
#include <memory>
#include <spdlog/fwd.h>
Expand All @@ -30,6 +29,8 @@ class CESIUM3DTILESSELECTION_API Batched3DModelContent final
*/
CesiumAsync::Future<std::unique_ptr<TileContentLoadResult>> load(
const CesiumAsync::AsyncSystem& asyncSystem,
const std::shared_ptr<CesiumAsync::IAssetAccessor>& pAssetAccessor,
const std::vector<std::pair<std::string, std::string>>& requestHeaders,
const TileContentLoadInput& input) override;

/**
Expand Down
4 changes: 4 additions & 0 deletions Cesium3DTilesSelection/src/CompositeContent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ TileContentLoadInput derive(
CesiumAsync::Future<std::unique_ptr<TileContentLoadResult>>
CompositeContent::load(
const CesiumAsync::AsyncSystem& asyncSystem,
const std::shared_ptr<CesiumAsync::IAssetAccessor>& pAssetAccessor,
const std::vector<std::pair<std::string, std::string>>& requestHeaders,
const TileContentLoadInput& input) {
CESIUM_TRACE("Cesium3DTilesSelection::CompositeContent::load");
const std::shared_ptr<spdlog::logger>& pLogger = input.pLogger;
Expand Down Expand Up @@ -136,6 +138,8 @@ CompositeContent::load(

innerTiles.push_back(std::move(TileContentFactory::createContent(
asyncSystem,
pAssetAccessor,
requestHeaders,
derive(input, innerData))));
}

Expand Down
3 changes: 2 additions & 1 deletion Cesium3DTilesSelection/src/CompositeContent.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include "Cesium3DTilesSelection/TileContentLoader.h"
#include "Cesium3DTilesSelection/TileID.h"
#include "Cesium3DTilesSelection/TileRefine.h"
#include "CesiumAsync/AsyncSystem.h"
#include <memory>
#include <spdlog/fwd.h>
#include <string>
Expand All @@ -23,6 +22,8 @@ class CESIUM3DTILESSELECTION_API CompositeContent final
public:
CesiumAsync::Future<std::unique_ptr<TileContentLoadResult>> load(
const CesiumAsync::AsyncSystem& asyncSystem,
const std::shared_ptr<CesiumAsync::IAssetAccessor>& pAssetAccessor,
const std::vector<std::pair<std::string, std::string>>& requestHeaders,
const TileContentLoadInput& input) override;
};

Expand Down
2 changes: 2 additions & 0 deletions Cesium3DTilesSelection/src/ExternalTilesetContent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ namespace Cesium3DTilesSelection {
CesiumAsync::Future<std::unique_ptr<TileContentLoadResult>>
ExternalTilesetContent::load(
const CesiumAsync::AsyncSystem& asyncSystem,
const std::shared_ptr<CesiumAsync::IAssetAccessor>& /*pAssetAccessor*/,
const std::vector<std::pair<std::string, std::string>>& /*requestHeaders*/,
const TileContentLoadInput& input) {
return asyncSystem.createResolvedFuture(load(
input.pLogger,
Expand Down
2 changes: 2 additions & 0 deletions Cesium3DTilesSelection/src/GltfContent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ namespace Cesium3DTilesSelection {

CesiumAsync::Future<std::unique_ptr<TileContentLoadResult>> GltfContent::load(
const CesiumAsync::AsyncSystem& asyncSystem,
const std::shared_ptr<CesiumAsync::IAssetAccessor>& /*pAssetAccessor*/,
const std::vector<std::pair<std::string, std::string>>& /*requestHeaders*/,
const TileContentLoadInput& input) {
return asyncSystem.createResolvedFuture(
load(input.pLogger, input.url, input.data));
Expand Down
2 changes: 2 additions & 0 deletions Cesium3DTilesSelection/src/QuantizedMeshContent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,8 @@ static std::vector<std::byte> generateNormals(
CesiumAsync::Future<std::unique_ptr<TileContentLoadResult>>
QuantizedMeshContent::load(
const CesiumAsync::AsyncSystem& asyncSystem,
const std::shared_ptr<CesiumAsync::IAssetAccessor>& /*pAssetAccessor*/,
const std::vector<std::pair<std::string, std::string>>& /*requestHeaders*/,
const TileContentLoadInput& input) {
return asyncSystem.createResolvedFuture(load(
input.pLogger,
Expand Down
3 changes: 2 additions & 1 deletion Cesium3DTilesSelection/src/QuantizedMeshContent.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include "Cesium3DTilesSelection/Library.h"
#include "Cesium3DTilesSelection/TileContentLoadResult.h"
#include "Cesium3DTilesSelection/TileContentLoader.h"
#include "CesiumAsync/AsyncSystem.h"
#include <cstddef>

namespace Cesium3DTilesSelection {
Expand All @@ -27,6 +26,8 @@ class CESIUM3DTILESSELECTION_API QuantizedMeshContent final
*/
CesiumAsync::Future<std::unique_ptr<TileContentLoadResult>> load(
const CesiumAsync::AsyncSystem& asyncSystem,
const std::shared_ptr<CesiumAsync::IAssetAccessor>& pAssetAccessor,
const std::vector<std::pair<std::string, std::string>>& requestHeaders,
const TileContentLoadInput& input) override;

/**
Expand Down
11 changes: 8 additions & 3 deletions Cesium3DTilesSelection/src/Tile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,6 @@ void Tile::loadContent() {
this->setState(LoadState::ContentLoading);

Tileset& tileset = *this->getTileset();
AsyncSystem& asyncSystem = tileset.getAsyncSystem();

// TODO: support overlay mapping for tiles that aren't region-based.
// Probably by creating a placeholder for each raster overlay and resolving it
Expand Down Expand Up @@ -296,7 +295,9 @@ void Tile::loadContent() {
gltfUpAxis,
pPrepareRendererResources =
tileset.getExternals().pPrepareRendererResources,
&asyncSystem,
&asyncSystem = tileset.getAsyncSystem(),
pAssetAccessor = tileset.getExternals().pAssetAccessor,
&requestHeaders = this->_pContext->requestHeaders,
pLogger = tileset.getExternals().pLogger,
generateMissingNormalsSmooth =
tileset.getOptions()
Expand Down Expand Up @@ -337,7 +338,11 @@ void Tile::loadContent() {
loadInput.contentType = pResponse->contentType();
loadInput.url = pRequest->url();

TileContentFactory::createContent(asyncSystem, loadInput)
TileContentFactory::createContent(
asyncSystem,
pAssetAccessor,
requestHeaders,
loadInput)
.thenInWorkerThread([httpStatusCode = pResponse->statusCode(),
gltfUpAxis,
loadInput = std::move(loadInput),
Expand Down
11 changes: 8 additions & 3 deletions Cesium3DTilesSelection/src/TileContentFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,17 @@ void TileContentFactory::registerContentType(
CesiumAsync::Future<std::unique_ptr<TileContentLoadResult>>
TileContentFactory::createContent(
const CesiumAsync::AsyncSystem& asyncSystem,
const std::shared_ptr<CesiumAsync::IAssetAccessor>& pAssetAccessor,
const std::vector<std::pair<std::string, std::string>>& requestHeaders,
const TileContentLoadInput& input) {

const gsl::span<const std::byte>& data = input.data;
std::string magic = TileContentFactory::getMagic(data).value_or("json");

auto itMagic = TileContentFactory::_loadersByMagic.find(magic);
if (itMagic != TileContentFactory::_loadersByMagic.end()) {
return itMagic->second->load(asyncSystem, input);
return itMagic->second
->load(asyncSystem, pAssetAccessor, requestHeaders, input);
}

const std::string& contentType = input.contentType;
Expand All @@ -48,7 +51,8 @@ TileContentFactory::createContent(
auto itContentType =
TileContentFactory::_loadersByContentType.find(baseContentType);
if (itContentType != TileContentFactory::_loadersByContentType.end()) {
return itContentType->second->load(asyncSystem, input);
return itContentType->second
->load(asyncSystem, pAssetAccessor, requestHeaders, input);
}

// Determine if this is plausibly a JSON external tileset.
Expand All @@ -63,7 +67,8 @@ TileContentFactory::createContent(
// Might be an external tileset, try loading it that way.
itMagic = TileContentFactory::_loadersByMagic.find("json");
if (itMagic != TileContentFactory::_loadersByMagic.end()) {
return itMagic->second->load(asyncSystem, input);
return itMagic->second
->load(asyncSystem, pAssetAccessor, requestHeaders, input);
}
}

Expand Down

0 comments on commit b762be0

Please sign in to comment.