initial commit-moved from vulkan_guide
This commit is contained in:
64
third_party/fastgltf/docs/CMakeLists.txt
vendored
Normal file
64
third_party/fastgltf/docs/CMakeLists.txt
vendored
Normal file
@@ -0,0 +1,64 @@
|
||||
find_package(Doxygen)
|
||||
if (NOT DOXYGEN)
|
||||
message(STATUS "fastgltf: Doxygen not found; docs will not be built")
|
||||
return()
|
||||
endif()
|
||||
|
||||
# Get the sources and create proper absolute paths
|
||||
get_target_property(FASTGLTF_SOURCES fastgltf SOURCES)
|
||||
set(FASTGLTF_ABS_SOURCES "")
|
||||
foreach (SOURCE_FILE ${FASTGLTF_SOURCES})
|
||||
list(APPEND FASTGLTF_ABS_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../${SOURCE_FILE}")
|
||||
endforeach()
|
||||
|
||||
# For the Doxygen file we remove the semicolons for spaces
|
||||
list(JOIN FASTGLTF_ABS_SOURCES " " DOXYGEN_INPUT)
|
||||
|
||||
set(DOXYGEN_OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/doxygen)
|
||||
set(DOXYGEN_INDEX_FILE ${DOXYGEN_OUTPUT}/xml/index.xml)
|
||||
set(DOXYGEN_FILE ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
|
||||
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in ${DOXYGEN_FILE} @ONLY)
|
||||
|
||||
# Generate doxygen XML
|
||||
add_custom_command(
|
||||
OUTPUT ${DOXYGEN_INDEX_FILE}
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
DEPENDS ${FASTGLTF_ABS_SOURCES}
|
||||
COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_FILE}
|
||||
MAIN_DEPENDENCY ${DOXYGEN_FILE} Doxyfile.in
|
||||
COMMENT "Generating docs"
|
||||
)
|
||||
|
||||
add_custom_target(generate_docs DEPENDS ${DOXYGEN_INDEX_FILE})
|
||||
|
||||
# Find sphinx-build
|
||||
find_program(SPHINX_EXECUTABLE
|
||||
NAMES sphinx-build
|
||||
DOC "Path to sphinx-build executable")
|
||||
|
||||
if (NOT SPHINX_EXECUTABLE)
|
||||
message(STATUS "fastgltf: Sphinx not found; docs website will not be built")
|
||||
return()
|
||||
endif()
|
||||
|
||||
set(SPHINX_OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/sphinx)
|
||||
set(SPHINX_INDEX_FILE ${SPHINX_OUTPUT}/index.html)
|
||||
set(SPHINX_CONF ${CMAKE_CURRENT_SOURCE_DIR}/conf.py)
|
||||
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/conf.py.in ${SPHINX_CONF} @ONLY)
|
||||
|
||||
# Let Sphinx generate our site's HTML
|
||||
add_custom_command(
|
||||
OUTPUT ${SPHINX_INDEX_FILE}
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
||||
DEPENDS ${DOXYGEN_INDEX_FILE} ${CMAKE_CURRENT_SOURCE_DIR}/index.rst ${CMAKE_CURRENT_SOURCE_DIR}/overview.rst
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/api.rst ${CMAKE_CURRENT_SOURCE_DIR}/tools.rst ${CMAKE_CURRENT_SOURCE_DIR}/options.rst
|
||||
COMMAND sphinx-build -b html
|
||||
-Dbreathe_projects.fastgltf=\"${DOXYGEN_OUTPUT}/xml\"
|
||||
${CMAKE_CURRENT_SOURCE_DIR} ${SPHINX_OUTPUT}
|
||||
MAIN_DEPENDENCY ${SPHINX_CONF}
|
||||
COMMENT "Generating docs with Sphinx"
|
||||
)
|
||||
|
||||
add_custom_target(generate_sphinx DEPENDS ${SPHINX_INDEX_FILE})
|
||||
18
third_party/fastgltf/docs/Doxyfile.in
vendored
Normal file
18
third_party/fastgltf/docs/Doxyfile.in
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
PROJECT_NAME = "fastgltf"
|
||||
PROJECT_NUMBER = "@PROJECT_VERSION@"
|
||||
DOXYFILE_ENCODING = UTF-8
|
||||
|
||||
GENERATE_LATEX = NO
|
||||
GENERATE_MAN = NO
|
||||
GENERATE_RTF = NO
|
||||
GENERATE_HTML = NO
|
||||
GENERATE_XML = YES
|
||||
|
||||
ENABLE_PREPROCESSING = YES
|
||||
QUIET = YES
|
||||
JAVADOC_AUTOBRIEF = YES
|
||||
|
||||
MACRO_EXPANSION = YES
|
||||
|
||||
INPUT = @DOXYGEN_INPUT@
|
||||
OUTPUT_DIRECTORY = @DOXYGEN_OUTPUT@
|
||||
268
third_party/fastgltf/docs/api.rst
vendored
Normal file
268
third_party/fastgltf/docs/api.rst
vendored
Normal file
@@ -0,0 +1,268 @@
|
||||
***
|
||||
API
|
||||
***
|
||||
|
||||
.. contents:: Table of Contents
|
||||
|
||||
glTF structs
|
||||
============
|
||||
|
||||
This section contains all types fastgltf provides to represent data from a glTF asset.
|
||||
|
||||
DataSource
|
||||
----------
|
||||
|
||||
.. doxygentypedef:: fastgltf::DataSource
|
||||
|
||||
AssetInfo
|
||||
---------
|
||||
|
||||
.. doxygenstruct:: fastgltf::AssetInfo
|
||||
:members:
|
||||
:undoc-members:
|
||||
|
||||
|
||||
Accessor
|
||||
---------
|
||||
|
||||
.. doxygenstruct:: fastgltf::Accessor
|
||||
:members:
|
||||
:undoc-members:
|
||||
|
||||
|
||||
Animation
|
||||
---------
|
||||
|
||||
.. doxygenstruct:: fastgltf::Animation
|
||||
:members:
|
||||
:undoc-members:
|
||||
|
||||
|
||||
Buffer
|
||||
------
|
||||
|
||||
.. doxygenstruct:: fastgltf::Buffer
|
||||
:members:
|
||||
:undoc-members:
|
||||
|
||||
|
||||
BufferView
|
||||
----------
|
||||
|
||||
.. doxygenstruct:: fastgltf::BufferView
|
||||
:members:
|
||||
:undoc-members:
|
||||
|
||||
|
||||
Camera
|
||||
------
|
||||
|
||||
.. doxygenstruct:: fastgltf::Camera
|
||||
:members:
|
||||
:undoc-members:
|
||||
|
||||
|
||||
Image
|
||||
-----
|
||||
|
||||
.. doxygenstruct:: fastgltf::Image
|
||||
:members:
|
||||
:undoc-members:
|
||||
|
||||
|
||||
Light
|
||||
-----
|
||||
|
||||
.. doxygenstruct:: fastgltf::Light
|
||||
:members:
|
||||
:undoc-members:
|
||||
|
||||
|
||||
Material
|
||||
--------
|
||||
|
||||
.. doxygenstruct:: fastgltf::Material
|
||||
:members:
|
||||
:undoc-members:
|
||||
|
||||
|
||||
Mesh
|
||||
----
|
||||
|
||||
.. doxygenstruct:: fastgltf::Mesh
|
||||
:members:
|
||||
:undoc-members:
|
||||
|
||||
|
||||
Node
|
||||
----
|
||||
|
||||
.. doxygenstruct:: fastgltf::Node
|
||||
:members:
|
||||
:undoc-members:
|
||||
|
||||
|
||||
Sampler
|
||||
-------
|
||||
|
||||
.. doxygenstruct:: fastgltf::Sampler
|
||||
:members:
|
||||
:undoc-members:
|
||||
|
||||
|
||||
Scene
|
||||
-----
|
||||
|
||||
.. doxygenstruct:: fastgltf::Scene
|
||||
:members:
|
||||
:undoc-members:
|
||||
|
||||
|
||||
Skin
|
||||
----
|
||||
|
||||
.. doxygenstruct:: fastgltf::Skin
|
||||
:members:
|
||||
:undoc-members:
|
||||
|
||||
|
||||
Texture
|
||||
-------
|
||||
|
||||
.. doxygenstruct:: fastgltf::Texture
|
||||
:members:
|
||||
:undoc-members:
|
||||
|
||||
|
||||
Asset
|
||||
-----
|
||||
|
||||
.. doxygenclass:: fastgltf::Asset
|
||||
:members:
|
||||
:undoc-members:
|
||||
|
||||
|
||||
Parser
|
||||
======
|
||||
|
||||
This section contains all types that one requires to load a glTF file using fastgltf.
|
||||
This includes the Parser class, options, and data buffers.
|
||||
|
||||
|
||||
Error
|
||||
-----
|
||||
|
||||
.. doxygenenum:: fastgltf::Error
|
||||
|
||||
|
||||
Extensions
|
||||
----------
|
||||
|
||||
.. doxygenenum:: fastgltf::Extensions
|
||||
|
||||
.. doxygenfunction:: fastgltf::stringifyExtension
|
||||
|
||||
|
||||
Category
|
||||
--------
|
||||
|
||||
.. doxygenenum:: fastgltf::Category
|
||||
|
||||
|
||||
.. _options:
|
||||
|
||||
Options
|
||||
-------
|
||||
|
||||
.. doxygenenum:: fastgltf::Options
|
||||
|
||||
|
||||
Expected
|
||||
--------
|
||||
|
||||
.. doxygenclass:: fastgltf::Expected
|
||||
:members:
|
||||
:undoc-members:
|
||||
|
||||
|
||||
GltfDataBuffer
|
||||
--------------
|
||||
|
||||
.. doxygenfunction:: fastgltf::getGltfBufferPadding
|
||||
|
||||
.. doxygenclass:: fastgltf::GltfDataBuffer
|
||||
:members:
|
||||
:undoc-members:
|
||||
|
||||
|
||||
Parser
|
||||
------
|
||||
|
||||
.. doxygenclass:: fastgltf::Parser
|
||||
:members:
|
||||
:undoc-members:
|
||||
|
||||
.. doxygenfunction:: fastgltf::determineGltfFileType
|
||||
|
||||
.. doxygenstruct:: fastgltf::BufferInfo
|
||||
:members:
|
||||
|
||||
|
||||
Utility
|
||||
=======
|
||||
|
||||
This sections contains various types used by fastgltf to simplify & process glTF data,
|
||||
and for types used to enhance performance & minimize memory usage.
|
||||
|
||||
URIView
|
||||
-------
|
||||
|
||||
.. doxygenclass:: fastgltf::URIView
|
||||
:members:
|
||||
:undoc-members:
|
||||
|
||||
|
||||
URI
|
||||
---
|
||||
|
||||
.. doxygenclass:: fastgltf::URI
|
||||
:members:
|
||||
:undoc-members:
|
||||
|
||||
|
||||
span
|
||||
----
|
||||
|
||||
.. doxygenclass:: fastgltf::span
|
||||
:members:
|
||||
:undoc-members:
|
||||
|
||||
|
||||
SmallVector
|
||||
-----------
|
||||
|
||||
.. doxygenclass:: fastgltf::SmallVector
|
||||
:members:
|
||||
:undoc-members:
|
||||
|
||||
|
||||
Optional
|
||||
--------
|
||||
|
||||
.. doxygentypedef:: fastgltf::Optional
|
||||
|
||||
|
||||
OptionalFlagValue
|
||||
-----------------
|
||||
|
||||
.. doxygenstruct:: fastgltf::OptionalFlagValue
|
||||
:members:
|
||||
:undoc-members:
|
||||
|
||||
|
||||
OptionalWithFlagValue
|
||||
---------------------
|
||||
|
||||
.. doxygenclass:: fastgltf::OptionalWithFlagValue
|
||||
:members:
|
||||
:undoc-members:
|
||||
22
third_party/fastgltf/docs/conf.py.in
vendored
Normal file
22
third_party/fastgltf/docs/conf.py.in
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
project = 'fastgltf'
|
||||
copyright = '2023, spnda'
|
||||
author = 'spnda'
|
||||
release = '@PROJECT_VERSION@'
|
||||
|
||||
extensions = ["breathe", "sphinx_rtd_theme"]
|
||||
|
||||
templates_path = ['_templates']
|
||||
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
|
||||
|
||||
html_theme = 'sphinx_rtd_theme'
|
||||
# html_static_path = ['_static']
|
||||
html_theme_options = {
|
||||
'display_version': True,
|
||||
'titles_only': True,
|
||||
'navigation_depth': 5,
|
||||
}
|
||||
|
||||
fastgltf_sources = "@DOXYGEN_INPUT@".split()
|
||||
|
||||
breathe_default_project = "fastgltf"
|
||||
breathe_projects = {"fastgltf": "@DOXYGEN_OUTPUT@/xml"}
|
||||
31
third_party/fastgltf/docs/index.rst
vendored
Normal file
31
third_party/fastgltf/docs/index.rst
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
fastgltf
|
||||
========
|
||||
|
||||
**fastgltf** is a speed and usability focused glTF 2.0 parser written in modern C++17 with minimal dependencies.
|
||||
It uses SIMD in various areas to decrease the time the application spends parsing and loading glTF data.
|
||||
By taking advantage of modern C++17 (and optionally C++20) it also provides easy and safe access to the properties and data.
|
||||
|
||||
The parser supports the entirety of glTF 2.0 specification, including many extensions.
|
||||
By default, fastgltf will only do the absolute minimum to work with a glTF model.
|
||||
However, it brings many additional features to ease working with the data,
|
||||
including accessor tools, the ability to directly write to mapped GPU buffers, and decomposing transform matrices.
|
||||
|
||||
|
||||
Indices and tables
|
||||
------------------
|
||||
|
||||
* :doc:`overview`
|
||||
* :doc:`tools`
|
||||
* :doc:`options`
|
||||
* :doc:`api`
|
||||
|
||||
|
||||
.. toctree::
|
||||
:caption: Documentation
|
||||
:hidden:
|
||||
:maxdepth: 2
|
||||
|
||||
overview
|
||||
tools
|
||||
options
|
||||
api
|
||||
67
third_party/fastgltf/docs/options.rst
vendored
Normal file
67
third_party/fastgltf/docs/options.rst
vendored
Normal file
@@ -0,0 +1,67 @@
|
||||
*******
|
||||
Options
|
||||
*******
|
||||
|
||||
.. contents:: Table of Contents
|
||||
|
||||
CMake options
|
||||
=============
|
||||
|
||||
FASTGLTF_DOWNLOAD_SIMDJSON
|
||||
--------------------------
|
||||
|
||||
A ``BOOL`` option that tells fastgltf's CMake script whether it should download the simdjson sources itself.
|
||||
|
||||
* If set to ``YES`` the script will automatically download the amalgamated simdjson header and source files and link them into fastgltf.
|
||||
* If set to ``NO`` the CMake script expects a ``simdjson::simdjson`` target to exist against which it tries to link.
|
||||
This target needs to also use the amalgamated simdjson.h header.
|
||||
|
||||
|
||||
FASTGLTF_USE_CUSTOM_SMALLVECTOR
|
||||
-------------------------------
|
||||
|
||||
While fastgltf uses its custom ``SmallVector`` class in various areas by default, it might be useful to enable it in more places.
|
||||
|
||||
|
||||
FASTGLTF_ENABLE_TESTS
|
||||
---------------------
|
||||
|
||||
To build and run the tests and benchmarks you need to set this ``BOOL`` option to ``YES``.
|
||||
When this option is set, the ``fastgltf_tests`` target will be configured.
|
||||
The tests target depends on various dependencies, which will need to be downloaded before configuring CMake using ``fetch_test_deps.py``.
|
||||
|
||||
|
||||
FASTGLTF_ENABLE_EXAMPLES
|
||||
------------------------
|
||||
|
||||
To build and run the examples you need to this ``BOOL`` option to ``YES``.
|
||||
When this option is set, all targets from examples will be configured.
|
||||
The CMake targets depend on various dependencies, which will need to be downloaded before configuring CMake using ``fetch_test_deps.py``.
|
||||
|
||||
|
||||
FASTGLTF_ENABLE_DOCS
|
||||
--------------------
|
||||
|
||||
.. _doxygen: https://https://www.doxygen.nl/
|
||||
.. _sphinx: https://github.com/sphinx-doc/sphinx
|
||||
.. _breathe: https://github.com/breathe-doc/breathe
|
||||
|
||||
This ``BOOL`` option controls whether the targets and commands related to the documentation should be configured.
|
||||
Setting this to ``YES`` requires `Doxygen`_, `Sphinx`_ and `breathe`_ to be installed.
|
||||
|
||||
|
||||
FASTGLTF_ENABLE_GLTF_RS
|
||||
-----------------------
|
||||
|
||||
.. _corrosion: https://github.com/corrosion-rs/corrosion/
|
||||
.. _gltf-rs: https://github.com/gltf-rs/gltf
|
||||
|
||||
When this ``BOOL`` option is set to ``YES`` fastgltf will use `corrosion`_, which is downloaded using ``fetch_test_deps.py``,
|
||||
to link against the `gltf-rs`_ Rust library for comparison within the benchmarks.
|
||||
Note that this option has no effect when ``FASTGLTF_ENABLE_TESTS`` is set to ``NO``.
|
||||
|
||||
|
||||
Parsing options
|
||||
===============
|
||||
|
||||
For more information about the options when parsing a file, see :ref:`the API reference<options>`.
|
||||
222
third_party/fastgltf/docs/overview.rst
vendored
Normal file
222
third_party/fastgltf/docs/overview.rst
vendored
Normal file
@@ -0,0 +1,222 @@
|
||||
********
|
||||
Overview
|
||||
********
|
||||
|
||||
.. contents:: Table of Contents
|
||||
|
||||
**fastgltf** is a speed and usability focused glTF 2.0 parser written in modern C++17 with minimal dependencies.
|
||||
It uses SIMD in various areas to decrease the time the application spends parsing and loading glTF data.
|
||||
By taking advantage of modern C++17 (and optionally C++20) it also provides easy and safe access to the properties and data.
|
||||
|
||||
The parser supports the entirety of glTF 2.0 specification, including many extensions.
|
||||
By default, fastgltf will only do the absolute minimum to work with a glTF model.
|
||||
However, it brings many additional features to ease working with the data,
|
||||
including accessor tools, the ability to directly write to mapped GPU buffers, and decomposing transform matrices.
|
||||
|
||||
|
||||
.. _why:
|
||||
|
||||
Why use fastgltf?
|
||||
=================
|
||||
|
||||
There are many other options for working with glTF in C and C++, including the two most popular libraries tinygltf_ and cgltf_.
|
||||
These have been around for years and support virtually everything you need, so why would you even switch?
|
||||
|
||||
.. _tinygltf: https://github.com/syoyo/tinygltf
|
||||
.. _cgltf: https://github.com/jkuhlmann/cgltf
|
||||
|
||||
This table includes a quick overview of a comparison of the general quality-of-life features of the popular
|
||||
glTF libraries.
|
||||
|
||||
.. list-table::
|
||||
:header-rows: 1
|
||||
|
||||
* -
|
||||
- cgltf
|
||||
- tinygltf
|
||||
- fastgltf
|
||||
* - glTF 2.0 reading
|
||||
- ✔️
|
||||
- ✔️
|
||||
- ✔️
|
||||
* - glTF 2.0 writing
|
||||
- ✔️
|
||||
- ✔️
|
||||
- ❌
|
||||
* - Extension support
|
||||
- ✔️
|
||||
- 🟡¹
|
||||
- ✔️
|
||||
* - Image decoding (PNG, JPEG, ...)
|
||||
- ✔️
|
||||
- ✔️
|
||||
- ❌
|
||||
* - Built-in Draco decompression
|
||||
- ❌
|
||||
- ✔️
|
||||
- ❌
|
||||
* - Memory callbacks
|
||||
- ✔️
|
||||
- ❌
|
||||
- 🟡²
|
||||
* - Android asset functionality
|
||||
- ❌
|
||||
- ✔️
|
||||
- ✔️
|
||||
* - Accessor utilities
|
||||
- ✔️
|
||||
- ❌
|
||||
- ✔️
|
||||
* - Sparse accessor utilities
|
||||
- 🟡³
|
||||
- ❌
|
||||
- ✔️
|
||||
* - Matrix accessor utilities
|
||||
- 🟡³
|
||||
- ❌
|
||||
- ✔️
|
||||
* - Node transform utilities
|
||||
- ✔️
|
||||
- ❌
|
||||
- ✔️
|
||||
|
||||
¹ tinygltf does provide the JSON structure for extension data, but leaves the deserialization for you to do.
|
||||
² fastgltf allows the user to allocate memory for buffers and images.
|
||||
It does not provide any mechanism for controlling all the heap allocations the library performs.
|
||||
³ cgltf supports sparse accessors and matrix data only with some accessor functions, but not all.
|
||||
|
||||
You can read more about the accessor utilities from fastgltf :ref:`here <accessor-tools>`.
|
||||
|
||||
fastgltf follows C++'s concept of "you don't pay for what you don't use" by only doing the absolute minimum by default.
|
||||
Without specifying any options, fastgltf will only parse the specified parts of the glTF JSON.
|
||||
For buffers and images, fastgltf will by default only either give you buffers,
|
||||
when the buffer or image data is embedded within the glTF, or just the plain old URIs.
|
||||
Still, fastgltf offers various options that will let the library load buffers and images into memory,
|
||||
which can be controlled with the memory map/unmap callbacks.
|
||||
These can also be used for mapping GPU buffers so that fastgltf will write or decode base64 data directly into GPU memory.
|
||||
|
||||
By using modern C++ features, the code that reads data and properties from the glTF becomes simpler and vastly more descriptive,
|
||||
which is a big aspect of guaranteeing code-correctness.
|
||||
A big factor for this improvement is the use of types which enforce certain properties about the data, like e.g. ``std::variant`` or ``std::optional``.
|
||||
Compared with tinygltf, where, for example, optional values are simply represented by a boolean or a ``-1`` for indices, this is a big improvement.
|
||||
|
||||
The biggest difference, which may not be as relevant to everyone, is the drastic increase in deserialization speed.
|
||||
In some cases, fastgltf is at least 2 times quicker than its competitors, while in others it can be as much as 20 times.
|
||||
You can read more about fastgltf's performance in the :ref:`performance chapter <performance>`.
|
||||
|
||||
|
||||
.. _usage:
|
||||
|
||||
Usage
|
||||
=====
|
||||
|
||||
.. _vcpkg: https://github.com/microsoft/vcpkg
|
||||
.. _conan: https://conan.io/
|
||||
|
||||
fastgltf is a pure C++17 library and only depends on simdjson.
|
||||
By using the included CMake 3.11 script, simdjson is automatically downloaded while configuring by default.
|
||||
The library is tested on GCC 9, GCC 10, Clang 13, and MSVC 14 (Visual Studio 2022) using CI.
|
||||
fastgltf is also available from vcpkg_ and conan_.
|
||||
|
||||
The following snippet illustrates how to use fastgltf to load a glTF file.
|
||||
|
||||
.. code:: c++
|
||||
|
||||
#include <fastgltf/parser.hpp>
|
||||
#include <fastgltf/types.hpp>
|
||||
|
||||
void load(std::filesystem::path path) {
|
||||
// Creates a Parser instance. Optimally, you should reuse this across loads, but don't use it
|
||||
// across threads. To enable extensions, you have to pass them into the parser's constructor.
|
||||
fastgltf::Parser parser;
|
||||
|
||||
// The GltfDataBuffer class is designed for re-usability of the same JSON string. It contains
|
||||
// utility functions to load data from a std::filesystem::path, copy from an existing buffer,
|
||||
// or re-use an already existing allocation. Note that it has to outlive the process of every
|
||||
// parsing function you call.
|
||||
fastgltf::GltfDataBuffer data;
|
||||
data.loadFromFile(path);
|
||||
|
||||
// This loads the glTF file into the gltf object and parses the JSON. For GLB files, use
|
||||
// Parser::loadBinaryGLTF instead.
|
||||
// You can detect the type of glTF using fastgltf::determineGltfFileType.
|
||||
auto asset = parser.loadGLTF(&data, path.parent_path(), fastgltf::Options::None);
|
||||
if (auto error = asset.error(); error != fastgltf::Error::None) {
|
||||
// Some error occurred while reading the buffer, parsing the JSON, or validating the data.
|
||||
}
|
||||
|
||||
// The glTF 2.0 asset is now ready to be used. Simply call asset.get(), asset.get_if() or
|
||||
// asset-> to get a direct reference to the Asset class. You can then access the glTF data
|
||||
// structures, like, for example, with buffers:
|
||||
for (auto& buffer : asset->buffers) {
|
||||
// Process the buffers.
|
||||
}
|
||||
|
||||
// Optionally, you can now also call the fastgltf::validate method. This will more strictly
|
||||
// enforce the glTF spec and is not needed most of the time, though I would certainly
|
||||
// recommend it in a development environment or when debugging to avoid mishaps.
|
||||
|
||||
// fastgltf::validate(asset.get());
|
||||
}
|
||||
|
||||
|
||||
All the nodes, meshes, buffers, textures, ... can now be accessed through the ``fastgltf::Asset`` type.
|
||||
References in between objects are done with a single ``size_t``,
|
||||
which is used to index into the various vectors in the asset.
|
||||
|
||||
|
||||
.. _accessor-tools:
|
||||
|
||||
Accessor tools
|
||||
==============
|
||||
|
||||
fastgltf provides a utility header for working with accessors.
|
||||
The header contains various functions and utilities for reading, copying, and converting accessor data.
|
||||
All of these tools also directly support sparse accessors to help add support for these without having to understand how they work.
|
||||
These utilities are meant to drastically simplify using glTF accessors and buffers.
|
||||
|
||||
You can learn more about this feature of fastgltf in the dedicated chapter: :doc:`tools`.
|
||||
However, to give a quick overview this is a simple example of how to load the indices of a primitive:
|
||||
|
||||
.. code:: c++
|
||||
|
||||
fastgltf::Primitive& primitive = ...;
|
||||
|
||||
std::vector<std::uint32_t> indices;
|
||||
if (primitive.indicesAccessor.has_value()) {
|
||||
auto& accessor = asset->accessors[primitive.indicesAccessor.value()];
|
||||
indices.resize(accessor.count);
|
||||
|
||||
fastgltf::iterateAccessorWithIndex<std::uint32_t>(
|
||||
asset.get(), accessor, [&](std::uint32_t index, std::size_t idx) {
|
||||
indices[idx] = index;
|
||||
});
|
||||
}
|
||||
|
||||
.. _performance:
|
||||
|
||||
Performance
|
||||
===========
|
||||
|
||||
.. _spreadsheet-link: https://docs.google.com/spreadsheets/d/1ocdHGoty-rF0N46ZlAlswzcPHVRsqG_tncy8paD3iMY/edit?usp=sharing
|
||||
.. _two-cylinder-engine: https://github.com/KhronosGroup/glTF-Sample-Models/tree/master/2.0/2CylinderEngine
|
||||
.. _bistro: https://developer.nvidia.com/orca/amazon-lumberyard-bistro
|
||||
|
||||
In this chapter, I'll show some graphs on how fastgltf compares to the two most used glTF libraries, cgltf and tinygltf.
|
||||
I've disabled loading of images and buffers to only compare the JSON parsing and deserialization of the glTF data.
|
||||
The values and the graphs themselves can be found in `this spreadsheet <spreadsheet-link>`_.
|
||||
These numbers were benchmarked using Catch2's benchmark tool on a Ryzen 5800X (with AVX2) with 32GB of RAM using Clang 16,
|
||||
as Clang showed a significant performance improvement over MSVC in every test.
|
||||
|
||||
First, I compared the performance with embedded buffers that are encoded with base64.
|
||||
This uses the `2CylinderEngine asset <two-cylinder-engine>`_ which contains a 1.7MB embedded buffer.
|
||||
fastgltf includes an optimised base64 decoding algorithm that can take advantage of AVX2, SSE4, and ARM Neon.
|
||||
With this asset, fastgltf is **20.56 times faster** than tinygltf using RapidJSON and **6.5 times faster** than cgltf.
|
||||
|
||||
.. image:: https://cdn.discordapp.com/attachments/442748131898032138/1088470860333060207/Mean_time_parsing_2CylinderEngine_ms_8.png
|
||||
|
||||
`Amazon's Bistro <bistro>`_ (converted to glTF 2.0 using Blender) is another excellent test subject, as it's a 148k line long JSON.
|
||||
This shows the raw deserialization speed of all the parsers.
|
||||
In this case fastgltf is **2.1 times faster** than tinygltf and **5.6 times faster** than cgltf.
|
||||
|
||||
.. image:: https://cdn.discordapp.com/attachments/442748131898032138/1088470983024840754/Bistro_load_from_memory_without_images_and_buffer_load_1.png
|
||||
125
third_party/fastgltf/docs/tools.rst
vendored
Normal file
125
third_party/fastgltf/docs/tools.rst
vendored
Normal file
@@ -0,0 +1,125 @@
|
||||
**************
|
||||
Accessor tools
|
||||
**************
|
||||
|
||||
.. contents:: Table of Contents
|
||||
|
||||
fastgltf provides a utility header for working with accessors. The header contains various functions
|
||||
and utilities for reading, copying, and converting accessor data. All of these tools also directly
|
||||
support sparse accessors to help add support for these without having to understand how they work.
|
||||
This header was written by `forenoonwatch <https://github.com/forenoonwatch>`_ with the help of
|
||||
`Eearslya <https://github.com/Eearslya>`_ and me.
|
||||
|
||||
All related functions are templated and take ``T`` as an argument.
|
||||
This type has to be have a ``ElementTraits`` specialization, which provides information about the
|
||||
vector properties and data properties.
|
||||
Using this information, fastgltf can convert the accessor data into your preferred format.
|
||||
For example, ``glm::vec3`` would be a vector of 3 floats, which would be defined like this:
|
||||
|
||||
.. code:: c++
|
||||
|
||||
template <>
|
||||
struct fastgltf::ElementTraits<glm::vec3> : fastgltf::ElementTraitsBase<glm::vec3, AccessorType::Vec3, float> {};
|
||||
|
||||
Note that, for glm types, there is a header with all pre-defined types shipped with fastgltf: ``fastgltf/glm_element_traits.hpp``.
|
||||
This header includes the ElementTraits definition for all relevant glm types.
|
||||
|
||||
|
||||
.. warning::
|
||||
|
||||
Note that, by default, these functions will only be able to load from buffers where the source is either a ``sources::ByteView`` or a ``sources::Vector``.
|
||||
For other data sources, you'll need to provide a functor similar to the already provided ``DefaultBufferDataAdapter`` to the last parameter of each function.
|
||||
For more detailed documentation about this see :ref:`this section <bufferdataadapter>`.
|
||||
|
||||
getAccessorElement
|
||||
==================
|
||||
|
||||
This function can be used to retrieve a single element from an accessor using an index.
|
||||
It handles sparse accessors and can properly convert the type.
|
||||
|
||||
.. doxygenfunction:: getAccessorElement(const Asset& asset, const Accessor& accessor, size_t index, const BufferDataAdapter& adapter) -> ElementType
|
||||
|
||||
|
||||
iterateAccessor
|
||||
===============
|
||||
|
||||
Using ``iterateAccessor`` you can iterate over the data of an accessor using a lambda, similarly to ``std::for_each``.
|
||||
|
||||
.. doxygenfunction:: iterateAccessor(const Asset &asset, const Accessor &accessor, Functor &&func, const BufferDataAdapter &adapter) -> void
|
||||
|
||||
.. code:: c++
|
||||
|
||||
fastgltf::Primitive& primitive = ...;
|
||||
|
||||
std::vector<std::uint32_t> indices;
|
||||
if (primitive.indicesAccessor.has_value()) {
|
||||
auto& accessor = asset->accessors[primitive.indicesAccessor.value()];
|
||||
indices.resize(accessor.count);
|
||||
|
||||
std::size_t idx = 0;
|
||||
fastgltf::iterateAccessor<std::uint32_t>(asset.get(), accessor, [&](std::uint32_t index) {
|
||||
indices[idx++] = index;
|
||||
});
|
||||
}
|
||||
|
||||
iterateAccessorWithIndex
|
||||
========================
|
||||
|
||||
Functionally identical to ``iterateAccessor``, but provides you with the current index as the second parameter to the lambda.
|
||||
|
||||
.. doxygenfunction:: iterateAccessorWithIndex(const Asset &asset, const Accessor &accessor, Functor &&func, const BufferDataAdapter &adapter) -> void
|
||||
|
||||
|
||||
copyFromAccessor
|
||||
================
|
||||
|
||||
This function essentially does a ``memcpy`` on the contents of the accessor data.
|
||||
In cases where the `ElementType` is default-constructible, and the accessor type allows direct copying, this performs a direct ``memcpy``.
|
||||
Otherwise, this function properly respects normalization and sparse accessors while copying and converting the data.
|
||||
|
||||
.. doxygenfunction:: copyFromAccessor(const Asset &asset, const Accessor &accessor, void *dest, const BufferDataAdapter &adapter = {}) -> void
|
||||
|
||||
|
||||
Accessor iterators
|
||||
==================
|
||||
|
||||
fastgltf also provides C++ iterators over accessor data to support the syntactic sugar of C++11's range-based for-loops.
|
||||
These iterators can be obtained using ``iterateAccessor``, and can be used like so:
|
||||
|
||||
.. doxygenfunction:: iterateAccessor(const Asset& asset, const Accessor& accessor, const BufferDataAdapter& adapter = {}) -> IterableAccessor<ElementType, BufferDataAdapter>
|
||||
|
||||
.. code:: c++
|
||||
|
||||
std::size_t idx = 0;
|
||||
for (auto element : fastgltf::iterateAccessor(asset.get(), accessor)) {
|
||||
array[idx++] = element;
|
||||
}
|
||||
|
||||
|
||||
.. _bufferdataadapter:
|
||||
|
||||
BufferDataAdapter interface
|
||||
===========================
|
||||
|
||||
The accessor tools acquire the binary data through this functional interface.
|
||||
By default, fastgltf provides a ``DefaultBufferDataAdapter`` struct.
|
||||
The accessor functions also default to using this class,
|
||||
however it is important to note that this default interface only works with buffers or images that have a ``sources::Vectors`` or a ``sources::ByteView`` in the ``DataSource`` member.
|
||||
|
||||
.. doxygenstruct:: fastgltf::DefaultBufferDataAdapter
|
||||
:members:
|
||||
:undoc-members:
|
||||
|
||||
If you do not provide Options::LoadExternalBuffers to the Parser while loading the glTF,
|
||||
external buffers will be available as ``sources::URI`` and will not work with the ``DefaultBufferDataAdapter``.
|
||||
Therefore, you'll either have to set that option or provide a custom functional interface that properly returns a pointer to the memory.
|
||||
|
||||
As this is a functional interface it is possible to also use lambdas for this:
|
||||
|
||||
.. code:: c++
|
||||
|
||||
std::vector<std::byte> fileBytes;
|
||||
std::vector<std::uint8_t> accessorData(accessor.count);
|
||||
fastgltf::copyFromAccessor(asset.get(), accessor, accessorData.data(), [&](const fastgltf::Buffer& buffer) const {
|
||||
return fileBytes.data();
|
||||
});
|
||||
Reference in New Issue
Block a user