cesium-native  0.41.0
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 <gsl/span>
18 
19 #include <functional>
20 #include <memory>
21 #include <optional>
22 #include <string>
23 #include <vector>
24 
25 namespace CesiumGltfReader {
26 
31 struct CESIUMGLTFREADER_API GltfReaderResult {
35  std::optional<CesiumGltf::Model> model;
36 
40  std::vector<std::string> errors;
41 
45  std::vector<std::string> warnings;
46 };
47 
51 struct CESIUMGLTFREADER_API GltfReaderOptions {
56  bool decodeDataUrls = true;
57 
64  bool clearDecodedDataUrls = true;
65 
74  bool decodeEmbeddedImages = true;
75 
79  bool resolveExternalImages = true;
80 
85  bool decodeDraco = true;
86 
92  bool decodeMeshOptData = true;
93 
99  bool dequantizeMeshData = true;
100 
105  bool applyTextureTransform = true;
106 
112 
118  GltfSharedAssetSystem::getDefault();
119 };
120 
124 class CESIUMGLTFREADER_API GltfReader {
125 public:
130 
135 
140 
149  const gsl::span<const std::byte>& data,
150  const GltfReaderOptions& options = GltfReaderOptions()) const;
151 
164  const CesiumAsync::AsyncSystem& asyncSystem,
165  const std::string& url,
166  const std::vector<CesiumAsync::IAssetAccessor::THeader>& headers,
167  const std::shared_ptr<CesiumAsync::IAssetAccessor>& pAssetAccessor,
168  const GltfReaderOptions& options = GltfReaderOptions()) const;
169 
177  void
179 
193  CesiumAsync::AsyncSystem asyncSystem,
194  const std::string& baseUrl,
195  const CesiumAsync::HttpHeaders& headers,
196  std::shared_ptr<CesiumAsync::IAssetAccessor> pAssetAccessor,
197  const GltfReaderOptions& options,
198  GltfReaderResult&& result);
199 
204  [[deprecated(
205  "Use ImageDecoder::readImage instead.")]] static ImageReaderResult
207  const gsl::span<const std::byte>& data,
208  const CesiumGltf::Ktx2TranscodeTargets& ktx2TranscodeTargets);
209 
214  [[deprecated("Use ImageDecoder::generateMipMaps instead.")]] static std::
215  optional<std::string>
217 
218 private:
220 };
221 
222 } // 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: Future.h:29
Reads glTF models and images.
Definition: GltfReader.h:124
GltfReader()
Constructs a new instance.
static CesiumAsync::Future< GltfReaderResult > resolveExternalData(CesiumAsync::AsyncSystem asyncSystem, const std::string &baseUrl, const CesiumAsync::HttpHeaders &headers, 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.
CesiumJsonReader::JsonReaderOptions & getOptions()
Gets the options controlling how the JSON is read.
void postprocessGltf(GltfReaderResult &readGltf, const GltfReaderOptions &options)
Performs post-load processing on a glTF. The specific operations performed are controlled by the prov...
GltfReaderResult readGltf(const gsl::span< const std::byte > &data, const GltfReaderOptions &options=GltfReaderOptions()) const
Reads a glTF or binary glTF (GLB) 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.
static ImageReaderResult readImage(const gsl::span< const std::byte > &data, const CesiumGltf::Ktx2TranscodeTargets &ktx2TranscodeTargets)
Reads an Image from a buffer.
const CesiumJsonReader::JsonReaderOptions & getExtensions() const
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:23
Classes for reading glTF models.
Definition: GltfReader.h:25
Options for how to read a glTF.
Definition: GltfReader.h:51
CesiumGltf::Ktx2TranscodeTargets ktx2TranscodeTargets
For each possible input transmission format, this struct names the ideal target gpu-compressed pixel ...
Definition: GltfReader.h:111
The result of reading a glTF model with GltfReader::readGltf.
Definition: GltfReader.h:31
std::optional< CesiumGltf::Model > model
The read model, or std::nullopt if the model could not be read.
Definition: GltfReader.h:35
std::vector< std::string > errors
Errors, if any, that occurred during the load process.
Definition: GltfReader.h:40
std::vector< std::string > warnings
Warnings, if any, that occurred during the load process.
Definition: GltfReader.h:45
The result of reading an image with ImageDecoder::readImage.
Definition: ImageDecoder.h:19
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 ...