//! Draw a 3 dimensional heart using solid //! //! >>> cargo run --example heart //! //! Writes an .stl file to target/stl/heart.stl use crater::{ csg::{ algebra::CSGAlgebra, marching_cubes::{marching_cubes, MarchingCubesParams}, surfaces::{parse_surface, IntoSurface, Surface3D}, transformations::{ScaleDim, Translate}, }, utils::Parallel, }; fn main() { // Two cones intersecting at their bases // with two spheres on top of the cones let heart = -parse_surface("x^2 + (-y + (x^2)^(1/3))^2 - 50") .unwrap() .transform(ScaleDim(0, 0.2)) .transform(ScaleDim(1, 0.2)) .transform(ScaleDim(2, 0.2)); let z0 = --Surface3D::Plane { normal: [0.0, 0.0, 1.0], } .into_surface(); let z1 = -Surface3D::Plane { normal: [0.0, 0.0, 1.0], } .into_surface() .transform(Translate([0.0, 0.0, 1.0])); // let csg = c1 | c2; let csg = heart & z0 & z1; let resolution = 50; let params = MarchingCubesParams { region: csg, bounds: ([-3.0, -3.0, -3.0], [3.0, 3.0, 3.0]), resolution: (resolution, resolution, resolution), algebra: CSGAlgebra::default(), }; let mesh = marching_cubes::(params); let mut path_buf = std::path::PathBuf::from("./target/stl/"); path_buf.push("heart"); path_buf.set_extension("stl"); std::fs::create_dir_all(&path_buf.parent().expect("Failed to get parent directory")) .expect("Failed to create directory"); mesh.write_stl(path_buf.to_str().unwrap()) .expect("Failed to write csg.stl"); }