Skip to content

AtelierArith/PlatonicSolidsGenerator.jl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PlatonicSolidsGenerator.jl

PlatonicSolidsGenerator.jl is a Julia package for generating Platonic solids, visualizing them with Makie.jl, and exporting them as STL files for 3D printing.

The package is designed for workflows that import STL files into slicers such as Bambu Studio. STL coordinates are treated as millimeters. Because STL files do not store unit metadata, slicers should interpret the value passed to bbox_mm as millimeters.

Features

  • Generate all 5 Platonic solids:
    • Tetrahedron :tetrahedron / 4
    • Cube :cube / 6
    • Octahedron :octahedron / 8
    • Dodecahedron :dodecahedron / 12
    • Icosahedron :icosahedron / 20
  • 3D visualization with Makie.jl
  • Binary STL export
  • Maximum bounding-box size control with bbox_mm
  • Print-bed placement with placement=:flat
  • write_mesh API prepared for future 3MF export support

Provenance

This project was generated with Codex.

Installation

To use this repository as a local package:

using Pkg
Pkg.develop(path="/path/to/PlatonicSolidsGenerator.jl")

To try it directly from this directory:

julia --project=.
using PlatonicSolidsGenerator

Quick Start

Export an STL File

using PlatonicSolidsGenerator

write_mesh("cube.stl", :cube; bbox_mm=30.0, placement=:flat)
write_stl("icosahedron.stl", :icosahedron; bbox_mm=40.0, placement=:flat)

placement=:flat places one face on the xy plane at z=0 and ensures that all vertices have z >= 0. This is convenient for STL files that will be imported into slicers such as Bambu Studio.

Visualize with Makie

using GLMakie
using PlatonicSolidsGenerator

fig = visualize_solid(:dodecahedron; bbox_mm=30.0, placement=:flat)
display(fig)

Choose the Makie backend in the consuming application. Load GLMakie, WGLMakie, CairoMakie, or another backend before calling visualize_solid.

Get a GeometryBasics.Mesh

using PlatonicSolidsGenerator

mesh = platonic_solid(20; bbox_mm=25.0)

platonic_solid returns a GeometryBasics.Mesh that can be passed to Makie's mesh! and related APIs.

Placement

placement accepts the following values:

  • :center: The default. Places the solid around the origin. Use this for mathematical visualization and geometry checks.
  • :flat: Places one face on the xy plane at z=0. Use this for 3D printing.

Example:

centered = platonic_solid(:tetrahedron; bbox_mm=30.0, placement=:center)
flat = platonic_solid(:tetrahedron; bbox_mm=30.0, placement=:flat)

API

supported_solids()
platonic_solid(kind; bbox_mm=30.0, placement=:center)
visualize_solid(kind; bbox_mm=30.0, placement=:center, axis=true)
write_stl(path, kind; bbox_mm=30.0, placement=:center, name=nothing)
write_mesh(path, kind; bbox_mm=30.0, placement=:center, format=:auto, metadata=Dict())

kind can be specified as a symbol or by number of faces.

platonic_solid(:cube)
platonic_solid(6)
write_mesh("solid.stl", 12; bbox_mm=50.0, placement=:flat)

3MF Support

write_mesh supports .3mf export directly:

write_mesh("cube.3mf", :cube; bbox_mm=30.0, placement=:flat)

The output is a spec-compliant ZIP archive containing [Content_Types].xml, _rels/.rels, and 3D/3dmodel.model. Coordinates are written in millimeters.

Example

Generate STL files for all 5 supported solids under exports/:

julia --project=. examples/generate_solids.jl

Generated files:

exports/tetrahedron.stl
exports/cube.stl
exports/octahedron.stl
exports/dodecahedron.stl
exports/icosahedron.stl

Testing

julia --project=. -e 'using Pkg; Pkg.test()'

The tests cover:

  • The list of supported Platonic solids
  • Symbol-based and face-count-based solid selection
  • Scaling with bbox_mm
  • Bottom-face placement at z=0 with placement=:flat
  • Triangle counts and file sizes for binary STL output
  • Explicit unsupported-format errors for .3mf
  • Makie visualization smoke tests

About

PlatonicSolidsGenerator.jl

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages