cesium-native 0.44.2
Loading...
Searching...
No Matches
GltfConverters.h
1#pragma once
2
3#include <Cesium3DTilesContent/GltfConverterResult.h>
4#include <Cesium3DTilesContent/Library.h>
5#include <CesiumAsync/Future.h>
6#include <CesiumAsync/IAssetAccessor.h>
7#include <CesiumGeometry/Axis.h>
8#include <CesiumGltfReader/GltfReader.h>
9
10#include <optional>
11#include <span>
12#include <string>
13#include <string_view>
14
15namespace Cesium3DTilesContent {
16
31
36struct CESIUM3DTILESCONTENT_API AssetFetcher {
52 const CesiumAsync::AsyncSystem& asyncSystem_,
53 const std::shared_ptr<CesiumAsync::IAssetAccessor>& pAssetAccessor_,
54 const std::string& baseUrl_,
55 const glm::dmat4 tileTransform_,
56 const std::vector<CesiumAsync::IAssetAccessor::THeader>& requestHeaders_,
58 : asyncSystem(asyncSystem_),
59 pAssetAccessor(pAssetAccessor_),
60 baseUrl(baseUrl_),
61 tileTransform(tileTransform_),
62 requestHeaders(requestHeaders_),
63 upAxis(upAxis_) {}
64
73 get(const std::string& relativeUrl) const;
74
83 std::shared_ptr<CesiumAsync::IAssetAccessor> pAssetAccessor;
88 std::string baseUrl;
93 glm::dmat4 tileTransform;
98 std::vector<CesiumAsync::IAssetAccessor::THeader> requestHeaders;
103};
104
119class CESIUM3DTILESCONTENT_API GltfConverters {
120public:
126 const std::span<const std::byte>& content,
128 const AssetFetcher& subprocessor);
129
142 static void
143 registerMagic(const std::string& magic, ConverterFunction converter);
144
159 const std::string& fileExtension,
160 ConverterFunction converter);
161
170 static ConverterFunction
171 getConverterByFileExtension(const std::string& filePath);
172
185 static ConverterFunction
186 getConverterByMagic(const std::span<const std::byte>& content);
187
217 const std::string& filePath,
218 const std::span<const std::byte>& content,
220 const AssetFetcher& assetFetcher);
221
245 const std::span<const std::byte>& content,
247 const AssetFetcher& assetFetcher);
248
249private:
250 static std::string toLowerCase(const std::string_view& str);
251
252 static std::string getFileExtension(const std::string_view& filePath);
253
254 static ConverterFunction getConverterByFileExtension(
255 const std::string& filePath,
256 std::string& fileExtension);
257
258 static ConverterFunction getConverterByMagic(
259 const std::span<const std::byte>& content,
260 std::string& magic);
261
262 static std::unordered_map<std::string, ConverterFunction> _loadersByMagic;
263 static std::unordered_map<std::string, ConverterFunction>
264 _loadersByFileExtension;
265};
266} // namespace Cesium3DTilesContent
Creates GltfConverterResult objects from a a binary content.
static void registerMagic(const std::string &magic, ConverterFunction converter)
Register the given function for the given magic header.
static CesiumAsync::Future< GltfConverterResult > convert(const std::span< const std::byte > &content, const CesiumGltfReader::GltfReaderOptions &options, const AssetFetcher &assetFetcher)
Creates the GltfConverterResult from the given binary content.
static void registerFileExtension(const std::string &fileExtension, ConverterFunction converter)
Register the given function for the given file extension.
static ConverterFunction getConverterByFileExtension(const std::string &filePath)
Retrieve the converter function that is already registered for the given file extension....
static CesiumAsync::Future< GltfConverterResult > convert(const std::string &filePath, const std::span< const std::byte > &content, const CesiumGltfReader::GltfReaderOptions &options, const AssetFetcher &assetFetcher)
Creates the GltfConverterResult from the given binary content.
CesiumAsync::Future< GltfConverterResult >(*)( const std::span< const std::byte > &content, const CesiumGltfReader::GltfReaderOptions &options, const AssetFetcher &subprocessor) ConverterFunction
A function pointer that can create a GltfConverterResult from a tile binary content.
static ConverterFunction getConverterByMagic(const std::span< const std::byte > &content)
Retrieve the converter function that is registered for the given magic header. If no such function is...
A system for managing asynchronous requests and tasks.
Definition AsyncSystem.h:36
A value that will be available in the future, as produced by AsyncSystem.
Definition Promise.h:12
Classes that support loading and converting 3D Tiles tile content.
Axis
An enum describing the x, y, and z axes.
Definition Axis.h:10
The result of an AssetFetcher::get call.
CesiumUtility::ErrorList errorList
The errors and warnings reported while fetching the asset.
std::vector< std::byte > bytes
The byte buffer obtained from a URL. This will be empty if fetching the asset failed.
glm::dmat4 tileTransform
The transformation matrix applied to this tile. Used for East-North-Up transforms in i3dm.
CesiumAsync::AsyncSystem asyncSystem
The CesiumAsync::AsyncSystem used for this AssetFetcher.
CesiumGeometry::Axis upAxis
The gltfUpAxis property that will be specified for loaded assets.
std::vector< CesiumAsync::IAssetAccessor::THeader > requestHeaders
Headers that will be attached to each request made with this AssetFetcher.
CesiumAsync::Future< AssetFetcherResult > get(const std::string &relativeUrl) const
Gets a buffer of bytes from the given relative URL.
std::string baseUrl
The base URL that this AssetFetcher's requests will be relative to.
std::shared_ptr< CesiumAsync::IAssetAccessor > pAssetAccessor
The CesiumAsync::IAssetAccessor used for this AssetFetcher.
AssetFetcher(const CesiumAsync::AsyncSystem &asyncSystem_, const std::shared_ptr< CesiumAsync::IAssetAccessor > &pAssetAccessor_, const std::string &baseUrl_, const glm::dmat4 tileTransform_, const std::vector< CesiumAsync::IAssetAccessor::THeader > &requestHeaders_, CesiumGeometry::Axis upAxis_)
Creates an AssetFetcher with the given base URL and settings.
Options for how to read a glTF.
Definition GltfReader.h:49
The container to store the error and warning list when loading a tile or glTF content.
Definition ErrorList.h:18