//! Draw two union-ed tori use crater::{ csg::{ algebra::CSGAlgebra, marching_cubes::{marching_cubes, MarchingCubesParams}, surfaces::{IntoSurface, Surface3D}, transformations::RotateAbout, }, utils::Parallel, }; fn main() { let z_torus = -(Surface3D::Torus { r1: 1.0, r2: 2.0 }).into_surface(); let y_torus = -(Surface3D::Torus { r1: 1.0, r2: 2.0 }) .into_surface() .transform(RotateAbout(0, 2, std::f64::consts::FRAC_PI_2)); // Run marching cubes to render this shape let resolution = 50; let params = MarchingCubesParams { region: z_torus | y_torus, 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("tori"); 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"); }