Skip to content

Commit 5bc926d

Browse files
Rapier 0.25 (#651)
1 parent 976da67 commit 5bc926d

File tree

17 files changed

+384
-43
lines changed

17 files changed

+384
-43
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010
## Modified
1111

1212
- Update Bevy to `0.16`.
13-
- Update from rapier `0.23` to rapier `0.24`,
13+
- Update from rapier `0.23` to rapier `0.25`,
1414
see [rapier's changelog](https://github.com/dimforge/rapier/blob/master/CHANGELOG.md).
15+
- Notably, support and examples for parry's new `Voxels` shape have been added.
1516
- `RapierContextInitialization::InitializeDefaultRapierContext` now has more fields for better control over default physics context.
1617
- `ContactPairView::collider1` and `ContactPairView::collider2` now return an `Option`.
1718

bevy_rapier2d/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ to-bevy-mesh = ["bevy/bevy_render", "bevy/bevy_asset"]
6666
[dependencies]
6767
bevy = { version = "0.16.0", default-features = false, features = ["std"] }
6868
nalgebra = { version = "0.33", features = ["convert-glam029"] }
69-
rapier2d = "0.24"
69+
rapier2d = "0.25"
7070
bitflags = "2.4"
7171
log = "0.4"
7272
serde = { version = "1", features = ["derive"], optional = true }
@@ -77,6 +77,7 @@ bevy = { version = "0.16.0", default-features = false, features = [
7777
"bevy_state",
7878
"bevy_window",
7979
"bevy_debug_stepping",
80+
"bevy_log",
8081
] }
8182
oorandom = "11"
8283
approx = "0.5.1"

bevy_rapier2d/examples/testbed2.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,12 @@ mod locked_rotations2;
1111
mod multiple_colliders2;
1212
mod player_movement2;
1313
mod rope_joint2;
14+
mod voxels2;
1415

15-
use bevy::prelude::*;
16+
use bevy::{
17+
ecs::world::error::{EntityDespawnError, EntityMutableFetchError},
18+
prelude::*,
19+
};
1620
use bevy_egui::{egui, EguiContexts, EguiPlugin};
1721
use bevy_inspector_egui::quick::WorldInspectorPlugin;
1822
use bevy_rapier2d::prelude::*;
@@ -22,6 +26,7 @@ pub enum Examples {
2226
#[default]
2327
None,
2428
Boxes2,
29+
Voxels2,
2530
DebugToggle2,
2631
RopeJoint2,
2732
DebugDespawn2,
@@ -75,6 +80,7 @@ fn main() {
7580
.init_state::<Examples>()
7681
.insert_resource(ExampleSet(vec![
7782
(Examples::Boxes2, "Boxes3").into(),
83+
(Examples::Voxels2, "Voxels2").into(),
7884
(Examples::RopeJoint2, "RopeJoint2").into(),
7985
(Examples::DebugDespawn2, "DebugDespawn2").into(),
8086
(Examples::Despawn2, "Despawn3").into(),
@@ -94,6 +100,13 @@ fn main() {
94100
)
95101
.add_systems(OnExit(Examples::Boxes2), cleanup)
96102
//
103+
//voxels2
104+
.add_systems(
105+
OnEnter(Examples::Voxels2),
106+
(voxels2::setup_graphics, voxels2::setup_physics),
107+
)
108+
.add_systems(OnExit(Examples::Voxels2), cleanup)
109+
//
97110
// Debug toggle
98111
.add_systems(
99112
OnEnter(Examples::DebugToggle2),
@@ -256,7 +269,11 @@ fn cleanup(world: &mut World) {
256269
.collect::<Vec<_>>();
257270

258271
for r in remove {
259-
world.despawn(r);
272+
if let Err(error @ EntityDespawnError(EntityMutableFetchError::AliasedMutability(_))) =
273+
world.try_despawn(r)
274+
{
275+
warn!("Cleanup error: {error:?}");
276+
}
260277
}
261278
}
262279

bevy_rapier2d/examples/voxels2.rs

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
use bevy::prelude::*;
2+
use bevy_rapier2d::prelude::*;
3+
use nalgebra::{point, Vector2};
4+
use rapier2d::prelude::{SharedShape, VoxelPrimitiveGeometry};
5+
6+
fn main() {
7+
App::new()
8+
.insert_resource(ClearColor(Color::srgb(
9+
0xF9 as f32 / 255.0,
10+
0xF9 as f32 / 255.0,
11+
0xFF as f32 / 255.0,
12+
)))
13+
.add_plugins((
14+
DefaultPlugins,
15+
RapierPhysicsPlugin::<NoUserData>::pixels_per_meter(10.0),
16+
RapierDebugRenderPlugin::default(),
17+
))
18+
.add_systems(Startup, (setup_graphics, setup_physics))
19+
.run();
20+
}
21+
22+
pub fn setup_graphics(mut commands: Commands) {
23+
commands.spawn((Camera2d, Transform::from_xyz(0.0, 20.0, 0.0)));
24+
}
25+
26+
pub fn setup_physics(mut commands: Commands) {
27+
let scale = 15f32;
28+
/*
29+
* Create dynamic objects to fall on voxels.
30+
*/
31+
let nx = 50;
32+
for i in 0..nx {
33+
for j in 0..10 {
34+
let falling_objects = (j + i) % 3;
35+
36+
let ball_radius = 0.5 * scale;
37+
let co = match falling_objects {
38+
0 => Collider::ball(ball_radius),
39+
1 => Collider::cuboid(ball_radius, ball_radius),
40+
2 => Collider::capsule_y(ball_radius, ball_radius),
41+
_ => unreachable!(),
42+
};
43+
commands.spawn((
44+
Transform::from_xyz(
45+
(i as f32 * 2.0 - nx as f32 / 2.0) * scale,
46+
(20.0 + j as f32 * 2.0) * scale,
47+
0.0,
48+
),
49+
RigidBody::Dynamic,
50+
co,
51+
));
52+
}
53+
}
54+
55+
/*
56+
* Voxelization.
57+
*/
58+
let polyline = [
59+
point![0.0, 0.0],
60+
point![0.0, 10.0],
61+
point![7.0, 4.0],
62+
point![14.0, 10.0],
63+
point![14.0, 0.0],
64+
point![13.0, 7.0],
65+
point![7.0, 2.0],
66+
point![1.0, 7.0],
67+
]
68+
.iter()
69+
.map(|p| p * scale)
70+
.collect::<Vec<_>>();
71+
let indices: Vec<_> = (0..polyline.len() as u32)
72+
.map(|i| [i, (i + 1) % polyline.len() as u32])
73+
.collect();
74+
75+
let shape = SharedShape::voxelized_mesh(
76+
VoxelPrimitiveGeometry::PseudoCube,
77+
&polyline,
78+
&indices,
79+
0.2 * scale,
80+
FillMode::default(),
81+
);
82+
commands.spawn((
83+
Transform::from_xyz(-20.0 * scale, -10.0 * scale, 0.0),
84+
Collider::from(shape),
85+
));
86+
87+
/*
88+
* A voxel wavy floor.
89+
*/
90+
let voxel_size = Vector2::new(scale, scale);
91+
let voxels: Vec<_> = (0..300)
92+
.map(|i| {
93+
let y = (i as f32 / 20.0).sin().clamp(-0.5, 0.5) * 20.0;
94+
point![(i as f32 - 125.0) * voxel_size.x / 2.0, y * voxel_size.y]
95+
})
96+
.collect();
97+
commands.spawn((
98+
Transform::from_xyz(0.0, 0.0, 0.0),
99+
Collider::from(rapier2d::prelude::SharedShape::voxels_from_points(
100+
VoxelPrimitiveGeometry::PseudoCube,
101+
voxel_size,
102+
&voxels,
103+
)),
104+
));
105+
}

bevy_rapier3d/Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ to-bevy-mesh = ["bevy/bevy_render", "bevy/bevy_asset"]
6767
[dependencies]
6868
bevy = { version = "0.16.0", default-features = false, features = ["std"] }
6969
nalgebra = { version = "0.33", features = ["convert-glam029"] }
70-
rapier3d = "0.24"
70+
rapier3d = "0.25"
7171
bitflags = "2.4"
7272
log = "0.4"
7373
serde = { version = "1", features = ["derive"], optional = true }
@@ -82,11 +82,14 @@ bevy = { version = "0.16.0", default-features = false, features = [
8282
"bevy_text",
8383
"bevy_ui",
8484
"default_font",
85+
"bevy_log",
8586
] }
8687
approx = "0.5.1"
8788
glam = { version = "0.29", features = ["approx"] }
8889
bevy-inspector-egui = "0.31"
8990
bevy_egui = "0.34"
91+
# FIXME: target a proper release when support for bevy 0.16 is released.
92+
bevy_mod_debugdump = { git = "https://github.com/jakobhellermann/bevy_mod_debugdump.git", rev = "ad310179be78abb3c16c581324d7d83b26275028" }
9093

9194
[package.metadata.docs.rs]
9295
# Enable all the features when building the docs on docs.rs
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//! Example using bevy_mod_debugdump to output a graph of systems execution order.
2+
//! run with:
3+
//! `cargo run --example debugdump3 > dump.dot && dot -Tsvg dump.dot > dump.svg`
4+
5+
use bevy::prelude::*;
6+
use bevy_mod_debugdump::{schedule_graph, schedule_graph_dot};
7+
use bevy_rapier3d::prelude::*;
8+
9+
fn main() {
10+
let mut app = App::new();
11+
app.add_plugins((
12+
DefaultPlugins,
13+
RapierPhysicsPlugin::<NoUserData>::default(),
14+
RapierDebugRenderPlugin::default(),
15+
));
16+
17+
let debugdump_settings = schedule_graph::Settings {
18+
include_system: Some(Box::new(|system| {
19+
if system.name().starts_with("bevy_pbr")
20+
|| system.name().starts_with("bevy_render")
21+
|| system.name().starts_with("bevy_gizmos")
22+
|| system.name().starts_with("bevy_winit")
23+
|| system.name().starts_with("bevy_sprite")
24+
{
25+
return false;
26+
}
27+
true
28+
})),
29+
..Default::default()
30+
};
31+
let dot = schedule_graph_dot(&mut app, PostUpdate, &debugdump_settings);
32+
println!("{dot}");
33+
}

bevy_rapier3d/examples/testbed3.rs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,12 @@ mod multiple_colliders3;
1111
mod picking3;
1212
mod ray_casting3;
1313
mod static_trimesh3;
14+
mod voxels3;
1415

15-
use bevy::prelude::*;
16+
use bevy::{
17+
ecs::world::error::{EntityDespawnError, EntityMutableFetchError},
18+
prelude::*,
19+
};
1620
use bevy_egui::{egui, EguiContexts, EguiPlugin};
1721
use bevy_inspector_egui::quick::WorldInspectorPlugin;
1822
use bevy_rapier3d::prelude::*;
@@ -22,6 +26,7 @@ pub enum Examples {
2226
#[default]
2327
None,
2428
Boxes3,
29+
Voxels3,
2530
DebugToggle3,
2631
Despawn3,
2732
Events3,
@@ -76,6 +81,7 @@ fn main() {
7681
.init_state::<Examples>()
7782
.insert_resource(ExampleSet(vec![
7883
(Examples::Boxes3, "Boxes3").into(),
84+
(Examples::Voxels3, "Voxels3").into(),
7985
(Examples::DebugToggle3, "DebugToggle3").into(),
8086
(Examples::Despawn3, "Despawn3").into(),
8187
(Examples::Events3, "Events3").into(),
@@ -89,13 +95,20 @@ fn main() {
8995
]))
9096
.init_resource::<ExampleSelected>()
9197
//
92-
//boxes2
98+
// boxes3
9399
.add_systems(
94100
OnEnter(Examples::Boxes3),
95101
(boxes3::setup_graphics, boxes3::setup_physics),
96102
)
97103
.add_systems(OnExit(Examples::Boxes3), cleanup)
98104
//
105+
// voxels3
106+
.add_systems(
107+
OnEnter(Examples::Voxels3),
108+
(voxels3::setup_graphics, voxels3::setup_physics),
109+
)
110+
.add_systems(OnExit(Examples::Voxels3), cleanup)
111+
//
99112
// Debug toggle
100113
.add_systems(
101114
OnEnter(Examples::DebugToggle3),
@@ -246,9 +259,12 @@ fn cleanup(world: &mut World) {
246259
.iter_entities()
247260
.filter_map(|e| (!keep_alive.contains(&e.id())).then_some(e.id()))
248261
.collect::<Vec<_>>();
249-
250262
for r in remove {
251-
world.despawn(r);
263+
if let Err(error @ EntityDespawnError(EntityMutableFetchError::AliasedMutability(_))) =
264+
world.try_despawn(r)
265+
{
266+
warn!("Cleanup error: {error:?}");
267+
}
252268
}
253269
}
254270

0 commit comments

Comments
 (0)