Skip to content
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# Changelog

## Unreleased

### Added

- Add a `PhysicsContext` struct containing top level rapier structs to help with reducing boilerplate.

## v0.23.0 (08 Jan 2025)

### Fix
Expand All @@ -16,7 +24,6 @@
- `RigidBodySet` and `ColliderSet` have a new constructor `with_capacity`.
- Use `profiling` crate to provide helpful profiling information in different tools.
- The testbeds have been updated to use `puffin_egui`

### Modified

- `InteractionGroups` default value for `memberships` is now `GROUP_1` (#706)
Expand Down
16 changes: 3 additions & 13 deletions examples2d/add_remove2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,8 @@ pub fn init_world(testbed: &mut Testbed) {
let x = rand::random::<f32>() * 10.0 - 5.0;
let y = rand::random::<f32>() * 10.0 + 10.0;
let rigid_body = RigidBodyBuilder::dynamic().translation(vector![x, y]);
let handle = physics.bodies.insert(rigid_body);
let collider = ColliderBuilder::cuboid(rad, rad);
physics
.colliders
.insert_with_parent(collider, handle, &mut physics.bodies);
let (handle, _) =
physics.insert_body_and_collider(rigid_body, ColliderBuilder::cuboid(rad, rad));

if let Some(graphics) = &mut graphics {
graphics.add_body(handle, &physics.bodies, &physics.colliders);
Expand All @@ -52,14 +49,7 @@ pub fn init_world(testbed: &mut Testbed) {
.map(|e| e.0)
.collect();
for handle in to_remove {
physics.bodies.remove(
handle,
&mut physics.islands,
&mut physics.colliders,
&mut physics.impulse_joints,
&mut physics.multibody_joints,
true,
);
physics.remove_rigidbody(handle, true);

if let Some(graphics) = &mut graphics {
graphics.remove_body(handle);
Expand Down
4 changes: 1 addition & 3 deletions examples2d/debug_intersection2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ pub fn init_world(testbed: &mut Testbed) {

testbed.add_callback(move |graphics, physics, _, run| {
let slow_time = run.timestep_id as f32 / 3.0;
let intersection = physics.query_pipeline.intersection_with_shape(
&physics.bodies,
&physics.colliders,
let intersection = physics.intersection_with_shape(
&Isometry::translation(slow_time.cos() * 10.0, slow_time.sin() * 10.0),
&Ball::new(rad / 2.0),
QueryFilter::default(),
Expand Down
11 changes: 5 additions & 6 deletions examples2d/one_way_platforms2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,18 +93,17 @@ pub fn init_world(testbed: &mut Testbed) {
if run_state.timestep_id % 200 == 0 && physics.bodies.len() <= 7 {
// Spawn a new cube.
let collider = ColliderBuilder::cuboid(1.5, 2.0);
let body = RigidBodyBuilder::dynamic().translation(vector![20.0, 10.0]);
let handle = physics.bodies.insert(body);
physics
.colliders
.insert_with_parent(collider, handle, &mut physics.bodies);
let (handle, _) = physics.insert_body_and_collider(
RigidBodyBuilder::dynamic().translation(vector![20.0, 10.0]),
collider,
);

if let Some(graphics) = graphics {
graphics.add_body(handle, &physics.bodies, &physics.colliders);
}
}

for handle in physics.islands.active_dynamic_bodies() {
for handle in physics.island_manager.active_dynamic_bodies() {
let body = &mut physics.bodies[*handle];
if body.position().translation.y > 1.0 {
body.set_gravity_scale(1.0, false);
Expand Down
2 changes: 1 addition & 1 deletion examples3d-f64/debug_serialized3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub fn init_world(testbed: &mut Testbed) {
state.impulse_joints,
state.multibody_joints,
);
testbed.harness_mut().physics.islands = state.islands;
testbed.harness_mut().physics.island_manager = state.islands;
testbed.harness_mut().physics.broad_phase = state.broad_phase;
testbed.harness_mut().physics.narrow_phase = state.narrow_phase;
testbed.harness_mut().physics.ccd_solver = state.ccd_solver;
Expand Down
2 changes: 1 addition & 1 deletion examples3d/debug_add_remove_collider3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub fn init_world(testbed: &mut Testbed) {
.colliders
.remove(
removed_collider_handle,
&mut physics.islands,
&mut physics.island_manager,
&mut physics.bodies,
true,
)
Expand Down
2 changes: 1 addition & 1 deletion examples3d/debug_deserialize3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub fn init_world(testbed: &mut Testbed) {
state.impulse_joints,
state.multibody_joints,
);
testbed.harness_mut().physics.islands = state.islands;
testbed.harness_mut().physics.island_manager = state.islands;
testbed.harness_mut().physics.broad_phase = state.broad_phase;
testbed.harness_mut().physics.narrow_phase = state.narrow_phase;
testbed.harness_mut().physics.integration_parameters = state.integration_parameters;
Expand Down
4 changes: 1 addition & 3 deletions examples3d/debug_dynamic_collider_add3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,7 @@ pub fn init_world(testbed: &mut Testbed) {
graphics.remove_collider(*handle, &physics.colliders);
}

physics
.colliders
.remove(*handle, &mut physics.islands, &mut physics.bodies, true);
physics.remove_collider(*handle, true);
}

extra_colliders.clear();
Expand Down
28 changes: 9 additions & 19 deletions examples3d/fountain3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,14 @@ pub fn init_world(testbed: &mut Testbed) {

// Callback that will be executed on the main loop to handle proximities.
testbed.add_callback(move |mut graphics, physics, _, run_state| {
let rigid_body = RigidBodyBuilder::dynamic().translation(vector![0.0, 10.0, 0.0]);
let handle = physics.bodies.insert(rigid_body);
let collider = match run_state.timestep_id % 3 {
0 => ColliderBuilder::round_cylinder(rad, rad, rad / 10.0),
1 => ColliderBuilder::cone(rad, rad),
_ => ColliderBuilder::cuboid(rad, rad, rad),
};

physics
.colliders
.insert_with_parent(collider, handle, &mut physics.bodies);
physics.insert_body_and_collider(
RigidBodyBuilder::dynamic().translation(vector![0.0, 10.0, 0.0]),
match run_state.timestep_id % 3 {
0 => ColliderBuilder::round_cylinder(rad, rad, rad / 10.0),
1 => ColliderBuilder::cone(rad, rad),
_ => ColliderBuilder::cuboid(rad, rad, rad),
},
);

if let Some(graphics) = &mut graphics {
graphics.add_body(handle, &physics.bodies, &physics.colliders);
Expand All @@ -57,14 +54,7 @@ pub fn init_world(testbed: &mut Testbed) {

let num_to_remove = to_remove.len() - MAX_NUMBER_OF_BODIES;
for (handle, _) in &to_remove[..num_to_remove] {
physics.bodies.remove(
*handle,
&mut physics.islands,
&mut physics.colliders,
&mut physics.impulse_joints,
&mut physics.multibody_joints,
true,
);
physics.remove_rigidbody(*handle, true);

if let Some(graphics) = &mut graphics {
graphics.remove_body(*handle);
Expand Down
2 changes: 1 addition & 1 deletion examples3d/one_way_platforms3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ pub fn init_world(testbed: &mut Testbed) {
}
}

for handle in physics.islands.active_dynamic_bodies() {
for handle in physics.island_manager.active_dynamic_bodies() {
let body = physics.bodies.get_mut(*handle).unwrap();
if body.position().translation.y > 1.0 {
body.set_gravity_scale(1.0, false);
Expand Down
2 changes: 1 addition & 1 deletion src/counters/ccd_counters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::counters::Timer;
use std::fmt::{Display, Formatter, Result};

/// Performance counters related to continuous collision detection (CCD).
#[derive(Default, Clone, Copy)]
#[derive(Default, Debug, Clone, Copy)]
pub struct CCDCounters {
/// The number of substeps actually performed by the CCD resolution.
pub num_substeps: usize,
Expand Down
2 changes: 1 addition & 1 deletion src/counters/collision_detection_counters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::counters::Timer;
use std::fmt::{Display, Formatter, Result};

/// Performance counters related to collision detection.
#[derive(Default, Clone, Copy)]
#[derive(Default, Debug, Clone, Copy)]
pub struct CollisionDetectionCounters {
/// Number of contact pairs detected.
pub ncontact_pairs: usize,
Expand Down
2 changes: 1 addition & 1 deletion src/counters/solver_counters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::counters::Timer;
use std::fmt::{Display, Formatter, Result};

/// Performance counters related to constraints resolution.
#[derive(Default, Clone, Copy)]
#[derive(Default, Debug, Clone, Copy)]
pub struct SolverCounters {
/// Number of constraints generated.
pub nconstraints: usize,
Expand Down
2 changes: 1 addition & 1 deletion src/counters/stages_counters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::counters::Timer;
use std::fmt::{Display, Formatter, Result};

/// Performance counters related to each stage of the time step.
#[derive(Default, Clone, Copy)]
#[derive(Default, Debug, Clone, Copy)]
pub struct StagesCounters {
/// Time spent for updating the kinematic and dynamics of every body.
pub update_time: Timer,
Expand Down
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ pub mod geometry;
pub mod pipeline;
pub mod utils;

mod physics_context;

/// Elementary mathematical entities (vectors, matrices, isometries, etc).
pub mod math {
pub use parry::math::*;
Expand Down Expand Up @@ -215,6 +217,7 @@ pub mod prelude {
pub use crate::dynamics::*;
pub use crate::geometry::*;
pub use crate::math::*;
pub use crate::physics_context::PhysicsContext;
pub use crate::pipeline::*;
pub use na::{point, vector, DMatrix, DVector};
pub extern crate nalgebra;
Expand Down
Loading
Loading