From 4fd97469894c9a2a836fa236c416ee16d1c95393 Mon Sep 17 00:00:00 2001 From: Thierry Berger Date: Wed, 26 Jun 2024 18:13:40 +0200 Subject: [PATCH] multiple worlds working + example example from https://github.com/dimforge/bevy_rapier/pull/328 Co-authored-by: Anthony Tornetta <25857049+AnthonyTornetta@users.noreply.github.com> --- CHANGELOG.md | 9 +- bevy_rapier3d/examples/multi_world3.rs | 117 +++ src/plugin/context/systemparams/mod.rs | 12 + .../rapier_context_access.rs} | 33 +- src/plugin/mod.rs | 2 +- src/plugin/plugin.rs | 13 + src/plugin/systems/character_controller.rs | 18 +- src/plugin/systems/collider.rs | 125 ++-- src/plugin/systems/joint.rs | 46 +- src/plugin/systems/remove.rs | 24 +- src/plugin/systems/rigid_body.rs | 677 ++++++++++-------- 11 files changed, 661 insertions(+), 415 deletions(-) create mode 100644 bevy_rapier3d/examples/multi_world3.rs create mode 100644 src/plugin/context/systemparams/mod.rs rename src/plugin/context/{systemparams.rs => systemparams/rapier_context_access.rs} (66%) diff --git a/CHANGELOG.md b/CHANGELOG.md index befabb27..b553961e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,11 +7,10 @@ - `RapierContext` is now a `Component` - Rapier now supports multiple worlds. - Migration guide: - - `ResMut` -> `RapierContextAccessMut` - - `Res` -> `Query<&RapierContext>` - - `ResMut` -> `Query<&mut RapierConfiguration>` - - `Res` -> `Query<&RapierConfiguration>` - - you can reach out for the underlying configuration via .single + - `ResMut` -> `DefaultRapierContextAccessMut` + - `Res` -> `DefaultRapierContextAccess` + - `ResMut` -> `DefaultRapierConfigurationMut` + - `Res` -> `DefaultRapierConfiguration` ## v0.27.0-rc.1 (18 June 2024) diff --git a/bevy_rapier3d/examples/multi_world3.rs b/bevy_rapier3d/examples/multi_world3.rs new file mode 100644 index 00000000..04f6b29c --- /dev/null +++ b/bevy_rapier3d/examples/multi_world3.rs @@ -0,0 +1,117 @@ +use bevy::prelude::*; +use bevy_rapier3d::prelude::*; + +const N_WORLDS: usize = 2; + +fn main() { + App::new() + .insert_resource(ClearColor(Color::rgb( + 0xF9 as f32 / 255.0, + 0xF9 as f32 / 255.0, + 0xFF as f32 / 255.0, + ))) + .add_plugins(( + DefaultPlugins, + RapierPhysicsPlugin::::default().with_default_world(None), + RapierDebugRenderPlugin::default(), + )) + .add_systems( + Startup, + ((create_worlds, setup_physics).chain(), setup_graphics), + ) + .add_systems(Update, move_platforms) + // .add_systems(Update, change_world) + // .add_systems(Update, despawn_last) + .run(); +} + +fn create_worlds(mut commands: Commands) { + for i in 0..N_WORLDS { + commands.spawn((RapierContext::default(), WorldId(i))); + } +} + +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() + }); +} + +#[derive(Component)] +pub struct WorldId(pub usize); + +#[derive(Component)] +struct Platform { + starting_y: f32, +} + +fn move_platforms(time: Res