Add editor debug grid

This commit is contained in:
mars 2022-06-28 20:41:01 -06:00
parent 80f150a9f5
commit 0316b7d2d1
1 changed files with 33 additions and 12 deletions

View File

@ -166,6 +166,7 @@ impl RenderState {
output_format: wgpu::TextureFormat,
render_pass: &mut egui_wgpu_backend::RenderPass,
) -> Self {
use cyborg::scene::{DebugDrawList, DebugIndex, DebugVertex};
use cyborg::shader::{ShaderStore, ShaderWatcher};
let mut world = legion::World::default();
@ -202,22 +203,42 @@ impl RenderState {
cyborg::legion::build_renderer(viewport_store, &mut resources, &mut render_schedule);
let render_schedule = render_schedule.build();
// make debug draw grid
let grid_size = 10;
let grid_color = [0.0, 1.0, 0.0];
let mut grid_vertices = Vec::new();
// draw horizontal lines
for x in -grid_size..=grid_size {
grid_vertices.push(DebugVertex {
position: [x as f32, 0.0, -grid_size as f32],
color: grid_color.clone(),
});
grid_vertices.push(DebugVertex {
position: [x as f32, 0.0, grid_size as f32],
color: grid_color.clone(),
});
}
// draw vertical lines
for z in -grid_size..=grid_size {
grid_vertices.push(DebugVertex {
position: [-grid_size as f32, 0.0, z as f32],
color: grid_color.clone(),
});
grid_vertices.push(DebugVertex {
position: [grid_size as f32, 0.0, z as f32],
color: grid_color.clone(),
});
}
world.push((
cyborg::scene::Transform {
transform: Default::default(),
},
cyborg::scene::DebugDrawList {
vertices: vec![
cyborg::scene::DebugVertex {
color: [1.0, 0.0, 0.0],
position: [0.0, 0.0, -1.0],
},
cyborg::scene::DebugVertex {
color: [0.0, 0.0, 1.0],
position: [0.0, 0.0, 1.0],
},
],
indices: vec![0, 1],
DebugDrawList {
indices: (0..(grid_vertices.len() as u32)).into_iter().collect(),
vertices: grid_vertices,
},
));