feat: migrate to glam whenever relevant + migrate testbed to kiss3d instead of bevy + release v0.32.0 (#909)

* feat: migrate to glam whenever relevant + migrate testbed to kiss3d instead of bevy

* chore: update changelog

* Fix warnings and tests

* Release v0.32.0
This commit is contained in:
Sébastien Crozet
2026-01-09 17:26:36 +01:00
committed by GitHub
parent 48de83817e
commit 0b7c3b34ec
265 changed files with 8501 additions and 8575 deletions

View File

@@ -0,0 +1,63 @@
use rapier_testbed2d::Testbed;
use rapier2d::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();
/*
* Ground
*/
let _ground_size = 25.0;
/*
let ground_shape = ShapeHandle::new(Cuboid::new(Vector2::new(ground_size, 1.0)));
let ground_handle = bodies.insert(Ground::new());
let co = ColliderDesc::new(ground_shape)
.translation(-Vector2::y())
.build(BodyPartHandle(ground_handle, 0));
colliders.insert_with_parent(co);
*/
/*
* Create the balls
*/
let num = 50;
let rad = 1.0;
let shiftx = rad * 2.5;
let shifty = rad * 2.0;
let centerx = shiftx * (num as f32) / 2.0;
let centery = shifty / 2.0;
for i in 0..num {
for j in 0usize..num * 5 {
let x = i as f32 * shiftx - centerx;
let y = j as f32 * shifty + centery;
let status = if j == 0 {
RigidBodyType::Fixed
} else {
RigidBodyType::Dynamic
};
// Build the rigid body.
let rigid_body = RigidBodyBuilder::new(status).translation(Vec2::new(x, y));
let handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::ball(rad);
colliders.insert_with_parent(collider, handle, &mut bodies);
}
}
/*
* Set up the testbed.
*/
testbed.set_world(bodies, colliders, impulse_joints, multibody_joints);
testbed.look_at(Vec2::new(0.0, 2.5), 5.0);
}

View File

@@ -0,0 +1,65 @@
use rapier_testbed2d::Testbed;
use rapier2d::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();
/*
* Ground
*/
let ground_size = 25.0;
let rigid_body = RigidBodyBuilder::fixed();
let handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::cuboid(ground_size, 1.2);
colliders.insert_with_parent(collider, handle, &mut bodies);
let rigid_body = RigidBodyBuilder::fixed()
.rotation(std::f32::consts::FRAC_PI_2)
.translation(Vec2::new(ground_size, ground_size * 2.0));
let handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::cuboid(ground_size * 2.0, 1.2);
colliders.insert_with_parent(collider, handle, &mut bodies);
let rigid_body = RigidBodyBuilder::fixed()
.rotation(std::f32::consts::FRAC_PI_2)
.translation(Vec2::new(-ground_size, ground_size * 2.0));
let handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::cuboid(ground_size * 2.0, 1.2);
colliders.insert_with_parent(collider, handle, &mut bodies);
/*
* Create the cubes
*/
let num = 26;
let rad = 0.5;
let shift = rad * 2.0;
let centerx = shift * (num as f32) / 2.0;
let centery = shift / 2.0;
for i in 0..num {
for j in 0usize..num * 5 {
let x = i as f32 * shift - centerx;
let y = j as f32 * shift + centery + 2.0;
// Build the rigid body.
let rigid_body = RigidBodyBuilder::dynamic().translation(Vec2::new(x, y));
let handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::cuboid(rad, rad);
colliders.insert_with_parent(collider, handle, &mut bodies);
}
}
/*
* Set up the testbed.
*/
testbed.set_world(bodies, colliders, impulse_joints, multibody_joints);
testbed.look_at(Vec2::new(0.0, 50.0), 10.0);
}

View File

