Sign in

    picogkshapes

    Higher-level shape construction helpers for the PicoGK geometry kernel

    geometry
    shapes
    cad
    Download zip
    Author
    Version
    0.2.1
    License
    Apache-2.0
    Last updated
    yesterday
    Downloads
    37

    Dependencies

    #picogkshapes — Higher-Level Shape Construction for PicoGK

    Convenient shape construction helpers built on top of picogkffi. Provides common 3D geometry patterns that combine multiple primitives.

    #Package Structure

    FileDescription
    shapes.mbtShape construction helpers

    #Available Shapes

    FunctionDescription
    hollow_sphereSphere with inner sphere subtracted
    connected_hollow_spheresTwo hollow spheres joined together
    flat_cylinderCylinder approximation (capsule-based)
    box_shapeAxis-aligned box
    torusDonut shape (ring of capsules)
    sphere_grid3D array of spheres
    cylinder_ringRing of cylinders
    perforateGrid of holes in a solid
    lattice_cageBeam-and-node lattice from corners

    #Usage

    import "@gmlewis/picogkshapes" as shapes

    fn main {
    // Create a perforated plate
    let plate = shapes.box_shape(-50.0, -50.0, -2.0, 50.0, 50.0, 2.0)
    let perforated = shapes.perforate(
    plate,
    Vec3::{ x: 0.0, y: 0.0, z: 0.0 },
    10.0, 10.0, 10, 10, 2.0, 4.0,
    )
    plate.destroy()
    // ... use perforated plate
    perforated.destroy()
    }

    #Dependencies

    • gmlewis/picogkffi — Direct FFI bindings to the PicoGK native library

    Box

    pub struct Box {
    frame : LocalFrame
    length : Double
    width : (Double) -> Double
    depth : (Double) -> Double
    frames : Frames?
    w_steps : Int
    d_steps : Int
    l_steps : Int
    transform : (Array[Vec3]) -> Array[Vec3]?
    }

    Box::to_mesh

    fn Box::to_mesh(self : Box) ->
    Mesh

    Box::to_voxels

    fn Box::to_voxels(self : Box) ->
    Voxels

    ColorScale3D

    pub struct ColorScale3D {
    rgb_arr : Array[RGB]
    min_value : Double
    max_value : Double
    }

    ColorScale3D::color

    fn ColorScale3D::color(self : ColorScale3D, value : Double) -> RGB

    ControlPointSpline

    pub struct ControlPointSpline {
    control_points : Array[Vec3]
    degree : Int
    knot : Array[Double]
    }

    ControlPointSpline::point_at

    fn ControlPointSpline::point_at(self : ControlPointSpline, t : Double) -> Vec3

    ControlPointSpline::points

    fn ControlPointSpline::points(self : ControlPointSpline, n : Int) -> Array[Vec3]

    Cylinder

    pub struct Cylinder {
    frame : LocalFrame
    length : Double
    radius : (Double, Double) -> Double
    frames : Frames?
    polar_steps : Int
    radial_steps : Int
    length_steps : Int
    }

    Cylinder::to_mesh

    Cylinder::to_voxels

    Frames

    pub struct Frames {
    spine : Array[Vec3]
    local_x : Array[Vec3]
    local_y : Array[Vec3]
    local_z : Array[Vec3]
    }

    Frames::frame_at

    fn Frames::frame_at(self : Frames, lr : Double) -> LocalFrame

    ImplicitGenus

    pub struct ImplicitGenus {
    gap : Double
    }

    ImplicitGyroid

    pub struct ImplicitGyroid {
    unit_size : Double
    thickness_ratio : Double
    frequency : Double
    }

    ImplicitSuperEllipsoid

    pub struct ImplicitSuperEllipsoid {
    center : Vec3
    ax : Double
    ay : Double
    az : Double
    e1 : Double
    e2 : Double
    }

    LatticeManifold

    pub struct LatticeManifold {
    frame : LocalFrame
    length : Double
    radius : (Double) -> Double
    frames : Frames?
    l_steps : Int
    max_overhang_angle : Double
    extend_both_sides : Bool
    min_printable_radius : Double
    }

    LatticeManifold::set_extend_both_sides

    fn LatticeManifold::set_extend_both_sides(self : LatticeManifold, b : Bool) -> LatticeManifold

    LatticeManifold::to_voxels

    LatticePipe

    pub struct LatticePipe {
    frame : LocalFrame
    length : Double
    radius : (Double) -> Double
    frames : Frames?
    l_steps : Int
    }

    LatticePipe::to_voxels

    Lens

    pub struct Lens {
    frame : LocalFrame
    height : Double
    inner_radius : Double
    outer_radius : Double
    lower : (Double, Double) -> Double
    upper : (Double, Double) -> Double
    radial_steps : Int
    polar_steps : Int
    height_steps : Int
    }

    Lens::to_mesh

    fn Lens::to_mesh(self : Lens) ->
    Mesh

    Lens::to_voxels

    fn Lens::to_voxels(self : Lens) ->
    Voxels

    LineModulation

    pub struct LineModulation {
    fn_ : (Double) -> Double
    }

    LineModulation::add

    LineModulation::call

    fn LineModulation::call(self : LineModulation, ratio : Double) -> Double

    LineModulation::const_val

    fn LineModulation::const_val(v : Double) -> LineModulation

    LineModulation::from_fn

    fn LineModulation::from_fn(f : (Double) -> Double) -> LineModulation

    LineModulation::mul

    fn LineModulation::mul(self : LineModulation, factor : Double) -> LineModulation

    LineModulation::new

    fn LineModulation::new(f : (Double) -> Double) -> LineModulation

    LineModulation::sub

    LocalFrame

    pub struct LocalFrame {
    pos : Vec3
    local_x : Vec3
    local_y : Vec3
    local_z : Vec3
    }

    LocalFrame::point_to_world

    fn LocalFrame::point_to_world(self : LocalFrame, local_pt : Vec3) -> Vec3

    LocalFrame::rotated

    fn LocalFrame::rotated(self : LocalFrame, angle : Double, axis : Vec3) -> LocalFrame

    LocalFrame::translated

    fn LocalFrame::translated(self : LocalFrame, offset : Vec3) -> LocalFrame

    Pipe

    pub struct Pipe {
    frame : LocalFrame
    length : Double
    inner : (Double, Double) -> Double
    outer : (Double, Double) -> Double
    frames : Frames?
    polar_steps : Int
    radial_steps : Int
    length_steps : Int
    transform : (Array[Vec3]) -> Array[Vec3]?
    phi_angle_func : (Double, Double) -> Double
    }

    Pipe::to_mesh

    fn Pipe::to_mesh(self : Pipe) ->
    Mesh

    Pipe::to_voxels

    fn Pipe::to_voxels(self : Pipe) ->
    Voxels

    PipeSegment

    pub struct PipeSegment {
    pipe : Pipe
    mid : (Double) -> Double
    rng : (Double) -> Double
    }

    PipeSegment::to_mesh

    PipeSegment::to_voxels

    RGB

    pub struct RGB {
    r : Double
    g : Double
    b : Double
    }

    RGB::new

    fn RGB::new(r : Double, g : Double, b : Double) -> RGB

    RGB::to_ffi

    Ring

    pub struct Ring {
    frame : LocalFrame
    ring_radius : Double
    radius : (Double, Double) -> Double
    radial_steps : Int
    polar_steps : Int
    }

    Ring::to_mesh

    fn Ring::to_mesh(self : Ring) ->
    Mesh

    Ring::to_voxels

    fn Ring::to_voxels(self : Ring) ->
    Voxels

    SceneGroup

    pub struct SceneGroup {
    voxels :
    Voxels
    ?
    mesh :
    Mesh
    ?
    color : RGB
    }

    Sphere

    pub struct Sphere {
    frame : LocalFrame
    radius : (Double, Double) -> Double
    azim_steps : Int
    polar_steps : Int
    transform : (Array[Vec3]) -> Array[Vec3]?
    }

    Sphere::to_mesh

    Sphere::to_voxels

    SurfaceMeshBuilder

    pub struct SurfaceMeshBuilder {
    verts : Array[Double]
    tris : Array[Int]
    }

    SurfaceMeshBuilder::add

    fn SurfaceMeshBuilder::add(self : SurfaceMeshBuilder, grid : Array[Array[Vec3]], flip : Bool) -> SurfaceMeshBuilder

    SurfaceMeshBuilder::build

    SurfaceModulation

    pub struct SurfaceModulation {
    fn_ : (Double, Double) -> Double
    }

    SurfaceModulation::add

    SurfaceModulation::call

    fn SurfaceModulation::call(self : SurfaceModulation, phi : Double, lr : Double) -> Double

    SurfaceModulation::const_val

    fn SurfaceModulation::const_val(v : Double) -> SurfaceModulation

    SurfaceModulation::from_fn

    fn SurfaceModulation::from_fn(f : (Double, Double) -> Double) -> SurfaceModulation

    SurfaceModulation::from_line

    fn SurfaceModulation::from_line(line : LineModulation, line_arg : String) -> SurfaceModulation

    SurfaceModulation::mul

    fn SurfaceModulation::mul(self : SurfaceModulation, factor : Double) -> SurfaceModulation

    SurfaceModulation::new

    fn SurfaceModulation::new(f : (Double, Double) -> Double) -> SurfaceModulation

    SurfaceModulation::sub

    Vec3

    pub struct Vec3 {
    x : Double
    y : Double
    z : Double
    }

    Vec3::add

    fn Vec3::add(self : Vec3, o : Vec3) -> Vec3

    Vec3::cross

    fn Vec3::cross(self : Vec3, o : Vec3) -> Vec3

    Vec3::dot

    fn Vec3::dot(self : Vec3, o : Vec3) -> Double

    Vec3::len

    fn Vec3::len(self : Vec3) -> Double

    Vec3::mul

    fn Vec3::mul(self : Vec3, s : Double) -> Vec3

    Vec3::new

    fn Vec3::new(x : Double, y : Double, z : Double) -> Vec3

    Vec3::normalized

    fn Vec3::normalized(self : Vec3) -> Vec3

    Vec3::sub

    fn Vec3::sub(self : Vec3, o : Vec3) -> Vec3

    frames_aligned_to_x

    fn frames_aligned_to_x(points : Array[Vec3], target_x : Vec3) -> Frames

    lerp

    fn lerp(p1 : Vec3, p2 : Vec3, t : Double) -> Vec3

    line_const

    fn line_const(v : Double) -> ((Double) -> Double)

    line_fn

    fn line_fn(f : (Double) -> Double) -> ((Double) -> Double)

    new_box

    fn new_box(frame : LocalFrame?, length : Double, width : (Double) -> Double, depth : (Double) -> Double) -> Box

    new_color_scale_3d

    fn new_color_scale_3d(spectrum : Array[RGB], min_value : Double, max_value : Double) -> ColorScale3D

    new_control_point_spline

    fn new_control_point_spline(control_points : Array[Vec3], degree : Int, closed : Bool) -> ControlPointSpline

    new_cylinder

    fn new_cylinder(frame : LocalFrame?, length : Double, radius : (Double, Double) -> Double) -> Cylinder

    new_implicit_genus

    fn new_implicit_genus(gap : Double) -> ImplicitGenus

    new_implicit_gyroid

    fn new_implicit_gyroid(unit_size : Double, thickness_ratio : Double) -> ImplicitGyroid

    new_implicit_super_ellipsoid

    fn new_implicit_super_ellipsoid(center : Vec3, ax : Double, ay : Double, az : Double, e1 : Double, e2 : Double) -> ImplicitSuperEllipsoid

    new_lattice_manifold

    fn new_lattice_manifold(frame : LocalFrame, length : Double, radius : Double, max_overhang_angle : Double) -> LatticeManifold

    new_lattice_pipe

    fn new_lattice_pipe(frame : LocalFrame?, length : Double, radius : (Double) -> Double) -> LatticePipe

    new_lattice_pipe_with_frames

    fn new_lattice_pipe_with_frames(frame : LocalFrame?, length : Double, radius : (Double) -> Double, fs : Frames) -> LatticePipe

    new_lens

    fn new_lens(frame : LocalFrame?, height : Double, inner_radius : Double, outer_radius : Double) -> Lens

    new_lens_with_mods

    fn new_lens_with_mods(frame : LocalFrame?, height : Double, inner_radius : Double, outer_radius : Double, lower : (Double, Double) -> Double, upper : (Double, Double) -> Double) -> Lens

    new_local_frame

    fn new_local_frame(position : Vec3, local_z : Vec3?) -> LocalFrame

    new_local_frame_xyz

    fn new_local_frame_xyz(position : Vec3, local_z : Vec3, local_x : Vec3) -> LocalFrame

    new_pipe

    fn new_pipe(frame : LocalFrame?, length : Double, inner_radius : (Double, Double) -> Double, outer_radius : (Double, Double) -> Double) -> Pipe

    new_pipe_segment

    fn new_pipe_segment(frame : LocalFrame?, length : Double, inner_radius : (Double, Double) -> Double, outer_radius : (Double, Double) -> Double, start : (Double) -> Double, end : (Double) -> Double, method_name : String) -> PipeSegment

    new_pipe_segment_with_frames

    fn new_pipe_segment_with_frames(frame : LocalFrame?, length : Double, inner_radius : (Double, Double) -> Double, outer_radius : (Double, Double) -> Double, start : (Double) -> Double, end : (Double) -> Double, method_name : String, fs : Frames) -> PipeSegment

    new_pipe_with_frames

    fn new_pipe_with_frames(frame : LocalFrame?, length : Double, inner_radius : (Double, Double) -> Double, outer_radius : (Double, Double) -> Double, fs : Frames) -> Pipe

    new_pipe_with_transform

    fn new_pipe_with_transform(frame : LocalFrame?, length : Double, inner_radius : (Double, Double) -> Double, outer_radius : (Double, Double) -> Double, trafo : (Array[Vec3]) -> Array[Vec3]) -> Pipe

    new_ring

    fn new_ring(frame : LocalFrame?, ring_radius : Double, radius : (Double, Double) -> Double) -> Ring

    new_sphere

    fn new_sphere(frame : LocalFrame?, radius : (Double, Double) -> Double) -> Sphere

    new_surface_mesh_builder

    fn new_surface_mesh_builder() -> SurfaceMeshBuilder

    orthogonal_dir

    fn orthogonal_dir(dir : Vec3) -> Vec3

    palette

    let palette : Map[String, RGB]

    rainbow_spectrum

    fn rainbow_spectrum() -> Array[RGB]

    RainbowSpectrum returns blue→green→yellow→orange→red control colors.

    rotate_around_axis

    fn rotate_around_axis(pt : Vec3, axis : Vec3, angle : Double, origin : Vec3) -> Vec3

    safe_normalized

    fn safe_normalized(v : Vec3, eps : Double) -> Vec3

    scene_group_mesh

    fn scene_group_mesh(mesh :
    Mesh
    , color : RGB) -> SceneGroup

    scene_group_voxels

    fn scene_group_voxels(vox :
    Voxels
    , color : RGB) -> SceneGroup

    spline_points

    fn spline_points() -> Array[Vec3]

    split_by_overhang_angle

    fn split_by_overhang_angle(mesh :
    Mesh
    , scale : ColorScale3D, n_classes : Int) -> Array[SceneGroup]

    SplitByOverhangAngle splits a mesh into colored sub-meshes by triangle overhang angle (degrees: 0 = vertical wall, 90 = horizontal).

    surf_const

    fn surf_const(v : Double) -> ((Double, Double) -> Double)

    surf_fn

    fn surf_fn(f : (Double, Double) -> Double) -> ((Double, Double) -> Double)

    surf_from_line

    fn surf_from_line(line : (Double) -> Double, line_arg : String) -> ((Double, Double) -> Double)

    vec3

    fn vec3(x : Double, y : Double, z : Double) -> Vec3

    Source Files