Skip to content

Commit

Permalink
Update to Bevy v0.11 (#84)
Browse files Browse the repository at this point in the history
* Update bevy to 0.11

Fix deriving Reflect - change type bound to `TypePath`
Migrate to new `add_systems`

* Fix screenspace projection

Use `camera.viewport_to_world()`

* Update examples for Bevy 0.11

Migrate to new `add` apis
Revert tonemapping to ReinhardLuminance to avoid the
`tonemapping_luts` feature

---------

Co-authored-by: Aevyrie <[email protected]>
  • Loading branch information
yyogo and aevyrie authored Jul 17, 2023
1 parent 67f5da0 commit 0552cf9
Show file tree
Hide file tree
Showing 9 changed files with 121 additions and 117 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ categories = ["game-engines", "rendering"]
resolver = "2"

[dependencies]
bevy = { version = "0.10", default-features = false, features = [
bevy = { version = "0.11", default-features = false, features = [
"bevy_render",
"bevy_asset",
] }

[dev-dependencies]
bevy = { version = "0.10", default-features = false, features = [
bevy = { version = "0.11", default-features = false, features = [
"bevy_pbr",
"bevy_winit",
"bevy_ui",
Expand Down
41 changes: 22 additions & 19 deletions examples/bounding_volume.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use bevy::{
diagnostic::{Diagnostics, FrameTimeDiagnosticsPlugin},
core_pipeline::tonemapping::Tonemapping,
diagnostic::{DiagnosticsStore, FrameTimeDiagnosticsPlugin},
math::Vec3A,
prelude::*,
render::primitives::Aabb,
Expand All @@ -17,28 +18,27 @@ use bevy_mod_raycast::{

fn main() {
App::new()
.add_plugins(DefaultPlugins.set(WindowPlugin {
primary_window: Some(Window {
present_mode: PresentMode::AutoNoVsync,
.add_plugins((
DefaultPlugins.set(WindowPlugin {
primary_window: Some(Window {
present_mode: PresentMode::AutoNoVsync,
..default()
}),
..default()
}),
..default()
}))
.add_plugin(FrameTimeDiagnosticsPlugin::default())
.add_plugin(DefaultRaycastingPlugin::<MyRaycastSet>::default())
FrameTimeDiagnosticsPlugin::default(),
DefaultRaycastingPlugin::<MyRaycastSet>::default(),
))
// You will need to pay attention to what order you add systems! Putting them in the wrong
// order can result in multiple frames of latency. Ray casting should probably happen after
// the positions of your meshes have been updated in the UPDATE stage.
.add_system(
update_raycast_with_cursor
.before(RaycastSystem::BuildRays::<MyRaycastSet>)
.in_base_set(CoreSet::First),
.add_systems(
First,
update_raycast_with_cursor.before(RaycastSystem::BuildRays::<MyRaycastSet>),
)
.add_startup_system(setup_scene)
.add_startup_system(setup_ui)
.add_system(update_fps)
.add_system(make_scene_pickable)
.add_system(manage_aabb.in_base_set(CoreSet::First))
.add_systems(Startup, (setup_scene, setup_ui))
.add_systems(Update, (update_fps, make_scene_pickable))
.add_systems(First, manage_aabb)
.run();
}

Expand Down Expand Up @@ -74,7 +74,10 @@ fn setup_scene(mut commands: Commands, asset_server: Res<AssetServer>) {
});

commands
.spawn(Camera3dBundle::default())
.spawn(Camera3dBundle {
tonemapping: Tonemapping::ReinhardLuminance,
..default()
})
.insert(RaycastSource::<MyRaycastSet>::new()); // Designate the camera as our source

// Spawn multiple mesh to raycast on
Expand Down Expand Up @@ -219,7 +222,7 @@ fn manage_aabb(
}
}

fn update_fps(diagnostics: Res<Diagnostics>, mut query: Query<&mut Text, With<FpsText>>) {
fn update_fps(diagnostics: Res<DiagnosticsStore>, mut query: Query<&mut Text, With<FpsText>>) {
for mut text in &mut query {
if let Some(fps) = diagnostics.get(FrameTimeDiagnosticsPlugin::FPS) {
if let Some(average) = fps.smoothed() {
Expand Down
14 changes: 8 additions & 6 deletions examples/minimal.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use bevy::prelude::*;
use bevy::{core_pipeline::tonemapping::Tonemapping, prelude::*};
use bevy_mod_raycast::{
DefaultPluginState, DefaultRaycastingPlugin, Intersection, RaycastMesh, RaycastSource,
};
Expand All @@ -11,11 +11,12 @@ use bevy_mod_raycast::{

fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugin(DefaultRaycastingPlugin::<MyRaycastSet>::default())
.add_startup_system(setup)
.add_system(rotator)
.add_system(intersection)
.add_plugins((
DefaultPlugins,
DefaultRaycastingPlugin::<MyRaycastSet>::default(),
))
.add_systems(Startup, setup)
.add_systems(Update, (rotator, intersection))
.run();
}

Expand All @@ -40,6 +41,7 @@ fn setup(
scale: 0.01,
..default()
}),
tonemapping: Tonemapping::ReinhardLuminance,
..default()
},
// Designate the camera as our ray casting source. Using `new_transform_empty()` means that
Expand Down
14 changes: 7 additions & 7 deletions examples/mouse_picking.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use bevy::{prelude::*, window::PresentMode};
use bevy::{core_pipeline::tonemapping::Tonemapping, prelude::*, window::PresentMode};

use bevy_mod_raycast::{
DefaultPluginState, DefaultRaycastingPlugin, RaycastMesh, RaycastMethod, RaycastSource,
Expand All @@ -22,18 +22,17 @@ fn main() {
// plugin. This includes building rays, casting them, and placing a debug cursor at the
// intersection. For more advanced uses, you can compose the systems in this plugin however
// you need. For example, you might exclude the debug cursor system.
.add_plugin(DefaultRaycastingPlugin::<MyRaycastSet>::default())
.add_plugins(DefaultRaycastingPlugin::<MyRaycastSet>::default())
// You will need to pay attention to what order you add systems! Putting them in the wrong
// order can result in multiple frames of latency. Ray casting should probably happen near
// start of the frame. For example, we want to be sure this system runs before we construct
// any rays, hence the ".before(...)". You can use these provided RaycastSystem labels to
// order your systems with the ones provided by the raycasting plugin.
.add_system(
update_raycast_with_cursor
.in_base_set(CoreSet::First)
.before(RaycastSystem::BuildRays::<MyRaycastSet>),
.add_systems(
First,
update_raycast_with_cursor.before(RaycastSystem::BuildRays::<MyRaycastSet>),
)
.add_startup_system(setup)
.add_systems(Startup, setup)
.run();
}

Expand Down Expand Up @@ -72,6 +71,7 @@ fn setup(
commands
.spawn(Camera3dBundle {
transform: Transform::from_xyz(-2.0, 2.0, 2.0).looking_at(Vec3::ZERO, Vec3::Y),
tonemapping: Tonemapping::ReinhardLuminance,
..Default::default()
})
.insert(RaycastSource::<MyRaycastSet>::new()); // Designate the camera as our source
Expand Down
24 changes: 14 additions & 10 deletions examples/mouse_picking_2d.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
use bevy::{prelude::*, sprite::MaterialMesh2dBundle};
use bevy::{core_pipeline::tonemapping::Tonemapping, prelude::*, sprite::MaterialMesh2dBundle};
use bevy_mod_raycast::{
DefaultRaycastingPlugin, Intersection, RaycastMesh, RaycastMethod, RaycastSource, RaycastSystem,
};

fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugin(DefaultRaycastingPlugin::<MyRaycastSet>::default())
.add_system(
update_raycast_with_cursor
.in_base_set(CoreSet::First)
.before(RaycastSystem::BuildRays::<MyRaycastSet>),
.add_plugins((
DefaultPlugins,
DefaultRaycastingPlugin::<MyRaycastSet>::default(),
))
.add_systems(
First,
update_raycast_with_cursor.before(RaycastSystem::BuildRays::<MyRaycastSet>),
)
.add_system(intersection)
.add_startup_system(setup)
.add_systems(Startup, setup)
.add_systems(Update, intersection)
.run();
}

Expand Down Expand Up @@ -53,7 +54,10 @@ fn setup(
mut materials: ResMut<Assets<ColorMaterial>>,
) {
commands
.spawn(Camera2dBundle::default())
.spawn(Camera2dBundle {
tonemapping: Tonemapping::ReinhardLuminance,
..default()
})
.insert(RaycastSource::<MyRaycastSet>::new()); // Designate the camera as our source;
commands
.spawn(MaterialMesh2dBundle {
Expand Down
30 changes: 15 additions & 15 deletions examples/ray_intersection_over_mesh.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::f32::consts::FRAC_PI_2;

use bevy::{prelude::*, window::PresentMode};
use bevy::{core_pipeline::tonemapping::Tonemapping, prelude::*, window::PresentMode};

use bevy_mod_raycast::{
ray_intersection_over_mesh, Backfaces, DefaultPluginState, DefaultRaycastingPlugin, Ray3d,
Expand All @@ -15,23 +15,22 @@ use bevy_mod_raycast::{

fn main() {
App::new()
.add_plugins(DefaultPlugins.set(WindowPlugin {
primary_window: Some(Window {
present_mode: PresentMode::AutoNoVsync, // Reduces input latency
.add_plugins((
DefaultPlugins.set(WindowPlugin {
primary_window: Some(Window {
present_mode: PresentMode::AutoNoVsync, // Reduces input latency
..default()
}),
..default()
}),
..default()
}))
.add_plugin(DefaultRaycastingPlugin::<Ground>::default())
.add_startup_system(setup)
.add_startup_system(setup_ui)
.add_system(
update_raycast_with_cursor
.before(RaycastSystem::BuildRays::<Ground>)
.in_base_set(CoreSet::First),
DefaultRaycastingPlugin::<Ground>::default(),
))
.add_systems(Startup, (setup, setup_ui))
.add_systems(
First,
update_raycast_with_cursor.before(RaycastSystem::BuildRays::<Ground>),
)
.add_system(check_path)
.add_system(move_origin)
.add_systems(Update, (check_path, move_origin))
.run();
}

Expand Down Expand Up @@ -116,6 +115,7 @@ fn setup(
commands
.spawn(Camera3dBundle {
transform: Transform::from_xyz(-5.0, 10.0, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
tonemapping: Tonemapping::ReinhardLuminance,
..Default::default()
})
.insert(RaycastSource::<Ground>::new());
Expand Down
41 changes: 22 additions & 19 deletions examples/simplified_mesh.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use bevy::{
diagnostic::{Diagnostics, FrameTimeDiagnosticsPlugin},
core_pipeline::tonemapping::Tonemapping,
diagnostic::{DiagnosticsStore, FrameTimeDiagnosticsPlugin},
prelude::*,
window::PresentMode,
};
Expand All @@ -14,27 +15,26 @@ use bevy_mod_raycast::{

fn main() {
App::new()
.add_plugins(DefaultPlugins.set(WindowPlugin {
primary_window: Some(Window {
present_mode: PresentMode::AutoNoVsync, // Reduces input lag.
..Default::default()
.add_plugins((
DefaultPlugins.set(WindowPlugin {
primary_window: Some(Window {
present_mode: PresentMode::AutoNoVsync, // Reduces input lag.
..Default::default()
}),
..default()
}),
..default()
}))
.add_plugin(FrameTimeDiagnosticsPlugin::default())
.add_plugin(DefaultRaycastingPlugin::<MyRaycastSet>::default())
FrameTimeDiagnosticsPlugin::default(),
DefaultRaycastingPlugin::<MyRaycastSet>::default(),
))
// You will need to pay attention to what order you add systems! Putting them in the wrong
// order can result in multiple frames of latency. Ray casting should probably happen after
// the positions of your meshes have been updated in the UPDATE stage.
.add_system(
update_raycast_with_cursor_position
.before(RaycastSystem::BuildRays::<MyRaycastSet>)
.in_base_set(CoreSet::First),
.add_systems(
First,
update_raycast_with_cursor_position.before(RaycastSystem::BuildRays::<MyRaycastSet>),
)
.add_startup_system(setup_scene)
.add_startup_system(setup_ui)
.add_system(update_fps)
.add_system(manage_simplified_mesh)
.add_systems(Startup, (setup_scene, setup_ui))
.add_systems(Update, (update_fps, manage_simplified_mesh))
.run();
}

Expand Down Expand Up @@ -65,7 +65,10 @@ fn setup_scene(
) {
commands.insert_resource(DefaultPluginState::<MyRaycastSet>::default().with_debug_cursor());
commands
.spawn(Camera3dBundle::default())
.spawn(Camera3dBundle {
tonemapping: Tonemapping::ReinhardLuminance,
..default()
})
.insert(RaycastSource::<MyRaycastSet>::new()); // Designate the camera as our source
commands.spawn((
PbrBundle {
Expand Down Expand Up @@ -191,7 +194,7 @@ fn manage_simplified_mesh(
}
}

fn update_fps(diagnostics: Res<Diagnostics>, mut query: Query<&mut Text, With<FpsText>>) {
fn update_fps(diagnostics: Res<DiagnosticsStore>, mut query: Query<&mut Text, With<FpsText>>) {
for mut text in &mut query {
if let Some(fps) = diagnostics.get(FrameTimeDiagnosticsPlugin::FPS) {
if let Some(average) = fps.average() {
Expand Down
Loading

0 comments on commit 0552cf9

Please sign in to comment.