feat: reduce the amount of duplicate work the broad-phase is doing for user changes and CCD + release v0.28.0 (#872)

* feat: reduce the amount of duplicate work the broad-phase is doing for user changes and CCD

* Release v0.28.0

* chore: fix warnings

* chore: clippy fixes

* chore: more clippy fixes
This commit is contained in:
Sébastien Crozet
2025-08-08 18:15:34 +02:00
committed by GitHub
parent 038eb34aba
commit 317322b31b
43 changed files with 351 additions and 328 deletions

View File

@@ -13,7 +13,7 @@ other-backends = ["rapier_testbed3d/other-backends"]
enhanced-determinism = ["rapier3d/enhanced-determinism"]
[dependencies]
rand = "0.8"
rand = "0.9"
getrandom = { version = "0.2", features = ["js"] }
wasm-bindgen = "0.2"
obj-rs = { version = "0.7", default-features = false }

View File

@@ -17,6 +17,7 @@ mod convex_polyhedron3;
mod damping3;
mod debug_add_remove_collider3;
mod debug_articulations3;
mod debug_balls3;
mod debug_big_colliders3;
mod debug_boxes3;
mod debug_cylinder3;
@@ -101,6 +102,7 @@ pub fn main() {
),
("(Debug) big colliders", debug_big_colliders3::init_world),
("(Debug) boxes", debug_boxes3::init_world),
("(Debug) balls", debug_balls3::init_world),
("(Debug) pop", debug_pop3::init_world),
(
"(Debug) dyn. coll. add",

View File

@@ -1,4 +1,4 @@
use rand::distributions::{Distribution, Standard};
use rand::distr::{Distribution, StandardUniform};
use rand::{SeedableRng, rngs::StdRng};
use rapier_testbed3d::Testbed;
use rapier3d::prelude::*;
@@ -36,7 +36,7 @@ pub fn init_world(testbed: &mut Testbed) {
let centerz = shift * (num / 2) as f32;
let mut rng = StdRng::seed_from_u64(0);
let distribution = Standard;
let distribution = StandardUniform;
for j in 0usize..25 {
for i in 0..num {

View File

@@ -0,0 +1,59 @@
use rapier_testbed3d::Testbed;
use rapier3d::prelude::*;
pub fn init_world(testbed: &mut Testbed) {
/*
* World
*/
let mut bodies = RigidBodySet::new();
let mut colliders = ColliderSet::new();
let impulse_joints = ImpulseJointSet::new();
let multibody_joints = MultibodyJointSet::new();
/*
* Create the balls
*/
let num_j = 10;
let num_ik = 10;
let rad = 0.5;
let shift = rad * 2.0;
let centerx = shift * (num_ik as f32) / 2.0;
let centery = shift / 2.0;
let centerz = shift * (num_ik as f32) / 2.0;
for i in 0..num_ik {
for j in 0usize..num_j {
for k in 0..num_ik {
let x = i as f32 * shift - centerx;
let z = k as f32 * shift - centerz;
let status = if j == 0 || i == 0 || k == 0 || i == num_ik - 1 || k == num_ik - 1 {
RigidBodyType::Fixed
} else {
RigidBodyType::Dynamic
};
let y = if status.is_fixed() {
j as f32 * shift + centery
} else {
j as f32 * shift * 2.0 + centery
};
// Build the rigid body.
let rigid_body = RigidBodyBuilder::new(status)
.translation(vector![x, y, z])
.can_sleep(false);
let handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::ball(rad).friction(0.0);
colliders.insert_with_parent(collider, handle, &mut bodies);
}
}
}
/*
* Set up the testbed.
*/
testbed.set_world(bodies, colliders, impulse_joints, multibody_joints);
testbed.look_at(point![100.0, 100.0, 100.0], Point::origin());
}

View File

@@ -54,7 +54,7 @@ pub fn init_world(testbed: &mut Testbed) {
);
testbed.harness_mut().physics.islands = state.islands;
testbed.harness_mut().physics.broad_phase = Box::new(state.broad_phase);
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;
testbed.harness_mut().physics.gravity = state.gravity;

View File

@@ -147,10 +147,7 @@ fn update_kinematic_controller(
let character_shape = character_collider.shared_shape().clone();
let character_mass = character_body.mass();
let Some(broad_phase) = phx.broad_phase.downcast_ref::<BroadPhaseBvh>() else {
return;
};
let mut query_pipeline = broad_phase.as_query_pipeline_mut(
let mut query_pipeline = phx.broad_phase.as_query_pipeline_mut(
phx.narrow_phase.query_dispatcher(),
&mut phx.bodies,
&mut phx.colliders,

View File

@@ -211,10 +211,7 @@ pub fn init_world(testbed: &mut Testbed) {
predicate: Some(&|_, co: &Collider| co.shape().as_voxels().is_some()),
..Default::default()
};
let Some(broad_phase) = physics.broad_phase.downcast_ref::<BroadPhaseBvh>() else {
return;
};
let query_pipeline = broad_phase.as_query_pipeline(
let query_pipeline = physics.broad_phase.as_query_pipeline(
physics.narrow_phase.query_dispatcher(),
&physics.bodies,
&physics.colliders,