parry3d/transformation/to_outline/
round_cone_to_outline.rs

1use crate::math::Real;
2use crate::shape::RoundCone;
3use crate::transformation::utils;
4use alloc::{vec, vec::Vec};
5use na::{self, Point3, Vector3};
6
7impl RoundCone {
8    /// Outlines this round cone’s shape using polylines.
9    pub fn to_outline(
10        &self,
11        nsubdiv: u32,
12        border_nsubdiv: u32,
13    ) -> (Vec<Point3<Real>>, Vec<[u32; 2]>) {
14        let r = self.inner_shape.radius;
15        let br = self.border_radius;
16        let he = self.inner_shape.half_height;
17
18        let mut out_vtx = vec![];
19        let mut out_idx = vec![];
20
21        // Compute the profile.
22        let center_ab = Point3::new(-r, -he, 0.0);
23        let center_cd = Point3::new(0.0, he, 0.0);
24        let side_dir = Vector3::new(-2.0 * he, r, 0.0).normalize();
25
26        let a = Point3::new(-r, -he - br, 0.0);
27        let b = Point3::new(-r, -he, 0.0) + side_dir * br;
28        let c = Point3::new(0.0, he, 0.0) + side_dir * br;
29        let d = Point3::new(0.0, he + br, 0.0);
30
31        out_vtx.push(a);
32        utils::push_arc(center_ab, a, b, border_nsubdiv, &mut out_vtx);
33        out_vtx.push(b);
34        out_vtx.push(c);
35        utils::push_arc(center_cd, c, d, border_nsubdiv, &mut out_vtx);
36        out_vtx.push(d);
37
38        let circles = [
39            0..1,
40            border_nsubdiv..border_nsubdiv + 2,
41            border_nsubdiv * 2 + 1..border_nsubdiv * 2 + 2,
42        ];
43        utils::apply_revolution(false, true, &circles, nsubdiv, &mut out_vtx, &mut out_idx);
44        (out_vtx, out_idx)
45    }
46}