Skip to content

chip2n/zig-obj

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

70 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

zig-obj

https://github.com/chip2n/zig-obj/workflows/CI/badge.svg

Minimal Zig parser for .obj and .mtl files.

Features

The following features are implemented:

OBJ files:

  • Vertices
  • Texture coordinates
  • Normals
  • Objects

MTL files:

  • Bump map
  • Diffuse map
  • Specular map
  • Ambient color
  • Diffuse color
  • Specular color
  • Specular highlight
  • Emissive coefficient
  • Optical density
  • Dissolve
  • Illumination

If something is missing or not working properly, feel free to open an issue/pull request and I’ll take a look.

Getting started

Add module to your projects build.zig.zon file (replacing <COMMIT> with the commit you want to use and <HASH> with the associated hash):

.{
    .name = "my-project",
    .version = "1.0.0",
    .dependencies = .{
        .obj = .{
            .url = "git+https://github.com/chip2n/zig-obj.git#<COMMIT>",
            .hash = "<HASH>",
        },
    },
}

Add the dependency to your executable in build.zig:

pub fn build(b: *std.build.Builder) void {
    ...
    const obj_mod = b.dependency("obj", .{ .target = target, .optimize = optimize }).module("obj");
    exe.addModule("obj", obj_mod);
}

Building a static library

Build a static library by running:

zig build

Usage

const obj = @import("obj");

var model = try obj.parseObj(allocator, @embedFile("cube.obj"));
defer model.deinit(allocator);
var material = try obj.parseMtl(allocator, @embedFile("cube.mtl"));
defer material.deinit(allocator);

Running tests

Tests are being ran automatically each day using the nightly Zig build.

Run the test suite manually with:

zig build test

About

Minimal Zig parser for .obj and .mtl files

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages