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
use rapier3d::geometry::{Collider, ColliderBuilder, SharedShape};
use rapier3d::math::Real;
use serde::Serialize;

#[derive(Debug, Copy, Clone, Serialize)]
#[serde(tag = "t", content = "c")]
pub enum Shape {
    Sphere(Real),
    Cuboid(Real, Real, Real),
}

impl From<Shape> for SharedShape {
    fn from(shape: Shape) -> Self {
        match shape {
            Shape::Sphere(radius) => SharedShape::ball(radius),
            Shape::Cuboid(x, y, z) => SharedShape::cuboid(x, y, z),
        }
    }
}

impl From<Shape> for Collider {
    fn from(shape: Shape) -> Self {
        ColliderBuilder::new(shape.into()).build()
    }
}