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.
- Generate all 5 Platonic solids:
- Tetrahedron
:tetrahedron/4 - Cube
:cube/6 - Octahedron
:octahedron/8 - Dodecahedron
:dodecahedron/12 - Icosahedron
:icosahedron/20
- Tetrahedron
- 3D visualization with Makie.jl
- Binary STL export
- Maximum bounding-box size control with
bbox_mm - Print-bed placement with
placement=:flat write_meshAPI prepared for future 3MF export support
This project was generated with Codex.
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 PlatonicSolidsGeneratorusing 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.
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.
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 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 atz=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)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)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.
Generate STL files for all 5 supported solids under exports/:
julia --project=. examples/generate_solids.jlGenerated files:
exports/tetrahedron.stl
exports/cube.stl
exports/octahedron.stl
exports/dodecahedron.stl
exports/icosahedron.stl
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=0withplacement=:flat - Triangle counts and file sizes for binary STL output
- Explicit unsupported-format errors for
.3mf - Makie visualization smoke tests
