1use serde::{Deserialize, Serialize};
2
3use crate::{graphics::Color, math::Vec3};
4
5#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
6pub enum GizmoKind {
7 WireCube { center: Vec3, half_extents: Vec3 },
8 WireSphere { center: Vec3, radius: f32 },
9 Arrow { start: Vec3, end: Vec3 },
10}
11
12#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
17pub struct Gizmo {
18 pub kind: GizmoKind,
19 pub color: Color,
20}
21
22impl Gizmo {
23 pub fn new(kind: GizmoKind, color: Color) -> Self {
25 Self { kind, color }
26 }
27
28 pub fn wire_cube(center: impl Into<Vec3>, half_extents: impl Into<Vec3>, color: Color) -> Self {
30 Self::new(
31 GizmoKind::WireCube {
32 center: center.into(),
33 half_extents: half_extents.into(),
34 },
35 color,
36 )
37 }
38
39 pub fn wire_sphere(center: impl Into<Vec3>, radius: impl Into<f32>, color: Color) -> Self {
41 Self::new(
42 GizmoKind::WireSphere {
43 center: center.into(),
44 radius: radius.into(),
45 },
46 color,
47 )
48 }
49
50 pub fn arrow(start: impl Into<Vec3>, end: impl Into<Vec3>, color: Color) -> Self {
52 Self::new(
53 GizmoKind::Arrow {
54 start: start.into(),
55 end: end.into(),
56 },
57 color,
58 )
59 }
60
61 #[cfg(feature = "ffi")]
63 pub fn draw(&self) {
64 use lotus_script_sys::FfiObject;
65
66 let obj = FfiObject::new(self);
67
68 unsafe {
69 lotus_script_sys::gizmo::draw(obj.packed());
70 }
71 }
72}