use serde::{Deserialize, Serialize};
use crate::{graphics::Color, math::Vec3};
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
pub enum GizmoKind {
WireCube { center: Vec3, half_extents: Vec3 },
WireSphere { center: Vec3, radius: f32 },
Arrow { start: Vec3, end: Vec3 },
}
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
pub struct Gizmo {
pub kind: GizmoKind,
pub color: Color,
}
impl Gizmo {
pub fn new(kind: GizmoKind, color: Color) -> Self {
Self { kind, color }
}
pub fn wire_cube(center: impl Into<Vec3>, half_extents: impl Into<Vec3>, color: Color) -> Self {
Self::new(
GizmoKind::WireCube {
center: center.into(),
half_extents: half_extents.into(),
},
color,
)
}
pub fn wire_sphere(center: impl Into<Vec3>, radius: impl Into<f32>, color: Color) -> Self {
Self::new(
GizmoKind::WireSphere {
center: center.into(),
radius: radius.into(),
},
color,
)
}
pub fn arrow(start: impl Into<Vec3>, end: impl Into<Vec3>, color: Color) -> Self {
Self::new(
GizmoKind::Arrow {
start: start.into(),
end: end.into(),
},
color,
)
}
#[cfg(feature = "ffi")]
pub fn draw(&self) {
use lotus_script_sys::FfiObject;
let obj = FfiObject::new(self);
unsafe {
lotus_script_sys::gizmo::draw(obj.packed());
}
}
}