1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
use crate::mesh::{Capsule3dMeshBuilder, CapsuleUvProfile, Mesh};

/// A cylinder with hemispheres at the top and bottom
#[deprecated(
    since = "0.13.0",
    note = "please use the `Capsule3d` primitive in `bevy_math` instead"
)]
#[derive(Debug, Copy, Clone)]
pub struct Capsule {
    /// Radius on the `XZ` plane.
    pub radius: f32,
    /// Number of sections in cylinder between hemispheres.
    pub rings: usize,
    /// Height of the middle cylinder on the `Y` axis, excluding the hemispheres.
    pub depth: f32,
    /// Number of latitudes, distributed by inclination. Must be even.
    pub latitudes: usize,
    /// Number of longitudes, or meridians, distributed by azimuth.
    pub longitudes: usize,
    /// Manner in which UV coordinates are distributed vertically.
    pub uv_profile: CapsuleUvProfile,
}
impl Default for Capsule {
    fn default() -> Self {
        Capsule {
            radius: 0.5,
            rings: 0,
            depth: 1.0,
            latitudes: 16,
            longitudes: 32,
            uv_profile: CapsuleUvProfile::Aspect,
        }
    }
}

impl From<Capsule> for Mesh {
    #[allow(clippy::needless_range_loop)]
    fn from(capsule: Capsule) -> Self {
        Capsule3dMeshBuilder::new(
            capsule.radius,
            capsule.depth,
            capsule.longitudes,
            capsule.latitudes,
        )
        .rings(capsule.rings)
        .uv_profile(capsule.uv_profile)
        .build()
    }
}