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();
// Format inferred from the extension
const mesh: three.Mesh = try three.formats.load(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()});
// Format-specific options ride in the union payload
try three.formats.save(&mesh, init.io, "out.stl", .{ .stl = .{ .encoding = .ascii } });
}You can also parse from any std.Io.Reader via formats.loadFromReader, or use a
format directly: formats.Stl.loadFromReader (auto-detects ascii/binary),
formats.Stl.parseAscii / parseBinary, formats.Stl.saveToWriter.
Run the bundled example against an STL file:
zig build run -- path/to/model.stlzig build testContributions are welcome, open an issue or PR!