A Zig library for loading and processing meshes.
Requires Zig 0.16.0.
Under active development, APIs may change.
- More loaders: OBJ, PLY, glTF...
- Writers for supported formats
- Mesh processing: normals, transforms, simplification, validation
- Compile to C compatible library
- Compile to Wasm with JS glue
Fetch and save the dependency:
zig fetch --save git+https://github.com/Sheol27/three.zigWire it into your build.zig:
const three = b.dependency("three", .{
.target = target,
.optimize = optimize,
});
exe.root_module.addImport("three", three.module("three"));const std = @import("std");
const three = @import("three");
pub fn main(init: std.process.Init) !void {
const allocator = init.arena.allocator();
const mesh: three.Mesh = try .fromFile(init.io, allocator, "model.stl");
defer mesh.deinit(allocator);
std.debug.print("triangles: {}\n", .{mesh.triangles_count});
const bb = mesh.computeBoundingBox();
std.debug.print("center: {any}\n", .{bb.center()});
}You can also parse from any std.Io.Reader via Mesh.fromReader, or
explicitly call Mesh.parseAscii / Mesh.parseBinary.
Run the bundled example against an STL file:
zig build run -- path/to/model.stlzig build testContributions are welcome, open an issue or PR!