From 7d8bab133a8ff843514fe9dfa2e6c879757a3c73 Mon Sep 17 00:00:00 2001 From: bstriker Date: Sun, 18 Feb 2024 01:55:58 -0500 Subject: [PATCH 01/40] Bump bevy to 0.13 --- Cargo.toml | 22 +++++++++++----------- backends/bevy_picking_egui/Cargo.toml | 8 ++++---- backends/bevy_picking_rapier/Cargo.toml | 12 ++++++------ backends/bevy_picking_raycast/Cargo.toml | 12 ++++++------ backends/bevy_picking_sprite/Cargo.toml | 16 ++++++++-------- backends/bevy_picking_ui/Cargo.toml | 12 ++++++------ crates/bevy_picking_core/Cargo.toml | 16 ++++++++-------- crates/bevy_picking_highlight/Cargo.toml | 14 +++++++------- crates/bevy_picking_input/Cargo.toml | 18 +++++++++--------- crates/bevy_picking_selection/Cargo.toml | 10 +++++----- 10 files changed, 70 insertions(+), 70 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 38025291..9e28cd57 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,18 +19,18 @@ all-features = true members = ["crates/*", "backends/*"] [dependencies] -bevy_app = { version = "0.12", default-features = false } -bevy_core = { version = "0.12", default-features = false } -bevy_ecs = { version = "0.12", default-features = false } -bevy_math = { version = "0.12", default-features = false } -bevy_reflect = { version = "0.12", default-features = false } -bevy_render = { version = "0.12", default-features = false } -bevy_text = { version = "0.12", optional = true, default-features = false, features = [ +bevy_app = { version = "0.13", default-features = false } +bevy_core = { version = "0.13", default-features = false } +bevy_ecs = { version = "0.13", default-features = false } +bevy_math = { version = "0.13", default-features = false } +bevy_reflect = { version = "0.13", default-features = false } +bevy_render = { version = "0.13", default-features = false } +bevy_text = { version = "0.13", optional = true, default-features = false, features = [ "default_font", ] } -bevy_ui = { version = "0.12", optional = true, default-features = false } -bevy_utils = { version = "0.12", default-features = false } -bevy_window = { version = "0.12", default-features = false } +bevy_ui = { version = "0.13", optional = true, default-features = false } +bevy_utils = { version = "0.13", default-features = false } +bevy_window = { version = "0.13", default-features = false } bevy_eventlistener = "0.6" bevy_egui = { optional = true, version = "0.23" } @@ -48,7 +48,7 @@ bevy_picking_sprite = { optional = true, path = "backends/bevy_picking_sprite", bevy_picking_egui = { optional = true, path = "backends/bevy_picking_egui", version = "0.17" } [dev-dependencies] -bevy = { version = "0.12", default-features = false, features = [ +bevy = { version = "0.13", default-features = false, features = [ "bevy_winit", "x11", "bevy_gltf", diff --git a/backends/bevy_picking_egui/Cargo.toml b/backends/bevy_picking_egui/Cargo.toml index b536a04a..bc633847 100644 --- a/backends/bevy_picking_egui/Cargo.toml +++ b/backends/bevy_picking_egui/Cargo.toml @@ -13,10 +13,10 @@ resolver = "2" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -bevy_app = { version = "0.12", default-features = false } -bevy_ecs = { version = "0.12", default-features = false } -bevy_reflect = { version = "0.12", default-features = false } -bevy_render = { version = "0.12", default-features = false } +bevy_app = { version = "0.13", default-features = false } +bevy_ecs = { version = "0.13", default-features = false } +bevy_reflect = { version = "0.13", default-features = false } +bevy_render = { version = "0.13", default-features = false } bevy_egui = "0.23" # Local diff --git a/backends/bevy_picking_rapier/Cargo.toml b/backends/bevy_picking_rapier/Cargo.toml index 0ce46f57..e0f8d7f9 100644 --- a/backends/bevy_picking_rapier/Cargo.toml +++ b/backends/bevy_picking_rapier/Cargo.toml @@ -13,12 +13,12 @@ resolver = "2" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -bevy_app = { version = "0.12", default-features = false } -bevy_ecs = { version = "0.12", default-features = false } -bevy_reflect = { version = "0.12", default-features = false } -bevy_render = { version = "0.12", default-features = false } -bevy_transform = { version = "0.12", default-features = false } -bevy_window = { version = "0.12", default-features = false } +bevy_app = { version = "0.13", default-features = false } +bevy_ecs = { version = "0.13", default-features = false } +bevy_reflect = { version = "0.13", default-features = false } +bevy_render = { version = "0.13", default-features = false } +bevy_transform = { version = "0.13", default-features = false } +bevy_window = { version = "0.13", default-features = false } bevy_rapier3d = "0.23" # Local diff --git a/backends/bevy_picking_raycast/Cargo.toml b/backends/bevy_picking_raycast/Cargo.toml index a356bd75..b25a3718 100644 --- a/backends/bevy_picking_raycast/Cargo.toml +++ b/backends/bevy_picking_raycast/Cargo.toml @@ -13,12 +13,12 @@ resolver = "2" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -bevy_app = { version = "0.12", default-features = false } -bevy_ecs = { version = "0.12", default-features = false } -bevy_reflect = { version = "0.12", default-features = false } -bevy_render = { version = "0.12", default-features = false } -bevy_transform = { version = "0.12", default-features = false } -bevy_window = { version = "0.12", default-features = false } +bevy_app = { version = "0.13", default-features = false } +bevy_ecs = { version = "0.13", default-features = false } +bevy_reflect = { version = "0.13", default-features = false } +bevy_render = { version = "0.13", default-features = false } +bevy_transform = { version = "0.13", default-features = false } +bevy_window = { version = "0.13", default-features = false } bevy_mod_raycast = "0.16" # Local diff --git a/backends/bevy_picking_sprite/Cargo.toml b/backends/bevy_picking_sprite/Cargo.toml index dd982213..d55c7d0d 100644 --- a/backends/bevy_picking_sprite/Cargo.toml +++ b/backends/bevy_picking_sprite/Cargo.toml @@ -13,13 +13,13 @@ resolver = "2" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -bevy_app = { version = "0.12", default-features = false } -bevy_asset = { version = "0.12", default-features = false } -bevy_ecs = { version = "0.12", default-features = false } -bevy_math = { version = "0.12", default-features = false } -bevy_render = { version = "0.12", default-features = false } -bevy_sprite = { version = "0.12", default-features = false } -bevy_transform = { version = "0.12", default-features = false } -bevy_window = { version = "0.12", default-features = false } +bevy_app = { version = "0.13", default-features = false } +bevy_asset = { version = "0.13", default-features = false } +bevy_ecs = { version = "0.13", default-features = false } +bevy_math = { version = "0.13", default-features = false } +bevy_render = { version = "0.13", default-features = false } +bevy_sprite = { version = "0.13", default-features = false } +bevy_transform = { version = "0.13", default-features = false } +bevy_window = { version = "0.13", default-features = false } # Local bevy_picking_core = { path = "../../crates/bevy_picking_core", version = "0.17" } diff --git a/backends/bevy_picking_ui/Cargo.toml b/backends/bevy_picking_ui/Cargo.toml index 66d176f7..f46d9213 100644 --- a/backends/bevy_picking_ui/Cargo.toml +++ b/backends/bevy_picking_ui/Cargo.toml @@ -13,11 +13,11 @@ resolver = "2" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -bevy_app = { version = "0.12", default-features = false } -bevy_ecs = { version = "0.12", default-features = false } -bevy_render = { version = "0.12", default-features = false } -bevy_transform = { version = "0.12", default-features = false } -bevy_window = { version = "0.12", default-features = false } -bevy_ui = { version = "0.12", default-features = false } +bevy_app = { version = "0.13", default-features = false } +bevy_ecs = { version = "0.13", default-features = false } +bevy_render = { version = "0.13", default-features = false } +bevy_transform = { version = "0.13", default-features = false } +bevy_window = { version = "0.13", default-features = false } +bevy_ui = { version = "0.13", default-features = false } # Local bevy_picking_core = { path = "../../crates/bevy_picking_core", version = "0.17" } diff --git a/crates/bevy_picking_core/Cargo.toml b/crates/bevy_picking_core/Cargo.toml index 7766ba35..34c14f22 100644 --- a/crates/bevy_picking_core/Cargo.toml +++ b/crates/bevy_picking_core/Cargo.toml @@ -13,13 +13,13 @@ resolver = "2" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -bevy_app = { version = "0.12", default-features = false } -bevy_derive = { version = "0.12", default-features = false } -bevy_ecs = { version = "0.12", default-features = false } -bevy_math = { version = "0.12", default-features = false } -bevy_reflect = { version = "0.12", default-features = false } -bevy_render = { version = "0.12", default-features = false } -bevy_utils = { version = "0.12", default-features = false } -bevy_window = { version = "0.12", default-features = false } +bevy_app = { version = "0.13", default-features = false } +bevy_derive = { version = "0.13", default-features = false } +bevy_ecs = { version = "0.13", default-features = false } +bevy_math = { version = "0.13", default-features = false } +bevy_reflect = { version = "0.13", default-features = false } +bevy_render = { version = "0.13", default-features = false } +bevy_utils = { version = "0.13", default-features = false } +bevy_window = { version = "0.13", default-features = false } bevy_eventlistener = "0.6" diff --git a/crates/bevy_picking_highlight/Cargo.toml b/crates/bevy_picking_highlight/Cargo.toml index eb4daa86..b4d7d2b4 100644 --- a/crates/bevy_picking_highlight/Cargo.toml +++ b/crates/bevy_picking_highlight/Cargo.toml @@ -13,13 +13,13 @@ resolver = "2" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -bevy_app = { version = "0.12", default-features = false } -bevy_asset = { version = "0.12", default-features = false } -bevy_ecs = { version = "0.12", default-features = false } -bevy_reflect = { version = "0.12", default-features = false } -bevy_render = { version = "0.12", optional = true, default-features = false } -bevy_pbr = { version = "0.12", optional = true, default-features = false } -bevy_sprite = { version = "0.12", optional = true, default-features = false } +bevy_app = { version = "0.13", default-features = false } +bevy_asset = { version = "0.13", default-features = false } +bevy_ecs = { version = "0.13", default-features = false } +bevy_reflect = { version = "0.13", default-features = false } +bevy_render = { version = "0.13", optional = true, default-features = false } +bevy_pbr = { version = "0.13", optional = true, default-features = false } +bevy_sprite = { version = "0.13", optional = true, default-features = false } bevy_picking_core = { path = "../bevy_picking_core", version = "0.17" } bevy_picking_selection = { optional = true, path = "../bevy_picking_selection", version = "0.17" } diff --git a/crates/bevy_picking_input/Cargo.toml b/crates/bevy_picking_input/Cargo.toml index 05f9fc16..e33c9e5a 100644 --- a/crates/bevy_picking_input/Cargo.toml +++ b/crates/bevy_picking_input/Cargo.toml @@ -13,15 +13,15 @@ resolver = "2" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -bevy_app = { version = "0.12", default-features = false } -bevy_ecs = { version = "0.12", default-features = false } -bevy_hierarchy = { version = "0.12", default-features = false } -bevy_input = { version = "0.12", default-features = false } -bevy_math = { version = "0.12", default-features = false } -bevy_reflect = { version = "0.12", default-features = false } -bevy_render = { version = "0.12", default-features = false } -bevy_utils = { version = "0.12", default-features = false } -bevy_window = { version = "0.12", default-features = false } +bevy_app = { version = "0.13", default-features = false } +bevy_ecs = { version = "0.13", default-features = false } +bevy_hierarchy = { version = "0.13", default-features = false } +bevy_input = { version = "0.13", default-features = false } +bevy_math = { version = "0.13", default-features = false } +bevy_reflect = { version = "0.13", default-features = false } +bevy_render = { version = "0.13", default-features = false } +bevy_utils = { version = "0.13", default-features = false } +bevy_window = { version = "0.13", default-features = false } bevy_picking_core = { path = "../bevy_picking_core", version = "0.17" } bevy_picking_selection = { optional = true, path = "../bevy_picking_selection", version = "0.17" } diff --git a/crates/bevy_picking_selection/Cargo.toml b/crates/bevy_picking_selection/Cargo.toml index acf1215c..bd04cae4 100644 --- a/crates/bevy_picking_selection/Cargo.toml +++ b/crates/bevy_picking_selection/Cargo.toml @@ -13,11 +13,11 @@ resolver = "2" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -bevy_app = { version = "0.12", default-features = false } -bevy_ecs = { version = "0.12", default-features = false } -bevy_input = { version = "0.12", default-features = false } -bevy_reflect = { version = "0.12", default-features = false } -bevy_utils = { version = "0.12", default-features = false } +bevy_app = { version = "0.13", default-features = false } +bevy_ecs = { version = "0.13", default-features = false } +bevy_input = { version = "0.13", default-features = false } +bevy_reflect = { version = "0.13", default-features = false } +bevy_utils = { version = "0.13", default-features = false } bevy_eventlistener = "0.6" From 0abfb1d8f3f9be5bb0dba0701c482ee6eeff4a31 Mon Sep 17 00:00:00 2001 From: bstriker Date: Sun, 18 Feb 2024 01:58:06 -0500 Subject: [PATCH 02/40] Explicitly discard returns --- backends/bevy_picking_egui/src/lib.rs | 2 +- backends/bevy_picking_sprite/src/lib.rs | 2 +- backends/bevy_picking_ui/src/lib.rs | 2 +- crates/bevy_picking_core/src/events.rs | 36 ++++++++++----------- crates/bevy_picking_input/src/mouse.rs | 4 +-- crates/bevy_picking_input/src/touch.rs | 4 +-- crates/bevy_picking_selection/src/lib.rs | 40 +++++++++++++----------- 7 files changed, 47 insertions(+), 43 deletions(-) diff --git a/backends/bevy_picking_egui/src/lib.rs b/backends/bevy_picking_egui/src/lib.rs index 07be445d..733ed075 100644 --- a/backends/bevy_picking_egui/src/lib.rs +++ b/backends/bevy_picking_egui/src/lib.rs @@ -88,7 +88,7 @@ pub fn egui_picking( if ctx.get_mut().wants_pointer_input() { let entry = (entity, HitData::new(entity, 0.0, None, None)); let order = 1_000_000f32; // Assume egui should be on top of everything else. - output.send(PointerHits::new(*pointer, Vec::from([entry]), order)) + let _ = output.send(PointerHits::new(*pointer, Vec::from([entry]), order)); } } } diff --git a/backends/bevy_picking_sprite/src/lib.rs b/backends/bevy_picking_sprite/src/lib.rs index 3edb2085..6d0849c2 100644 --- a/backends/bevy_picking_sprite/src/lib.rs +++ b/backends/bevy_picking_sprite/src/lib.rs @@ -131,6 +131,6 @@ pub fn sprite_picking( .collect(); let order = camera.order as f32; - output.send(PointerHits::new(*pointer, picks, order)) + let _ = output.send(PointerHits::new(*pointer, picks, order)); } } diff --git a/backends/bevy_picking_ui/src/lib.rs b/backends/bevy_picking_ui/src/lib.rs index e78006d4..67a2bb2f 100644 --- a/backends/bevy_picking_ui/src/lib.rs +++ b/backends/bevy_picking_ui/src/lib.rs @@ -171,6 +171,6 @@ pub fn ui_picking( depth += 0.00001; // keep depth near 0 for precision } let order = camera.order as f32 + 0.5; // bevy ui can run on any camera, it's a special case - output.send(PointerHits::new(*pointer, picks, order)) + let _ = output.send(PointerHits::new(*pointer, picks, order)); } } diff --git a/crates/bevy_picking_core/src/events.rs b/crates/bevy_picking_core/src/events.rs index def8ce55..1ed53cc7 100644 --- a/crates/bevy_picking_core/src/events.rs +++ b/crates/bevy_picking_core/src/events.rs @@ -227,12 +227,12 @@ pub fn pointer_events( .iter() .flat_map(|h| h.iter().map(|(entity, data)| (*entity, data.to_owned()))) { - pointer_move.send(Pointer::new( + let _ = pointer_move.send(Pointer::new( pointer_id, location.clone(), hovered_entity, Move { hit, delta }, - )) + )); } } @@ -254,12 +254,12 @@ pub fn pointer_events( ); continue; }; - pointer_up.send(Pointer::new( + let _ = pointer_up.send(Pointer::new( press_event.pointer_id, location, hovered_entity, Up { button, hit }, - )) + )); } } for (hovered_entity, hit) in hover_map @@ -275,12 +275,12 @@ pub fn pointer_events( ); continue; }; - pointer_down.send(Pointer::new( + let _ = pointer_down.send(Pointer::new( press_event.pointer_id, location, hovered_entity, Down { button, hit }, - )) + )); } } } @@ -300,7 +300,7 @@ pub fn pointer_events( error!("Unable to get location for pointer {:?}", pointer_id); continue; }; - pointer_over.send(Pointer::new( + let _ = pointer_over.send(Pointer::new( pointer_id, location, hovered_entity, @@ -324,7 +324,7 @@ pub fn pointer_events( error!("Unable to get location for pointer {:?}", pointer_id); continue; }; - pointer_out.send(Pointer::new( + let _ = pointer_out.send(Pointer::new( pointer_id, location, hovered_entity, @@ -396,7 +396,7 @@ pub fn send_click_and_drag_events( latest_pos: down.pointer_location.position, }, ); - pointer_drag_start.send(Pointer::new( + let _ = pointer_drag_start.send(Pointer::new( pointer_id, down.pointer_location.clone(), down.target, @@ -404,7 +404,7 @@ pub fn send_click_and_drag_events( button, hit: down.hit.clone(), }, - )) + )); } for (dragged_entity, drag) in drag_list.iter_mut() { @@ -414,12 +414,12 @@ pub fn send_click_and_drag_events( delta: location.position - drag.latest_pos, }; drag.latest_pos = location.position; - pointer_drag.send(Pointer::new( + let _ = pointer_drag.send(Pointer::new( pointer_id, location.clone(), *dragged_entity, drag_event, - )) + )); } } } @@ -525,12 +525,12 @@ pub fn send_drag_over_events( dragged: *drag_target, hit: hit.clone(), }; - pointer_drag_enter.send(Pointer::new( + let _ = pointer_drag_enter.send(Pointer::new( pointer_id, pointer_location.clone(), target, event, - )) + )); } } } @@ -552,7 +552,7 @@ pub fn send_drag_over_events( |&&drag_target| target != drag_target, /* can't drag over itself */ ) { - pointer_drag_over.send(Pointer::new( + let _ = pointer_drag_over.send(Pointer::new( pointer_id, pointer_location.clone(), target, @@ -561,7 +561,7 @@ pub fn send_drag_over_events( dragged: *drag_target, hit: hit.clone(), }, - )) + )); } } } @@ -623,7 +623,7 @@ pub fn send_drag_over_events( continue; }; for drag_target in drag_list.keys() { - pointer_drag_leave.send(Pointer::new( + let _ = pointer_drag_leave.send(Pointer::new( pointer_id, pointer_location.clone(), target, @@ -632,7 +632,7 @@ pub fn send_drag_over_events( dragged: *drag_target, hit: hit.clone(), }, - )) + )); } } } diff --git a/crates/bevy_picking_input/src/mouse.rs b/crates/bevy_picking_input/src/mouse.rs index d3b5ad6d..a6a0417c 100644 --- a/crates/bevy_picking_input/src/mouse.rs +++ b/crates/bevy_picking_input/src/mouse.rs @@ -55,10 +55,10 @@ pub fn mouse_pick_events( match input.state { ButtonState::Pressed => { - pointer_presses.send(InputPress::new_down(PointerId::Mouse, button)) + let _ = pointer_presses.send(InputPress::new_down(PointerId::Mouse, button)); } ButtonState::Released => { - pointer_presses.send(InputPress::new_up(PointerId::Mouse, button)) + let _ = pointer_presses.send(InputPress::new_up(PointerId::Mouse, button)); } } } diff --git a/crates/bevy_picking_input/src/touch.rs b/crates/bevy_picking_input/src/touch.rs index 6908f66b..72c7421a 100644 --- a/crates/bevy_picking_input/src/touch.rs +++ b/crates/bevy_picking_input/src/touch.rs @@ -71,9 +71,9 @@ pub fn touch_pick_events( TouchPhase::Ended | TouchPhase::Canceled => { input_presses.send(InputPress::new_up(pointer, PointerButton::Primary)); location_cache.remove(&touch.id); - cancel_events.send(PointerCancel { + let _ = cancel_events.send(PointerCancel { pointer_id: pointer, - }) + }); } } } diff --git a/crates/bevy_picking_selection/src/lib.rs b/crates/bevy_picking_selection/src/lib.rs index 19694f24..485c29c3 100644 --- a/crates/bevy_picking_selection/src/lib.rs +++ b/crates/bevy_picking_selection/src/lib.rs @@ -157,12 +157,12 @@ pub fn send_selection_events( for (entity, selection) in selectables.iter() { let not_click_target = *target != entity; if selection.is_selected && not_click_target { - deselections.send(Pointer::new( + let _ = deselections.send(Pointer::new( *pointer_id, pointer_location.to_owned(), entity, Deselect, - )) + )); } } } @@ -189,7 +189,7 @@ pub fn send_selection_events( if !pointer_down_list.contains(&id) && !multiselect { for (entity, selection) in selectables.iter() { if selection.is_selected { - deselections.send(Pointer::new(id, location.clone(), entity, Deselect)) + let _ = deselections.send(Pointer::new(id, location.clone(), entity, Deselect)); } } } @@ -212,26 +212,30 @@ pub fn send_selection_events( if let Ok((entity, selection)) = selectables.get(*target) { if multiselect { match selection.is_selected { - true => deselections.send(Pointer::new( - *pointer_id, - pointer_location.to_owned(), - entity, - Deselect, - )), - false => selections.send(Pointer::new( - *pointer_id, - pointer_location.to_owned(), - entity, - Select, - )), - } + true => { + let _ = deselections.send(Pointer::new( + *pointer_id, + pointer_location.to_owned(), + entity, + Deselect, + )); + }, + false => { + let _ = selections.send(Pointer::new( + *pointer_id, + pointer_location.to_owned(), + entity, + Select, + )); + }, + }; } else if !selection.is_selected { - selections.send(Pointer::new( + let _ = selections.send(Pointer::new( *pointer_id, pointer_location.to_owned(), entity, Select, - )) + )); } } } From e2c3f91028b1229b55517686fbf651915cf3c5c4 Mon Sep 17 00:00:00 2001 From: bstriker Date: Sun, 18 Feb 2024 02:04:50 -0500 Subject: [PATCH 03/40] Replace deprecated Query::for_each_mut usage https://github.com/bevyengine/bevy/blob/e0778bf407631f9ae0f1e7326bb63e98d0e6fe87/crates/bevy_ecs/src/system/query.rs#L783-L786 --- crates/bevy_picking_core/src/pointer.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/bevy_picking_core/src/pointer.rs b/crates/bevy_picking_core/src/pointer.rs index ccfbe44a..c89688b8 100644 --- a/crates/bevy_picking_core/src/pointer.rs +++ b/crates/bevy_picking_core/src/pointer.rs @@ -176,7 +176,7 @@ impl InputPress { mut pointers: Query<(&PointerId, &mut PointerPress)>, ) { for input_press_event in events.read() { - pointers.for_each_mut(|(pointer_id, mut pointer)| { + pointers.iter_mut().for_each(|(pointer_id, mut pointer)| { if *pointer_id == input_press_event.pointer_id { let is_down = input_press_event.direction == PressDirection::Down; match input_press_event.button { @@ -260,7 +260,7 @@ impl InputMove { mut pointers: Query<(&PointerId, &mut PointerLocation)>, ) { for event_pointer in events.read() { - pointers.for_each_mut(|(id, mut pointer)| { + pointers.iter_mut().for_each(|(id, mut pointer)| { if *id == event_pointer.pointer_id { pointer.location = Some(event_pointer.location.to_owned()); } From 85e98dab220f4e8c7c16adc5b5d858f60a19f242 Mon Sep 17 00:00:00 2001 From: bstriker Date: Sun, 18 Feb 2024 02:05:31 -0500 Subject: [PATCH 04/40] Add remaining patterns for MouseButton --- crates/bevy_picking_input/src/mouse.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/crates/bevy_picking_input/src/mouse.rs b/crates/bevy_picking_input/src/mouse.rs index a6a0417c..d42b0df5 100644 --- a/crates/bevy_picking_input/src/mouse.rs +++ b/crates/bevy_picking_input/src/mouse.rs @@ -51,6 +51,8 @@ pub fn mouse_pick_events( MouseButton::Right => PointerButton::Secondary, MouseButton::Middle => PointerButton::Middle, MouseButton::Other(_) => continue, + MouseButton::Back => continue, + MouseButton::Forward => continue, }; match input.state { From 9e75c0ffd71daaaa09560f457124e15b7010e8f1 Mon Sep 17 00:00:00 2001 From: bstriker Date: Sun, 18 Feb 2024 02:06:53 -0500 Subject: [PATCH 05/40] Replace WorldQuery with QueryData --- backends/bevy_picking_ui/src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/backends/bevy_picking_ui/src/lib.rs b/backends/bevy_picking_ui/src/lib.rs index 67a2bb2f..cfe30462 100644 --- a/backends/bevy_picking_ui/src/lib.rs +++ b/backends/bevy_picking_ui/src/lib.rs @@ -23,7 +23,7 @@ #![deny(missing_docs)] use bevy_app::prelude::*; -use bevy_ecs::{prelude::*, query::WorldQuery}; +use bevy_ecs::{prelude::*, query::QueryData}; use bevy_render::{camera::NormalizedRenderTarget, prelude::*}; use bevy_transform::prelude::*; use bevy_ui::{prelude::*, RelativeCursorPosition, UiStack}; @@ -47,8 +47,8 @@ impl Plugin for BevyUiBackend { } /// Main query from bevy's `ui_focus_system` -#[derive(WorldQuery)] -#[world_query(mutable)] +#[derive(QueryData)] +#[query_data(mutable)] pub struct NodeQuery { entity: Entity, node: &'static Node, From 53acd94df7eb1237bcb44c9196eaa0ef35d6bddb Mon Sep 17 00:00:00 2001 From: bstriker Date: Sun, 18 Feb 2024 02:07:38 -0500 Subject: [PATCH 06/40] Replace bevy_input::Input usage with ButtonInput --- crates/bevy_picking_selection/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/bevy_picking_selection/src/lib.rs b/crates/bevy_picking_selection/src/lib.rs index 485c29c3..cb728070 100644 --- a/crates/bevy_picking_selection/src/lib.rs +++ b/crates/bevy_picking_selection/src/lib.rs @@ -9,7 +9,7 @@ use bevy_app::prelude::*; use bevy_ecs::prelude::*; -use bevy_input::{keyboard::KeyCode, Input}; +use bevy_input::{keyboard::KeyCode, ButtonInput}; use bevy_reflect::prelude::*; use bevy_utils::hashbrown::HashSet; @@ -105,7 +105,7 @@ pub struct Deselect; /// Unsurprising default multiselect inputs: both control and shift keys. pub fn multiselect_events( - keyboard: Res>, + keyboard: Res>, mut pointer_query: Query<&mut PointerMultiselect>, ) { let is_multiselect_pressed = keyboard.any_pressed([ From 85f5c54e5a9b16bab40b754ec97c8a504f185230 Mon Sep 17 00:00:00 2001 From: bstriker Date: Sun, 18 Feb 2024 02:08:38 -0500 Subject: [PATCH 07/40] Replace UICameraConfig Query with (Node, Visibility) --- backends/bevy_picking_ui/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backends/bevy_picking_ui/src/lib.rs b/backends/bevy_picking_ui/src/lib.rs index cfe30462..e000d811 100644 --- a/backends/bevy_picking_ui/src/lib.rs +++ b/backends/bevy_picking_ui/src/lib.rs @@ -65,7 +65,7 @@ pub struct NodeQuery { /// we need for determining picking. pub fn ui_picking( pointers: Query<(&PointerId, &PointerLocation)>, - cameras: Query<(Entity, &Camera, Option<&UiCameraConfig>)>, + cameras: Query<(Entity, &Camera, Option<(&Node, &Visibility)>)>, primary_window: Query>, ui_stack: Res, ui_scale: Option>, @@ -108,7 +108,7 @@ pub fn ui_picking( camera.is_active && camera.target.normalize(Some(window_entity)).unwrap() == location.target }) - .filter(|(_, _, ui_config)| ui_config.map(|config| config.show_ui).unwrap_or(true)) + .filter(|(_, _, optional_root_node)| optional_root_node.map(|(_node, visibility)| visibility == Visibility::Visible).unwrap_or(true)) .collect(); ui_cameras.sort_by_key(|(_, camera, _)| camera.order); From 7686829bc278b97988bcbbe18dec6b18498481ac Mon Sep 17 00:00:00 2001 From: bstriker Date: Sun, 18 Feb 2024 02:11:14 -0500 Subject: [PATCH 08/40] Replace TextureAtlasSprite usage with TextureAtlasLayout --- backends/bevy_picking_sprite/src/lib.rs | 20 +++++++++++--------- examples/sprite.rs | 16 +++++++++------- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/backends/bevy_picking_sprite/src/lib.rs b/backends/bevy_picking_sprite/src/lib.rs index 6d0849c2..b1fa1c78 100644 --- a/backends/bevy_picking_sprite/src/lib.rs +++ b/backends/bevy_picking_sprite/src/lib.rs @@ -11,7 +11,7 @@ use bevy_asset::prelude::*; use bevy_ecs::prelude::*; use bevy_math::prelude::*; use bevy_render::prelude::*; -use bevy_sprite::{Sprite, TextureAtlas, TextureAtlasSprite}; +use bevy_sprite::{Sprite, TextureAtlas, TextureAtlasLayout}; use bevy_transform::prelude::*; use bevy_window::PrimaryWindow; @@ -38,17 +38,17 @@ pub fn sprite_picking( cameras: Query<(Entity, &Camera, &GlobalTransform)>, primary_window: Query>, images: Res>, - texture_atlas: Res>, + texture_atlas_layout: Res>, sprite_query: Query< ( Entity, - (Option<&Sprite>, Option<&TextureAtlasSprite>), - (Option<&Handle>, Option<&Handle>), + (Option<&Sprite>, Option<&TextureAtlas>), + (Option<&Handle>, Option<&TextureAtlas>), &GlobalTransform, Option<&Pickable>, &ViewVisibility, ), - Or<(With, With)>, + Or<(With, With)>, >, mut output: EventWriter, ) { @@ -98,11 +98,13 @@ pub fn sprite_picking( .or_else(|| images.get(image).map(|f| f.size().as_vec2()))?; let anchor = sprite.anchor.as_vec(); (extents, anchor) - } else if let Some((sprite, atlas)) = sprite.1.zip(image.1) { + } else if let Some((sprite, atlas)) = sprite.0.zip(image.1) { let extents = sprite.custom_size.or_else(|| { - texture_atlas - .get(atlas) - .map(|f| f.textures[sprite.index].size()) + texture_atlas_layout + .get(&atlas.layout) + .map(|f| { + f.textures[atlas.index].size() + }) })?; let anchor = sprite.anchor.as_vec(); (extents, anchor) diff --git a/examples/sprite.rs b/examples/sprite.rs index 17c9ebc1..1e90f6ed 100644 --- a/examples/sprite.rs +++ b/examples/sprite.rs @@ -101,7 +101,7 @@ fn animate_sprite( mut query: Query<( &AnimationIndices, &mut AnimationTimer, - &mut TextureAtlasSprite, + &mut TextureAtlas, )>, ) { for (indices, mut timer, mut sprite) in &mut query { @@ -119,18 +119,20 @@ fn animate_sprite( fn setup_atlas( mut commands: Commands, asset_server: Res, - mut texture_atlases: ResMut>, + mut texture_atlas_layouts: ResMut>, ) { let texture_handle = asset_server.load("images/gabe-idle-run.png"); - let texture_atlas = - TextureAtlas::from_grid(texture_handle, Vec2::new(24.0, 24.0), 7, 1, None, None); - let texture_atlas_handle = texture_atlases.add(texture_atlas); + let layout = TextureAtlasLayout::from_grid(Vec2::new(24.0, 24.0), 7, 1, None, None); + let texture_atlas_layout_handle = texture_atlas_layouts.add(layout); // Use only the subset of sprites in the sheet that make up the run animation let animation_indices = AnimationIndices { first: 1, last: 6 }; commands.spawn(( SpriteSheetBundle { - texture_atlas: texture_atlas_handle, - sprite: TextureAtlasSprite::new(animation_indices.first), + texture: texture_handle, + atlas: TextureAtlas { + layout: texture_atlas_layout_handle, + index: animation_indices.first, + }, transform: Transform::from_xyz(300.0, 0.0, 0.0).with_scale(Vec3::splat(6.0)), ..default() }, From a9774f7f13befbd8d8b597878ca7af5ed1e1cf34 Mon Sep 17 00:00:00 2001 From: bstriker Date: Sun, 18 Feb 2024 02:11:55 -0500 Subject: [PATCH 09/40] Remove into() calls failing to infer types --- crates/bevy_picking_highlight/src/lib.rs | 12 ++++++------ examples/bevy_ui.rs | 4 ++-- examples/debug.rs | 4 ++-- examples/deselection.rs | 4 ++-- examples/egui.rs | 4 ++-- examples/event_listener.rs | 4 ++-- examples/many_events.rs | 2 +- examples/minimal.rs | 4 ++-- examples/multiple_windows.rs | 4 ++-- examples/rapier.rs | 4 ++-- examples/render_layers.rs | 6 +++--- examples/split_screen.rs | 4 ++-- examples/two_passes.rs | 12 ++++++------ examples/virtual_pointer.rs | 4 ++-- 14 files changed, 36 insertions(+), 36 deletions(-) diff --git a/crates/bevy_picking_highlight/src/lib.rs b/crates/bevy_picking_highlight/src/lib.rs index ea53251f..036bcb5c 100644 --- a/crates/bevy_picking_highlight/src/lib.rs +++ b/crates/bevy_picking_highlight/src/lib.rs @@ -68,20 +68,20 @@ impl Plugin for DefaultHighlightingPlugin { #[cfg(feature = "pbr")] app.add_plugins(HighlightPlugin:: { highlighting_default: |mut assets| GlobalHighlight { - hovered: assets.add(bevy_render::color::Color::rgb(0.35, 0.35, 0.35).into()), - pressed: assets.add(bevy_render::color::Color::rgb(0.35, 0.75, 0.35).into()), + hovered: assets.add(bevy_render::color::Color::rgb(0.35, 0.35, 0.35)), + pressed: assets.add(bevy_render::color::Color::rgb(0.35, 0.75, 0.35)), #[cfg(feature = "selection")] - selected: assets.add(bevy_render::color::Color::rgb(0.35, 0.35, 0.75).into()), + selected: assets.add(bevy_render::color::Color::rgb(0.35, 0.35, 0.75)), }, }); #[cfg(feature = "sprite")] app.add_plugins(HighlightPlugin:: { highlighting_default: |mut assets| GlobalHighlight { - hovered: assets.add(bevy_render::color::Color::rgb(0.35, 0.35, 0.35).into()), - pressed: assets.add(bevy_render::color::Color::rgb(0.35, 0.75, 0.35).into()), + hovered: assets.add(bevy_render::color::Color::rgb(0.35, 0.35, 0.35)), + pressed: assets.add(bevy_render::color::Color::rgb(0.35, 0.75, 0.35)), #[cfg(feature = "selection")] - selected: assets.add(bevy_render::color::Color::rgb(0.35, 0.35, 0.75).into()), + selected: assets.add(bevy_render::color::Color::rgb(0.35, 0.35, 0.75)), }, }); } diff --git a/examples/bevy_ui.rs b/examples/bevy_ui.rs index 6dd7a121..d673aeba 100644 --- a/examples/bevy_ui.rs +++ b/examples/bevy_ui.rs @@ -69,7 +69,7 @@ fn setup_3d( commands.spawn(( PbrBundle { mesh: meshes.add(Mesh::from(shape::Plane::from_size(5.0))), - material: materials.add(Color::rgb(0.3, 0.5, 0.3).into()), + material: materials.add(Color::rgb(0.3, 0.5, 0.3)), ..default() }, PickableBundle::default(), // <- Makes the mesh pickable. @@ -77,7 +77,7 @@ fn setup_3d( commands.spawn(( PbrBundle { mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), - material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()), + material: materials.add(Color::rgb(0.8, 0.7, 0.6)), transform: Transform::from_xyz(0.0, 0.5, 0.0), ..default() }, diff --git a/examples/debug.rs b/examples/debug.rs index f93154f8..514ddded 100644 --- a/examples/debug.rs +++ b/examples/debug.rs @@ -143,7 +143,7 @@ fn setup_3d( commands.spawn(( PbrBundle { mesh: meshes.add(Mesh::from(shape::Plane::from_size(5.0))), - material: materials.add(Color::rgb(0.3, 0.5, 0.3).into()), + material: materials.add(Color::rgb(0.3, 0.5, 0.3)), ..default() }, PickableBundle::default(), // <- Makes the mesh pickable. @@ -151,7 +151,7 @@ fn setup_3d( commands.spawn(( PbrBundle { mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), - material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()), + material: materials.add(Color::rgb(0.8, 0.7, 0.6)), transform: Transform::from_xyz(0.0, 0.5, 0.0), ..default() }, diff --git a/examples/deselection.rs b/examples/deselection.rs index 5135822d..98c3a9fe 100644 --- a/examples/deselection.rs +++ b/examples/deselection.rs @@ -22,7 +22,7 @@ fn setup( .spawn(( PbrBundle { mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), - material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()), + material: materials.add(Color::rgb(0.8, 0.7, 0.6)), transform: Transform::from_xyz(1.5, 0.5, 0.0), ..default() }, @@ -34,7 +34,7 @@ fn setup( commands.spawn(( PbrBundle { mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), - material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()), + material: materials.add(Color::rgb(0.8, 0.7, 0.6)), transform: Transform::from_xyz(0.0, 0.5, 0.0), ..default() }, diff --git a/examples/egui.rs b/examples/egui.rs index 820f902c..69e4d823 100644 --- a/examples/egui.rs +++ b/examples/egui.rs @@ -50,7 +50,7 @@ fn setup( commands.spawn(( PbrBundle { mesh: meshes.add(Mesh::from(shape::Plane::from_size(5.0))), - material: materials.add(Color::WHITE.into()), + material: materials.add(Color::WHITE), ..default() }, PickableBundle::default(), @@ -58,7 +58,7 @@ fn setup( commands.spawn(( PbrBundle { mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), - material: materials.add(Color::WHITE.into()), + material: materials.add(Color::WHITE), transform: Transform::from_xyz(0.0, 0.5, 0.0), ..default() }, diff --git a/examples/event_listener.rs b/examples/event_listener.rs index 82575f28..a27d6c93 100644 --- a/examples/event_listener.rs +++ b/examples/event_listener.rs @@ -38,7 +38,7 @@ fn setup( .spawn(( PbrBundle { mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), - material: materials.add(Color::WHITE.into()), + material: materials.add(Color::WHITE), ..default() }, PickableBundle::default(), @@ -102,7 +102,7 @@ fn setup( // listener. Events on children will bubble up to the parent! PbrBundle { mesh: meshes.add(Mesh::from(shape::Cube { size: 0.4 })), - material: materials.add(Color::RED.into()), + material: materials.add(Color::RED), transform: Transform::from_xyz(0.0, 1.0 + 0.5 * i as f32, 0.0), ..default() }, diff --git a/examples/many_events.rs b/examples/many_events.rs index 0980cf62..ec4330cb 100644 --- a/examples/many_events.rs +++ b/examples/many_events.rs @@ -32,7 +32,7 @@ fn setup( mut materials: ResMut>, ) { let mesh = &meshes.add(Mesh::from(shape::Cube { size: 1.0 })); - let material = &materials.add(Color::rgb(0.8, 0.7, 0.6).into()); + let material = &materials.add(Color::rgb(0.8, 0.7, 0.6)); for x in -WIDTH..=WIDTH { for y in -HEIGHT..=HEIGHT { diff --git a/examples/minimal.rs b/examples/minimal.rs index 6574ed95..23b7071a 100644 --- a/examples/minimal.rs +++ b/examples/minimal.rs @@ -22,7 +22,7 @@ fn setup( commands.spawn(( PbrBundle { mesh: meshes.add(Mesh::from(shape::Plane::from_size(5.0))), - material: materials.add(Color::rgb(0.3, 0.5, 0.3).into()), + material: materials.add(Color::rgb(0.3, 0.5, 0.3)), ..default() }, PickableBundle::default(), // Optional: adds selection, highlighting, and helper components. @@ -30,7 +30,7 @@ fn setup( commands.spawn(( PbrBundle { mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), - material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()), + material: materials.add(Color::rgb(0.8, 0.7, 0.6)), transform: Transform::from_xyz(0.0, 0.5, 0.0), ..default() }, diff --git a/examples/multiple_windows.rs b/examples/multiple_windows.rs index 2d3b067e..19d8a806 100644 --- a/examples/multiple_windows.rs +++ b/examples/multiple_windows.rs @@ -22,7 +22,7 @@ fn setup( commands.spawn(( PbrBundle { mesh: meshes.add(Mesh::from(shape::Plane::from_size(5.0))), - material: materials.add(Color::rgb(0.3, 0.5, 0.3).into()), + material: materials.add(Color::rgb(0.3, 0.5, 0.3)), ..default() }, PickableBundle::default(), // <- Makes the mesh pickable. @@ -30,7 +30,7 @@ fn setup( commands.spawn(( PbrBundle { mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), - material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()), + material: materials.add(Color::rgb(0.8, 0.7, 0.6)), transform: Transform::from_xyz(0.0, 0.5, 0.0), ..default() }, diff --git a/examples/rapier.rs b/examples/rapier.rs index 9b043aad..8a640877 100644 --- a/examples/rapier.rs +++ b/examples/rapier.rs @@ -32,7 +32,7 @@ fn setup( commands.spawn(( PbrBundle { mesh: meshes.add(Mesh::from(shape::Plane::from_size(5.0))), - material: materials.add(Color::WHITE.into()), + material: materials.add(Color::WHITE), ..default() }, Collider::cuboid(2.5, 0.01, 2.5), @@ -42,7 +42,7 @@ fn setup( commands.spawn(( PbrBundle { mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), - material: materials.add(Color::WHITE.into()), + material: materials.add(Color::WHITE), transform: Transform::from_xyz(0.0, 0.5, 0.0), ..default() }, diff --git a/examples/render_layers.rs b/examples/render_layers.rs index 349a5ba0..3205ed8e 100644 --- a/examples/render_layers.rs +++ b/examples/render_layers.rs @@ -23,8 +23,8 @@ fn setup( // plane commands.spawn(( PbrBundle { - mesh: meshes.add(shape::Plane::from_size(5.0).into()), - material: materials.add(Color::rgb(0.3, 0.5, 0.3).into()), + mesh: meshes.add(shape::Plane::from_size(5.0)), + material: materials.add(Color::rgb(0.3, 0.5, 0.3)), ..default() }, PickableBundle::default(), // <- Makes the mesh pickable. @@ -39,7 +39,7 @@ fn setup( }) .unwrap(), ), - material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()), + material: materials.add(Color::rgb(0.8, 0.7, 0.6)), transform: Transform::from_xyz(0.0, 0.0, 0.0), ..default() }, diff --git a/examples/split_screen.rs b/examples/split_screen.rs index 24539cbf..a3e99430 100644 --- a/examples/split_screen.rs +++ b/examples/split_screen.rs @@ -24,7 +24,7 @@ fn setup( commands.spawn(( PbrBundle { mesh: meshes.add(Mesh::from(shape::Plane::from_size(5.0))), - material: materials.add(Color::rgb(0.3, 0.5, 0.3).into()), + material: materials.add(Color::rgb(0.3, 0.5, 0.3)), ..default() }, PickableBundle::default(), // <- Makes the mesh pickable. @@ -32,7 +32,7 @@ fn setup( commands.spawn(( PbrBundle { mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), - material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()), + material: materials.add(Color::rgb(0.8, 0.7, 0.6)), transform: Transform::from_xyz(0.0, 0.5, 0.0), ..default() }, diff --git a/examples/two_passes.rs b/examples/two_passes.rs index a7853028..8ee08253 100644 --- a/examples/two_passes.rs +++ b/examples/two_passes.rs @@ -22,8 +22,8 @@ fn setup( // plane commands.spawn(( PbrBundle { - mesh: meshes.add(shape::Plane::from_size(5.0).into()), - material: materials.add(Color::rgb(0.3, 0.5, 0.3).into()), + mesh: meshes.add(shape::Plane::from_size(5.0)), + material: materials.add(Color::rgb(0.3, 0.5, 0.3)), ..default() }, PickableBundle::default(), // <- Makes the mesh pickable. @@ -32,7 +32,7 @@ fn setup( commands.spawn(( PbrBundle { mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), - material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()), + material: materials.add(Color::rgb(0.8, 0.7, 0.6)), transform: Transform::from_xyz(0.0, 0.5, 0.0), ..default() }, @@ -57,8 +57,8 @@ fn setup( // plane 2 commands.spawn(( PbrBundle { - mesh: meshes.add(shape::Plane::from_size(5.0).into()), - material: materials.add(Color::CYAN.into()), + mesh: meshes.add(shape::Plane::from_size(5.0)), + material: materials.add(Color::CYAN), transform: Transform::from_xyz(20., 20., 20.), ..default() }, @@ -68,7 +68,7 @@ fn setup( commands.spawn(( PbrBundle { mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), - material: materials.add(Color::YELLOW.into()), + material: materials.add(Color::YELLOW), transform: Transform::from_xyz(20., 20.5, 20.), ..default() }, diff --git a/examples/virtual_pointer.rs b/examples/virtual_pointer.rs index 6a7a4444..132c297f 100644 --- a/examples/virtual_pointer.rs +++ b/examples/virtual_pointer.rs @@ -62,7 +62,7 @@ fn setup( commands.spawn(( PbrBundle { mesh: meshes.add(Mesh::from(shape::Plane::from_size(5.0))), - material: materials.add(Color::WHITE.into()), + material: materials.add(Color::WHITE), ..default() }, PickableBundle::default(), // <- Makes the mesh pickable. @@ -72,7 +72,7 @@ fn setup( commands.spawn(( PbrBundle { mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), - material: materials.add(Color::WHITE.into()), + material: materials.add(Color::WHITE), transform: Transform::from_xyz(0.0, 0.5, 0.0), ..default() }, From 13d1784ba0b4b8f1682455aefc0f444aa8a0f6a3 Mon Sep 17 00:00:00 2001 From: bstriker Date: Sun, 18 Feb 2024 15:40:54 -0500 Subject: [PATCH 10/40] Add dependency bevy_hierarchy@^0.13 for backend/bevy_picking_ui --- backends/bevy_picking_ui/Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/backends/bevy_picking_ui/Cargo.toml b/backends/bevy_picking_ui/Cargo.toml index f46d9213..66c79a3e 100644 --- a/backends/bevy_picking_ui/Cargo.toml +++ b/backends/bevy_picking_ui/Cargo.toml @@ -15,6 +15,7 @@ resolver = "2" [dependencies] bevy_app = { version = "0.13", default-features = false } bevy_ecs = { version = "0.13", default-features = false } +bevy_hierarchy = { version = "0.13", default-features = false } bevy_render = { version = "0.13", default-features = false } bevy_transform = { version = "0.13", default-features = false } bevy_window = { version = "0.13", default-features = false } From 369bc62d9c982939836530ab40ab0ffa9ad321d0 Mon Sep 17 00:00:00 2001 From: bstriker Date: Sun, 18 Feb 2024 15:41:51 -0500 Subject: [PATCH 11/40] Update ui_picking --- backends/bevy_picking_ui/src/lib.rs | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/backends/bevy_picking_ui/src/lib.rs b/backends/bevy_picking_ui/src/lib.rs index e000d811..f95edd23 100644 --- a/backends/bevy_picking_ui/src/lib.rs +++ b/backends/bevy_picking_ui/src/lib.rs @@ -24,6 +24,7 @@ use bevy_app::prelude::*; use bevy_ecs::{prelude::*, query::QueryData}; +use bevy_hierarchy::Parent; use bevy_render::{camera::NormalizedRenderTarget, prelude::*}; use bevy_transform::prelude::*; use bevy_ui::{prelude::*, RelativeCursorPosition, UiStack}; @@ -65,7 +66,8 @@ pub struct NodeQuery { /// we need for determining picking. pub fn ui_picking( pointers: Query<(&PointerId, &PointerLocation)>, - cameras: Query<(Entity, &Camera, Option<(&Node, &Visibility)>)>, + root_nodes: Query<(Entity, &Visibility, Option<&TargetCamera>), Without>, + cameras: Query<(Entity, &Camera)>, primary_window: Query>, ui_stack: Res, ui_scale: Option>, @@ -104,16 +106,26 @@ pub fn ui_picking( // consider the topmost one rendering UI in this window. let mut ui_cameras: Vec<_> = cameras .iter() - .filter(|(_entity, camera, _)| { + .filter(|(_, camera)| camera.is_active && camera.target.normalize(Some(window_entity)).unwrap() == location.target + ) + .filter(|(entity, _camera)| { + let matching_root_node = root_nodes + .iter() + .find(|(_, _visibility, root_node_target_camera_marker_option)| { + root_node_target_camera_marker_option + .map_or(false, |marker| marker.entity() == *entity) + }); + matching_root_node.map_or(true, |(_, visibility, _)| { + matches!(visibility, Visibility::Visible | Visibility::Inherited) + }) }) - .filter(|(_, _, optional_root_node)| optional_root_node.map(|(_node, visibility)| visibility == Visibility::Visible).unwrap_or(true)) .collect(); - ui_cameras.sort_by_key(|(_, camera, _)| camera.order); + ui_cameras.sort_by_key(|(_, camera)| camera.order); // The last camera in the list will be the one with the highest order, and be the topmost. - let Some((camera_entity, camera, _)) = ui_cameras.last() else { + let Some((camera_entity, camera)) = ui_cameras.last() else { continue; }; From 85f58f61a148964aa9c675e79b5ca573fb1671fb Mon Sep 17 00:00:00 2001 From: bstriker Date: Mon, 19 Feb 2024 18:04:35 -0500 Subject: [PATCH 12/40] Bump dependencies bevy_eventlistener@^0.7, bevy_egui@^0.25, bevy_rapier3d@^0.25 --- Cargo.toml | 6 +++--- backends/bevy_picking_egui/Cargo.toml | 2 +- backends/bevy_picking_rapier/Cargo.toml | 2 +- crates/bevy_picking_core/Cargo.toml | 2 +- crates/bevy_picking_selection/Cargo.toml | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9e28cd57..134f04f1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,9 +32,9 @@ bevy_ui = { version = "0.13", optional = true, default-features = false } bevy_utils = { version = "0.13", default-features = false } bevy_window = { version = "0.13", default-features = false } -bevy_eventlistener = "0.6" -bevy_egui = { optional = true, version = "0.23" } -bevy_rapier3d = { optional = true, version = "0.23" } +bevy_eventlistener = "0.7" +bevy_egui = { optional = true, version = "0.25" } +bevy_rapier3d = { optional = true, version = "0.25" } # Local bevy_picking_core = { path = "crates/bevy_picking_core", version = "0.17" } diff --git a/backends/bevy_picking_egui/Cargo.toml b/backends/bevy_picking_egui/Cargo.toml index bc633847..85a5c76f 100644 --- a/backends/bevy_picking_egui/Cargo.toml +++ b/backends/bevy_picking_egui/Cargo.toml @@ -18,7 +18,7 @@ bevy_ecs = { version = "0.13", default-features = false } bevy_reflect = { version = "0.13", default-features = false } bevy_render = { version = "0.13", default-features = false } -bevy_egui = "0.23" +bevy_egui = "0.25" # Local bevy_picking_core = { path = "../../crates/bevy_picking_core", version = "0.17" } bevy_picking_selection = { path = "../../crates/bevy_picking_selection", optional = true, version = "0.17" } diff --git a/backends/bevy_picking_rapier/Cargo.toml b/backends/bevy_picking_rapier/Cargo.toml index e0f8d7f9..c9704427 100644 --- a/backends/bevy_picking_rapier/Cargo.toml +++ b/backends/bevy_picking_rapier/Cargo.toml @@ -20,6 +20,6 @@ bevy_render = { version = "0.13", default-features = false } bevy_transform = { version = "0.13", default-features = false } bevy_window = { version = "0.13", default-features = false } -bevy_rapier3d = "0.23" +bevy_rapier3d = "0.25" # Local bevy_picking_core = { path = "../../crates/bevy_picking_core", version = "0.17" } diff --git a/crates/bevy_picking_core/Cargo.toml b/crates/bevy_picking_core/Cargo.toml index 34c14f22..713febff 100644 --- a/crates/bevy_picking_core/Cargo.toml +++ b/crates/bevy_picking_core/Cargo.toml @@ -22,4 +22,4 @@ bevy_render = { version = "0.13", default-features = false } bevy_utils = { version = "0.13", default-features = false } bevy_window = { version = "0.13", default-features = false } -bevy_eventlistener = "0.6" +bevy_eventlistener = "0.7" diff --git a/crates/bevy_picking_selection/Cargo.toml b/crates/bevy_picking_selection/Cargo.toml index bd04cae4..2dd53966 100644 --- a/crates/bevy_picking_selection/Cargo.toml +++ b/crates/bevy_picking_selection/Cargo.toml @@ -19,6 +19,6 @@ bevy_input = { version = "0.13", default-features = false } bevy_reflect = { version = "0.13", default-features = false } bevy_utils = { version = "0.13", default-features = false } -bevy_eventlistener = "0.6" +bevy_eventlistener = "0.7" bevy_picking_core = { path = "../bevy_picking_core", version = "0.17" } From 2500474ff3fb1bf779c1f138dfa688728eb8e7ab Mon Sep 17 00:00:00 2001 From: bstriker Date: Mon, 19 Feb 2024 18:06:07 -0500 Subject: [PATCH 13/40] WIP: Bump dependency bevy_mod_raycast@^0.16 --- backends/bevy_picking_raycast/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backends/bevy_picking_raycast/Cargo.toml b/backends/bevy_picking_raycast/Cargo.toml index b25a3718..8e3f3a18 100644 --- a/backends/bevy_picking_raycast/Cargo.toml +++ b/backends/bevy_picking_raycast/Cargo.toml @@ -20,6 +20,6 @@ bevy_render = { version = "0.13", default-features = false } bevy_transform = { version = "0.13", default-features = false } bevy_window = { version = "0.13", default-features = false } -bevy_mod_raycast = "0.16" +bevy_mod_raycast = { git = "https://github.com/aevyrie/bevy_mod_raycast.git", branch = "bevy-0.13" } # Local bevy_picking_core = { path = "../../crates/bevy_picking_core", version = "0.17" } From 3539124f3888087fbb7867df28d4125cc154fb9c Mon Sep 17 00:00:00 2001 From: bstriker Date: Mon, 19 Feb 2024 17:50:00 -0500 Subject: [PATCH 14/40] Add default to LogPlugin --- examples/debug.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/debug.rs b/examples/debug.rs index 514ddded..2d5c9ca3 100644 --- a/examples/debug.rs +++ b/examples/debug.rs @@ -67,6 +67,7 @@ fn main() { .set(LogPlugin { filter: "bevy_mod_picking=trace".into(), // Show picking logs trace level and up level: Level::ERROR, // Show all other logs only at the error level and up + ..default() }), ) .add_plugins(DefaultPickingPlugins) From e8befeb0a8b5c85b93c91d326d7f484ab83e496c Mon Sep 17 00:00:00 2001 From: bstriker Date: Mon, 19 Feb 2024 17:51:12 -0500 Subject: [PATCH 15/40] Replace Color + Vec4 usages with Color + Color:rgba --- examples/gltf.rs | 6 +++--- examples/tinted_highlight.rs | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/gltf.rs b/examples/gltf.rs index 799ebe9b..3d10223e 100644 --- a/examples/gltf.rs +++ b/examples/gltf.rs @@ -56,15 +56,15 @@ fn make_pickable( /// `tinted_highlight` for more details. const HIGHLIGHT_TINT: Highlight = Highlight { hovered: Some(HighlightKind::new_dynamic(|matl| StandardMaterial { - base_color: matl.base_color + vec4(-0.5, -0.3, 0.9, 0.8), // hovered is blue + base_color: matl.base_color + Color::rgba(-0.5, -0.3, 0.9, 0.8), // hovered is blue ..matl.to_owned() })), pressed: Some(HighlightKind::new_dynamic(|matl| StandardMaterial { - base_color: matl.base_color + vec4(-0.4, -0.4, 0.8, 0.8), // pressed is a different blue + base_color: matl.base_color + Color::rgba(-0.4, -0.4, 0.8, 0.8), // pressed is a different blue ..matl.to_owned() })), selected: Some(HighlightKind::new_dynamic(|matl| StandardMaterial { - base_color: matl.base_color + vec4(-0.4, 0.8, -0.4, 0.0), // selected is green + base_color: matl.base_color + Color::rgba(-0.4, 0.8, -0.4, 0.0), // selected is green ..matl.to_owned() })), }; diff --git a/examples/tinted_highlight.rs b/examples/tinted_highlight.rs index 9186572a..e0902aff 100644 --- a/examples/tinted_highlight.rs +++ b/examples/tinted_highlight.rs @@ -23,15 +23,15 @@ fn main() { // Note that this works for *any* type of asset, not just bevy's built in materials. const HIGHLIGHT_TINT: Highlight = Highlight { hovered: Some(HighlightKind::new_dynamic(|matl| StandardMaterial { - base_color: matl.base_color + vec4(-0.2, -0.2, 0.4, 0.0), + base_color: matl.base_color + Color::rgba(-0.2, -0.2, 0.4, 0.0), ..matl.to_owned() })), pressed: Some(HighlightKind::new_dynamic(|matl| StandardMaterial { - base_color: matl.base_color + vec4(-0.3, -0.3, 0.5, 0.0), + base_color: matl.base_color + Color::rgba(-0.3, -0.3, 0.5, 0.0), ..matl.to_owned() })), selected: Some(HighlightKind::new_dynamic(|matl| StandardMaterial { - base_color: matl.base_color + vec4(-0.3, 0.2, -0.3, 0.0), + base_color: matl.base_color + Color::rgba(-0.3, 0.2, -0.3, 0.0), ..matl.to_owned() })), }; From ad249bbf37d4f35972a89b55a3fb15a0439c55cd Mon Sep 17 00:00:00 2001 From: bstriker Date: Mon, 19 Feb 2024 17:51:43 -0500 Subject: [PATCH 16/40] Update ClearColorConfig usages --- examples/render_layers.rs | 7 ++----- examples/split_screen.rs | 7 ++----- examples/two_passes.rs | 7 ++----- 3 files changed, 6 insertions(+), 15 deletions(-) diff --git a/examples/render_layers.rs b/examples/render_layers.rs index 3205ed8e..b533f035 100644 --- a/examples/render_layers.rs +++ b/examples/render_layers.rs @@ -1,6 +1,6 @@ //! Demonstrates that picking respects render layers and order. -use bevy::{core_pipeline::clear_color::ClearColorConfig, prelude::*}; +use bevy::{render::camera::ClearColorConfig, prelude::*}; use bevy_mod_picking::prelude::*; use bevy_render::view::RenderLayers; @@ -67,11 +67,8 @@ fn setup( commands.spawn(( Camera3dBundle { transform: camera_transform, - camera_3d: Camera3d { - clear_color: ClearColorConfig::None, - ..default() - }, camera: Camera { + clear_color: ClearColorConfig::None, // renders after / on top of the main camera order: 1, ..default() diff --git a/examples/split_screen.rs b/examples/split_screen.rs index a3e99430..97364cd5 100644 --- a/examples/split_screen.rs +++ b/examples/split_screen.rs @@ -62,15 +62,12 @@ fn setup( Camera3dBundle { transform: Transform::from_xyz(10.0, 10., 15.0).looking_at(Vec3::ZERO, Vec3::Y), camera: Camera { + // don't clear on the second camera because the first camera already cleared the window + clear_color: ClearColorConfig::None, // Renders the right camera after the left camera, which has a default priority of 0 order: 1, ..default() }, - camera_3d: Camera3d { - // don't clear on the second camera because the first camera already cleared the window - clear_color: bevy::core_pipeline::clear_color::ClearColorConfig::None, - ..default() - }, ..default() }, RightCamera, diff --git a/examples/two_passes.rs b/examples/two_passes.rs index 8ee08253..5a0824c9 100644 --- a/examples/two_passes.rs +++ b/examples/two_passes.rs @@ -1,6 +1,6 @@ //! Demonstrates that picking respects camera render order. -use bevy::{core_pipeline::clear_color::ClearColorConfig, prelude::*}; +use bevy::{render::camera::ClearColorConfig, prelude::*}; use bevy_mod_picking::prelude::*; fn main() { @@ -88,11 +88,8 @@ fn setup( commands.spawn((Camera3dBundle { transform: Transform::from_xyz(30., 30., 30.0) .looking_at(Vec3::new(20., 20.5, 20.), Vec3::Y), - camera_3d: Camera3d { - clear_color: ClearColorConfig::None, - ..default() - }, camera: Camera { + clear_color: ClearColorConfig::None, // renders after / on top of the main camera order: 1, ..default() From 2e520e0bbf1f677c001e3f8f1b2e93768db20165 Mon Sep 17 00:00:00 2001 From: bstriker Date: Mon, 19 Feb 2024 17:53:28 -0500 Subject: [PATCH 17/40] Update generic parameters for EntityCommands implementation --- examples/bevy_ui.rs | 2 +- examples/debug.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/bevy_ui.rs b/examples/bevy_ui.rs index d673aeba..aa2b0f5a 100644 --- a/examples/bevy_ui.rs +++ b/examples/bevy_ui.rs @@ -106,7 +106,7 @@ trait NewButton { fn add_button(self, text: &str) -> Self; } -impl<'w, 's, 'a> NewButton for EntityCommands<'w, 's, 'a> { +impl<'a> NewButton for EntityCommands<'a> { fn add_button(mut self, text: &str) -> Self { let text_string = text.to_string(); let child = self diff --git a/examples/debug.rs b/examples/debug.rs index 2d5c9ca3..ae4a893a 100644 --- a/examples/debug.rs +++ b/examples/debug.rs @@ -181,7 +181,7 @@ trait NewButton { fn add_button(self, text: &str, on_click_action: On>) -> Self; } -impl<'w, 's, 'a> NewButton for EntityCommands<'w, 's, 'a> { +impl<'a> NewButton for EntityCommands<'a> { fn add_button(mut self, text: &str, on_click_action: On>) -> Self { let child = self .commands() From 80e02a603b58f57b8b95be09e5d367449898610b Mon Sep 17 00:00:00 2001 From: bstriker Date: Mon, 19 Feb 2024 17:53:57 -0500 Subject: [PATCH 18/40] Replace App.add_state usage with App.init_state --- src/debug/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/debug/mod.rs b/src/debug/mod.rs index d4ccd922..b816fda0 100644 --- a/src/debug/mod.rs +++ b/src/debug/mod.rs @@ -90,7 +90,7 @@ impl Plugin for DebugPickingPlugin { DebugPickingMode::Normal }; - app.add_state::() + app.init_state::() .insert_resource(State::new(start_mode)) .add_systems( PreUpdate, From 5d6fb645180173c4429a89b11daf8d412879e684 Mon Sep 17 00:00:00 2001 From: bstriker Date: Mon, 19 Feb 2024 17:54:34 -0500 Subject: [PATCH 19/40] Replace Ray3d::from_screenspace usage with ray_from_screenspace --- backends/bevy_picking_raycast/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backends/bevy_picking_raycast/src/lib.rs b/backends/bevy_picking_raycast/src/lib.rs index 4a7efb38..9068c2e0 100644 --- a/backends/bevy_picking_raycast/src/lib.rs +++ b/backends/bevy_picking_raycast/src/lib.rs @@ -104,7 +104,7 @@ pub fn update_hits( }) .filter(|(.., marker, _)| marker.is_some() || !backend_settings.require_markers) .filter_map(|(entity, camera, transform, _, layers)| { - Ray3d::from_screenspace( + ray_from_screenspace( pointer_location.position, camera, transform, From 56f3aabcabf0c9803ea4eae02368403e37094c09 Mon Sep 17 00:00:00 2001 From: bstriker Date: Mon, 19 Feb 2024 17:55:10 -0500 Subject: [PATCH 20/40] Dereference ray.direction before passing to cast_ray_and_get_normal --- backends/bevy_picking_rapier/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backends/bevy_picking_rapier/src/lib.rs b/backends/bevy_picking_rapier/src/lib.rs index 2f52021f..770eb3f8 100644 --- a/backends/bevy_picking_rapier/src/lib.rs +++ b/backends/bevy_picking_rapier/src/lib.rs @@ -118,7 +118,7 @@ pub fn update_hits( if let Some((entity, hit_data)) = rapier_context .cast_ray_and_get_normal( ray.origin, - ray.direction, + *ray.direction, f32::MAX, true, QueryFilter::new().predicate(&|entity| { From c0e6b8961fafb9fc085945f1ab7827cdcd13c136 Mon Sep 17 00:00:00 2001 From: bstriker Date: Wed, 21 Feb 2024 00:46:58 -0500 Subject: [PATCH 21/40] Add can_bubble attribute to Pointer --- crates/bevy_picking_core/src/events.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/bevy_picking_core/src/events.rs b/crates/bevy_picking_core/src/events.rs index 1ed53cc7..21bc24bd 100644 --- a/crates/bevy_picking_core/src/events.rs +++ b/crates/bevy_picking_core/src/events.rs @@ -19,6 +19,7 @@ use bevy_utils::{tracing::error, HashMap}; /// Stores the common data needed for all `PointerEvent`s. #[derive(Clone, PartialEq, Debug, Reflect, Event, EntityEvent)] +#[can_bubble] pub struct Pointer { /// The target of this event #[target] From 3cb0d0623bcfda5ca2ec85b93d366b70c60b9245 Mon Sep 17 00:00:00 2001 From: aviac Date: Wed, 21 Feb 2024 10:24:25 +0100 Subject: [PATCH 22/40] chore(update): flatten system params Authored-by: RobWalt --- backends/bevy_picking_sprite/src/lib.rs | 97 +++++++++++++------------ 1 file changed, 49 insertions(+), 48 deletions(-) diff --git a/backends/bevy_picking_sprite/src/lib.rs b/backends/bevy_picking_sprite/src/lib.rs index b1fa1c78..4bf1d9a8 100644 --- a/backends/bevy_picking_sprite/src/lib.rs +++ b/backends/bevy_picking_sprite/src/lib.rs @@ -42,8 +42,9 @@ pub fn sprite_picking( sprite_query: Query< ( Entity, - (Option<&Sprite>, Option<&TextureAtlas>), - (Option<&Handle>, Option<&TextureAtlas>), + Option<&Sprite>, + Option<&TextureAtlas>, + Option<&Handle>, &GlobalTransform, Option<&Pickable>, &ViewVisibility, @@ -54,8 +55,8 @@ pub fn sprite_picking( ) { let mut sorted_sprites: Vec<_> = sprite_query.iter().collect(); sorted_sprites.sort_by(|a, b| { - (b.3.translation().z) - .partial_cmp(&a.3.translation().z) + (b.4.translation().z) + .partial_cmp(&a.4.translation().z) .unwrap_or(Ordering::Equal) }); @@ -86,50 +87,50 @@ pub fn sprite_picking( .iter() .copied() .filter(|(.., visibility)| visibility.get()) - .filter_map(|(entity, sprite, image, sprite_transform, pickable, ..)| { - if blocked { - return None; - } - - // Hit box in sprite coordinate system - let (extents, anchor) = if let Some((sprite, image)) = sprite.0.zip(image.0) { - let extents = sprite - .custom_size - .or_else(|| images.get(image).map(|f| f.size().as_vec2()))?; - let anchor = sprite.anchor.as_vec(); - (extents, anchor) - } else if let Some((sprite, atlas)) = sprite.0.zip(image.1) { - let extents = sprite.custom_size.or_else(|| { - texture_atlas_layout - .get(&atlas.layout) - .map(|f| { - f.textures[atlas.index].size() - }) - })?; - let anchor = sprite.anchor.as_vec(); - (extents, anchor) - } else { - return None; - }; - - let center = -anchor * extents; - let rect = Rect::from_center_half_size(center, extents / 2.0); - - // Transform cursor pos to sprite coordinate system - let cursor_pos_sprite = sprite_transform - .affine() - .inverse() - .transform_point3((cursor_pos_world, 0.0).into()); - - let is_cursor_in_sprite = rect.contains(cursor_pos_sprite.truncate()); - blocked = - is_cursor_in_sprite && pickable.map(|p| p.should_block_lower) != Some(false); - - is_cursor_in_sprite.then_some(( - entity, - HitData::new(cam_entity, sprite_transform.translation().z, None, None), - )) - }) + .filter_map( + |(entity, sprite, atlas, image, sprite_transform, pickable, ..)| { + if blocked { + return None; + } + + // Hit box in sprite coordinate system + let (extents, anchor) = if let Some((sprite, image)) = sprite.zip(image) { + let extents = sprite + .custom_size + .or_else(|| images.get(image).map(|f| f.size().as_vec2()))?; + let anchor = sprite.anchor.as_vec(); + (extents, anchor) + } else if let Some((sprite, atlas)) = sprite.zip(atlas) { + let extents = sprite.custom_size.or_else(|| { + texture_atlas_layout + .get(&atlas.layout) + .map(|f| f.textures[atlas.index].size()) + })?; + let anchor = sprite.anchor.as_vec(); + (extents, anchor) + } else { + return None; + }; + + let center = -anchor * extents; + let rect = Rect::from_center_half_size(center, extents / 2.0); + + // Transform cursor pos to sprite coordinate system + let cursor_pos_sprite = sprite_transform + .affine() + .inverse() + .transform_point3((cursor_pos_world, 0.0).into()); + + let is_cursor_in_sprite = rect.contains(cursor_pos_sprite.truncate()); + blocked = is_cursor_in_sprite + && pickable.map(|p| p.should_block_lower) != Some(false); + + is_cursor_in_sprite.then_some(( + entity, + HitData::new(cam_entity, sprite_transform.translation().z, None, None), + )) + }, + ) .collect(); let order = camera.order as f32; From 27760f3a16c83b357c0bb77c1239db70e8f283c6 Mon Sep 17 00:00:00 2001 From: aviac Date: Wed, 21 Feb 2024 10:27:25 +0100 Subject: [PATCH 23/40] chore(update): use InheritedVisibility instead of Visibility Authored-by: RobWalt --- backends/bevy_picking_ui/src/lib.rs | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/backends/bevy_picking_ui/src/lib.rs b/backends/bevy_picking_ui/src/lib.rs index f95edd23..697158e5 100644 --- a/backends/bevy_picking_ui/src/lib.rs +++ b/backends/bevy_picking_ui/src/lib.rs @@ -66,7 +66,7 @@ pub struct NodeQuery { /// we need for determining picking. pub fn ui_picking( pointers: Query<(&PointerId, &PointerLocation)>, - root_nodes: Query<(Entity, &Visibility, Option<&TargetCamera>), Without>, + root_nodes: Query<(Entity, &InheritedVisibility, Option<&TargetCamera>), Without>, cameras: Query<(Entity, &Camera)>, primary_window: Query>, ui_stack: Res, @@ -106,20 +106,18 @@ pub fn ui_picking( // consider the topmost one rendering UI in this window. let mut ui_cameras: Vec<_> = cameras .iter() - .filter(|(_, camera)| + .filter(|(_, camera)| { camera.is_active && camera.target.normalize(Some(window_entity)).unwrap() == location.target - ) + }) .filter(|(entity, _camera)| { - let matching_root_node = root_nodes - .iter() - .find(|(_, _visibility, root_node_target_camera_marker_option)| { + let matching_root_node = root_nodes.iter().find( + |(_, _visibility, root_node_target_camera_marker_option)| { root_node_target_camera_marker_option .map_or(false, |marker| marker.entity() == *entity) - }); - matching_root_node.map_or(true, |(_, visibility, _)| { - matches!(visibility, Visibility::Visible | Visibility::Inherited) - }) + }, + ); + matching_root_node.map_or(true, |(_, visibility, _)| visibility.get()) }) .collect(); ui_cameras.sort_by_key(|(_, camera)| camera.order); From 664a8830bd689680c5c8c6348520b6c1e7397c02 Mon Sep 17 00:00:00 2001 From: aviac Date: Wed, 21 Feb 2024 10:30:17 +0100 Subject: [PATCH 24/40] chore(update): add sorting based on `IsDefaultUiCamera` marker Authored-by: RobWalt --- backends/bevy_picking_ui/src/lib.rs | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/backends/bevy_picking_ui/src/lib.rs b/backends/bevy_picking_ui/src/lib.rs index 697158e5..380d5dbe 100644 --- a/backends/bevy_picking_ui/src/lib.rs +++ b/backends/bevy_picking_ui/src/lib.rs @@ -67,7 +67,7 @@ pub struct NodeQuery { pub fn ui_picking( pointers: Query<(&PointerId, &PointerLocation)>, root_nodes: Query<(Entity, &InheritedVisibility, Option<&TargetCamera>), Without>, - cameras: Query<(Entity, &Camera)>, + cameras: Query<(Entity, &Camera, Has)>, primary_window: Query>, ui_stack: Res, ui_scale: Option>, @@ -106,24 +106,32 @@ pub fn ui_picking( // consider the topmost one rendering UI in this window. let mut ui_cameras: Vec<_> = cameras .iter() - .filter(|(_, camera)| { + .filter(|(_, camera, _)| { camera.is_active && camera.target.normalize(Some(window_entity)).unwrap() == location.target }) - .filter(|(entity, _camera)| { + .filter(|(camera_entity, _, _)| { let matching_root_node = root_nodes.iter().find( |(_, _visibility, root_node_target_camera_marker_option)| { root_node_target_camera_marker_option - .map_or(false, |marker| marker.entity() == *entity) + .map_or(false, |marker| marker.entity() == *camera_entity) }, ); matching_root_node.map_or(true, |(_, visibility, _)| visibility.get()) }) .collect(); - ui_cameras.sort_by_key(|(_, camera)| camera.order); + + // sort by default camera marker, then by priority value + ui_cameras.sort_by( + |(_, cam_a, has_default_marker_a), (_, cam_b, has_default_marker_b)| { + has_default_marker_a + .cmp(has_default_marker_b) + .then_with(|| cam_a.order.cmp(&cam_b.order)) + }, + ); // The last camera in the list will be the one with the highest order, and be the topmost. - let Some((camera_entity, camera)) = ui_cameras.last() else { + let Some((camera_entity, camera, _)) = ui_cameras.last() else { continue; }; From 0693b604bbc69df4bdb5d9ec6df4dd99e1e16d41 Mon Sep 17 00:00:00 2001 From: aviac Date: Wed, 21 Feb 2024 10:31:57 +0100 Subject: [PATCH 25/40] chore(update): remove `let _ = ` and just ignore event sends Authored-by: RobWalt --- backends/bevy_picking_egui/src/lib.rs | 2 +- backends/bevy_picking_sprite/src/lib.rs | 2 +- backends/bevy_picking_ui/src/lib.rs | 2 +- crates/bevy_picking_core/src/events.rs | 20 ++++++++++---------- crates/bevy_picking_input/src/mouse.rs | 4 ++-- crates/bevy_picking_input/src/touch.rs | 2 +- crates/bevy_picking_selection/src/lib.rs | 10 +++++----- 7 files changed, 21 insertions(+), 21 deletions(-) diff --git a/backends/bevy_picking_egui/src/lib.rs b/backends/bevy_picking_egui/src/lib.rs index 733ed075..10ca759f 100644 --- a/backends/bevy_picking_egui/src/lib.rs +++ b/backends/bevy_picking_egui/src/lib.rs @@ -88,7 +88,7 @@ pub fn egui_picking( if ctx.get_mut().wants_pointer_input() { let entry = (entity, HitData::new(entity, 0.0, None, None)); let order = 1_000_000f32; // Assume egui should be on top of everything else. - let _ = output.send(PointerHits::new(*pointer, Vec::from([entry]), order)); + output.send(PointerHits::new(*pointer, Vec::from([entry]), order)); } } } diff --git a/backends/bevy_picking_sprite/src/lib.rs b/backends/bevy_picking_sprite/src/lib.rs index 4bf1d9a8..9b6a72ce 100644 --- a/backends/bevy_picking_sprite/src/lib.rs +++ b/backends/bevy_picking_sprite/src/lib.rs @@ -134,6 +134,6 @@ pub fn sprite_picking( .collect(); let order = camera.order as f32; - let _ = output.send(PointerHits::new(*pointer, picks, order)); + output.send(PointerHits::new(*pointer, picks, order)); } } diff --git a/backends/bevy_picking_ui/src/lib.rs b/backends/bevy_picking_ui/src/lib.rs index 380d5dbe..237f3b70 100644 --- a/backends/bevy_picking_ui/src/lib.rs +++ b/backends/bevy_picking_ui/src/lib.rs @@ -189,6 +189,6 @@ pub fn ui_picking( depth += 0.00001; // keep depth near 0 for precision } let order = camera.order as f32 + 0.5; // bevy ui can run on any camera, it's a special case - let _ = output.send(PointerHits::new(*pointer, picks, order)); + output.send(PointerHits::new(*pointer, picks, order)); } } diff --git a/crates/bevy_picking_core/src/events.rs b/crates/bevy_picking_core/src/events.rs index 21bc24bd..21a82144 100644 --- a/crates/bevy_picking_core/src/events.rs +++ b/crates/bevy_picking_core/src/events.rs @@ -228,7 +228,7 @@ pub fn pointer_events( .iter() .flat_map(|h| h.iter().map(|(entity, data)| (*entity, data.to_owned()))) { - let _ = pointer_move.send(Pointer::new( + pointer_move.send(Pointer::new( pointer_id, location.clone(), hovered_entity, @@ -255,7 +255,7 @@ pub fn pointer_events( ); continue; }; - let _ = pointer_up.send(Pointer::new( + pointer_up.send(Pointer::new( press_event.pointer_id, location, hovered_entity, @@ -276,7 +276,7 @@ pub fn pointer_events( ); continue; }; - let _ = pointer_down.send(Pointer::new( + pointer_down.send(Pointer::new( press_event.pointer_id, location, hovered_entity, @@ -301,7 +301,7 @@ pub fn pointer_events( error!("Unable to get location for pointer {:?}", pointer_id); continue; }; - let _ = pointer_over.send(Pointer::new( + pointer_over.send(Pointer::new( pointer_id, location, hovered_entity, @@ -325,7 +325,7 @@ pub fn pointer_events( error!("Unable to get location for pointer {:?}", pointer_id); continue; }; - let _ = pointer_out.send(Pointer::new( + pointer_out.send(Pointer::new( pointer_id, location, hovered_entity, @@ -397,7 +397,7 @@ pub fn send_click_and_drag_events( latest_pos: down.pointer_location.position, }, ); - let _ = pointer_drag_start.send(Pointer::new( + pointer_drag_start.send(Pointer::new( pointer_id, down.pointer_location.clone(), down.target, @@ -415,7 +415,7 @@ pub fn send_click_and_drag_events( delta: location.position - drag.latest_pos, }; drag.latest_pos = location.position; - let _ = pointer_drag.send(Pointer::new( + pointer_drag.send(Pointer::new( pointer_id, location.clone(), *dragged_entity, @@ -526,7 +526,7 @@ pub fn send_drag_over_events( dragged: *drag_target, hit: hit.clone(), }; - let _ = pointer_drag_enter.send(Pointer::new( + pointer_drag_enter.send(Pointer::new( pointer_id, pointer_location.clone(), target, @@ -553,7 +553,7 @@ pub fn send_drag_over_events( |&&drag_target| target != drag_target, /* can't drag over itself */ ) { - let _ = pointer_drag_over.send(Pointer::new( + pointer_drag_over.send(Pointer::new( pointer_id, pointer_location.clone(), target, @@ -624,7 +624,7 @@ pub fn send_drag_over_events( continue; }; for drag_target in drag_list.keys() { - let _ = pointer_drag_leave.send(Pointer::new( + pointer_drag_leave.send(Pointer::new( pointer_id, pointer_location.clone(), target, diff --git a/crates/bevy_picking_input/src/mouse.rs b/crates/bevy_picking_input/src/mouse.rs index d42b0df5..252c021e 100644 --- a/crates/bevy_picking_input/src/mouse.rs +++ b/crates/bevy_picking_input/src/mouse.rs @@ -57,10 +57,10 @@ pub fn mouse_pick_events( match input.state { ButtonState::Pressed => { - let _ = pointer_presses.send(InputPress::new_down(PointerId::Mouse, button)); + pointer_presses.send(InputPress::new_down(PointerId::Mouse, button)); } ButtonState::Released => { - let _ = pointer_presses.send(InputPress::new_up(PointerId::Mouse, button)); + pointer_presses.send(InputPress::new_up(PointerId::Mouse, button)); } } } diff --git a/crates/bevy_picking_input/src/touch.rs b/crates/bevy_picking_input/src/touch.rs index 72c7421a..c159b68e 100644 --- a/crates/bevy_picking_input/src/touch.rs +++ b/crates/bevy_picking_input/src/touch.rs @@ -71,7 +71,7 @@ pub fn touch_pick_events( TouchPhase::Ended | TouchPhase::Canceled => { input_presses.send(InputPress::new_up(pointer, PointerButton::Primary)); location_cache.remove(&touch.id); - let _ = cancel_events.send(PointerCancel { + cancel_events.send(PointerCancel { pointer_id: pointer, }); } diff --git a/crates/bevy_picking_selection/src/lib.rs b/crates/bevy_picking_selection/src/lib.rs index cb728070..eaa7adeb 100644 --- a/crates/bevy_picking_selection/src/lib.rs +++ b/crates/bevy_picking_selection/src/lib.rs @@ -157,7 +157,7 @@ pub fn send_selection_events( for (entity, selection) in selectables.iter() { let not_click_target = *target != entity; if selection.is_selected && not_click_target { - let _ = deselections.send(Pointer::new( + deselections.send(Pointer::new( *pointer_id, pointer_location.to_owned(), entity, @@ -189,7 +189,7 @@ pub fn send_selection_events( if !pointer_down_list.contains(&id) && !multiselect { for (entity, selection) in selectables.iter() { if selection.is_selected { - let _ = deselections.send(Pointer::new(id, location.clone(), entity, Deselect)); + deselections.send(Pointer::new(id, location.clone(), entity, Deselect)); } } } @@ -213,7 +213,7 @@ pub fn send_selection_events( if multiselect { match selection.is_selected { true => { - let _ = deselections.send(Pointer::new( + deselections.send(Pointer::new( *pointer_id, pointer_location.to_owned(), entity, @@ -221,7 +221,7 @@ pub fn send_selection_events( )); }, false => { - let _ = selections.send(Pointer::new( + selections.send(Pointer::new( *pointer_id, pointer_location.to_owned(), entity, @@ -230,7 +230,7 @@ pub fn send_selection_events( }, }; } else if !selection.is_selected { - let _ = selections.send(Pointer::new( + selections.send(Pointer::new( *pointer_id, pointer_location.to_owned(), entity, From a5672ee62e7cb0fa7971785128d496fdee37101a Mon Sep 17 00:00:00 2001 From: bstriker Date: Fri, 23 Feb 2024 15:55:28 -0500 Subject: [PATCH 26/40] Bump dependency bevy_mod_raycast@^0.17 --- backends/bevy_picking_raycast/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backends/bevy_picking_raycast/Cargo.toml b/backends/bevy_picking_raycast/Cargo.toml index 8e3f3a18..e12cfd1e 100644 --- a/backends/bevy_picking_raycast/Cargo.toml +++ b/backends/bevy_picking_raycast/Cargo.toml @@ -20,6 +20,6 @@ bevy_render = { version = "0.13", default-features = false } bevy_transform = { version = "0.13", default-features = false } bevy_window = { version = "0.13", default-features = false } -bevy_mod_raycast = { git = "https://github.com/aevyrie/bevy_mod_raycast.git", branch = "bevy-0.13" } +bevy_mod_raycast = { version = "0.17.0" } # Local bevy_picking_core = { path = "../../crates/bevy_picking_core", version = "0.17" } From 81e3774b76570608082b559f5aedd194d5502198 Mon Sep 17 00:00:00 2001 From: bstriker Date: Fri, 23 Feb 2024 16:06:19 -0500 Subject: [PATCH 27/40] Remove into() calls failing to infer types --- examples/hidden.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/hidden.rs b/examples/hidden.rs index bc03d1aa..7f81c9a3 100644 --- a/examples/hidden.rs +++ b/examples/hidden.rs @@ -25,7 +25,7 @@ fn setup( commands.spawn(( PbrBundle { mesh: meshes.add(Mesh::from(shape::Plane::from_size(5.0))), - material: materials.add(Color::rgb(0.3, 0.5, 0.3).into()), + material: materials.add(Color::rgb(0.3, 0.5, 0.3)), ..default() }, PickableBundle::default(), // Optional: adds selection, highlighting, and helper components. @@ -34,7 +34,7 @@ fn setup( PbrBundle { visibility: Visibility::Hidden, mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), - material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()), + material: materials.add(Color::rgb(0.8, 0.7, 0.6)), transform: Transform::from_xyz(0.0, 0.5, 0.0), ..default() }, From 042c58a0f246900c613ae8dea981de5363d80c8a Mon Sep 17 00:00:00 2001 From: bstriker Date: Fri, 23 Feb 2024 16:08:00 -0500 Subject: [PATCH 28/40] chore: apply rustfmt to satisfy linter --- crates/bevy_picking_selection/src/lib.rs | 4 ++-- examples/render_layers.rs | 2 +- examples/sprite.rs | 6 +----- examples/two_passes.rs | 2 +- 4 files changed, 5 insertions(+), 9 deletions(-) diff --git a/crates/bevy_picking_selection/src/lib.rs b/crates/bevy_picking_selection/src/lib.rs index eaa7adeb..c95da4ee 100644 --- a/crates/bevy_picking_selection/src/lib.rs +++ b/crates/bevy_picking_selection/src/lib.rs @@ -219,7 +219,7 @@ pub fn send_selection_events( entity, Deselect, )); - }, + } false => { selections.send(Pointer::new( *pointer_id, @@ -227,7 +227,7 @@ pub fn send_selection_events( entity, Select, )); - }, + } }; } else if !selection.is_selected { selections.send(Pointer::new( diff --git a/examples/render_layers.rs b/examples/render_layers.rs index b533f035..706637f7 100644 --- a/examples/render_layers.rs +++ b/examples/render_layers.rs @@ -1,6 +1,6 @@ //! Demonstrates that picking respects render layers and order. -use bevy::{render::camera::ClearColorConfig, prelude::*}; +use bevy::{prelude::*, render::camera::ClearColorConfig}; use bevy_mod_picking::prelude::*; use bevy_render::view::RenderLayers; diff --git a/examples/sprite.rs b/examples/sprite.rs index 1e90f6ed..2b6645fd 100644 --- a/examples/sprite.rs +++ b/examples/sprite.rs @@ -98,11 +98,7 @@ struct AnimationTimer(Timer); fn animate_sprite( time: Res