The root object for a glTF asset.
More...
#include <GREM/core/formats/gltf.hpp>
The root object for a glTF asset.
See the glTF 2.0 API Reference Guide and specification for more info.
◆ parse()
Parse a glTF asset from a JSON string.
- Parameters
-
| glTFString | input JSON string to parse. |
| source | initial source location corresponding to the start of the given input string, used when reporting errors. |
| binChunk | BIN chunk data of the surrounding binary glTF file, if any. Must outlive its use in the asset if not empty. See the warning on Asset::binChunk for more info. |
- Returns
- the parsed glTF asset.
- Exceptions
-
| gltf::Error | on failure to parse the glTF structure. |
| std::length_error | if an internal size limit was exceeded. |
| std::bad_array_new_length | if an internal size limit was exceeded. |
| std::bad_alloc | on allocation failure. |
- Warning
- The parser only checks that the values it reads are the correct JSON types; it does NOT validate that any of the values are in-bounds, consistent or otherwise valid according to the glTF specification. Always validate any indices, accessors, etc. of the parsed asset before using them!
◆ parseBinary()
| Asset grem::gltf::Asset::parseBinary |
( |
Span< const byte > | glbData, |
|
|
CStringView | sourceFilepath = {} ) |
|
staticnodiscard |
Parse a binary glTF asset from a span of bytes.
- Parameters
-
| glbData | input binary data to parse. Must outlive its use in the asset. See the warning on Asset::binChunk for more info. |
| sourceFilepath | source filepath to use when reporting errors. |
- Returns
- the parsed glTF asset.
- Exceptions
-
| gltf::Error | on failure to parse the binary glTF or its nested glTF structure. |
| std::length_error | if an internal size limit was exceeded. |
| std::bad_array_new_length | if an internal size limit was exceeded. |
| std::bad_alloc | on allocation failure. |
- Warning
- The parser only checks that the values it reads are the correct JSON types; it does NOT validate that any of the values are in-bounds, consistent or otherwise valid according to the glTF specification. Always validate any indices, accessors, etc. of the parsed asset before using them!
◆ extensionsUsed
◆ extensionsRequired
◆ accessors
◆ animations
◆ asset
◆ buffers
◆ bufferViews
◆ cameras
◆ images
◆ materials
◆ meshes
◆ nodes
◆ samplers
◆ scene
◆ scenes
◆ skins
◆ textures
◆ extensions
◆ extras
◆ binChunk
| Span<const byte> grem::gltf::Asset::binChunk |
View into the glbData parameter passed to parseBinary(), or the binChunk parameter passed to parse().
- Warning
- When accessing this view, make sure the container for the binary data that was passed to the parser is still valid! For example, this is correct: cpp
const Allocation<byte> data = filesystem.readInputFile(filepath);
const gltf::Asset asset = gltf::Asset::parse(data, filepath);
doSomething(asset); // Good, data is still in scope.
doSomething(gltf::Asset::parse(filesystem.readInputFile(filepath), filepath)); // This is also ok.
but this is incorrect, and a potential security vulnerability: cpp
const gltf::Asset asset = gltf::Asset::parse(filesystem.readInputFile(filepath), filepath);
doSomething(asset); // Bad! The temporary allocation was deleted at the end of the statement above, so the binChunk view is invalid.
This unfortunate footgun is necessary to make binChunk available to consumers of Asset without unnecessarily copying the entire file contents, or constraining its source container type.
The documentation for this struct was generated from the following file: