diff --git a/CHANGELOG.md b/CHANGELOG.md index 509033c8..24c9e61d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,18 +23,36 @@ which was its hardcoded behaviour. ### 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. +- Rapier now supports multiple independent physics contexts, see example `multi_contexts3` for usage details. + - Each entity managed by bevy_rapier has a `RapierContextEntityLink` pointing to the entity containing the components above. + - If you are building a library on top of `bevy_rapier` and would want to support multiple independent physics contexts too, + you can check out the details of [#545](https://github.com/dimforge/bevy_rapier/pull/545) + to find more information. + - Rapier now supports multiple independent physics contexts, see example `multi_contexts3` 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, + - If you are building a library on top of `bevy_rapier` and would want to support multiple independent physics contexts 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. +- `RapierContext`, `RapierConfiguration` and `SimulationToRenderTime` are no longer `Resource`s. + - They have been split in multiple `Component`s: + - `RapierContextColliders` + - `RapierContextJoints` + - `RapierContextSimulation` + - `RapierRigidBodySet` + - `SimulationToRenderTime` + - `RapierConfiguration` + - Migration guide: + - `ResMut` -> `WriteRapierContext` + - `Res` -> `ReadRapierContext` + - Access to `RapierConfiguration` and `SimulationToRenderTime` should query for it + on the responsible entity owning the `RenderContext`. + - See [`ray_casting`](bevy_rapier3d/examples/ray_casting3.rs) example for a usage example. ## v0.27.0 (07 July 2024) diff --git a/bevy_rapier2d/examples/debugdump2.rs b/bevy_rapier2d/examples/debugdump2.rs index 190a5079..4d133d91 100644 --- a/bevy_rapier2d/examples/debugdump2.rs +++ b/bevy_rapier2d/examples/debugdump2.rs @@ -1,6 +1,6 @@ //! Example using bevy_mod_debugdump to output a graph of systems execution order. //! run with: -//! `cargo run --example debugdump2 > dump.dot && dot -Tsvg dump.dot > dump.svg` +//! `cargo run --example debugdump2 > dump.dot && dot -Tsvg dump.dot > dump.svg` use bevy::prelude::*; use bevy_mod_debugdump::{schedule_graph, schedule_graph_dot}; diff --git a/bevy_rapier2d/examples/testbed2.rs b/bevy_rapier2d/examples/testbed2.rs index 8a433e22..f415fb1f 100644 --- a/bevy_rapier2d/examples/testbed2.rs +++ b/bevy_rapier2d/examples/testbed2.rs @@ -204,11 +204,12 @@ fn main() { OnExit(Examples::PlayerMovement2), ( cleanup, - |mut rapier_config: Query<&mut RapierConfiguration>, - ctxt: ReadDefaultRapierContext| { + |mut rapier_config: Query<&mut RapierConfiguration>, ctxt: ReadRapierContext| { let mut rapier_config = rapier_config.single_mut(); - rapier_config.gravity = - RapierConfiguration::new(ctxt.integration_parameters.length_unit).gravity; + rapier_config.gravity = RapierConfiguration::new( + ctxt.single().simulation.integration_parameters.length_unit, + ) + .gravity; }, ), ) diff --git a/bevy_rapier3d/examples/joints3.rs b/bevy_rapier3d/examples/joints3.rs index 2864d33b..4a229177 100644 --- a/bevy_rapier3d/examples/joints3.rs +++ b/bevy_rapier3d/examples/joints3.rs @@ -284,7 +284,7 @@ pub fn setup_physics(mut commands: Commands) { } pub fn print_impulse_revolute_joints( - context: ReadDefaultRapierContext, + context: ReadRapierContext, joints: Query<(Entity, &ImpulseJoint)>, ) { for (entity, impulse_joint) in joints.iter() { @@ -293,7 +293,7 @@ pub fn print_impulse_revolute_joints( println!( "angle for {}: {:?}", entity, - context.impulse_revolute_joint_angle(entity), + context.single().impulse_revolute_joint_angle(entity), ); } _ => {} diff --git a/bevy_rapier3d/examples/multi_world3.rs b/bevy_rapier3d/examples/multi_contexts3.rs similarity index 80% rename from bevy_rapier3d/examples/multi_world3.rs rename to bevy_rapier3d/examples/multi_contexts3.rs index dc5fa807..33baaf39 100644 --- a/bevy_rapier3d/examples/multi_world3.rs +++ b/bevy_rapier3d/examples/multi_contexts3.rs @@ -1,7 +1,7 @@ use bevy::{input::common_conditions::input_just_pressed, prelude::*}; use bevy_rapier3d::prelude::*; -const N_WORLDS: usize = 2; +const N_CONTEXTS: usize = 2; fn main() { App::new() @@ -18,21 +18,21 @@ fn main() { )) .add_systems( Startup, - ((create_worlds, setup_physics).chain(), setup_graphics), + ((create_contexts, setup_physics).chain(), setup_graphics), ) .add_systems(Update, move_platforms) .add_systems( Update, - change_world.run_if(input_just_pressed(KeyCode::KeyC)), + change_context.run_if(input_just_pressed(KeyCode::KeyC)), ) .run(); } -fn create_worlds(mut commands: Commands) { - for i in 0..N_WORLDS { - let mut world = commands.spawn((RapierContext::default(), WorldId(i))); +fn create_contexts(mut commands: Commands) { + for i in 0..N_CONTEXTS { + let mut context = commands.spawn((RapierContextBundle::default(), ContextId(i))); if i == 0 { - world.insert(DefaultRapierContext); + context.insert((DefaultRapierContext, RapierContextBundle::default())); } } } @@ -46,7 +46,7 @@ fn setup_graphics(mut commands: Commands) { } #[derive(Component)] -pub struct WorldId(pub usize); +pub struct ContextId(pub usize); #[derive(Component)] struct Platform { @@ -59,8 +59,8 @@ fn move_platforms(time: Res