#pragma once #include #include #include #include #include namespace Cesium3DTilesReader { /** * @brief Reads 3D Tiles subtrees from a binary or JSON subtree file. * * While {@link SubtreeReader} can parse a {@link Cesium3DTiles::Subtree} from * a binary buffer as well, `SubtreeFileReader` additionally supports: * * 1. Loading binary subtree files. * 2. Loading external buffers asynchronously. * 3. Decoding buffers from data URIs. * * The subtree file need not be an actual file on disk. */ class CESIUM3DTILESREADER_API SubtreeFileReader { public: /** * @brief Constructs a new instance. */ SubtreeFileReader(); /** * @brief Gets the options controlling how the JSON is read. */ CesiumJsonReader::JsonReaderOptions& getOptions(); /** * @brief Gets the options controlling how the JSON is read. */ const CesiumJsonReader::JsonReaderOptions& getOptions() const; /** * @brief Asynchronously loads a subtree from a URL. * * \attention Please note that the `SubtreeFileReader` instance must remain * valid until the returned future resolves or rejects. Destroying it earlier * will result in undefined behavior. One easy way to achieve this is to * construct the reader with `std::make_shared` and capture the * `std::shared_ptr` in the continuation lambda. * * @param asyncSystem The AsyncSystem used to do asynchronous work. * @param pAssetAccessor The accessor used to retrieve the URL and any other * required resources. * @param url The URL from which to get the subtree file. * @param headers Headers to include in the request for the initial subtree * file and any additional resources that are required. * @return A future that resolves to the result of loading the subtree. */ CesiumAsync::Future> load( const CesiumAsync::AsyncSystem& asyncSystem, const std::shared_ptr& pAssetAccessor, const std::string& url, const std::vector& headers = {}) const noexcept; /** * @brief Asynchronously loads a subtree from a request. * * \attention Please note that the `SubtreeFileReader` instance must remain * valid until the returned future resolves or rejects. Destroying it earlier * will result in undefined behavior. One easy way to achieve this is to * construct the reader with `std::make_shared` and capture the * `std::shared_ptr` in the continuation lambda. * * @param asyncSystem The AsyncSystem used to do asynchronous work. * @param pAssetAccessor The accessor used to retrieve the URL and any other * required resources. * @param pRequest The request to get the subtree file. * @return A future that resolves to the result of loading the subtree. */ CesiumAsync::Future> load( const CesiumAsync::AsyncSystem& asyncSystem, const std::shared_ptr& pAssetAccessor, const std::shared_ptr& pRequest) const noexcept; /** * @brief Asynchronously loads loads a subtree from data obtained from a URL. * * \attention Please note that the `SubtreeFileReader` instance must remain * valid until the returned future resolves or rejects. Destroying it earlier * will result in undefined behavior. One easy way to achieve this is to * construct the reader with `std::make_shared` and capture the * `std::shared_ptr` in the continuation lambda. * * @param asyncSystem The AsyncSystem used to do asynchronous work. * @param pAssetAccessor The accessor used to retrieve the URL and any other * required resources. * @param url The URL from which the subtree file was obtained. * @param requestHeaders Headers that were included in the request for the * initial subtree file and should be included for any additional resources * that are required. * @param data The subtree file data that was obtained. * @return A future that resolves to the result of loading the subtree. */ CesiumAsync::Future> load( const CesiumAsync::AsyncSystem& asyncSystem, const std::shared_ptr& pAssetAccessor, const std::string& url, const std::vector& requestHeaders, const std::span& data) const noexcept; private: CesiumAsync::Future> loadBinary( const CesiumAsync::AsyncSystem& asyncSystem, const std::shared_ptr& pAssetAccessor, const std::string& url, const std::vector& requestHeaders, const std::span& data) const noexcept; CesiumAsync::Future> loadJson( const CesiumAsync::AsyncSystem& asyncSystem, const std::shared_ptr& pAssetAccessor, const std::string& url, const std::vector& requestHeaders, const std::span& data) const noexcept; CesiumAsync::Future> postprocess( const CesiumAsync::AsyncSystem& asyncSystem, const std::shared_ptr& pAssetAccessor, const std::string& url, const std::vector& requestHeaders, CesiumJsonReader::ReadJsonResult&& loaded) const noexcept; SubtreeReader _reader; }; } // namespace Cesium3DTilesReader