@@ -0,0 +1,67 @@
use rapier_testbed2d::Testbed;
use rapier2d::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();
/*
* Ground
*/
let ground_size = 25.0;
let rigid_body = RigidBodyBuilder::fixed();
let handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::cuboid(ground_size, 1.2);
colliders.insert_with_parent(collider, handle, &mut bodies);
let rigid_body = RigidBodyBuilder::fixed()
.rotation(std::f32::consts::FRAC_PI_2)
.translation(Vec2::new(ground_size, ground_size * 4.0));
let handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::cuboid(ground_size * 4.0, 1.2);
colliders.insert_with_parent(collider, handle, &mut bodies);
let rigid_body = RigidBodyBuilder::fixed()
.rotation(std::f32::consts::FRAC_PI_2)
.translation(Vec2::new(-ground_size, ground_size * 4.0));
let handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::cuboid(ground_size * 4.0, 1.2);
colliders.insert_with_parent(collider, handle, &mut bodies);
/*
* Create the cubes
*/
let num = 26;
let numy = num * 5;
let rad = 0.5;
let shift = rad * 2.0;
let shifty = rad * 5.0;
let centerx = shift * (num as f32) / 2.0;
let centery = shift / 2.0;
for i in 0..num {
for j in 0usize..numy {
let x = i as f32 * shift - centerx;
let y = j as f32 * shifty + centery + 3.0;
// Build the rigid body.
let rigid_body = RigidBodyBuilder::dynamic().translation(Vec2::new(x, y));
let handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::capsule_y(rad * 1.5, rad);
colliders.insert_with_parent(collider, handle, &mut bodies);
}
}
/*
* Set up the testbed.
*/
testbed.set_world(bodies, colliders, impulse_joints, multibody_joints);
testbed.look_at(Vec2::new(0.0, 50.0), 10.0);
}

View File

@@ -0,0 +1,78 @@
use rand::distr::{Distribution, StandardUniform};
use rand::{SeedableRng, rngs::StdRng};
use rapier_testbed2d::Testbed;
use rapier2d::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();
/*
* Ground
*/
let ground_size = 30.0;
let rigid_body = RigidBodyBuilder::fixed();
let handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::cuboid(ground_size, 1.2);
colliders.insert_with_parent(collider, handle, &mut bodies);
let rigid_body = RigidBodyBuilder::fixed()
.rotation(std::f32::consts::FRAC_PI_2)
.translation(Vec2::new(ground_size, ground_size * 2.0));
let handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::cuboid(ground_size * 2.0, 1.2);
colliders.insert_with_parent(collider, handle, &mut bodies);
let rigid_body = RigidBodyBuilder::fixed()
.rotation(std::f32::consts::FRAC_PI_2)
.translation(Vec2::new(-ground_size, ground_size * 2.0));
let handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::cuboid(ground_size * 2.0, 1.2);
colliders.insert_with_parent(collider, handle, &mut bodies);
/*
* Create the convex polygons
*/
let num = 26;
let scale = 2.0;
let border_rad = 0.0;
let shift = border_rad * 2.0 + scale;
let centerx = shift * (num as f32) / 2.0;
let centery = shift / 2.0;
let mut rng = StdRng::seed_from_u64(0);
let distribution = StandardUniform;
for i in 0..num {
for j in 0usize..num * 5 {
let x = i as f32 * shift - centerx;
let y = j as f32 * shift * 2.0 + centery + 2.0;
let rigid_body = RigidBodyBuilder::dynamic().translation(Vec2::new(x, y));
let handle = bodies.insert(rigid_body);
let mut points = Vec::new();
for _ in 0..10 {
let pt: [f32; 2] = distribution.sample(&mut rng);
points.push(Vec2::from(pt) * scale);
}
let collider = ColliderBuilder::convex_hull(&points).unwrap();
colliders.insert_with_parent(collider, handle, &mut bodies);
}
}
/*
* Set up the testbed.
*/
testbed.set_world(bodies, colliders, impulse_joints, multibody_joints);
testbed.look_at(Vec2::new(0.0, 50.0), 10.0);
}

