Skip to content

Commit 2ce013b

Browse files
committed
clean up example
1 parent 40eadfa commit 2ce013b

File tree

1 file changed

+4
-34
lines changed

1 file changed

+4
-34
lines changed

examples/input/gpu_picking.rs

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ fn main() {
2626
// Add the plugin
2727
.add_plugin(GpuPickingPlugin)
2828
.add_systems(Startup, setup)
29-
.add_systems(Update, (mouse_picking, save_buffer_to_file, move_cube))
29+
.add_systems(Update, (mouse_picking, move_cube))
3030
.run();
3131
}
3232

@@ -88,7 +88,7 @@ fn setup(
8888
GpuPickingMesh,
8989
));
9090

91-
// opaque cube
91+
// This cube will move from left to right. It shows that picking works correctly when things are moving.
9292
commands.spawn((
9393
PbrBundle {
9494
mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })),
@@ -172,38 +172,6 @@ fn mouse_picking(
172172
}
173173
}
174174

175-
// TODO remove before merging, this is just for testing purposes
176-
fn save_buffer_to_file(
177-
keyboard_input: Res<Input<KeyCode>>,
178-
gpu_picking_cameras: Query<(&GpuPickingCamera, &Camera)>,
179-
) {
180-
if keyboard_input.just_pressed(KeyCode::P) {
181-
for (i, (gpu_picking_camera, camera)) in gpu_picking_cameras.iter().enumerate() {
182-
let mut data = vec![];
183-
data.push("P3".to_string());
184-
let size = camera.logical_viewport_size().unwrap();
185-
data.push(format!("{} {}", size.x, size.y));
186-
data.push("255".to_string());
187-
188-
for y in 0..=size.y as u32 {
189-
for x in 0..=size.x as u32 {
190-
let entity = gpu_picking_camera.get_entity(UVec2::new(x, y));
191-
if entity.is_some() {
192-
data.push("255 0 0".to_string());
193-
} else {
194-
data.push("0 0 0".to_string());
195-
}
196-
}
197-
}
198-
199-
std::fs::write(format!("entity_out_{i}.ppm"), data.join("\n"))
200-
.expect("Unable to write file");
201-
202-
println!("buffer saved to entity_out_{i}.ppm");
203-
}
204-
}
205-
}
206-
207175
// You can also use a custom material with it, you just need to make sure it correctly outputs the entity id
208176
// See assets/shaders/gpu_picking_material.wgsl for more information
209177
#[derive(AsBindGroup, TypeUuid, TypePath, Debug, Clone)]
@@ -222,6 +190,8 @@ impl Material for GpuPickingMaterial {
222190
#[derive(Component)]
223191
struct MoveCube;
224192

193+
// Moves a mesh from left to right
194+
// Used to show that picking works even if things are moving
225195
fn move_cube(
226196
mut q: Query<&mut Transform, With<MoveCube>>,
227197
time: Res<Time>,

0 commit comments

Comments
 (0)