Skip to content

Sheol27/three.zig

Repository files navigation

three.zig

CI Zig License: MIT

A Zig library for loading and processing meshes.

Requires Zig 0.16.0.

Roadmap

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

Install

Fetch and save the dependency:

zig fetch --save git+https://github.com/Sheol27/three.zig

Wire it into your build.zig:

const three = b.dependency("three", .{
    .target = target,
    .optimize = optimize,
});

exe.root_module.addImport("three", three.module("three"));

Usage

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.

Example

Run the bundled example against an STL file:

zig build run -- path/to/model.stl

Test

zig build test

Contributing

Contributions are welcome, open an issue or PR!

License

MIT

About

Zig 3D library

Resources

License

Stars

Watchers

Forks

Contributors