From f77bda7f850486087539fa92ea56ca3c8b69aaa9 Mon Sep 17 00:00:00 2001 From: Aceeri Date: Fri, 12 Jul 2024 15:38:25 -0700 Subject: [PATCH 1/2] Bevy 0.14 --- Cargo.toml | 17 +++---- examples/first_person.rs | 76 +++++++++++------------------ examples/playground.rs | 102 ++++++++++++++++++--------------------- examples/starship.rs | 13 +++-- src/bundles.rs | 6 +-- src/controller/ground.rs | 52 ++++++++++++-------- src/plugins.rs | 10 ++-- 7 files changed, 129 insertions(+), 147 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 4852f52..dd8e0d0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,21 +18,21 @@ debug_lines = [] rapier = ["bevy_rapier3d"] [dependencies] -bevy = { version = "0.11", default-features = false, features = [ +bevy = { version = "0.14", default-features = false, features = [ "bevy_render", "bevy_gizmos", ] } -bevy_rapier3d = { version = "0.22", default-features = false, features = [ +bevy_rapier3d = { version = "0.27", default-features = false, features = [ "async-collider", "dim3", ], optional = true } [dev-dependencies] -bevy = "0.11" -aether_spyglass = "0.2" -bevy-inspector-egui = "0.19" -bevy_framepace = "0.13" -bevy_rapier3d = { version = "0.22", features = ["debug-render"] } +bevy = "0.14" +#aether_spyglass = "0.2" +bevy-inspector-egui = "0.25" +bevy_framepace = "0.17" +bevy_rapier3d = { version = "0.27", features = ["debug-render"] } # Enable a small amount of optimization in debug mode [profile.dev] @@ -43,5 +43,4 @@ opt-level = 1 opt-level = 3 [patch.crates-io] -#bevy_rapier3d = { path = "../bevy_rapier/bevy_rapier3d" } -bevy_rapier3d = { git = "https://github.com/dimforge/bevy_rapier", rev = "0ea000b" } \ No newline at end of file +#bevy_rapier3d = { path = "../bevy_rapier/bevy_rapier3d" } \ No newline at end of file diff --git a/examples/first_person.rs b/examples/first_person.rs index aa8c9fa..5fcd442 100644 --- a/examples/first_person.rs +++ b/examples/first_person.rs @@ -6,6 +6,7 @@ use bevy::{ input::mouse::MouseMotion, prelude::*, window::{Cursor, PrimaryWindow}, + color::palettes::css, }; use bevy_framepace::{FramepacePlugin, FramepaceSettings, Limiter}; use bevy_mod_wanderlust::{ @@ -30,11 +31,11 @@ fn main() { ..default() }), RapierPhysicsPlugin::::default(), + bevy_inspector_egui::quick::WorldInspectorPlugin::default(), // This plugin was causing unhelpful glitchy orange planes, so it's commented out until // it's working again - // RapierDebugRenderPlugin::default(), + RapierDebugRenderPlugin::default(), WanderlustPlugin::default(), - aether_spyglass::SpyglassPlugin, FramepacePlugin, )) .insert_resource(RapierConfiguration { @@ -42,7 +43,7 @@ fn main() { dt: 0.008, substeps: 4, }, - ..default() + ..RapierConfiguration::new(1.0) }) .insert_resource(FramepaceSettings { limiter: Limiter::Manual(std::time::Duration::from_secs_f64(0.008)), @@ -58,7 +59,7 @@ fn main() { toggle_cursor_lock, ), ) - .run() + .run(); } #[derive(Component, Default, Reflect)] @@ -78,15 +79,14 @@ fn setup( mut mats: ResMut>, ) { let mesh = meshes.add( - shape::Capsule { + Capsule3d { radius: 0.5, - depth: 1.0, + half_length: 0.5, ..default() } - .into(), ); - let material = mats.add(Color::WHITE.into()); + let material = mats.add(Color::from(css::WHITE)); commands .spawn(( @@ -127,7 +127,7 @@ fn setup( PlayerCam, )) .with_children(|commands| { - let mesh = meshes.add(shape::Cube { size: 0.5 }.into()); + let mesh = meshes.add(Cuboid { half_size: Vec3::splat(0.25), }); commands.spawn(PbrBundle { mesh, @@ -138,13 +138,7 @@ fn setup( }); }); - let mesh = meshes.add( - shape::Plane { - size: 10.0, - ..default() - } - .into(), - ); + let mesh = meshes.add(Plane3d::new(Vec3::Y, Vec2::splat(5.0))); commands.spawn(( PbrBundle { @@ -163,17 +157,9 @@ fn setup( }); let (hw, hh, hl) = (1.5, 0.5, 5.0); - let mesh = meshes.add( - shape::Box { - min_x: -hw, - max_x: hw, - min_y: -hh, - max_y: hh, - min_z: -hl, - max_z: hl, - } - .into(), - ); + let min = Vec3::new(-hw, -hh, -hl); + let max = Vec3::new(hw, hh, hl); + let mesh = meshes.add( Cuboid::from_corners(min, max)); commands.spawn(( PbrBundle { @@ -192,17 +178,9 @@ fn setup( )); let (hw, hh, hl) = (0.25, 3.0, 5.0); - let mesh = meshes.add( - shape::Box { - min_x: -hw, - max_x: hw, - min_y: -hh, - max_y: hh, - min_z: -hl, - max_z: hl, - } - .into(), - ); + let min = Vec3::new(-hw, -hh, -hl); + let max = Vec3::new(hw, hh, hl); + let mesh = meshes.add( Cuboid::from_corners(min, max)); commands.spawn(( PbrBundle { @@ -235,24 +213,24 @@ fn setup( fn movement_input( mut body: Query<&mut ControllerInput, With>, camera: Query<&GlobalTransform, (With, Without)>, - input: Res>, + input: Res>, ) { let tf = camera.single(); let mut player_input = body.single_mut(); let mut dir = Vec3::ZERO; - if input.pressed(KeyCode::A) { - dir += -tf.right(); + if input.pressed(KeyCode::KeyA) { + dir += -tf.right().as_vec3(); } - if input.pressed(KeyCode::D) { - dir += tf.right(); + if input.pressed(KeyCode::KeyD) { + dir += tf.right().as_vec3(); } - if input.pressed(KeyCode::S) { - dir += -tf.forward(); + if input.pressed(KeyCode::KeyS) { + dir += -tf.forward().as_vec3(); } - if input.pressed(KeyCode::W) { - dir += tf.forward(); + if input.pressed(KeyCode::KeyW) { + dir += tf.forward().as_vec3(); } dir.y = 0.0; player_input.movement = dir.normalize_or_zero(); @@ -271,7 +249,7 @@ fn mouse_look( let sens = sensitivity.0; - let mut cumulative: Vec2 = -(input.iter().map(|motion| &motion.delta).sum::()); + let mut cumulative: Vec2 = -(input.read().map(|motion| &motion.delta).sum::()); // Vertical let rot = cam_tf.rotation; @@ -295,7 +273,7 @@ fn mouse_look( } fn toggle_cursor_lock( - input: Res>, + input: Res>, mut windows: Query<&mut Window, With>, ) { if input.just_pressed(KeyCode::Escape) { diff --git a/examples/playground.rs b/examples/playground.rs index 1c81f54..ecf3e4f 100644 --- a/examples/playground.rs +++ b/examples/playground.rs @@ -6,6 +6,7 @@ use bevy::{ input::mouse::MouseMotion, prelude::*, window::{Cursor, PrimaryWindow}, + color::palettes::css, }; use bevy_framepace::*; use bevy_mod_wanderlust::{ @@ -16,7 +17,7 @@ use bevy_mod_wanderlust::{ use bevy_rapier3d::prelude::*; use std::f32::consts::{FRAC_2_PI, PI}; -fn main() { +fn main() -> AppExit { App::new() .add_plugins(( DefaultPlugins.set(WindowPlugin { @@ -43,7 +44,7 @@ fn main() { dt: 0.016, substeps: 32, }, - ..default() + ..RapierConfiguration::new(1.0) }) .insert_resource(FramepaceSettings { limiter: Limiter::Manual(std::time::Duration::from_secs_f64(0.016)), @@ -65,16 +66,16 @@ fn main() { ) .add_systems( Last, - |input: Res>, + |input: Res>, //mut freeze: ResMut, mut freeze: Local, mut time: ResMut