use bevy_color::Color;
use bevy_ecs::component::Component;
use bevy_ecs::prelude::ReflectComponent;
use bevy_ecs::system::{Query, Res};
use bevy_gizmos::prelude::Gizmos;
use bevy_math::Vec3;
use bevy_reflect::Reflect;
use bevy_transform::prelude::GlobalTransform;
use crate::cell::GeoCell;
use crate::geometry::cell_boundary_local;
use crate::planet::PlanetSettings;
#[derive(Component, Debug, Clone, Copy, Reflect)]
#[reflect(Component)]
pub struct DrawCellOutline {
pub color: Color,
}
impl Default for DrawCellOutline {
fn default() -> Self {
Self {
color: Color::linear_rgb(0.0, 1.0, 0.85),
}
}
}
pub fn draw_cell_outlines(
planet: Res<PlanetSettings>,
mut gizmos: Gizmos,
q: Query<(&GeoCell, &GlobalTransform, &DrawCellOutline)>,
) {
for (cell, gt, marker) in q.iter() {
let Some(local_verts) = cell_boundary_local(cell.raw(), planet.radius) else {
continue;
};
if local_verts.len() < 2 {
continue;
}
let world: Vec<Vec3> = local_verts
.iter()
.map(|v| gt.transform_point(*v))
.collect();
let n = world.len();
for i in 0..n {
let next = (i + 1) % n;
gizmos.line(world[i], world[next], marker.color);
}
}
}