View File

@@ -0,0 +1,68 @@
use rapier_testbed2d::Testbed;
use rapier2d::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();
/*
* Ground
*/
let ground_size = Vec2::new(50.0, 1.0);
let nsubdivs = 2000;
let heights = (0..nsubdivs + 1)
.map(|i| {
if i == 0 || i == nsubdivs {
80.0
} else {
(i as f32 * ground_size.x / (nsubdivs as f32)).cos() * 2.0
}
})
.collect();
let rigid_body = RigidBodyBuilder::fixed();
let handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::heightfield(heights, ground_size);
colliders.insert_with_parent(collider, handle, &mut bodies);
/*
* Create the cubes
*/
let num = 26;
let rad = 0.5;
let shift = rad * 2.0;
let centerx = shift * (num / 2) as f32;
let centery = shift / 2.0;
for i in 0..num {
for j in 0usize..num * 5 {
let x = i as f32 * shift - centerx;
let y = j as f32 * shift + centery + 3.0;
// Build the rigid body.
let rigid_body = RigidBodyBuilder::dynamic().translation(Vec2::new(x, y));
let handle = bodies.insert(rigid_body);
if j % 2 == 0 {
let collider = ColliderBuilder::cuboid(rad, rad);
colliders.insert_with_parent(collider, handle, &mut bodies);
} else {
let collider = ColliderBuilder::ball(rad);
colliders.insert_with_parent(collider, handle, &mut bodies);
}
}
}
/*
* Set up the testbed.
*/
testbed.set_world(bodies, colliders, impulse_joints, multibody_joints);
testbed.look_at(Vec2::new(0.0, 50.0), 10.0);
}

View File

@@ -0,0 +1,65 @@
use rapier_testbed2d::Testbed;
use rapier2d::prelude::*;
pub fn init_world(testbed: &mut Testbed) {
/*
* World
*/
let mut bodies = RigidBodySet::new();
let mut colliders = ColliderSet::new();
let mut impulse_joints = ImpulseJointSet::new();
let multibody_joints = MultibodyJointSet::new();
/*
* Create the balls
*/
// Build the rigid body.
let rad = 0.4;
let numi = 100; // Num vertical nodes.
let numk = 100; // Num horizontal nodes.
let shift = 1.0;
let mut body_handles = Vec::new();
for k in 0..numk {
for i in 0..numi {
let fk = k as f32;
let fi = i as f32;
let status = if k >= numk / 2 - 3 && k <= numk / 2 + 3 && i == 0 {
RigidBodyType::Fixed
} else {
RigidBodyType::Dynamic
};
let rigid_body =
RigidBodyBuilder::new(status).translation(Vec2::new(fk * shift, -fi * shift));
let child_handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::ball(rad);
colliders.insert_with_parent(collider, child_handle, &mut bodies);
// Vertical joint.
if i > 0 {
let parent_handle = *body_handles.last().unwrap();
let joint = RevoluteJointBuilder::new().local_anchor2(Vec2::new(0.0, shift));
impulse_joints.insert(parent_handle, child_handle, joint, true);
}
// Horizontal joint.
if k > 0 {
let parent_index = body_handles.len() - numi;
let parent_handle = body_handles[parent_index];
let joint = RevoluteJointBuilder::new().local_anchor2(Vec2::new(-shift, 0.0));
impulse_joints.insert(parent_handle, child_handle, joint, true);
}
body_handles.push(child_handle);
}
}
/*
* Set up the testbed.
*/
testbed.set_world(bodies, colliders, impulse_joints, multibody_joints);
testbed.look_at(Vec2::new(numk as f32 * rad, numi as f32 * -rad), 5.0);
}

View File

