GREM 3.12.0
Game/Rendering Engine Modules for C++
Loading...
Searching...
No Matches
grem::gltf::Asset Struct Reference

The root object for a glTF asset. More...

#include <GREM/core/formats/gltf.hpp>

Classes

struct  Extension

Static Public Member Functions

static Asset parse (StringView glTFString, const SourceLocation &source={}, Span< const byte > binChunk={})
 Parse a glTF asset from a JSON string.
static Asset parseBinary (Span< const byte > glbData, CStringView sourceFilepath={})
 Parse a binary glTF asset from a span of bytes.

Public Attributes

ArrayList< String > extensionsUsed
ArrayList< String > extensionsRequired
ArrayList< Accessor > accessors
ArrayList< Animation > animations
Metadata asset
ArrayList< Buffer > buffers
ArrayList< BufferView > bufferViews
ArrayList< Camera > cameras
ArrayList< Image > images
ArrayList< Material > materials
ArrayList< Mesh > meshes
ArrayList< Node > nodes
ArrayList< Sampler > samplers
Optional< SceneIndex > scene
ArrayList< Scene > scenes
ArrayList< Skin > skins
ArrayList< Texture > textures
Extension extensions
json::Value extras
Span< const byte > binChunk
 View into the glbData parameter passed to parseBinary(), or the binChunk parameter passed to parse().

Detailed Description

The root object for a glTF asset.

See the glTF 2.0 API Reference Guide and specification for more info.

Member Function Documentation

◆ parse()

Asset grem::gltf::Asset::parse ( StringView glTFString,
const SourceLocation & source = {},
Span< const byte > binChunk = {} )
staticnodiscard

Parse a glTF asset from a JSON string.

Parameters
glTFStringinput JSON string to parse.
sourceinitial source location corresponding to the start of the given input string, used when reporting errors.
binChunkBIN 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::Erroron failure to parse the glTF structure.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon 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
glbDatainput binary data to parse. Must outlive its use in the asset. See the warning on Asset::binChunk for more info.
sourceFilepathsource filepath to use when reporting errors.
Returns
the parsed glTF asset.
Exceptions
gltf::Erroron failure to parse the binary glTF or its nested glTF structure.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon 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!

Member Data Documentation

◆ extensionsUsed

ArrayList<String> grem::gltf::Asset::extensionsUsed

◆ extensionsRequired

ArrayList<String> grem::gltf::Asset::extensionsRequired

◆ accessors

ArrayList<Accessor> grem::gltf::Asset::accessors

◆ animations

ArrayList<Animation> grem::gltf::Asset::animations

◆ asset

Metadata grem::gltf::Asset::asset

◆ buffers

ArrayList<Buffer> grem::gltf::Asset::buffers

◆ bufferViews

ArrayList<BufferView> grem::gltf::Asset::bufferViews

◆ cameras

ArrayList<Camera> grem::gltf::Asset::cameras

◆ images

ArrayList<Image> grem::gltf::Asset::images

◆ materials

ArrayList<Material> grem::gltf::Asset::materials

◆ meshes

ArrayList<Mesh> grem::gltf::Asset::meshes

◆ nodes

ArrayList<Node> grem::gltf::Asset::nodes

◆ samplers

ArrayList<Sampler> grem::gltf::Asset::samplers

◆ scene

Optional<SceneIndex> grem::gltf::Asset::scene

◆ scenes

ArrayList<Scene> grem::gltf::Asset::scenes

◆ skins

ArrayList<Skin> grem::gltf::Asset::skins

◆ textures

ArrayList<Texture> grem::gltf::Asset::textures

◆ extensions

Extension grem::gltf::Asset::extensions

◆ extras

json::Value grem::gltf::Asset::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: