use std::sync::Arc;
use std::time::Instant;
use manifold_rust::csg_tree::{CsgLeafNode, CsgNode};
use manifold_rust::linalg::{mat4_to_mat3x4, translation_matrix, Vec3};
use manifold_rust::manifold::Manifold;
fn main() {
let n: i32 = std::env::args()
.nth(1)
.and_then(|a| a.parse().ok())
.unwrap_or(20);
println!("n = {}", n);
let start = Instant::now();
let sphere = Manifold::sphere(1.0, 0);
let sphere_impl = Arc::new(sphere.as_impl().clone());
let mut leaves: Vec<CsgNode> = Vec::new();
for i in 0..n {
for j in 0..n {
for k in 0..n {
if i == 0 && j == 0 && k == 0 {
continue;
}
let leaf = CsgLeafNode {
p_impl: Arc::clone(&sphere_impl),
transform: mat4_to_mat3x4(translation_matrix(Vec3::new(
i as f64, j as f64, k as f64,
))),
};
leaves.push(CsgNode::leaf_node(leaf));
}
}
}
let scene = CsgNode::op_n(manifold_rust::types::OpType::Add, leaves).evaluate();
let n_tri = scene.num_tri();
let elapsed = start.elapsed().as_secs_f64();
std::hint::black_box(&scene);
println!("nTri = {}, time = {} sec", n_tri, elapsed);
}