MoonBit FFI binding to the PicoGK native library
| File | Description |
|---|---|
| types.mbt | Core types: Vec3, BBox3, Triangle, ColorFloat |
| ffi.mbt | Low-level extern "C" declarations for all C API functions |
| runtime.mbt | Library lifecycle: init, shutdown, version, memory stats |
| voxels.mbt | Voxel operations: create, boolean, offset, query, slice |
| sdf.mbt | Implicit SDF rendering: gyroid sphere, gyroid genus, superellipsoid |
| mesh.mbt | Mesh operations: create, vertices, triangles, bounding box |
| lattice.mbt | Lattice operations: beams, nodes, voxelize |
| polyline.mbt | PolyLine for debug visualization |
| vdbfile.mbt | OpenVDB file I/O |
| scalarfield.mbt | Scalar field operations |
| vectorfield.mbt | Vector field operations |
| metadata.mbt | Key/value metadata for voxel fields |
| viewer.mbt | OpenGL Viewer + ViewerEx with camera callbacks |
| tga.mbt | Screenshot to PNG conversion utilities |
| File | Description |
|---|---|
| picogk_loader.c | dlopen-based loader for all PicoGK C API functions |
| picogk_stl.c | Binary STL writer |
| picogk_png.c | PNG writer (stb_image_write) + TGA→PNG screenshot converter |
| picogk_sdf.c | C-side SDF implementations (gyroid, superellipsoid) + implicit rendering |
| picogk_viewer.c | ViewerEx with camera callbacks (orbit, pan, zoom, autofit) |
let v = @pk.new_viewer_ex("Title", 1280, 960, 0.16, 0.16, 0.20, 1.0)
v.add_voxels(0, part)
v.set_group_material(0, @pk.ColorFloat::new(0.35, 0.6, 0.9, 1.0), 0.1, 0.5)
v.screenshot_png("/tmp/output.png", 12)
v.request_close()
v.destroy()import "@gmlewis/picogkffi" as pf
fn main {
pf.init_with_size(0.5).unwrap()
defer pf.shutdown()
let body = pf.new_sphere(Vec3::{ x: 0.0, y: 0.0, z: 0.0 }, 10.0)
let hole = pf.new_sphere(Vec3::{ x: 6.0, y: 0.0, z: 0.0 }, 6.0)
let part = body.sub(hole)
hole.destroy()
part.shell(1.0)
let mesh = part.to_mesh()
mesh.save_stl("/tmp/part.stl")
mesh.destroy()
part.destroy()
}moon build --target nativepub struct ColorFloat {
r : Double
g : Double
b : Double
a : Double
}pub struct GpuTex {
h : Int64
}pub struct Lattice {
h : Int64
}pub struct Mesh {
h : Int64
}pub struct Metadata {
h : Int64
}pub struct PolyLine {
h : Int64
}pub struct Quad {
h : Int64
}pub struct ScalarField {
h : Int64
}pub struct SideBar {
h : Int64
}pub struct Triangle {
a : Int
b : Int
c : Int
}pub struct VdbFile {
h : Int64
}pub struct Vec3 {
x : Double
y : Double
z : Double
}pub struct VectorField {
h : Int64
}pub struct Viewer {
h : Int64
}fn Viewer::set_group_material(self : Viewer, group : Int, color : ColorFloat, metallic : Double, roughness : Double) -> Unitpub struct ViewerEx {
h : Int64
}fn ViewerEx::set_group_material(self : ViewerEx, group : Int, color : ColorFloat, metallic : Double, roughness : Double) -> Unitpub struct Voxels {
h : Int64
}let default_azimuth : Doublelet default_elevation : Doublefn new_box(min_x : Double, min_y : Double, min_z : Double, max_x : Double, max_y : Double, max_z : Double) -> Voxelsfn new_cylinder(x : Double, y : Double, z : Double, radius : Double, height : Double, dir_x : Double?, dir_y : Double?, dir_z : Double?) -> Voxelsfn new_quad(viewer : Viewer, tex : GpuTex, color : ColorFloat, size : Double, matrix : FixedArray[Byte], screen_space : Bool, centered : Bool, flip_y : Bool) -> Quadfn new_sidebar(viewer : Viewer, right : Bool, width : Int, height : Int, font_size : Int, bg_color : ColorFloat, fg_color : ColorFloat) -> SideBarfn new_viewer_ex(title : String, width : Int, height : Int, bg_r : Double, bg_g : Double, bg_b : Double, bg_a : Double) -> ViewerExfn open_url(url : String) -> Boolfn picogk_write_png(path : FixedArray[Byte], width : Int, height : Int, pixels : Bytes, stride : Int, bytes_per_pixel : Int, top_origin : Int) -> Intfn scalar_field_traverse_active(h_this : Int64, h_sf : Int64, p_cb : FixedArray[Byte]) -> Unitfn vector_field_traverse_active(h_this : Int64, h_vf : Int64, p_cb : FixedArray[Byte]) -> Unitfn voxels_intersect_implicit(h_this : Int64, h_vox : Int64, p_sdf : FixedArray[Byte]) -> Unitfn voxels_render_implicit(h_this : Int64, h_vox : Int64, p_bbox : FixedArray[Byte], p_sdf : FixedArray[Byte]) -> Unitfn write_file(path : String, data : String) -> BoolMoonBit FFI binding to the PicoGK native library