{"id":26491995,"url":"https://github.com/zig-gamedev/zmesh","last_synced_at":"2025-03-20T08:51:38.427Z","repository":{"id":270770705,"uuid":"882854872","full_name":"zig-gamedev/zmesh","owner":"zig-gamedev","description":"Zig library for loading, generating, processing and optimising triangle meshes.","archived":false,"fork":false,"pushed_at":"2025-02-16T19:09:41.000Z","size":594,"stargazers_count":9,"open_issues_count":0,"forks_count":6,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-16T20:20:58.584Z","etag":null,"topics":["3d","gamedev","mesh-generation","mesh-optimization","mesh-processing","zig"],"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/zig-gamedev.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":"2024-11-03T23:16:59.000Z","updated_at":"2025-02-16T19:09:45.000Z","dependencies_parsed_at":null,"dependency_job_id":"1c7d407a-a2af-405a-894a-1389ea223706","html_url":"https://github.com/zig-gamedev/zmesh","commit_stats":null,"previous_names":["zig-gamedev/zmesh"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zig-gamedev%2Fzmesh","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zig-gamedev%2Fzmesh/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zig-gamedev%2Fzmesh/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zig-gamedev%2Fzmesh/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zig-gamedev","download_url":"https://codeload.github.com/zig-gamedev/zmesh/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244583172,"owners_count":20476233,"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","gamedev","mesh-generation","mesh-optimization","mesh-processing","zig"],"created_at":"2025-03-20T08:51:37.904Z","updated_at":"2025-03-20T08:51:38.411Z","avatar_url":"https://github.com/zig-gamedev.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"![image](logo.jpg)\n\n# [zmesh](https://github.com/zig-gamedev/zmesh)\n\nZig library for loading, generating, processing and optimising triangle meshes.\n\nUnder the hood this library uses below C/C++ libraries:\n\n* [par shapes](https://github.com/prideout/par/blob/master/par_shapes.h)\n* [meshoptimizer](https://github.com/zeux/meshoptimizer)\n* [cgltf](https://github.com/jkuhlmann/cgltf)\n\nAll memory allocations go through user-supplied, Zig allocator.\n\nAs an example program please see [procedural mesh (wgpu)](https://github.com/michal-z/zig-gamedev/tree/main/samples/procedural_mesh_wgpu).\n\n## Getting started\n\nExample `build.zig`:\n```zig\npub fn build(b: *std.Build) void {\n    const exe = b.addExecutable(.{ ... });\n\n    const zmesh = b.dependency(\"zmesh\", .{});\n    exe.root_module.addImport(\"zmesh\", zmesh.module(\"root\"));\n    exe.linkLibrary(zmesh.artifact(\"zmesh\"));\n}\n```\n\nNow in your code you may import and use `zmesh`:\n\n```zig\nconst zmesh = @import(\"zmesh\");\n\npub fn main() !void {\n    ...\n    zmesh.init(allocator);\n    defer zmesh.deinit();\n\n    var custom = zmesh.Shape.init(indices, positions, normals, texcoords);\n    defer custom.deinit();\n\n    var disk = zmesh.Shape.initParametricDisk(10, 2);\n    defer disk.deinit();\n    disk.invert(0, 0);\n\n    var cylinder = zmesh.Shape.initCylinder(10, 4);\n    defer cylinder.deinit();\n\n    cylinder.merge(disk);\n    cylinder.translate(0, 0, -1);\n    disk.invert(0, 0);\n    cylinder.merge(disk);\n\n    cylinder.scale(0.5, 0.5, 2);\n    cylinder.rotate(math.pi * 0.5, 1.0, 0.0, 0.0);\n\n    cylinder.unweld();\n    cylinder.computeNormals();\n    ...\n}\n```\n\n```zig\nconst zmesh = @import(\"zmesh\");\n\npub fn main() !void {\n    zmesh.init(allocator);\n    defer zmesh.deinit();\n\n    //\n    // Load mesh\n    //\n    const data = try zmesh.io.zcgltf.parseAndLoadFile(content_dir ++ \"cube.gltf\");\n    defer zmesh.io.zcgltf.freeData(data);\n\n    var mesh_indices = std.ArrayList(u32).init(allocator);\n    var mesh_positions = std.ArrayList([3]f32).init(allocator);\n    var mesh_normals = std.ArrayList([3]f32).init(allocator);\n\n    zmesh.io.zcgltf.appendMeshPrimitive(\n        data,\n        0, // mesh index\n        0, // gltf primitive index (submesh index)\n        \u0026mesh_indices,\n        \u0026mesh_positions,\n        \u0026mesh_normals, // normals (optional)\n        null, // texcoords (optional)\n        null, // tangents (optional)\n    );\n    ...\n\n    //\n    // Optimize mesh\n    //\n    const Vertex = struct {\n        position: [3]f32,\n        normal: [3]f32,\n    };\n\n    var remap = std.ArrayList(u32).init(allocator);\n    remap.resize(src_indices.items.len) catch unreachable;\n\n    const num_unique_vertices = zmesh.opt.generateVertexRemap(\n        remap.items, // 'vertex remap' (destination)\n        src_indices.items, // non-optimized indices\n        Vertex, // Zig type describing your vertex\n        src_vertices.items, // non-optimized vertices\n    );\n\n    var optimized_vertices = std.ArrayList(Vertex).init(allocator);\n    optimized_vertices.resize(num_unique_vertices) catch unreachable;\n\n    zmesh.opt.remapVertexBuffer(\n        Vertex, // Zig type describing your vertex\n        optimized_vertices.items, // optimized vertices (destination)\n        src_vertices.items, // non-optimized vertices (source)\n        remap.items, // 'vertex remap' generated by generateVertexRemap()\n    );\n\n    // More optimization steps are available - see `zmeshoptimizer.zig` file.\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzig-gamedev%2Fzmesh","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzig-gamedev%2Fzmesh","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzig-gamedev%2Fzmesh/lists"}