gdk-graphics 0a0aef92e917cfbac53dffbc32c295e4de914093
Loading...
Searching...
No Matches
gltf.h
1// © Joseph Cameron - MIT License
2
3#ifndef GDK_GRAPHICS_EXT_GLTF_H
4#define GDK_GRAPHICS_EXT_GLTF_H
5
6#include <gdk/graphics/ext/animation/skeleton.h>
7#include <gdk/graphics/ext/animation/skinning.h>
8#include <gdk/graphics/model_data.h>
9
10#include <array>
11#include <cstddef>
12#include <string>
13#include <unordered_map>
14#include <vector>
15
16namespace gdk::graphics {
21 struct gltf_mesh final {
22 model_data data;
23
25 std::string mesh_name;
26
28 std::string node_name;
29
31 std::string parent_name;
32
34 std::string material_name;
35
38
40 std::array<float, 16> local_transform{
41 1, 0, 0, 0,
42 0, 1, 0, 0,
43 0, 0, 1, 0,
44 0, 0, 0, 1};
45
47 std::vector<animation::vertex_weights> weights;
48
50 int skeleton = -1;
51 };
52
54 struct gltf_node final {
55 std::string name;
56
58 std::string parent_name;
59
61 std::array<float, 16> local_transform{
62 1, 0, 0, 0,
63 0, 1, 0, 0,
64 0, 0, 1, 0,
65 0, 0, 0, 1};
66
68 bool draws = false;
69 };
70
72 struct gltf_image final {
73 std::string name;
74
76 std::string mime_type;
77
79 std::vector<std::byte> bytes;
80 };
81
82 struct gltf_content final {
84 std::vector<gltf_mesh> meshes;
85
87 std::vector<gltf_image> images;
88
90 std::vector<gltf_node> nodes;
93 std::vector<animation::skeleton> skeletons;
94
96 std::vector<animation::clip> animations;
97 };
98
99 using gltf_attribute_names = std::unordered_map<std::string, std::string>;
100
101 [[nodiscard]] const gltf_attribute_names &default_gltf_attribute_names();
102
110 [[nodiscard]] gltf_content read_gltf(const std::string_view aData,
111 const gltf_attribute_names &aNames = default_gltf_attribute_names());
112}
113
114#endif
vertex data stored in system memory.
Definition model_data.h:25
Definition gltf.h:82
std::vector< gltf_mesh > meshes
meshes carried by the document
Definition gltf.h:84
std::vector< animation::skeleton > skeletons
Definition gltf.h:93
std::vector< gltf_image > images
images carried by the document
Definition gltf.h:87
std::vector< animation::clip > animations
every animation, as it drives the first skin
Definition gltf.h:96
std::vector< gltf_node > nodes
every node, drawing or not
Definition gltf.h:90
an encoded image in the document
Definition gltf.h:72
std::string mime_type
"image/png", "image/jpeg", or empty when the document did not say
Definition gltf.h:76
std::vector< std::byte > bytes
the file as it sits in the document, PNG or JPEG bytes and not channel data
Definition gltf.h:79
one drawable piece of a glTF document: a primitive, as one node draws it
Definition gltf.h:21
std::string material_name
the name of the glTF material this primitive draws with, empty if it has none
Definition gltf.h:34
std::string parent_name
the name of the parent node, empty if this is the root node
Definition gltf.h:31
std::array< float, 16 > local_transform
this node's transform relative to its parent, row major, identity by default
Definition gltf.h:40
int skeleton
index into gltf_content::skeletons, or -1 when the primitive is not skinned
Definition gltf.h:50
int base_color_image
the image this primitive's material paints with, or -1 for none
Definition gltf.h:37
std::string mesh_name
the name of the glTF mesh this came from, empty if it is unnamed
Definition gltf.h:25
std::string node_name
the name of the node that draws this mesh, empty if no node does
Definition gltf.h:28
std::vector< animation::vertex_weights > weights
per-vertex influences, empty if the primitive is not skinned.
Definition gltf.h:47
a node of the document
Definition gltf.h:54
std::string parent_name
empty if root node
Definition gltf.h:58
bool draws
whether it draws, and so whether it also appears in gltf_content::meshes
Definition gltf.h:68
std::array< float, 16 > local_transform
relative to the parent
Definition gltf.h:61