parry3d/transformation/to_outline/
cuboid_to_outline.rs1use crate::bounding_volume::Aabb;
2use crate::math::{Point, Real, Vector};
3use crate::shape::Cuboid;
4use crate::transformation::utils;
5use alloc::{vec, vec::Vec};
6
7impl Aabb {
8 pub fn to_outline(&self) -> (Vec<Point<Real>>, Vec<[u32; 2]>) {
10 let center = self.center();
11 let half_extents = self.half_extents();
12 let mut cube_mesh = Cuboid::new(half_extents).to_outline();
13 cube_mesh.0.iter_mut().for_each(|p| *p += center.coords);
14 cube_mesh
15 }
16}
17
18impl Cuboid {
19 pub fn to_outline(&self) -> (Vec<Point<Real>>, Vec<[u32; 2]>) {
21 let (vtx, idx) = unit_cuboid_outline();
22 (utils::scaled(vtx, self.half_extents * 2.0), idx)
23 }
24}
25
26fn unit_cuboid_outline() -> (Vec<Point<Real>>, Vec<[u32; 2]>) {
32 let aabb = Aabb::from_half_extents(Point::origin(), Vector::repeat(0.5));
33 (
34 aabb.vertices().to_vec(),
35 vec![
36 [0, 1],
37 [1, 2],
38 [2, 3],
39 [3, 0],
40 [4, 5],
41 [5, 6],
42 [6, 7],
43 [7, 4],
44 [0, 4],
45 [1, 5],
46 [2, 6],
47 [3, 7],
48 ],
49 )
50}