From 953dccb545006480e8436b02f4b3199e6ac9986c Mon Sep 17 00:00:00 2001 From: Thierry Berger Date: Wed, 4 Dec 2024 10:15:49 +0100 Subject: [PATCH 01/10] Fix CI (#604) ignore doc for tests + ignore lifetime ellision --- Cargo.toml | 3 +++ src/plugin/systems/collider.rs | 1 + src/plugin/systems/mod.rs | 1 + 3 files changed, 5 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 684265ff..c112b763 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,6 +7,9 @@ rust.unexpected_cfgs = { level = "warn", check-cfg = [ 'cfg(feature, values("dim2", "dim3"))', ] } +[workspace.lints.clippy] +needless_lifetimes = "allow" + [profile.dev] # Use slightly better optimization by default, as examples otherwise seem laggy. opt-level = 1 diff --git a/src/plugin/systems/collider.rs b/src/plugin/systems/collider.rs index 7d094f0d..42250ffb 100644 --- a/src/plugin/systems/collider.rs +++ b/src/plugin/systems/collider.rs @@ -573,6 +573,7 @@ pub fn update_colliding_entities( } #[cfg(test)] +#[allow(missing_docs)] pub mod test { #[test] #[cfg(all(feature = "dim3", feature = "async-collider"))] diff --git a/src/plugin/systems/mod.rs b/src/plugin/systems/mod.rs index b1cc80f6..4905deeb 100644 --- a/src/plugin/systems/mod.rs +++ b/src/plugin/systems/mod.rs @@ -69,6 +69,7 @@ pub fn step_simulation( } #[cfg(test)] +#[allow(missing_docs)] pub mod tests { use bevy::{ asset::AssetPlugin, From 6d7b84b6cd7df1c1d5f070bf20d5ef85153571ef Mon Sep 17 00:00:00 2001 From: Thierry Berger Date: Wed, 4 Dec 2024 15:15:37 +0100 Subject: [PATCH 02/10] fix compilation without debug-render-3d (#601) * fix #598 * fix async-collider without default features --- bevy_rapier2d/Cargo.toml | 2 +- bevy_rapier3d/Cargo.toml | 2 +- src/plugin/plugin.rs | 4 +--- src/render/mod.rs | 1 + 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/bevy_rapier2d/Cargo.toml b/bevy_rapier2d/Cargo.toml index d1d1d6ca..90274ff3 100644 --- a/bevy_rapier2d/Cargo.toml +++ b/bevy_rapier2d/Cargo.toml @@ -46,7 +46,7 @@ wasm-bindgen = ["rapier2d/wasm-bindgen"] serde-serialize = ["rapier2d/serde-serialize", "bevy/serialize", "serde"] enhanced-determinism = ["rapier2d/enhanced-determinism"] headless = [] -async-collider = ["bevy/bevy_asset", "bevy/bevy_scene"] +async-collider = ["bevy/bevy_asset", "bevy/bevy_scene", "bevy/bevy_render"] [dependencies] bevy = { version = "0.14", default-features = false } diff --git a/bevy_rapier3d/Cargo.toml b/bevy_rapier3d/Cargo.toml index 3ab3cfcb..b8f8069e 100644 --- a/bevy_rapier3d/Cargo.toml +++ b/bevy_rapier3d/Cargo.toml @@ -47,7 +47,7 @@ wasm-bindgen = ["rapier3d/wasm-bindgen"] serde-serialize = ["rapier3d/serde-serialize", "bevy/serialize", "serde"] enhanced-determinism = ["rapier3d/enhanced-determinism"] headless = [] -async-collider = ["bevy/bevy_asset", "bevy/bevy_scene"] +async-collider = ["bevy/bevy_asset", "bevy/bevy_scene", "bevy/bevy_render"] [dependencies] bevy = { version = "0.14", default-features = false } diff --git a/src/plugin/plugin.rs b/src/plugin/plugin.rs index 8933a7c8..33fc4287 100644 --- a/src/plugin/plugin.rs +++ b/src/plugin/plugin.rs @@ -210,12 +210,10 @@ where .register_type::() .register_type::() .register_type::() - .register_type::() .register_type::() .register_type::() .register_type::() - .register_type::() - .register_type::(); + .register_type::(); app.insert_resource(Events::::default()) .insert_resource(Events::::default()) diff --git a/src/render/mod.rs b/src/render/mod.rs index abdd20b4..78239fd2 100644 --- a/src/render/mod.rs +++ b/src/render/mod.rs @@ -107,6 +107,7 @@ impl Plugin for RapierDebugRenderPlugin { fn build(&self, app: &mut App) { app.register_type::(); app.register_type::(); + app.register_type::(); app.insert_resource(DebugRenderContext { enabled: self.enabled, From cda43aa4ddbdc51101261e7f5d9870172c137462 Mon Sep 17 00:00:00 2001 From: Thierry Berger Date: Wed, 4 Dec 2024 15:33:28 +0100 Subject: [PATCH 03/10] correctly setup default world configuration before startup (#603) --- src/plugin/plugin.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/plugin/plugin.rs b/src/plugin/plugin.rs index 33fc4287..48effac6 100644 --- a/src/plugin/plugin.rs +++ b/src/plugin/plugin.rs @@ -228,6 +228,7 @@ where app.insert_resource(self.default_world_setup.clone()); } + // FIXME: Those are great candidates for RequiredComponents with bevy 0.15 app.add_systems( self.schedule, ( @@ -236,7 +237,15 @@ where ) .before(PhysicsSet::SyncBackend), ); - app.add_systems(PreStartup, insert_default_world); + app.add_systems( + PreStartup, + ( + insert_default_world, + setup_rapier_configuration, + setup_rapier_simulation_to_render_time, + ) + .chain(), + ); // Add each set as necessary if self.default_system_setup { From 821cde98b7868472041e64d5f67cc2dea05198a1 Mon Sep 17 00:00:00 2001 From: Thierry Berger Date: Wed, 4 Dec 2024 17:22:52 +0100 Subject: [PATCH 04/10] Fix sync_removals with low physics fixed rate (#600) * fix sync_removals with low physics fixed rate * simplify test_sync_removal --- src/plugin/plugin.rs | 86 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) diff --git a/src/plugin/plugin.rs b/src/plugin/plugin.rs index 48effac6..00328a79 100644 --- a/src/plugin/plugin.rs +++ b/src/plugin/plugin.rs @@ -247,6 +247,10 @@ where .chain(), ); + // These *must* be in the main schedule currently so that they do not miss events. + // See test `test_sync_removal` for an example of this. + app.add_systems(PostUpdate, (systems::sync_removals,)); + // Add each set as necessary if self.default_system_setup { app.configure_sets( @@ -498,4 +502,86 @@ mod test { )); } } + + #[test] + pub fn test_sync_removal() { + return main(); + + use bevy::prelude::*; + + fn run_test(app: &mut App) { + app.insert_resource(TimeUpdateStrategy::ManualDuration( + std::time::Duration::from_secs_f32(1f32 / 60f32), + )); + app.insert_resource(Time::::from_hz(20.0)); + + app.add_systems(Startup, setup_physics); + app.add_systems(Update, remove_rapier_entity); + app.add_systems(FixedUpdate, || println!("Fixed Update")); + app.add_systems(Update, || println!("Update")); + // startup + app.update(); + // normal updates starting + // render only + app.update(); + app.update(); + // render + physics + app.update(); + + let context = app + .world_mut() + .query::<&RapierContext>() + .get_single(&app.world()) + .unwrap(); + assert_eq!(context.entity2body.len(), 1); + + // render only + remove entities + app.update(); + // Fixed Update hasn´t run yet, so it's a risk of not having caught the bevy removed event, which will be cleaned next frame. + + let context = app + .world_mut() + .query::<&RapierContext>() + .get_single(&app.world()) + .unwrap(); + + println!("{:?}", &context.entity2body); + assert_eq!(context.entity2body.len(), 0); + } + + fn main() { + let mut app = App::new(); + app.add_plugins(( + HeadlessRenderPlugin, + TransformPlugin, + TimePlugin, + RapierPhysicsPlugin::::default().in_fixed_schedule(), + )); + run_test(&mut app); + } + + pub fn setup_physics(mut commands: Commands) { + commands.spawn(( + TransformBundle::from(Transform::from_xyz(0.0, 13.0, 0.0)), + RigidBody::Dynamic, + cuboid(0.5, 0.5, 0.5), + TestMarker, + )); + println!("spawned rapier entity"); + } + pub fn remove_rapier_entity( + mut commands: Commands, + to_remove: Query>, + mut counter: Local, + ) { + *counter += 1; + if *counter != 5 { + return; + } + println!("removing rapier entity"); + for e in &to_remove { + commands.entity(e).despawn(); + } + } + } } From c70edaeba5e1787372b4eeb74bae2d174327b320 Mon Sep 17 00:00:00 2001 From: Thierry Berger Date: Thu, 5 Dec 2024 12:05:08 +0100 Subject: [PATCH 05/10] chore: solve deprecation warnings from cargo-deny (#554) + add unicode-3.0 from unicode-ident from naga-oil. --- deny.toml | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/deny.toml b/deny.toml index 0a3e2530..75d7492c 100644 --- a/deny.toml +++ b/deny.toml @@ -1,11 +1,19 @@ [advisories] -unmaintained = "deny" yanked = "deny" -notice = "deny" [licenses] -copyleft = "deny" -allow-osi-fsf-free = "either" +allow = [ + "MIT-0", + "MIT", + "Apache-2.0", + "Unicode-DFS-2016", + "Zlib", + "CC0-1.0", + "BSD-2-Clause", + "BSD-3-Clause", + "ISC", + "Unicode-3.0", +] [[licenses.clarify]] name = "stretch" From 577ecb15923a3d954885ff9d0ed8e5c3ecbe46ef Mon Sep 17 00:00:00 2001 From: jf908 Date: Fri, 6 Dec 2024 08:10:20 +0000 Subject: [PATCH 06/10] Expose WriteDefaultRapierContext (#608) --- src/plugin/mod.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/plugin/mod.rs b/src/plugin/mod.rs index 195bcc2b..eed144bf 100644 --- a/src/plugin/mod.rs +++ b/src/plugin/mod.rs @@ -1,6 +1,9 @@ pub use self::configuration::{RapierConfiguration, SimulationToRenderTime, TimestepMode}; pub use self::context::{ - systemparams::{RapierContextAccess, ReadDefaultRapierContext, WriteRapierContext}, + systemparams::{ + RapierContextAccess, ReadDefaultRapierContext, WriteDefaultRapierContext, + WriteRapierContext, + }, DefaultRapierContext, RapierContext, RapierContextEntityLink, }; pub use self::plugin::{ From d87f7c2e8262aa744bfeda1e10e58672fa89b271 Mon Sep 17 00:00:00 2001 From: Thierry Berger Date: Mon, 9 Dec 2024 09:08:35 +0100 Subject: [PATCH 07/10] Update bevy to 0.15 (#595) --- CHANGELOG.md | 28 +++++----- Cargo.toml | 1 - bevy_rapier2d/Cargo.toml | 15 +++--- bevy_rapier2d/examples/boxes2.rs | 9 ++-- bevy_rapier2d/examples/contact_filter2.rs | 11 ++-- .../examples/custom_system_setup2.rs | 9 ++-- bevy_rapier2d/examples/debug_despawn2.rs | 24 ++++----- bevy_rapier2d/examples/debug_toggle2.rs | 17 +++---- bevy_rapier2d/examples/despawn2.rs | 11 ++-- bevy_rapier2d/examples/events2.rs | 8 +-- bevy_rapier2d/examples/joints2.rs | 7 +-- bevy_rapier2d/examples/joints_despawn2.rs | 7 +-- bevy_rapier2d/examples/locked_rotations2.rs | 13 ++--- bevy_rapier2d/examples/multiple_colliders2.rs | 13 ++--- bevy_rapier2d/examples/player_movement2.rs | 11 ++-- bevy_rapier2d/examples/rope_joint2.rs | 9 ++-- bevy_rapier2d/examples/testbed2.rs | 1 + bevy_rapier3d/Cargo.toml | 13 ++--- bevy_rapier3d/examples/boxes3.rs | 17 +++---- .../examples/character_controller3.rs | 39 ++++---------- bevy_rapier3d/examples/contact_filter3.rs | 15 +++--- .../examples/custom_system_setup3.rs | 13 +++-- bevy_rapier3d/examples/debug_toggle3.rs | 17 +++---- bevy_rapier3d/examples/despawn3.rs | 13 +++-- bevy_rapier3d/examples/events3.rs | 14 ++--- bevy_rapier3d/examples/joints3.rs | 29 +++++------ bevy_rapier3d/examples/joints_despawn3.rs | 25 ++++----- bevy_rapier3d/examples/locked_rotations3.rs | 17 +++---- bevy_rapier3d/examples/multi_world3.rs | 15 +++--- bevy_rapier3d/examples/multiple_colliders3.rs | 24 +++------ bevy_rapier3d/examples/ray_casting3.rs | 15 +++--- bevy_rapier3d/examples/static_trimesh3.rs | 19 +++---- bevy_rapier3d/examples/testbed3.rs | 1 + bevy_rapier_benches3d/Cargo.toml | 2 +- bevy_rapier_benches3d/src/common.rs | 22 +------- deny.toml | 3 ++ src/pipeline/events.rs | 15 +++--- src/plugin/context/mod.rs | 4 +- src/plugin/plugin.rs | 15 ++++-- src/plugin/systems/collider.rs | 20 +++++--- src/plugin/systems/mod.rs | 18 +++---- .../systems/multiple_rapier_contexts.rs | 51 ++++++++++--------- 42 files changed, 259 insertions(+), 371 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 509033c8..4d6984fc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,19 @@ - Update from rapier `0.21` to rapier `0.22`, see [rapier's changelog](https://github.com/dimforge/rapier/blob/master/CHANGELOG.md). +- Update bevy to 0.15. +- `RapierContext`, `RapierConfiguration` and `RenderToSimulationTime` are now a `Component` instead of resources. + - Rapier now supports multiple independent physics worlds, see example `multi_world3` for usage details. + - Migration guide: + - `ResMut` -> `WriteDefaultRapierContext` + - `Res` -> `ReadDefaultRapierContext` + - Access to `RapierConfiguration` and `RenderToSimulationTime` should query for it +on the responsible entity owning the `RenderContext`. + - If you are building a library on top of `bevy_rapier` and would want to support multiple independent physics worlds too, +you can check out the details of [#545](https://github.com/dimforge/bevy_rapier/pull/545) +to get more context and information. +- `colliders_with_aabb_intersecting_aabb` now takes `bevy::math::bounding::Aabb3d` (or `[..]::Aabb2d` in 2D) as parameter. + - it is now accessible with `headless` feature enabled. ### Fix @@ -21,21 +34,6 @@ which was its hardcoded behaviour. `RapierDebugColliderPlugin` and `DebugRenderContext`, as well as individual collider setup via a `ColliderDebug` component. -### Modified - -- `RapierContext`, `RapierConfiguration` and `RenderToSimulationTime` are now a `Component` instead of resources. - - Rapier now supports multiple independent physics worlds, see example `multi_world3` for usage details. - - Migration guide: - - `ResMut` -> `WriteDefaultRapierContext` - - `Res` -> `ReadDefaultRapierContext` - - Access to `RapierConfiguration` and `RenderToSimulationTime` should query for it -on the responsible entity owning the `RenderContext`. - - If you are building a library on top of `bevy_rapier` and would want to support multiple independent physics worlds too, -you can check out the details of [#545](https://github.com/dimforge/bevy_rapier/pull/545) -to get more context and information. -- `colliders_with_aabb_intersecting_aabb` now takes `bevy::math::bounding::Aabb3d` (or `[..]::Aabb2d` in 2D) as parameter. - - it is now accessible with `headless` feature enabled. - ## v0.27.0 (07 July 2024) **This is an update from rapier 0.19 to Rapier 0.21 which includes several stability improvements diff --git a/Cargo.toml b/Cargo.toml index c112b763..34dc302b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,7 +23,6 @@ codegen-units = 1 #parry3d = { path = "../parry/crates/parry3d" } #rapier2d = { path = "../rapier/crates/rapier2d" } #rapier3d = { path = "../rapier/crates/rapier3d" } - #nalgebra = { git = "https://github.com/dimforge/nalgebra", branch = "dev" } #parry2d = { git = "https://github.com/dimforge/parry", branch = "master" } #parry3d = { git = "https://github.com/dimforge/parry", branch = "master" } diff --git a/bevy_rapier2d/Cargo.toml b/bevy_rapier2d/Cargo.toml index 90274ff3..cd29ecad 100644 --- a/bevy_rapier2d/Cargo.toml +++ b/bevy_rapier2d/Cargo.toml @@ -49,25 +49,26 @@ headless = [] async-collider = ["bevy/bevy_asset", "bevy/bevy_scene", "bevy/bevy_render"] [dependencies] -bevy = { version = "0.14", default-features = false } -nalgebra = { version = "0.33", features = ["convert-glam027"] } +bevy = { version = "0.15", default-features = false } +nalgebra = { version = "0.33", features = ["convert-glam029"] } rapier2d = "0.22" bitflags = "2.4" log = "0.4" serde = { version = "1", features = ["derive"], optional = true } [dev-dependencies] -bevy = { version = "0.14", default-features = false, features = [ +bevy = { version = "0.15", default-features = false, features = [ "x11", "bevy_state", + "bevy_window", "bevy_debug_stepping", ] } oorandom = "11" approx = "0.5.1" -glam = { version = "0.27", features = ["approx"] } -bevy-inspector-egui = "0.25.1" -bevy_egui = "0.28.0" -bevy_mod_debugdump = "0.11" +glam = { version = "0.29", features = ["approx"] } +bevy-inspector-egui = "0.28.0" +bevy_egui = "0.31" +bevy_mod_debugdump = "0.12" [package.metadata.docs.rs] # Enable all the features when building the docs on docs.rs diff --git a/bevy_rapier2d/examples/boxes2.rs b/bevy_rapier2d/examples/boxes2.rs index a653575e..b63f7f56 100644 --- a/bevy_rapier2d/examples/boxes2.rs +++ b/bevy_rapier2d/examples/boxes2.rs @@ -18,10 +18,7 @@ fn main() { } pub fn setup_graphics(mut commands: Commands) { - commands.spawn(Camera2dBundle { - transform: Transform::from_xyz(0.0, 20.0, 0.0), - ..default() - }); + commands.spawn((Camera2d::default(), Transform::from_xyz(0.0, 20.0, 0.0))); } pub fn setup_physics(mut commands: Commands) { @@ -32,7 +29,7 @@ pub fn setup_physics(mut commands: Commands) { let ground_height = 10.0; commands.spawn(( - TransformBundle::from(Transform::from_xyz(0.0, 0.0 * -ground_height, 0.0)), + Transform::from_xyz(0.0, 0.0 * -ground_height, 0.0), Collider::cuboid(ground_size, ground_height), )); @@ -54,7 +51,7 @@ pub fn setup_physics(mut commands: Commands) { let y = j as f32 * shift + centery + 30.0; commands.spawn(( - TransformBundle::from(Transform::from_xyz(x, y, 0.0)), + Transform::from_xyz(x, y, 0.0), RigidBody::Dynamic, Collider::cuboid(rad, rad), )); diff --git a/bevy_rapier2d/examples/contact_filter2.rs b/bevy_rapier2d/examples/contact_filter2.rs index d286151d..7e3538c2 100644 --- a/bevy_rapier2d/examples/contact_filter2.rs +++ b/bevy_rapier2d/examples/contact_filter2.rs @@ -45,10 +45,7 @@ fn main() { } fn setup_graphics(mut commands: Commands) { - commands.spawn(Camera2dBundle { - transform: Transform::from_xyz(0.0, 20.0, 0.0), - ..default() - }); + commands.spawn((Camera2d::default(), Transform::from_xyz(0.0, 20.0, 0.0))); } pub fn setup_physics(mut commands: Commands) { @@ -58,13 +55,13 @@ pub fn setup_physics(mut commands: Commands) { let ground_size = 100.0; commands.spawn(( - TransformBundle::from(Transform::from_xyz(0.0, -100.0, 0.0)), + Transform::from_xyz(0.0, -100.0, 0.0), Collider::cuboid(ground_size, 12.0), CustomFilterTag::GroupA, )); commands.spawn(( - TransformBundle::from(Transform::from_xyz(0.0, 0.0, 0.0)), + Transform::from_xyz(0.0, 0.0, 0.0), Collider::cuboid(ground_size, 12.0), CustomFilterTag::GroupB, )); @@ -89,7 +86,7 @@ pub fn setup_physics(mut commands: Commands) { group_id += 1; commands.spawn(( - TransformBundle::from(Transform::from_xyz(x, y, 0.0)), + Transform::from_xyz(x, y, 0.0), RigidBody::Dynamic, Collider::cuboid(rad, rad), ActiveHooks::FILTER_CONTACT_PAIRS, diff --git a/bevy_rapier2d/examples/custom_system_setup2.rs b/bevy_rapier2d/examples/custom_system_setup2.rs index 31232e9f..71b5ac56 100644 --- a/bevy_rapier2d/examples/custom_system_setup2.rs +++ b/bevy_rapier2d/examples/custom_system_setup2.rs @@ -61,10 +61,7 @@ fn despawn_one_box( } fn setup_graphics(mut commands: Commands) { - commands.spawn(Camera2dBundle { - transform: Transform::from_xyz(0.0, 20.0, 0.0), - ..default() - }); + commands.spawn((Camera2d::default(), Transform::from_xyz(0.0, 20.0, 0.0))); } pub fn setup_physics(mut commands: Commands) { @@ -75,7 +72,7 @@ pub fn setup_physics(mut commands: Commands) { let ground_height = 10.0; commands.spawn(( - TransformBundle::from(Transform::from_xyz(0.0, 0.0 * -ground_height, 0.0)), + Transform::from_xyz(0.0, 0.0 * -ground_height, 0.0), Collider::cuboid(ground_size, ground_height), )); @@ -97,7 +94,7 @@ pub fn setup_physics(mut commands: Commands) { let y = j as f32 * shift + centery + 30.0; commands.spawn(( - TransformBundle::from(Transform::from_xyz(x, y, 0.0)), + Transform::from_xyz(x, y, 0.0), RigidBody::Dynamic, Collider::cuboid(rad, rad), )); diff --git a/bevy_rapier2d/examples/debug_despawn2.rs b/bevy_rapier2d/examples/debug_despawn2.rs index 3eeab482..4fdf28b5 100644 --- a/bevy_rapier2d/examples/debug_despawn2.rs +++ b/bevy_rapier2d/examples/debug_despawn2.rs @@ -92,7 +92,7 @@ pub fn setup_game(mut commands: Commands, mut game: ResMut) { byte_rgb(255, 0, 0), ]; - commands.spawn(Camera2dBundle::default()); + commands.spawn(Camera2d::default()); setup_board(&mut commands, &game); @@ -131,15 +131,12 @@ fn setup_board(commands: &mut Commands, game: &Game) { // Add floor commands.spawn(( - SpriteBundle { - sprite: Sprite { - color: Color::srgb(0.5, 0.5, 0.5), - custom_size: Some(Vec2::new(game.n_lanes as f32 * 30.0, 60.0)), - ..Default::default() - }, - transform: Transform::from_xyz(0.0, floor_y - 30.0 * 0.5, 0.0), + Sprite { + color: Color::srgb(0.5, 0.5, 0.5), + custom_size: Some(Vec2::new(game.n_lanes as f32 * 30.0, 60.0)), ..Default::default() }, + Transform::from_xyz(0.0, floor_y - 30.0 * 0.5, 0.0), RigidBody::Fixed, Collider::cuboid(game.n_lanes as f32 * 30.0 / 2.0, 60.0 / 2.0), )); @@ -200,15 +197,12 @@ fn spawn_block( commands .spawn(( - SpriteBundle { - sprite: Sprite { - color: game.cube_colors[kind as usize], - custom_size: Some(Vec2::new(30.0, 30.0)), - ..Default::default() - }, - transform: Transform::from_xyz(x, y, 0.0), + Sprite { + color: game.cube_colors[kind as usize], + custom_size: Some(Vec2::new(30.0, 30.0)), ..Default::default() }, + Transform::from_xyz(x, y, 0.0), RigidBody::Dynamic, Damping { linear_damping, diff --git a/bevy_rapier2d/examples/debug_toggle2.rs b/bevy_rapier2d/examples/debug_toggle2.rs index da161f1b..a5b1e1e0 100644 --- a/bevy_rapier2d/examples/debug_toggle2.rs +++ b/bevy_rapier2d/examples/debug_toggle2.rs @@ -31,11 +31,10 @@ fn main() { } pub fn setup_graphics(mut commands: Commands) { - commands.spawn(Camera3dBundle { - transform: Transform::from_xyz(-30.0, 30.0, 100.0) - .looking_at(Vec3::new(0.0, 10.0, 0.0), Vec3::Y), - ..Default::default() - }); + commands.spawn(( + Camera3d::default(), + Transform::from_xyz(-30.0, 30.0, 100.0).looking_at(Vec3::new(0.0, 10.0, 0.0), Vec3::Y), + )); } #[derive(Component)] @@ -49,7 +48,7 @@ pub fn setup_physics(mut commands: Commands) { let ground_height = 0.1; commands.spawn(( - TransformBundle::from(Transform::from_xyz(0.0, -ground_height, 0.0)), + Transform::from_xyz(0.0, -ground_height, 0.0), Collider::cuboid(ground_size, ground_height), )); @@ -81,12 +80,10 @@ pub fn setup_physics(mut commands: Commands) { color += 1; commands - .spawn(TransformBundle::from(Transform::from_rotation( - Quat::from_rotation_x(0.2), - ))) + .spawn(Transform::from_rotation(Quat::from_rotation_x(0.2))) .with_children(|child| { child.spawn(( - TransformBundle::from(Transform::from_xyz(x, y, z)), + Transform::from_xyz(x, y, z), RigidBody::Dynamic, Collider::cuboid(rad, rad), ColliderDebugColor(colors[color % 3]), diff --git a/bevy_rapier2d/examples/despawn2.rs b/bevy_rapier2d/examples/despawn2.rs index a2b5288d..ed20bc80 100644 --- a/bevy_rapier2d/examples/despawn2.rs +++ b/bevy_rapier2d/examples/despawn2.rs @@ -43,10 +43,7 @@ pub fn setup_graphics( resize.timer = Timer::from_seconds(6.0, TimerMode::Once); despawn.timer = Timer::from_seconds(5.0, TimerMode::Once); - commands.spawn(Camera2dBundle { - transform: Transform::from_xyz(0.0, 20.0, 0.0), - ..default() - }); + commands.spawn((Camera2d::default(), Transform::from_xyz(0.0, 20.0, 0.0))); } pub fn setup_physics(mut commands: Commands) { @@ -58,12 +55,12 @@ pub fn setup_physics(mut commands: Commands) { commands.spawn((Collider::cuboid(ground_size, 12.0), Despawn)); commands.spawn(( - TransformBundle::from(Transform::from_xyz(ground_size, ground_size * 2.0, 0.0)), + Transform::from_xyz(ground_size, ground_size * 2.0, 0.0), Collider::cuboid(12.0, ground_size * 2.0), )); commands.spawn(( - TransformBundle::from(Transform::from_xyz(-ground_size, ground_size * 2.0, 0.0)), + Transform::from_xyz(-ground_size, ground_size * 2.0, 0.0), Collider::cuboid(12.0, ground_size * 2.0), )); @@ -83,7 +80,7 @@ pub fn setup_physics(mut commands: Commands) { let y = j as f32 * shift + centery + 2.0; let mut entity = commands.spawn(( - TransformBundle::from(Transform::from_xyz(x, y, 0.0)), + Transform::from_xyz(x, y, 0.0), RigidBody::Dynamic, Collider::cuboid(rad, rad), )); diff --git a/bevy_rapier2d/examples/events2.rs b/bevy_rapier2d/examples/events2.rs index d772d3f8..0b49e486 100644 --- a/bevy_rapier2d/examples/events2.rs +++ b/bevy_rapier2d/examples/events2.rs @@ -19,7 +19,7 @@ fn main() { } pub fn setup_graphics(mut commands: Commands) { - commands.spawn(Camera2dBundle::default()); + commands.spawn(Camera2d::default()); } pub fn display_events( @@ -40,18 +40,18 @@ pub fn setup_physics(mut commands: Commands) { * Ground */ commands.spawn(( - TransformBundle::from(Transform::from_xyz(0.0, -24.0, 0.0)), + Transform::from_xyz(0.0, -24.0, 0.0), Collider::cuboid(80.0, 20.0), )); commands.spawn(( - TransformBundle::from(Transform::from_xyz(0.0, 100.0, 0.0)), + Transform::from_xyz(0.0, 100.0, 0.0), Collider::cuboid(80.0, 30.0), Sensor, )); commands.spawn(( - TransformBundle::from(Transform::from_xyz(0.0, 260.0, 0.0)), + Transform::from_xyz(0.0, 260.0, 0.0), RigidBody::Dynamic, Collider::cuboid(10.0, 10.0), ActiveEvents::COLLISION_EVENTS, diff --git a/bevy_rapier2d/examples/joints2.rs b/bevy_rapier2d/examples/joints2.rs index e30352ca..a7c16cee 100644 --- a/bevy_rapier2d/examples/joints2.rs +++ b/bevy_rapier2d/examples/joints2.rs @@ -18,10 +18,7 @@ fn main() { } pub fn setup_graphics(mut commands: Commands) { - commands.spawn(Camera2dBundle { - transform: Transform::from_xyz(0.0, -200.0, 0.0), - ..default() - }); + commands.spawn((Camera2d::default(), Transform::from_xyz(0.0, -200.0, 0.0))); } pub fn setup_physics(mut commands: Commands) { @@ -46,7 +43,7 @@ pub fn setup_physics(mut commands: Commands) { let child_entity = commands .spawn(( - TransformBundle::from(Transform::from_xyz(fk * shift, -fi * shift, 0.0)), + Transform::from_xyz(fk * shift, -fi * shift, 0.0), rigid_body, Collider::cuboid(rad, rad), )) diff --git a/bevy_rapier2d/examples/joints_despawn2.rs b/bevy_rapier2d/examples/joints_despawn2.rs index 736d868b..f5fa1977 100644 --- a/bevy_rapier2d/examples/joints_despawn2.rs +++ b/bevy_rapier2d/examples/joints_despawn2.rs @@ -28,10 +28,7 @@ fn main() { } pub fn setup_graphics(mut commands: Commands) { - commands.spawn(Camera2dBundle { - transform: Transform::from_xyz(0.0, -200.0, 0.0), - ..default() - }); + commands.spawn((Camera2d::default(), Transform::from_xyz(0.0, -200.0, 0.0))); } pub fn setup_physics(mut commands: Commands, mut despawn: ResMut) { @@ -58,7 +55,7 @@ pub fn setup_physics(mut commands: Commands, mut despawn: ResMut) { res.timer = Timer::from_seconds(5.0, TimerMode::Once); - commands.spawn(Camera3dBundle { - transform: Transform::from_xyz(-30.0, 30.0, 100.0) - .looking_at(Vec3::new(0.0, 10.0, 0.0), Vec3::Y), - ..Default::default() - }); + commands.spawn(( + Camera3d::default(), + Transform::from_xyz(-30.0, 30.0, 100.0).looking_at(Vec3::new(0.0, 10.0, 0.0), Vec3::Y), + )); } pub fn setup_physics(mut commands: Commands) { @@ -45,7 +44,7 @@ pub fn setup_physics(mut commands: Commands) { let ground_height = 0.1; commands.spawn(( - TransformBundle::from(Transform::from_xyz(0.0, -ground_height, 0.0)), + Transform::from_xyz(0.0, -ground_height, 0.0), Collider::cuboid(ground_size, ground_height, ground_size), Despawn, )); @@ -78,7 +77,7 @@ pub fn setup_physics(mut commands: Commands) { color += 1; commands.spawn(( - TransformBundle::from(Transform::from_xyz(x, y, z)), + Transform::from_xyz(x, y, z), RigidBody::Dynamic, Collider::cuboid(rad, rad, rad), ColliderDebugColor(colors[color % 3]), diff --git a/bevy_rapier3d/examples/events3.rs b/bevy_rapier3d/examples/events3.rs index 3f8791d7..9f1a23e8 100644 --- a/bevy_rapier3d/examples/events3.rs +++ b/bevy_rapier3d/examples/events3.rs @@ -19,10 +19,10 @@ fn main() { } pub fn setup_graphics(mut commands: Commands) { - commands.spawn(Camera3dBundle { - transform: Transform::from_xyz(0.0, 0.0, 25.0).looking_at(Vec3::ZERO, Vec3::Y), - ..Default::default() - }); + commands.spawn(( + Camera3d::default(), + Transform::from_xyz(0.0, 0.0, 25.0).looking_at(Vec3::ZERO, Vec3::Y), + )); } pub fn display_events( @@ -43,18 +43,18 @@ pub fn setup_physics(mut commands: Commands) { * Ground */ commands.spawn(( - TransformBundle::from(Transform::from_xyz(0.0, -1.2, 0.0)), + Transform::from_xyz(0.0, -1.2, 0.0), Collider::cuboid(4.0, 1.0, 1.0), )); commands.spawn(( - TransformBundle::from(Transform::from_xyz(0.0, 5.0, 0.0)), + Transform::from_xyz(0.0, 5.0, 0.0), Collider::cuboid(4.0, 1.5, 1.0), Sensor, )); commands.spawn(( - TransformBundle::from(Transform::from_xyz(0.0, 13.0, 0.0)), + Transform::from_xyz(0.0, 13.0, 0.0), RigidBody::Dynamic, Collider::cuboid(0.5, 0.5, 0.5), ActiveEvents::COLLISION_EVENTS, diff --git a/bevy_rapier3d/examples/joints3.rs b/bevy_rapier3d/examples/joints3.rs index 2864d33b..3edecc74 100644 --- a/bevy_rapier3d/examples/joints3.rs +++ b/bevy_rapier3d/examples/joints3.rs @@ -25,11 +25,10 @@ fn main() { } pub fn setup_graphics(mut commands: Commands) { - commands.spawn(Camera3dBundle { - transform: Transform::from_xyz(15.0, 5.0, 42.0) - .looking_at(Vec3::new(13.0, 1.0, 1.0), Vec3::Y), - ..Default::default() - }); + commands.spawn(( + Camera3d::default(), + Transform::from_xyz(15.0, 5.0, 42.0).looking_at(Vec3::new(13.0, 1.0, 1.0), Vec3::Y), + )); } fn create_prismatic_joints(commands: &mut Commands, origin: Vect, num: usize) { @@ -38,7 +37,7 @@ fn create_prismatic_joints(commands: &mut Commands, origin: Vect, num: usize) { let mut curr_parent = commands .spawn(( - TransformBundle::from(Transform::from_xyz(origin.x, origin.y, origin.z)), + Transform::from_xyz(origin.x, origin.y, origin.z), RigidBody::Fixed, Collider::cuboid(rad, rad, rad), )) @@ -60,7 +59,7 @@ fn create_prismatic_joints(commands: &mut Commands, origin: Vect, num: usize) { curr_parent = commands .spawn(( - TransformBundle::from(Transform::from_xyz(origin.x, origin.y, origin.z + dz)), + Transform::from_xyz(origin.x, origin.y, origin.z + dz), RigidBody::Dynamic, Collider::cuboid(rad, rad, rad), joint, @@ -75,7 +74,7 @@ fn create_rope_joints(commands: &mut Commands, origin: Vect, num: usize) { let mut curr_parent = commands .spawn(( - TransformBundle::from(Transform::from_xyz(origin.x, origin.y, origin.z)), + Transform::from_xyz(origin.x, origin.y, origin.z), RigidBody::Fixed, Collider::cuboid(rad, rad, rad), )) @@ -89,7 +88,7 @@ fn create_rope_joints(commands: &mut Commands, origin: Vect, num: usize) { curr_parent = commands .spawn(( - TransformBundle::from(Transform::from_xyz(origin.x, origin.y, origin.z + dz)), + Transform::from_xyz(origin.x, origin.y, origin.z + dz), RigidBody::Dynamic, Collider::cuboid(rad, rad, rad), joint, @@ -104,7 +103,7 @@ fn create_revolute_joints(commands: &mut Commands, origin: Vec3, num: usize) { let mut curr_parent = commands .spawn(( - TransformBundle::from(Transform::from_xyz(origin.x, origin.y, 0.0)), + Transform::from_xyz(origin.x, origin.y, 0.0), RigidBody::Fixed, Collider::cuboid(rad, rad, rad), )) @@ -124,7 +123,7 @@ fn create_revolute_joints(commands: &mut Commands, origin: Vec3, num: usize) { for k in 0..4 { handles[k] = commands .spawn(( - TransformBundle::from(Transform::from_translation(positions[k])), + Transform::from_translation(positions[k]), RigidBody::Dynamic, Collider::cuboid(rad, rad, rad), )) @@ -180,11 +179,7 @@ fn create_fixed_joints(commands: &mut Commands, origin: Vec3, num: usize) { let child_entity = commands .spawn(( - TransformBundle::from(Transform::from_xyz( - origin.x + fk * shift, - origin.y, - origin.z + fi * shift, - )), + Transform::from_xyz(origin.x + fk * shift, origin.y, origin.z + fi * shift), rigid_body, Collider::ball(rad), )) @@ -239,7 +234,7 @@ fn create_ball_joints(commands: &mut Commands, num: usize) { let child_entity = commands .spawn(( - TransformBundle::from(Transform::from_xyz(fk * shift, 0.0, fi * shift)), + Transform::from_xyz(fk * shift, 0.0, fi * shift), rigid_body, Collider::ball(rad), )) diff --git a/bevy_rapier3d/examples/joints_despawn3.rs b/bevy_rapier3d/examples/joints_despawn3.rs index 17d1608f..fe1795c7 100644 --- a/bevy_rapier3d/examples/joints_despawn3.rs +++ b/bevy_rapier3d/examples/joints_despawn3.rs @@ -30,11 +30,10 @@ fn main() { pub fn setup_graphics(mut commands: Commands, mut res: ResMut) { res.timer = Timer::from_seconds(5.0, TimerMode::Once); - commands.spawn(Camera3dBundle { - transform: Transform::from_xyz(15.0, 5.0, 42.0) - .looking_at(Vec3::new(13.0, 1.0, 1.0), Vec3::Y), - ..Default::default() - }); + commands.spawn(( + Camera3d::default(), + Transform::from_xyz(15.0, 5.0, 42.0).looking_at(Vec3::new(13.0, 1.0, 1.0), Vec3::Y), + )); } fn create_prismatic_joints(commands: &mut Commands, origin: Vect, num: usize) { @@ -43,7 +42,7 @@ fn create_prismatic_joints(commands: &mut Commands, origin: Vect, num: usize) { let mut curr_parent = commands .spawn(( - TransformBundle::from(Transform::from_xyz(origin.x, origin.y, origin.z)), + Transform::from_xyz(origin.x, origin.y, origin.z), RigidBody::Fixed, Collider::cuboid(rad, rad, rad), )) @@ -64,7 +63,7 @@ fn create_prismatic_joints(commands: &mut Commands, origin: Vect, num: usize) { let joint = ImpulseJoint::new(curr_parent, prism); let mut entity = commands.spawn(( - TransformBundle::from(Transform::from_xyz(origin.x, origin.y, origin.z + dz)), + Transform::from_xyz(origin.x, origin.y, origin.z + dz), RigidBody::Dynamic, Collider::cuboid(rad, rad, rad), joint, @@ -84,7 +83,7 @@ fn create_revolute_joints(commands: &mut Commands, origin: Vec3, num: usize) { let mut curr_parent = commands .spawn(( - TransformBundle::from(Transform::from_xyz(origin.x, origin.y, 0.0)), + Transform::from_xyz(origin.x, origin.y, 0.0), RigidBody::Fixed, Collider::cuboid(rad, rad, rad), )) @@ -104,7 +103,7 @@ fn create_revolute_joints(commands: &mut Commands, origin: Vec3, num: usize) { for k in 0..4 { handles[k] = commands .spawn(( - TransformBundle::from(Transform::from_translation(positions[k])), + Transform::from_translation(positions[k]), RigidBody::Dynamic, Collider::cuboid(rad, rad, rad), )) @@ -167,11 +166,7 @@ fn create_fixed_joints(commands: &mut Commands, origin: Vec3, num: usize) { let child_entity = commands .spawn(( - TransformBundle::from(Transform::from_xyz( - origin.x + fk * shift, - origin.y, - origin.z + fi * shift, - )), + Transform::from_xyz(origin.x + fk * shift, origin.y, origin.z + fi * shift), rigid_body, Collider::ball(rad), )) @@ -226,7 +221,7 @@ fn create_ball_joints(commands: &mut Commands, num: usize) { let child_entity = commands .spawn(( - TransformBundle::from(Transform::from_xyz(fk * shift, 0.0, fi * shift)), + Transform::from_xyz(fk * shift, 0.0, fi * shift), rigid_body, Collider::ball(rad), )) diff --git a/bevy_rapier3d/examples/locked_rotations3.rs b/bevy_rapier3d/examples/locked_rotations3.rs index 0288db5f..a4feab94 100644 --- a/bevy_rapier3d/examples/locked_rotations3.rs +++ b/bevy_rapier3d/examples/locked_rotations3.rs @@ -18,11 +18,10 @@ fn main() { } pub fn setup_graphics(mut commands: Commands) { - commands.spawn(Camera3dBundle { - transform: Transform::from_xyz(10.0, 3.0, 0.0) - .looking_at(Vec3::new(0.0, 3.0, 0.0), Vec3::Y), - ..Default::default() - }); + commands.spawn(( + Camera3d::default(), + Transform::from_xyz(10.0, 3.0, 0.0).looking_at(Vec3::new(0.0, 3.0, 0.0), Vec3::Y), + )); } pub fn setup_physics(mut commands: Commands) { @@ -33,7 +32,7 @@ pub fn setup_physics(mut commands: Commands) { let ground_height = 0.1; commands.spawn(( - TransformBundle::from(Transform::from_xyz(0.0, -ground_height, 0.0)), + Transform::from_xyz(0.0, -ground_height, 0.0), Collider::cuboid(ground_size, ground_height, ground_size), )); @@ -41,7 +40,7 @@ pub fn setup_physics(mut commands: Commands) { * A rectangle that only rotates along the `x` axis. */ commands.spawn(( - TransformBundle::from(Transform::from_xyz(0.0, 3.0, 0.0)), + Transform::from_xyz(0.0, 3.0, 0.0), RigidBody::Dynamic, LockedAxes::TRANSLATION_LOCKED | LockedAxes::ROTATION_LOCKED_Y @@ -53,9 +52,7 @@ pub fn setup_physics(mut commands: Commands) { * A tilted cuboid that cannot rotate. */ commands.spawn(( - TransformBundle::from( - Transform::from_xyz(0.0, 5.0, 0.0).with_rotation(Quat::from_rotation_x(1.0)), - ), + Transform::from_xyz(0.0, 5.0, 0.0).with_rotation(Quat::from_rotation_x(1.0)), RigidBody::Dynamic, LockedAxes::ROTATION_LOCKED, Collider::cuboid(0.6, 0.4, 0.4), diff --git a/bevy_rapier3d/examples/multi_world3.rs b/bevy_rapier3d/examples/multi_world3.rs index dc5fa807..54a0ad93 100644 --- a/bevy_rapier3d/examples/multi_world3.rs +++ b/bevy_rapier3d/examples/multi_world3.rs @@ -38,11 +38,10 @@ fn create_worlds(mut commands: Commands) { } fn setup_graphics(mut commands: Commands) { - commands.spawn(Camera3dBundle { - transform: Transform::from_xyz(0.0, 3.0, -10.0) - .looking_at(Vec3::new(0.0, 0.0, 0.0), Vec3::Y), - ..Default::default() - }); + commands.spawn(( + Camera3d::default(), + Transform::from_xyz(0.0, 3.0, -10.0).looking_at(Vec3::new(0.0, 0.0, 0.0), Vec3::Y), + )); } #[derive(Component)] @@ -55,7 +54,7 @@ struct Platform { fn move_platforms(time: Res