{"id":16985204,"url":"https://github.com/kooparse/zgltf","last_synced_at":"2025-04-09T07:09:54.833Z","repository":{"id":78350568,"uuid":"474277621","full_name":"kooparse/zgltf","owner":"kooparse","description":"A glTF parser for Zig codebase.","archived":false,"fork":false,"pushed_at":"2025-03-08T14:08:27.000Z","size":106,"stargazers_count":61,"open_issues_count":2,"forks_count":16,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-02T21:40:14.466Z","etag":null,"topics":["gamedev","gltf","parser","zig"],"latest_commit_sha":null,"homepage":"","language":"Zig","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/kooparse.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":"2022-03-26T07:43:15.000Z","updated_at":"2025-03-28T18:32:36.000Z","dependencies_parsed_at":"2024-02-16T11:29:17.199Z","dependency_job_id":"523af5ba-1c51-41c0-8790-21dbd61e0754","html_url":"https://github.com/kooparse/zgltf","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kooparse%2Fzgltf","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kooparse%2Fzgltf/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kooparse%2Fzgltf/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kooparse%2Fzgltf/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kooparse","download_url":"https://codeload.github.com/kooparse/zgltf/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247994122,"owners_count":21030050,"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":["gamedev","gltf","parser","zig"],"created_at":"2024-10-14T02:42:55.441Z","updated_at":"2025-04-09T07:09:54.805Z","avatar_url":"https://github.com/kooparse.png","language":"Zig","funding_links":[],"categories":[],"sub_categories":[],"readme":"# glTF parser for Zig codebase\n\nThis project is a glTF 2.0 parser written in Zig, aiming to replace the use of some C/C++ libraries. All glTF types are fully documented, so it comes nicely with IDE autocompletion, reducing\nback and forth with the [specification](https://www.khronos.org/registry/glTF/specs/2.0/glTF-2.0.html).\n\nThis library intends to mimic the glTF file structure in memory. Thereby it's designed around arrays and indexes instead of pointers as you may see in `cgltf` or other libraries. Also, it's the **user's responsibility** to load glTF files and their related binaries in memory.\n\nNote: It's not as complete as the glTF specification yet, but because it's straightforward to add new parsed fields, we'll get new stuff incrementally and on-demand.\n\nIf you would like to contribute, don't hesitate! :)\n\nNote: The main branch is for the latest Zig release (0.14.x).\n\n## Examples\n\n```zig\nconst std = @import(\"std\");\nconst Gltf = @import(\"zgltf\");\n\nconst allocator = std.heap.page_allocator;\nconst print = std.debug.print;\n\npub fn main() void {\n    const buffer = try std.fs.cwd().readFileAllocOptions(\n        allocator,\n        \"test-samples/rigged_simple/RiggedSimple.gltf\",\n        512_000,\n        null,\n        4,\n        null\n    );\n    defer allocator.free(buf);\n\n    var gltf = Self.init(allocator);\n    defer gltf.deinit();\n\n    try gltf.parse(buf);\n\n    for (gltf.nodes.items) |node| {\n        const message =\n            \\\\\\ Node's name: {s}\n            \\\\\\ Children count: {}\n            \\\\\\ Have skin: {}\n        ;\n\n        print(message, .{\n            node.name,\n            node.children.items.len,\n            node.skin != null,\n        });\n    }\n\n    // Or use the debufPrint method.\n    gltf.debugPrint();\n}\n```\n\nAlso you could easily load data from an `Accessor` with `getDataFromBufferView`:\n\n```zig\nconst gltf = Gltf.init(allocator);\ntry gltf.parse(my_gltf_buf);\n\nconst bin = try std.fs.cwd().readFileAllocOptions(\n    allocator,\n    \"test-samples/rigged_simple/RiggedSimple0.bin\",\n    5_000_000,\n    null,\n    4,\n    null\n);\ndefer allocator.free(buf);\n\nvar vertices = ArrayList(f32).init(allocator);\ndefer vertices.deinit();\n\nconst mesh = gltf.data.meshes.items[0];\nfor (mesh.primitives.items) |primitive| {\n    for (primitive.attributes.items) |attribute| {\n        switch (attribute) {\n            // Accessor for mesh vertices:\n            .position =\u003e |accessor_index| {\n                const accessor = gltf.data.accessors.items[accessor_index];\n                gltf.getDataFromBufferView(f32, \u0026vertices, accessor, bin);\n            },\n            else =\u003e {}\n        }\n    }\n}\n\n```\n\nAlso, there is an `iterator` method that helps you pull data from accessors:\n\n```zig\n// ...\nfor (primitive.attributes.items) |attribute| {\n    switch (attribute) {\n        .position =\u003e |idx| {\n            const accessor = gltf.data.accessors.items[idx];\n            var it = accessor.iterator(f32, \u0026gltf, gltf.glb_binary.?);\n            while (it.next()) |v| {\n                try vertices.append(.{\n                    .pos = .{ v[0], v[1], v[2] },\n                    .normal = .{ 1, 0, 0 },\n                    .color = .{ 1, 1, 1, 1 },\n                    .uv_x = 0,\n                    .uv_y = 0,\n                });\n            }\n        },\n        .normal =\u003e |idx| {\n            const accessor = gltf.data.accessors.items[idx];\n            var it = accessor.iterator(f32, \u0026gltf, gltf.glb_binary.?);\n            var i: u32 = 0;\n            while (it.next()) |n| : (i += 1) {\n                vertices.items[initial_vertex + i].normal = .{ n[0], n[1], n[2] };\n            }\n        },\n        else =\u003e {},\n    }\n}\n```\n\n## Install\n\nNote: **Zig 0.11.x is required.**\n\n```zig\nconst zgltf = @import(\"path-to-zgltf/build.zig\");\nexe.addModule(\"zgltf\", zgltf.module(b));\n```\n\n## Features\n\n- [x] glTF 2.0 json file\n- [x] Scenes\n- [x] Nodes\n- [x] Buffers/BufferViews\n- [x] Meshes\n- [x] Images\n- [x] Materials\n- [x] Animations\n- [x] Skins\n- [x] Cameras\n- [x] Parse `glb` files\n- [ ] Morth targets\n- [ ] Extras data\n- [ ] glTF writer\n\nAlso, we supports some glTF extensions:\n\n- [x] khr_lights_punctual\n- [x] khr_materials_emissive_strength\n- [x] khr_materials_ior\n- [x] khr_materials_transmission\n- [x] khr_materials_volume\n- [x] khr_materials_dispersion\n\n## Contributing to the project\n\nDon’t be shy about shooting any questions you may have. If you are a beginner/junior, don’t hesitate, I will always encourage you. It’s a safe place here. Also, I would be very happy to receive any kind of pull requests, you will have (at least) some feedback/guidance rapidly.\n\nBehind screens, there are human beings, living any sort of story. So be always kind and respectful, because we all sheer to learn new things.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkooparse%2Fzgltf","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkooparse%2Fzgltf","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkooparse%2Fzgltf/lists"}