aboutsummaryrefslogtreecommitdiff
path: root/contrib/cgltf/README.md
diff options
context:
space:
mode:
author3gg <3gg@shellblade.net>2025-06-27 10:18:39 -0700
committer3gg <3gg@shellblade.net>2025-06-27 10:18:39 -0700
commitbd57f345ed9dbed1d81683e48199626de2ea9044 (patch)
tree4221f2f2a7ad2244d2e93052bd68187ec91b8ea9 /contrib/cgltf/README.md
parent9a82ce0083437a4f9f58108b2c23b957d2249ad8 (diff)
Restructure projectHEADmain
Diffstat (limited to 'contrib/cgltf/README.md')
-rw-r--r--contrib/cgltf/README.md154
1 files changed, 154 insertions, 0 deletions
diff --git a/contrib/cgltf/README.md b/contrib/cgltf/README.md
new file mode 100644
index 0000000..3b49d52
--- /dev/null
+++ b/contrib/cgltf/README.md
@@ -0,0 +1,154 @@
1# :diamond_shape_with_a_dot_inside: cgltf
2**Single-file/stb-style C glTF loader and writer**
3
4[![Build Status](https://travis-ci.org/jkuhlmann/cgltf.svg?branch=master)](https://travis-ci.org/jkuhlmann/cgltf)
5
6Used in: [bgfx](https://github.com/bkaradzic/bgfx), [Filament](https://github.com/google/filament), [meshoptimizer](https://github.com/zeux/meshoptimizer), [raylib](https://github.com/raysan5/raylib), and more!
7
8## Usage: Loading
9Loading from file:
10```c
11#define CGLTF_IMPLEMENTATION
12#include "cgltf.h"
13
14cgltf_options options = {0};
15cgltf_data* data = NULL;
16cgltf_result result = cgltf_parse_file(&options, "scene.gltf", &data);
17if (result == cgltf_result_success)
18{
19 /* TODO make awesome stuff */
20 cgltf_free(data);
21}
22```
23
24Loading from memory:
25```c
26#define CGLTF_IMPLEMENTATION
27#include "cgltf.h"
28
29void* buf; /* Pointer to glb or gltf file data */
30size_t size; /* Size of the file data */
31
32cgltf_options options = {0};
33cgltf_data* data = NULL;
34cgltf_result result = cgltf_parse(&options, buf, size, &data);
35if (result == cgltf_result_success)
36{
37 /* TODO make awesome stuff */
38 cgltf_free(data);
39}
40```
41
42Note that cgltf does not load the contents of extra files such as buffers or images into memory by default. You'll need to read these files yourself using URIs from `data.buffers[]` or `data.images[]` respectively.
43For buffer data, you can alternatively call `cgltf_load_buffers`, which will use `FILE*` APIs to open and read buffer files.
44
45**For more in-depth documentation and a description of the public interface refer to the top of the `cgltf.h` file.**
46
47## Usage: Writing
48When writing glTF data, you need a valid `cgltf_data` structure that represents a valid glTF document. You can construct such a structure yourself or load it using the loader functions described above. The writer functions do not deallocate any memory. So, you either have to do it manually or call `cgltf_free()` if you got the data by loading it from a glTF document.
49
50Writing to file:
51```c
52#define CGLTF_IMPLEMENTATION
53#define CGLTF_WRITE_IMPLEMENTATION
54#include "cgltf_write.h"
55
56cgltf_options options = {0};
57cgltf_data* data = /* TODO must be valid data */;
58cgltf_result result = cgltf_write_file(&options, "out.gltf", data);
59if (result != cgltf_result_success)
60{
61 /* TODO handle error */
62}
63```
64
65Writing to memory:
66```c
67#define CGLTF_IMPLEMENTATION
68#define CGLTF_WRITE_IMPLEMENTATION
69#include "cgltf_write.h"
70cgltf_options options = {0};
71cgltf_data* data = /* TODO must be valid data */;
72
73cgltf_size size = cgltf_write(&options, NULL, 0, data);
74
75char* buf = malloc(size);
76
77cgltf_size written = cgltf_write(&options, buf, size, data);
78if (written != size)
79{
80 /* TODO handle error */
81}
82```
83
84Note that cgltf does not write the contents of extra files such as buffers or images. You'll need to write this data yourself.
85
86Writing does not yet support "extras" data.
87
88**For more in-depth documentation and a description of the public interface refer to the top of the `cgltf_write.h` file.**
89
90
91## Features
92cgltf supports core glTF 2.0:
93- glb (binary files) and gltf (JSON files)
94- meshes (including accessors, buffer views, buffers)
95- materials (including textures, samplers, images)
96- scenes and nodes
97- skins
98- animations
99- cameras
100- morph targets
101- extras data
102
103cgltf also supports some glTF extensions:
104- KHR_draco_mesh_compression (requires a library like [Google's Draco](https://github.com/google/draco) for decompression though)
105- KHR_lights_punctual
106- KHR_materials_clearcoat
107- KHR_materials_ior
108- KHR_materials_pbrSpecularGlossiness
109- KHR_materials_specular
110- KHR_materials_transmission
111- KHR_materials_unlit
112- KHR_texture_transform
113
114cgltf does **not** yet support unlisted extensions. However, unlisted extensions can be accessed via "extensions" member on objects.
115
116## Building
117The easiest approach is to integrate the `cgltf.h` header file into your project. If you are unfamiliar with single-file C libraries (also known as stb-style libraries), this is how it goes:
118
1191. Include `cgltf.h` where you need the functionality.
1201. Have exactly one source file that defines `CGLTF_IMPLEMENTATION` before including `cgltf.h`.
1211. Use the cgltf functions as described above.
122
123Support for writing can be found in a separate file called `cgltf_write.h` (which includes `cgltf.h`). Building it works analogously using the `CGLTF_WRITE_IMPLEMENTATION` define.
124
125## Contributing
126Everyone is welcome to contribute to the library. If you find any problems, you can submit them using [GitHub's issue system](https://github.com/jkuhlmann/cgltf/issues). If you want to contribute code, you should fork the project and then send a pull request.
127
128
129## Dependencies
130None.
131
132C headers being used by implementation:
133```
134#include <stddef.h>
135#include <stdint.h>
136#include <string.h>
137#include <stdlib.h>
138#include <stdio.h>
139#include <limits.h>
140```
141
142Note, this library has a copy of the [JSMN JSON parser](https://github.com/zserge/jsmn) embedded in its source.
143
144## Testing
145There is a Python script in the `test/` folder that retrieves the glTF 2.0 sample files from the glTF-Sample-Models repository (https://github.com/KhronosGroup/glTF-Sample-Models/tree/master/2.0) and runs the library against all gltf and glb files.
146
147Here's one way to build and run the test:
148
149 cd test ; mkdir build ; cd build ; cmake .. -DCMAKE_BUILD_TYPE=Debug
150 make -j
151 cd ..
152 ./test_all.py
153
154There is also a llvm-fuzz test in `fuzz/`. See http://llvm.org/docs/LibFuzzer.html for more information.