{"id":13530857,"url":"https://github.com/jkuhlmann/cgltf","last_synced_at":"2025-05-14T00:07:25.553Z","repository":{"id":37579984,"uuid":"132188670","full_name":"jkuhlmann/cgltf","owner":"jkuhlmann","description":":diamond_shape_with_a_dot_inside: Single-file glTF 2.0 loader and writer written in C99","archived":false,"fork":false,"pushed_at":"2025-03-13T19:56:04.000Z","size":446,"stargazers_count":1585,"open_issues_count":37,"forks_count":145,"subscribers_count":27,"default_branch":"master","last_synced_at":"2025-05-13T19:17:50.471Z","etag":null,"topics":["3d","c","c99","glb","gltf","gltf-loader","gltf2","gltf2-loader","single-header-lib","stb-style"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jkuhlmann.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-05-04T21:00:11.000Z","updated_at":"2025-05-12T20:45:23.000Z","dependencies_parsed_at":"2023-11-27T16:54:38.719Z","dependency_job_id":"7f72d2ea-01e9-4ad6-9871-55c7ab30c244","html_url":"https://github.com/jkuhlmann/cgltf","commit_stats":{"total_commits":331,"total_committers":37,"mean_commits":8.945945945945946,"dds":0.6344410876132931,"last_synced_commit":"7177c019be6c105fd12bc35f249e431314f2bab1"},"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jkuhlmann%2Fcgltf","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jkuhlmann%2Fcgltf/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jkuhlmann%2Fcgltf/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jkuhlmann%2Fcgltf/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jkuhlmann","download_url":"https://codeload.github.com/jkuhlmann/cgltf/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254043766,"owners_count":22005013,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["3d","c","c99","glb","gltf","gltf-loader","gltf2","gltf2-loader","single-header-lib","stb-style"],"created_at":"2024-08-01T07:00:56.602Z","updated_at":"2025-05-14T00:07:25.536Z","avatar_url":"https://github.com/jkuhlmann.png","language":"C","funding_links":[],"categories":["Libraries \u0026 Frameworks:","Libraries","C"],"sub_categories":["Other","C"],"readme":"# :diamond_shape_with_a_dot_inside: cgltf\n**Single-file/stb-style C glTF loader and writer**\n\n[![Build Status](https://github.com/jkuhlmann/cgltf/workflows/build/badge.svg)](https://github.com/jkuhlmann/cgltf/actions)\n\nUsed in: [bgfx](https://github.com/bkaradzic/bgfx), [Filament](https://github.com/google/filament), [gltfpack](https://github.com/zeux/meshoptimizer/tree/master/gltf), [raylib](https://github.com/raysan5/raylib), [Unigine](https://developer.unigine.com/en/docs/2.14.1/third_party?rlang=cpp#cgltf), and more!\n\n## Usage: Loading\nLoading from file:\n```c\n#define CGLTF_IMPLEMENTATION\n#include \"cgltf.h\"\n\ncgltf_options options = {0};\ncgltf_data* data = NULL;\ncgltf_result result = cgltf_parse_file(\u0026options, \"scene.gltf\", \u0026data);\nif (result == cgltf_result_success)\n{\n\t/* TODO make awesome stuff */\n\tcgltf_free(data);\n}\n```\n\nLoading from memory:\n```c\n#define CGLTF_IMPLEMENTATION\n#include \"cgltf.h\"\n\nvoid* buf; /* Pointer to glb or gltf file data */\nsize_t size; /* Size of the file data */\n\ncgltf_options options = {0};\ncgltf_data* data = NULL;\ncgltf_result result = cgltf_parse(\u0026options, buf, size, \u0026data);\nif (result == cgltf_result_success)\n{\n\t/* TODO make awesome stuff */\n\tcgltf_free(data);\n}\n```\n\nNote 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.\nFor buffer data, you can alternatively call `cgltf_load_buffers`, which will use `FILE*` APIs to open and read buffer files. This automatically decodes base64 data URIs in buffers. For data URIs in images, you will need to use `cgltf_load_buffer_base64`.\n\n**For more in-depth documentation and a description of the public interface refer to the top of the `cgltf.h` file.**\n\n## Usage: Writing\nWhen 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.\n\nWriting to file:\n```c\n#define CGLTF_IMPLEMENTATION\n#define CGLTF_WRITE_IMPLEMENTATION\n#include \"cgltf_write.h\"\n\ncgltf_options options = {0};\ncgltf_data* data = /* TODO must be valid data */;\ncgltf_result result = cgltf_write_file(\u0026options, \"out.gltf\", data);\nif (result != cgltf_result_success)\n{\n\t/* TODO handle error */\n}\n```\n\nWriting to memory:\n```c\n#define CGLTF_IMPLEMENTATION\n#define CGLTF_WRITE_IMPLEMENTATION\n#include \"cgltf_write.h\"\ncgltf_options options = {0};\ncgltf_data* data = /* TODO must be valid data */;\n\ncgltf_size size = cgltf_write(\u0026options, NULL, 0, data);\n\nchar* buf = malloc(size);\n\ncgltf_size written = cgltf_write(\u0026options, buf, size, data);\nif (written != size)\n{\n\t/* TODO handle error */\n}\n```\n\nNote that cgltf does not write the contents of extra files such as buffers or images. You'll need to write this data yourself.\n\n**For more in-depth documentation and a description of the public interface refer to the top of the `cgltf_write.h` file.**\n\n\n## Features\ncgltf supports core glTF 2.0:\n- glb (binary files) and gltf (JSON files)\n- meshes (including accessors, buffer views, buffers)\n- materials (including textures, samplers, images)\n- scenes and nodes\n- skins\n- animations\n- cameras\n- morph targets\n- extras data\n\ncgltf also supports some glTF extensions:\n- EXT_mesh_gpu_instancing\n- EXT_meshopt_compression\n- EXT_texture_webp\n- KHR_draco_mesh_compression (requires a library like [Google's Draco](https://github.com/google/draco) for decompression though)\n- KHR_lights_punctual\n- KHR_materials_anisotropy\n- KHR_materials_clearcoat\n- KHR_materials_diffuse_transmission\n- KHR_materials_dispersion\n- KHR_materials_emissive_strength\n- KHR_materials_ior\n- KHR_materials_iridescence\n- KHR_materials_pbrSpecularGlossiness\n- KHR_materials_sheen\n- KHR_materials_specular\n- KHR_materials_transmission\n- KHR_materials_unlit\n- KHR_materials_variants\n- KHR_materials_volume\n- KHR_texture_basisu (requires a library like [Binomial Basisu](https://github.com/BinomialLLC/basis_universal) for transcoding to native compressed texture)\n- KHR_texture_transform\n\ncgltf does **not** yet support unlisted extensions. However, unlisted extensions can be accessed via \"extensions\" member on objects.\n\n## Building\nThe 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:\n\n1. Include `cgltf.h` where you need the functionality.\n1. Have exactly one source file that defines `CGLTF_IMPLEMENTATION` before including `cgltf.h`.\n1. Use the cgltf functions as described above.\n\nSupport 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.\n\n## Contributing\nEveryone 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.\n\n\n## Dependencies\nNone.\n\nC headers being used by the implementation:\n```\n#include \u003cstddef.h\u003e\n#include \u003cstdint.h\u003e\n#include \u003cstring.h\u003e\n#include \u003cstdlib.h\u003e\n#include \u003cstdio.h\u003e\n#include \u003climits.h\u003e\n#include \u003cassert.h\u003e // If asserts are enabled.\n```\n\nNote, this library has a copy of the [JSMN JSON parser](https://github.com/zserge/jsmn) embedded in its source.\n\n## Testing\nThere 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.\n\nHere's one way to build and run the test:\n\n    cd test ; mkdir build ; cd build ; cmake .. -DCMAKE_BUILD_TYPE=Debug\n    make -j\n    cd ..\n    ./test_all.py\n\nThere is also a llvm-fuzz test in `fuzz/`. See http://llvm.org/docs/LibFuzzer.html for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjkuhlmann%2Fcgltf","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjkuhlmann%2Fcgltf","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjkuhlmann%2Fcgltf/lists"}