cesium-native 0.43.0
Loading...
Searching...
No Matches
GltfReader.h
1#pragma once
2
3#include "CesiumGltfReader/ImageDecoder.h"
4#include "CesiumGltfReader/Library.h"
5
6#include <CesiumAsync/AsyncSystem.h>
7#include <CesiumAsync/Future.h>
8#include <CesiumAsync/HttpHeaders.h>
9#include <CesiumAsync/IAssetAccessor.h>
10#include <CesiumGltf/ImageAsset.h>
11#include <CesiumGltf/Ktx2TranscodeTargets.h>
12#include <CesiumGltf/Model.h>
13#include <CesiumGltfReader/GltfSharedAssetSystem.h>
14#include <CesiumJsonReader/IExtensionJsonHandler.h>
15#include <CesiumJsonReader/JsonReaderOptions.h>
16
17#include <functional>
18#include <memory>
19#include <optional>
20#include <span>
21#include <string>
22#include <vector>
23
25
30struct CESIUMGLTFREADER_API GltfReaderResult {
34 std::optional<CesiumGltf::Model> model;
35
39 std::vector<std::string> errors;
40
44 std::vector<std::string> warnings;
45};
46
50struct CESIUMGLTFREADER_API GltfReaderOptions {
55 bool decodeDataUrls = true;
56
63 bool clearDecodedDataUrls = true;
64
73 bool decodeEmbeddedImages = true;
74
78 bool resolveExternalImages = true;
79
84 bool decodeDraco = true;
85
91 bool decodeMeshOptData = true;
92
98 bool dequantizeMeshData = true;
99
104 bool applyTextureTransform = true;
105
111
117 GltfSharedAssetSystem::getDefault();
118
123 bool resolveExternalStructuralMetadata = true;
124};
125
129class CESIUMGLTFREADER_API GltfReader {
130public:
135
140
145
154 const std::span<const std::byte>& data,
155 const GltfReaderOptions& options = GltfReaderOptions()) const;
156
169 const CesiumAsync::AsyncSystem& asyncSystem,
170 const std::string& url,
171 const std::vector<CesiumAsync::IAssetAccessor::THeader>& headers,
172 const std::shared_ptr<CesiumAsync::IAssetAccessor>& pAssetAccessor,
173 const GltfReaderOptions& options = GltfReaderOptions()) const;
174
182 void
184
198 const CesiumAsync::AsyncSystem& asyncSystem,
199 const std::string& baseUrl,
200 const CesiumAsync::HttpHeaders& headers,
201 const std::shared_ptr<CesiumAsync::IAssetAccessor>& pAssetAccessor,
202 const GltfReaderOptions& options,
203 GltfReaderResult&& result);
204
209 [[deprecated(
210 "Use ImageDecoder::readImage instead.")]] static ImageReaderResult
212 const std::span<const std::byte>& data,
213 const CesiumGltf::Ktx2TranscodeTargets& ktx2TranscodeTargets);
214
219 [[deprecated("Use ImageDecoder::generateMipMaps instead.")]] static std::
220 optional<std::string>
222
223private:
225};
226
227} // namespace CesiumGltfReader
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
Reads glTF models and images.
Definition GltfReader.h:129
GltfReaderResult readGltf(const std::span< const std::byte > &data, const GltfReaderOptions &options=GltfReaderOptions()) const
Reads a glTF or binary glTF (GLB) from a buffer.
GltfReader()
Constructs a new instance.
const CesiumJsonReader::JsonReaderOptions & getExtensions() const
Gets the options controlling how the JSON is read.
static CesiumAsync::Future< GltfReaderResult > resolveExternalData(const CesiumAsync::AsyncSystem &asyncSystem, const std::string &baseUrl, const CesiumAsync::HttpHeaders &headers, const std::shared_ptr< CesiumAsync::IAssetAccessor > &pAssetAccessor, const GltfReaderOptions &options, GltfReaderResult &&result)
Accepts the result of readGltf and resolves any remaining external buffers and images.
static std::optional< std::string > generateMipMaps(CesiumGltf::ImageAsset &image)
Generate mipmaps for this image.
void postprocessGltf(GltfReaderResult &readGltf, const GltfReaderOptions &options)
Performs post-load processing on a glTF. The specific operations performed are controlled by the prov...
static ImageReaderResult readImage(const std::span< const std::byte > &data, const CesiumGltf::Ktx2TranscodeTargets &ktx2TranscodeTargets)
Reads an Image from a buffer.
CesiumAsync::Future< GltfReaderResult > loadGltf(const CesiumAsync::AsyncSystem &asyncSystem, const std::string &url, const std::vector< CesiumAsync::IAssetAccessor::THeader > &headers, const std::shared_ptr< CesiumAsync::IAssetAccessor > &pAssetAccessor, const GltfReaderOptions &options=GltfReaderOptions()) const
Reads a glTF or binary glTF file from a URL and resolves external buffers and images.
CesiumJsonReader::JsonReaderOptions & getOptions()
Gets the options controlling how the JSON is read.
Holds options for reading statically-typed data structures from JSON.
A smart pointer that calls addReference and releaseReference on the controlled object.
std::map< std::string, std::string, CaseInsensitiveCompare > HttpHeaders
Http Headers that maps case-insensitive header key with header value.
Definition HttpHeaders.h:25
Classes for reading glTF models.
Definition GltfReader.h:24
Options for how to read a glTF.
Definition GltfReader.h:50
CesiumGltf::Ktx2TranscodeTargets ktx2TranscodeTargets
For each possible input transmission format, this struct names the ideal target gpu-compressed pixel ...
Definition GltfReader.h:110
The result of reading a glTF model with GltfReader::readGltf.
Definition GltfReader.h:30
std::optional< CesiumGltf::Model > model
The read model, or std::nullopt if the model could not be read.
Definition GltfReader.h:34
std::vector< std::string > errors
Errors, if any, that occurred during the load process.
Definition GltfReader.h:39
std::vector< std::string > warnings
Warnings, if any, that occurred during the load process.
Definition GltfReader.h:44
The result of reading an image with ImageDecoder::readImage.
A 2D image asset, including its pixel data. The image may have mipmaps, and it may be encoded in a GP...
Definition ImageAsset.h:34
For each possible input transmission format, this struct names the ideal target gpu-compressed pixel ...