@@ -0,0 +1,74 @@
use rapier_testbed2d::Testbed;
use rapier2d::prelude::*;
pub fn init_world(testbed: &mut Testbed) {
/*
* World
*/
let mut bodies = RigidBodySet::new();
let mut colliders = ColliderSet::new();
let mut impulse_joints = ImpulseJointSet::new();
let multibody_joints = MultibodyJointSet::new();
/*
* Create the balls
*/
// Build the rigid body.
let rad = 0.4;
let num = 30; // Num vertical nodes.
let shift = 1.0;
let mut body_handles = Vec::new();
for xx in 0..4 {
let x = xx as f32 * shift * (num as f32 + 2.0);
for yy in 0..4 {
let y = yy as f32 * shift * (num as f32 + 4.0);
for k in 0..num {
for i in 0..num {
let fk = k as f32;
let fi = i as f32;
let status = if k == 0 {
RigidBodyType::Fixed
} else {
RigidBodyType::Dynamic
};
let rigid_body = RigidBodyBuilder::new(status)
.translation(Vec2::new(x + fk * shift, y - fi * shift));
let child_handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::ball(rad);
colliders.insert_with_parent(collider, child_handle, &mut bodies);
// Vertical joint.
if i > 0 {
let parent_handle = *body_handles.last().unwrap();
let joint =
FixedJointBuilder::new().local_frame2(Pose2::translation(0.0, shift));
impulse_joints.insert(parent_handle, child_handle, joint, true);
}
// Horizontal joint.
if k > 0 {
let parent_index = body_handles.len() - num;
let parent_handle = body_handles[parent_index];
let joint =
FixedJointBuilder::new().local_frame2(Pose2::translation(-shift, 0.0));
impulse_joints.insert(parent_handle, child_handle, joint, true);
}
body_handles.push(child_handle);
}
}
}
}
/*
* Set up the testbed.
*/
testbed.set_world(bodies, colliders, impulse_joints, multibody_joints);
testbed.look_at(Vec2::new(50.0, 50.0), 5.0);
}

View File

@@ -0,0 +1,61 @@
use rapier_testbed2d::Testbed;
use rapier2d::prelude::*;
pub fn init_world(testbed: &mut Testbed) {
/*
* World
*/
let mut bodies = RigidBodySet::new();
let mut colliders = ColliderSet::new();
let mut impulse_joints = ImpulseJointSet::new();
let multibody_joints = MultibodyJointSet::new();
/*
* Create the balls
*/
// Build the rigid body.
let rad = 0.4;
let num = 10;
let shift = 1.0;
for l in 0..25 {
let y = l as f32 * shift * (num as f32 + 2.0) * 2.0;
for j in 0..50 {
let x = j as f32 * shift * 4.0;
let ground = RigidBodyBuilder::fixed().translation(Vec2::new(x, y));
let mut curr_parent = bodies.insert(ground);
let collider = ColliderBuilder::cuboid(rad, rad);
colliders.insert_with_parent(collider, curr_parent, &mut bodies);
for i in 0..num {
let y = y - (i + 1) as f32 * shift;
let density = 1.0;
let rigid_body = RigidBodyBuilder::dynamic().translation(Vec2::new(x, y));
let curr_child = bodies.insert(rigid_body);
let collider = ColliderBuilder::cuboid(rad, rad).density(density);
colliders.insert_with_parent(collider, curr_child, &mut bodies);
let axis = if i % 2 == 0 {
Vec2::new(1.0, 1.0).normalize()
} else {
Vec2::new(-1.0, 1.0).normalize()
};
let prism = PrismaticJointBuilder::new(axis)
.local_anchor2(Vec2::new(0.0, shift))
.limits([-1.5, 1.5]);
impulse_joints.insert(curr_parent, curr_child, prism, true);
curr_parent = curr_child;
}
}
}
/*
* Set up the testbed.
*/
testbed.set_world(bodies, colliders, impulse_joints, multibody_joints);
testbed.look_at(Vec2::new(80.0, 80.0), 15.0);
}

View File

