use crate::mesh::Mesh;
pub(crate) fn box_from_positions_aabb(mesh: &Mesh) -> Mesh {
if mesh.is_empty() {
return mesh.clone();
}
let (min, max) = mesh.bounds();
box_from_corners(mesh, [min.x, min.y, min.z], [max.x, max.y, max.z])
}
pub(crate) fn box_from_corners(template: &Mesh, min: [f32; 3], max: [f32; 3]) -> Mesh {
let [x0, y0, z0] = min;
let [x1, y1, z1] = max;
#[rustfmt::skip]
let positions: Vec<f32> = vec![
x0,y0,z0, x1,y0,z0, x1,y1,z0, x0,y1,z0,
x0,y0,z1, x1,y0,z1, x1,y1,z1, x0,y1,z1,
x0,y0,z0, x1,y0,z0, x1,y0,z1, x0,y0,z1,
x0,y1,z0, x1,y1,z0, x1,y1,z1, x0,y1,z1,
x0,y0,z0, x0,y1,z0, x0,y1,z1, x0,y0,z1,
x1,y0,z0, x1,y1,z0, x1,y1,z1, x1,y0,z1,
];
#[rustfmt::skip]
let normals: Vec<f32> = vec![
0.0,0.0,-1.0, 0.0,0.0,-1.0, 0.0,0.0,-1.0, 0.0,0.0,-1.0, 0.0,0.0, 1.0, 0.0,0.0, 1.0, 0.0,0.0, 1.0, 0.0,0.0, 1.0, 0.0,-1.0,0.0, 0.0,-1.0,0.0, 0.0,-1.0,0.0, 0.0,-1.0,0.0, 0.0, 1.0,0.0, 0.0, 1.0,0.0, 0.0, 1.0,0.0, 0.0, 1.0,0.0, -1.0,0.0,0.0, -1.0,0.0,0.0, -1.0,0.0,0.0, -1.0,0.0,0.0, 1.0,0.0,0.0, 1.0,0.0,0.0, 1.0,0.0,0.0, 1.0,0.0,0.0, ];
#[rustfmt::skip]
let indices: Vec<u32> = vec![
0,2,1, 0,3,2, 4,5,6, 4,6,7, 8,9,10, 8,10,11, 12,14,13, 12,15,14, 16,18,17, 16,19,18, 20,21,22, 20,22,23, ];
template.rebuilt_like(positions, normals, indices)
}