cesium-native 0.43.0
Loading...
Searching...
No Matches
GltfConverters.h
1#pragma once
2
3#include "Library.h"
4
5#include <Cesium3DTilesContent/GltfConverterResult.h>
6#include <CesiumAsync/Future.h>
7#include <CesiumAsync/IAssetAccessor.h>
8#include <CesiumGeometry/Axis.h>
9#include <CesiumGltfReader/GltfReader.h>
10
11#include <optional>
12#include <span>
13#include <string>
14#include <string_view>
15
16namespace Cesium3DTilesContent {
17
32
37struct CESIUM3DTILESCONTENT_API AssetFetcher {
53 const CesiumAsync::AsyncSystem& asyncSystem_,
54 const std::shared_ptr<CesiumAsync::IAssetAccessor>& pAssetAccessor_,
55 const std::string& baseUrl_,
56 const glm::dmat4 tileTransform_,
57 const std::vector<CesiumAsync::IAssetAccessor::THeader>& requestHeaders_,
59 : asyncSystem(asyncSystem_),
60 pAssetAccessor(pAssetAccessor_),
61 baseUrl(baseUrl_),
62 tileTransform(tileTransform_),
63 requestHeaders(requestHeaders_),
64 upAxis(upAxis_) {}
65
74 get(const std::string& relativeUrl) const;
75
84 std::shared_ptr<CesiumAsync::IAssetAccessor> pAssetAccessor;
89 std::string baseUrl;
94 glm::dmat4 tileTransform;
99 std::vector<CesiumAsync::IAssetAccessor::THeader> requestHeaders;
104};
105
120class CESIUM3DTILESCONTENT_API GltfConverters {
121public:
127 const std::span<const std::byte>& content,
129 const AssetFetcher& subprocessor);
130
143 static void
144 registerMagic(const std::string& magic, ConverterFunction converter);
145
160 const std::string& fileExtension,
161 ConverterFunction converter);
162
171 static ConverterFunction
172 getConverterByFileExtension(const std::string& filePath);
173
186 static ConverterFunction
187 getConverterByMagic(const std::span<const std::byte>& content);
188
218 const std::string& filePath,
219 const std::span<const std::byte>& content,
221 const AssetFetcher& assetFetcher);
222
246 const std::span<const std::byte>& content,
248 const AssetFetcher& assetFetcher);
249
250private:
251 static std::string toLowerCase(const std::string_view& str);
252
253 static std::string getFileExtension(const std::string_view& filePath);
254
255 static ConverterFunction getConverterByFileExtension(
256 const std::string& filePath,
257 std::string& fileExtension);
258
259 static ConverterFunction getConverterByMagic(
260 const std::span<const std::byte>& content,
261 std::string& magic);
262
263 static std::unordered_map<std::string, ConverterFunction> _loadersByMagic;
264 static std::unordered_map<std::string, ConverterFunction>
265 _loadersByFileExtension;
266};
267} // 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:11
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:50
The container to store the error and warning list when loading a tile or glTF content.
Definition ErrorList.h:17