@@ -0,0 +1,37 @@
use rapier_testbed2d::Example;
mod balls2;
mod boxes2;
mod capsules2;
mod convex_polygons2;
mod heightfield2;
mod joint_ball2;
mod joint_fixed2;
mod joint_prismatic2;
mod pyramid2;
mod vertical_stacks2;
pub fn builders() -> Vec<Example> {
const STRESS: &str = "Stress Tests";
vec![
Example::new(STRESS, "Balls", balls2::init_world),
Example::new(STRESS, "Boxes", boxes2::init_world),
Example::new(STRESS, "Capsules", capsules2::init_world),
Example::new(STRESS, "Convex polygons", convex_polygons2::init_world),
Example::new(STRESS, "Heightfield", heightfield2::init_world),
Example::new(STRESS, "Pyramid", pyramid2::init_world),
Example::new(STRESS, "Verticals stacks", vertical_stacks2::init_world),
Example::new(STRESS, "(Stress test) joint ball", joint_ball2::init_world),
Example::new(
STRESS,
"(Stress test) joint fixed",
joint_fixed2::init_world,
),
Example::new(
STRESS,
"(Stress test) joint prismatic",
joint_prismatic2::init_world,
),
]
}

View File

@@ -0,0 +1,54 @@
use rapier_testbed2d::Testbed;
use rapier2d::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();
/*
* Ground
*/
let ground_size = 100.0;
let ground_thickness = 1.0;
let rigid_body = RigidBodyBuilder::fixed();
let ground_handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::cuboid(ground_size, ground_thickness);
colliders.insert_with_parent(collider, ground_handle, &mut bodies);
/*
* Create the cubes
*/
let num = 100;
let rad = 0.5;
let shift = rad * 2.0;
let centerx = shift * (num as f32) / 2.0;
let centery = shift / 2.0 + ground_thickness + rad * 1.5;
for i in 0usize..num {
for j in i..num {
let fj = j as f32;
let fi = i as f32;
let x = (fi * shift / 2.0) + (fj - fi) * shift - centerx;
let y = fi * shift + centery;
// Build the rigid body.
let rigid_body = RigidBodyBuilder::dynamic().translation(Vec2::new(x, y));
let handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::cuboid(rad, rad);
colliders.insert_with_parent(collider, handle, &mut bodies);
}
}
/*
* Set up the testbed.
*/
testbed.set_world(bodies, colliders, impulse_joints, multibody_joints);
testbed.look_at(Vec2::new(0.0, 2.5), 5.0);
}

View File

@@ -0,0 +1,61 @@
use rapier_testbed2d::Testbed;
use rapier2d::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();
let num = 80;
let rad = 0.5;
/*
* Ground
*/
let ground_size = num as f32 * rad * 10.0;
let ground_thickness = 1.0;
let rigid_body = RigidBodyBuilder::fixed();
let ground_handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::cuboid(ground_size, ground_thickness);
colliders.insert_with_parent(collider, ground_handle, &mut bodies);
/*
* Create the cubes
*/
let shiftx_centerx = [
(rad * 2.0 + 0.0002, -(num as f32) * rad * 2.0 * 1.5),
(rad * 2.0 + rad, num as f32 * rad * 2.0 * 1.5),
];
for (shiftx, centerx) in shiftx_centerx {
let shifty = rad * 2.0;
let centery = shifty / 2.0 + ground_thickness;
for i in 0..num {
for j in 0usize..1 + i * 2 {
let fj = j as f32;
let fi = i as f32;
let x = (fj - fi) * shiftx + centerx;
let y = (num as f32 - fi - 1.0) * shifty + centery;
// Build the rigid body.
let rigid_body = RigidBodyBuilder::dynamic().translation(Vec2::new(x, y));
let handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::cuboid(rad, rad);
colliders.insert_with_parent(collider, handle, &mut bodies);
}
}
}
/*
* Set up the testbed.
*/
testbed.set_world(bodies, colliders, impulse_joints, multibody_joints);
testbed.look_at(Vec2::new(0.0, 2.5), 5.0);
}