Skip to content
This repository was archived by the owner on Mar 4, 2025. It is now read-only.

Commit e685eea

Browse files
Fincapsoerenmeieraevyrie
authored
Migrate to bevy 0.10 (#191)
* Migrate to bevy 0.10 * fixes * Removed unused import * Re-added pre-existing `PickingSystem` labels to systems. * Fixed missing dependency on `bevy_ui` feature * Use latest mod_raycast * Fix accidental stage change * formatting --------- Co-authored-by: Sören Meier <[email protected]> Co-authored-by: Aevyrie Roessler <[email protected]>
1 parent 785240a commit e685eea

File tree

8 files changed

+111
-117
lines changed

8 files changed

+111
-117
lines changed

Cargo.toml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,15 @@ categories = ["game-engines", "rendering"]
1111
resolver = "2"
1212

1313
[dependencies]
14-
bevy = { version = "0.9", default-features = false, features = ["render"] }
14+
bevy = { version = "0.10.0", default-features = false, features = [
15+
"bevy_render",
16+
"bevy_ui",
17+
] }
1518

16-
bevy_mod_raycast = "0.7"
19+
bevy_mod_raycast = "0.8"
1720

1821
[dev-dependencies]
19-
bevy = { version = "0.9", default-features = false, features = [
22+
bevy = { version = "0.10.0", default-features = false, features = [
2023
"bevy_pbr",
2124
"bevy_winit",
2225
"bevy_ui",

examples/deselection.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ use bevy_mod_picking::{DefaultPickingPlugins, NoDeselect, PickableBundle, Pickin
66
fn main() {
77
App::new()
88
.add_plugins(DefaultPlugins.set(WindowPlugin {
9-
window: WindowDescriptor {
9+
primary_window: Some(Window {
1010
present_mode: PresentMode::AutoNoVsync, // Reduce input latency
1111
..default()
12-
},
12+
}),
1313
..default()
1414
}))
1515
.add_plugins(DefaultPickingPlugins) // <- Adds picking, interaction, and highlighting
@@ -26,7 +26,7 @@ fn setup(
2626
// plane
2727
commands.spawn((
2828
PbrBundle {
29-
mesh: meshes.add(Mesh::from(shape::Plane { size: 5.0 })),
29+
mesh: meshes.add(Mesh::from(shape::Plane::from_size(5.0))),
3030
material: materials.add(Color::rgb(0.3, 0.5, 0.3).into()),
3131
..Default::default()
3232
},

examples/events.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ fn main() {
77
.add_plugins(DefaultPlugins)
88
.add_plugins(DefaultPickingPlugins) // <- Adds picking, interaction, and highlighting
99
.add_startup_system(setup)
10-
.add_system_to_stage(CoreStage::PostUpdate, print_events)
10+
.add_system(print_events.in_base_set(CoreSet::PostUpdate))
1111
.run();
1212
}
1313

@@ -28,7 +28,7 @@ fn setup(
2828
) {
2929
commands.spawn((
3030
PbrBundle {
31-
mesh: meshes.add(Mesh::from(shape::Plane { size: 5.0 })),
31+
mesh: meshes.add(Mesh::from(shape::Plane::from_size(5.0))),
3232
material: materials.add(Color::rgb(0.3, 0.5, 0.3).into()),
3333
..Default::default()
3434
},

examples/minimal.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ use bevy_mod_picking::{
88
fn main() {
99
App::new()
1010
.add_plugins(DefaultPlugins.set(WindowPlugin {
11-
window: WindowDescriptor {
11+
primary_window: Some(Window {
1212
present_mode: PresentMode::AutoNoVsync, // Reduce input latency
1313
..default()
14-
},
14+
}),
1515
..default()
1616
}))
1717
.add_plugins(DefaultPickingPlugins) // <- Adds picking, interaction, and highlighting
@@ -29,7 +29,7 @@ fn setup(
2929
) {
3030
commands.spawn((
3131
PbrBundle {
32-
mesh: meshes.add(Mesh::from(shape::Plane { size: 5.0 })),
32+
mesh: meshes.add(Mesh::from(shape::Plane::from_size(5.0))),
3333
material: materials.add(Color::rgb(0.3, 0.5, 0.3).into()),
3434
..Default::default()
3535
},

examples/stress_test.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,12 @@ use bevy_mod_picking::*;
88
fn main() {
99
App::new()
1010
.add_plugins(DefaultPlugins.set(WindowPlugin {
11-
window: WindowDescriptor {
11+
primary_window: Some(Window {
1212
title: "bevy_mod_picking stress test".to_string(),
13-
width: 800.,
14-
height: 600.,
13+
resolution: (800., 600.).into(),
1514
present_mode: PresentMode::AutoNoVsync, // Reduce input latency
1615
..default()
17-
},
16+
}),
1817
..default()
1918
}))
2019
.add_plugins(DefaultPickingPlugins) // <- Adds picking, interaction, and highlighting
@@ -36,10 +35,13 @@ fn setup(
3635
let tris_total = tris_sphere * (half_width as usize * 2).pow(3);
3736
info!("Total tris: {}, Tris per mesh: {}", tris_total, tris_sphere);
3837

39-
let mesh_handle = meshes.add(Mesh::from(shape::Icosphere {
40-
radius: 0.2,
41-
subdivisions,
42-
}));
38+
let mesh_handle = meshes.add(
39+
Mesh::try_from(shape::Icosphere {
40+
radius: 0.2,
41+
subdivisions,
42+
})
43+
.unwrap(),
44+
);
4345

4446
let matl_handle = materials.add(StandardMaterial {
4547
perceptual_roughness: 0.5,

src/events.rs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,12 @@ pub fn mesh_events_system(
2929
mouse_button_input: Res<Input<MouseButton>>,
3030
touches_input: Res<Touches>,
3131
mut picking_events: EventWriter<PickingEvent>,
32-
hover_query: Query<
33-
(Entity, &Hover, ChangeTrackers<Hover>),
34-
(Changed<Hover>, With<PickableMesh>),
35-
>,
36-
selection_query: Query<
37-
(Entity, &Selection, ChangeTrackers<Selection>),
38-
(Changed<Selection>, With<PickableMesh>),
39-
>,
32+
hover_query: Query<(Entity, Ref<Hover>), (Changed<Hover>, With<PickableMesh>)>,
33+
selection_query: Query<(Entity, Ref<Selection>), (Changed<Selection>, With<PickableMesh>)>,
4034
click_query: Query<(Entity, &Hover)>,
4135
) {
42-
for (entity, hover, hover_change) in hover_query.iter() {
43-
if hover_change.is_added() {
36+
for (entity, hover) in hover_query.iter() {
37+
if hover.is_added() {
4438
continue; // Avoid a false change detection when a component is added.
4539
}
4640
if hover.hovered() {
@@ -49,8 +43,8 @@ pub fn mesh_events_system(
4943
picking_events.send(PickingEvent::Hover(HoverEvent::JustLeft(entity)));
5044
}
5145
}
52-
for (entity, selection, selection_change) in selection_query.iter() {
53-
if selection_change.is_added() {
46+
for (entity, selection) in selection_query.iter() {
47+
if selection.is_added() {
5448
continue; // Avoid a false change detection when a component is added.
5549
}
5650
if selection.selected() {

src/lib.rs

Lines changed: 72 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,10 @@ pub use crate::{
1313
};
1414
pub use bevy_mod_raycast::{Primitive3d, RaycastMesh, RaycastSource};
1515

16-
use bevy::{
17-
app::PluginGroupBuilder, asset::Asset, ecs::schedule::ShouldRun, prelude::*, ui::FocusPolicy,
18-
};
16+
use bevy::{app::PluginGroupBuilder, asset::Asset, prelude::*, ui::FocusPolicy};
1917
use highlight::{get_initial_mesh_highlight_asset, Highlight};
2018

21-
#[derive(Debug, Hash, PartialEq, Eq, Clone, SystemLabel)]
19+
#[derive(Debug, Hash, PartialEq, Eq, Clone, SystemSet)]
2220
pub enum PickingSystem {
2321
UpdatePickSourcePositions,
2422
BuildRays,
@@ -29,6 +27,9 @@ pub enum PickingSystem {
2927
PauseForBlockers,
3028
Focus,
3129
Events,
30+
PickingSet,
31+
InteractableSet,
32+
CustomHighlightSet,
3233
}
3334

3435
/// A type alias for the concrete [RaycastMesh](bevy_mod_raycast::RaycastMesh) type used for Picking.
@@ -41,6 +42,7 @@ pub type PickingCamera = RaycastSource<PickingRaycastSet>;
4142
/// meshes or ray sources that are being used by the picking plugin can be used by other ray
4243
/// casting systems because they will have distinct types, e.g.: `RaycastMesh<PickingRaycastSet>`
4344
/// vs. `RaycastMesh<MySuperCoolRaycastingType>`, and as such wil not result in collisions.
45+
#[derive(Clone, Reflect)]
4446
pub struct PickingRaycastSet;
4547

4648
#[derive(Clone, Debug, Resource)]
@@ -60,14 +62,6 @@ impl Default for PickingPluginsState {
6062
}
6163
}
6264

63-
fn simple_criteria(flag: bool) -> ShouldRun {
64-
if flag {
65-
ShouldRun::Yes
66-
} else {
67-
ShouldRun::No
68-
}
69-
}
70-
7165
#[derive(Default, Resource)]
7266
pub struct PausedForBlockers(pub(crate) bool);
7367
impl PausedForBlockers {
@@ -115,31 +109,23 @@ pub struct PickingPlugin;
115109
impl Plugin for PickingPlugin {
116110
fn build(&self, app: &mut App) {
117111
app.init_resource::<PickingPluginsState>()
118-
.add_system_set_to_stage(
119-
CoreStage::PreUpdate,
120-
SystemSet::new()
121-
.with_run_criteria(|state: Res<PickingPluginsState>| {
122-
simple_criteria(state.enable_picking)
123-
})
124-
.with_system(
125-
update_pick_source_positions
126-
.label(PickingSystem::UpdatePickSourcePositions)
127-
.before(PickingSystem::BuildRays),
128-
)
129-
.with_system(
130-
bevy_mod_raycast::build_rays::<PickingRaycastSet>
131-
.label(PickingSystem::BuildRays)
132-
.before(PickingSystem::UpdateRaycast),
133-
)
134-
.with_system(
135-
bevy_mod_raycast::update_raycast::<PickingRaycastSet>
136-
.label(PickingSystem::UpdateRaycast)
137-
.before(PickingSystem::UpdateIntersections),
138-
)
139-
.with_system(
140-
bevy_mod_raycast::update_intersections::<PickingRaycastSet>
141-
.label(PickingSystem::UpdateIntersections),
142-
),
112+
.add_systems(
113+
(
114+
update_pick_source_positions.in_set(PickingSystem::UpdatePickSourcePositions),
115+
bevy_mod_raycast::build_rays::<PickingRaycastSet>
116+
.in_set(PickingSystem::BuildRays),
117+
bevy_mod_raycast::update_raycast::<PickingRaycastSet>
118+
.in_set(PickingSystem::UpdateRaycast),
119+
bevy_mod_raycast::update_intersections::<PickingRaycastSet>
120+
.in_set(PickingSystem::UpdateIntersections),
121+
)
122+
.chain()
123+
.in_set(PickingSystem::PickingSet),
124+
)
125+
.configure_set(
126+
PickingSystem::PickingSet
127+
.run_if(|state: Res<PickingPluginsState>| state.enable_picking)
128+
.in_base_set(CoreSet::PreUpdate),
143129
);
144130
}
145131
}
@@ -149,32 +135,21 @@ impl Plugin for InteractablePickingPlugin {
149135
fn build(&self, app: &mut App) {
150136
app.init_resource::<PausedForBlockers>()
151137
.add_event::<PickingEvent>()
152-
.add_system_set_to_stage(
153-
CoreStage::PreUpdate,
154-
SystemSet::new()
155-
.with_run_criteria(|state: Res<PickingPluginsState>| {
156-
simple_criteria(state.enable_interacting)
157-
})
158-
.with_system(
159-
pause_for_picking_blockers
160-
.label(PickingSystem::PauseForBlockers)
161-
.after(PickingSystem::UpdateIntersections),
162-
)
163-
.with_system(
164-
mesh_focus
165-
.label(PickingSystem::Focus)
166-
.after(PickingSystem::PauseForBlockers),
167-
)
168-
.with_system(
169-
mesh_selection
170-
.label(PickingSystem::Selection)
171-
.after(PickingSystem::Focus),
172-
)
173-
.with_system(
174-
mesh_events_system
175-
.label(PickingSystem::Events)
176-
.after(PickingSystem::Selection),
177-
),
138+
.add_systems(
139+
(
140+
pause_for_picking_blockers.in_set(PickingSystem::PauseForBlockers),
141+
mesh_focus.in_set(PickingSystem::Focus),
142+
mesh_selection.in_set(PickingSystem::Selection),
143+
mesh_events_system.in_set(PickingSystem::Events),
144+
)
145+
.chain()
146+
.in_set(PickingSystem::InteractableSet),
147+
)
148+
.configure_set(
149+
PickingSystem::InteractableSet
150+
.run_if(|state: Res<PickingPluginsState>| state.enable_interacting)
151+
.in_base_set(CoreSet::PreUpdate)
152+
.after(PickingSystem::UpdateIntersections),
178153
);
179154
}
180155
}
@@ -194,32 +169,30 @@ where
194169
app.add_startup_system(move |mut commands: Commands, assets: ResMut<Assets<T>>| {
195170
commands.insert_resource(highlighting_default(assets));
196171
})
197-
.add_system_set_to_stage(
198-
CoreStage::PreUpdate,
199-
SystemSet::new()
200-
.with_run_criteria(|state: Res<PickingPluginsState>| {
201-
simple_criteria(state.enable_highlighting)
202-
})
203-
.with_system(
204-
get_initial_mesh_highlight_asset::<T>
205-
.after(PickingSystem::UpdateIntersections)
206-
.before(PickingSystem::Highlighting),
207-
)
208-
.with_system(
209-
mesh_highlighting::<T>
210-
.label(PickingSystem::Highlighting)
211-
.before(PickingSystem::Events),
212-
),
172+
.add_systems(
173+
(
174+
get_initial_mesh_highlight_asset::<T>,
175+
mesh_highlighting::<T>.in_set(PickingSystem::Highlighting),
176+
)
177+
.chain()
178+
.in_set(PickingSystem::CustomHighlightSet),
179+
)
180+
.configure_set(
181+
PickingSystem::CustomHighlightSet
182+
.run_if(|state: Res<PickingPluginsState>| state.enable_highlighting)
183+
.in_base_set(CoreSet::PreUpdate)
184+
.before(PickingSystem::Events)
185+
.after(PickingSystem::UpdateIntersections),
213186
);
214187
}
215188
}
216189

217190
pub struct DebugCursorPickingPlugin;
218191
impl Plugin for DebugCursorPickingPlugin {
219192
fn build(&self, app: &mut App) {
220-
app.add_system_to_stage(
221-
CoreStage::PreUpdate,
193+
app.add_system(
222194
bevy_mod_raycast::update_debug_cursor::<PickingRaycastSet>
195+
.in_base_set(CoreSet::PreUpdate)
223196
.after(PickingSystem::UpdateIntersections),
224197
);
225198
}
@@ -228,9 +201,10 @@ impl Plugin for DebugCursorPickingPlugin {
228201
pub struct DebugEventsPickingPlugin;
229202
impl Plugin for DebugEventsPickingPlugin {
230203
fn build(&self, app: &mut App) {
231-
app.add_system_to_stage(
232-
CoreStage::PreUpdate,
233-
event_debug_system.after(PickingSystem::Events),
204+
app.add_system(
205+
event_debug_system
206+
.in_base_set(CoreSet::PreUpdate)
207+
.after(PickingSystem::Events),
234208
);
235209
}
236210
}
@@ -250,7 +224,7 @@ impl Default for PickingCameraBundle {
250224
}
251225
}
252226

253-
#[derive(Bundle, Default)]
227+
#[derive(Bundle)]
254228
pub struct PickableBundle {
255229
pub pickable_mesh: PickableMesh,
256230
pub interaction: Interaction,
@@ -259,3 +233,16 @@ pub struct PickableBundle {
259233
pub selection: Selection,
260234
pub hover: Hover,
261235
}
236+
237+
impl Default for PickableBundle {
238+
fn default() -> Self {
239+
Self {
240+
pickable_mesh: default(),
241+
interaction: default(),
242+
focus_policy: FocusPolicy::Block,
243+
highlight: default(),
244+
selection: default(),
245+
hover: default(),
246+
}
247+
}
248+
}

0 commit comments

Comments
 (0)