Skip to content

Commit

Permalink
Merge pull request #625 from Vrixyz/rapier_0.23
Browse files Browse the repository at this point in the history
Update rapier to 0.23
  • Loading branch information
Vrixyz authored Feb 3, 2025
2 parents 3d0e4c4 + 9c6e15f commit dc1d56e
Show file tree
Hide file tree
Showing 14 changed files with 87 additions and 76 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
with:
prefix-key: ${{ env.RUST_CACHE_KEY }}
- name: Cargo doc
run: cargo doc
run: cargo doc --no-deps
test:
runs-on: ubuntu-latest
env:
Expand Down Expand Up @@ -72,6 +72,6 @@ jobs:
with:
prefix-key: ${{ env.RUST_CACHE_KEY }}
- name: Clippy bevy_rapier2d
run: cd bevy_rapier2d && cargo clippy --verbose --features wasm-bindgen,bevy/webgl2 --target wasm32-unknown-unknown
run: cd bevy_rapier2d && cargo clippy --verbose --features bevy/webgl2 --target wasm32-unknown-unknown
- name: Clippy bevy_rapier3d
run: cd bevy_rapier3d && cargo clippy --verbose --features wasm-bindgen,bevy/webgl2 --target wasm32-unknown-unknown
run: cd bevy_rapier3d && cargo clippy --verbose --features bevy/webgl2 --target wasm32-unknown-unknown
18 changes: 12 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,19 @@

### Modified

- Update from rapier `0.22` to rapier `0.23`,
see [rapier's changelog](https://github.com/dimforge/rapier/blob/master/CHANGELOG.md).
- `Collider::trimesh` and `Collider::trimesh_with_flags` now return a `Result`.
- Under the feature `async-collider`, The `RapierPhysicsPlugin` now adds
`AssetPlugin`, `MeshPlugin` and `ScenePlugin` if these were not added, to circumvent a runtime crash
over missing required resources.
- `RapierContext` has been split in multiple `Component`s:
- `RapierContextColliders`
- `RapierContextJoints`
- `RapierContextSimulation`
- `RapierRigidBodySet`
- Renamed `DefaultReadRapierContext` and `DefaultWriteRapierContext`.
- Use `ReadRapierContext` and its associated `single()` method.
- `RapierContextColliders`
- `RapierContextJoints`
- `RapierContextSimulation`
- `RapierRigidBodySet`
- Renamed `DefaultReadRapierContext` to `ReadRapierContext` and `DefaultWriteRapierContext` to `WriteRapierContext`.
They have a new `bevy::QueryFilter` type parameter, defaulting to `With<DefaultRapierContext>`.

## v0.28.0 (09 December 2024)

Expand Down
10 changes: 7 additions & 3 deletions bevy_rapier2d/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,20 @@ rapier-debug-render = ["rapier2d/debug-render"]
parallel = ["rapier2d/parallel"]
simd-stable = ["rapier2d/simd-stable"]
simd-nightly = ["rapier2d/simd-nightly"]
wasm-bindgen = ["rapier2d/wasm-bindgen"]
serde-serialize = ["rapier2d/serde-serialize", "bevy/serialize", "serde"]
enhanced-determinism = ["rapier2d/enhanced-determinism"]
headless = []
async-collider = ["bevy/bevy_asset", "bevy/bevy_scene", "bevy/bevy_render"]
async-collider = [
"bevy/bevy_asset",
"bevy/bevy_scene",
"bevy/bevy_render",
"bevy/bevy_image",
]

[dependencies]
bevy = { version = "0.15", default-features = false }
nalgebra = { version = "0.33", features = ["convert-glam029"] }
rapier2d = "0.22"
rapier2d = "0.23"
bitflags = "2.4"
log = "0.4"
serde = { version = "1", features = ["derive"], optional = true }
Expand Down
10 changes: 7 additions & 3 deletions bevy_rapier3d/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,20 @@ rapier-debug-render = ["rapier3d/debug-render"]
parallel = ["rapier3d/parallel"]
simd-stable = ["rapier3d/simd-stable"]
simd-nightly = ["rapier3d/simd-nightly"]
wasm-bindgen = ["rapier3d/wasm-bindgen"]
serde-serialize = ["rapier3d/serde-serialize", "bevy/serialize", "serde"]
enhanced-determinism = ["rapier3d/enhanced-determinism"]
headless = []
async-collider = ["bevy/bevy_asset", "bevy/bevy_scene", "bevy/bevy_render"]
async-collider = [
"bevy/bevy_asset",
"bevy/bevy_scene",
"bevy/bevy_render",
"bevy/bevy_image",
]

[dependencies]
bevy = { version = "0.15", default-features = false }
nalgebra = { version = "0.33", features = ["convert-glam029"] }
rapier3d = "0.22"
rapier3d = "0.23"
bitflags = "2.4"
log = "0.4"
serde = { version = "1", features = ["derive"], optional = true }
Expand Down
4 changes: 2 additions & 2 deletions bevy_rapier3d/examples/static_trimesh3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub fn setup_physics(mut commands: Commands, mut ball_state: ResMut<BallState>)
indices.push([2 * i + 2, 2 * i + 1, 2 * i + 3]);
}

commands.spawn(Collider::trimesh(vertices, indices));
commands.spawn(Collider::trimesh(vertices, indices).unwrap());

// Create a bowl with a cosine cross-section,
// so that we can join the end of the ramp smoothly
Expand Down Expand Up @@ -97,7 +97,7 @@ pub fn setup_physics(mut commands: Commands, mut ball_state: ResMut<BallState>)
-bowl_size.y / 2.0,
bowl_size.z / 2.0 - ramp_size.z / 2.0,
),
Collider::trimesh(vertices, indices),
Collider::trimesh(vertices, indices).unwrap(),
));
}

Expand Down
2 changes: 1 addition & 1 deletion bevy_rapier_benches3d/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
rapier3d = { features = ["profiler"], version = "0.22" }
rapier3d = { features = ["profiler"], version = "0.23" }
bevy_rapier3d = { version = "0.28", path = "../bevy_rapier3d" }
bevy = { version = "0.15", default-features = false }

Expand Down
12 changes: 8 additions & 4 deletions bevy_rapier_benches3d/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,25 @@ pub fn custom_bencher(steps: usize, setup: impl Fn(&mut App)) {
timer_full_update.start();
app.update();
timer_full_update.pause();
let elapsed_time = timer_full_update.time() as f32;
let elapsed_time = timer_full_update.time().as_millis();
let rc = app
.world_mut()
.query::<&RapierContextSimulation>()
.single(app.world());
rapier_step_times.push(rc.pipeline.counters.step_time.time() as f32);
rapier_step_times.push(rc.pipeline.counters.step_time.time().as_millis() as f32);
total_update_times.push(elapsed_time);
}
timer_total.pause();
let average_total = total_update_times.iter().sum::<f32>() / total_update_times.len() as f32;
let average_total = total_update_times
.iter()
.map(|time| *time as f32)
.sum::<f32>()
/ total_update_times.len() as f32;
println!("average total time: {} ms", average_total);
let average_rapier_step =
rapier_step_times.iter().sum::<f32>() / rapier_step_times.len() as f32;
println!("average rapier step time: {} ms", average_rapier_step);
let average_rapier_overhead = average_total - average_rapier_step;
println!("average bevy overhead: {} ms", average_rapier_overhead);
println!("total time: {} ms", timer_total.time());
println!("total time: {} ms", timer_total.time().as_millis());
}
19 changes: 12 additions & 7 deletions src/geometry/collider_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,12 @@ impl Collider {
}

/// Initializes a collider with a triangle mesh shape defined by its vertex and index buffers.
pub fn trimesh(vertices: Vec<Vect>, indices: Vec<[u32; 3]>) -> Self {
pub fn trimesh(
vertices: Vec<Vect>,
indices: Vec<[u32; 3]>,
) -> Result<Self, crate::rapier::prelude::TriMeshBuilderError> {
let vertices = vertices.into_iter().map(|v| v.into()).collect();
SharedShape::trimesh(vertices, indices).into()
Ok(SharedShape::trimesh(vertices, indices)?.into())
}

/// Initializes a collider with a triangle mesh shape defined by its vertex and index buffers, and flags
Expand All @@ -162,9 +165,9 @@ impl Collider {
vertices: Vec<Vect>,
indices: Vec<[u32; 3]>,
flags: TriMeshFlags,
) -> Self {
) -> Result<Self, crate::rapier::prelude::TriMeshBuilderError> {
let vertices = vertices.into_iter().map(|v| v.into()).collect();
SharedShape::trimesh_with_flags(vertices, indices, flags).into()
Ok(SharedShape::trimesh_with_flags(vertices, indices, flags)?.into())
}

/// Initializes a collider with a Bevy Mesh.
Expand All @@ -175,9 +178,11 @@ impl Collider {
let (vtx, idx) = extract_mesh_vertices_indices(mesh)?;

match collider_shape {
ComputedColliderShape::TriMesh(flags) => {
Some(SharedShape::trimesh_with_flags(vtx, idx, *flags).into())
}
ComputedColliderShape::TriMesh(flags) => Some(
SharedShape::trimesh_with_flags(vtx, idx, *flags)
.ok()?
.into(),
),
ComputedColliderShape::ConvexHull => {
SharedShape::convex_hull(&vtx).map(|shape| shape.into())
}
Expand Down
6 changes: 3 additions & 3 deletions src/pipeline/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ mod test {
transform::{components::Transform, TransformPlugin},
MinimalPlugins,
};
use systems::tests::HeadlessRenderPlugin;

use crate::{plugin::*, prelude::*};

Expand Down Expand Up @@ -180,6 +179,7 @@ mod test {
app.insert_resource(TimeUpdateStrategy::ManualDuration(
std::time::Duration::from_secs_f32(1f32 / 60f32),
));
app.finish();
// 2 seconds should be plenty of time for the cube to fall on the
// lowest collider.
for _ in 0..120 {
Expand All @@ -201,7 +201,6 @@ mod test {
fn main() {
let mut app = App::new();
app.add_plugins((
HeadlessRenderPlugin,
TransformPlugin,
TimePlugin,
RapierPhysicsPlugin::<NoUserData>::default(),
Expand Down Expand Up @@ -236,7 +235,6 @@ mod test {
pub fn spam_remove_rapier_entity_interpolated() {
let mut app = App::new();
app.add_plugins((
HeadlessRenderPlugin,
MinimalPlugins,
TransformPlugin,
RapierPhysicsPlugin::<NoUserData>::default(),
Expand All @@ -253,6 +251,8 @@ mod test {
std::time::Duration::from_secs_f32(1f32 / 60f32),
));

app.finish();

for _ in 0..100 {
app.update();
}
Expand Down
22 changes: 19 additions & 3 deletions src/plugin/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,22 @@ where
}
}
}

fn finish(&self, _app: &mut App) {
#[cfg(feature = "async-collider")]
{
use bevy::{asset::AssetPlugin, render::mesh::MeshPlugin, scene::ScenePlugin};
if !_app.is_plugin_added::<AssetPlugin>() {
_app.add_plugins(AssetPlugin::default());
}
if !_app.is_plugin_added::<MeshPlugin>() {
_app.add_plugins(MeshPlugin);
}
if !_app.is_plugin_added::<ScenePlugin>() {
_app.add_plugins(ScenePlugin);
}
}
}
}

/// Specifies a default configuration for the default [`RapierContext`]
Expand Down Expand Up @@ -374,7 +390,6 @@ mod test {
time::{TimePlugin, TimeUpdateStrategy},
};
use rapier::{data::Index, dynamics::RigidBodyHandle};
use systems::tests::HeadlessRenderPlugin;

use crate::{plugin::context::*, plugin::*, prelude::*};

Expand Down Expand Up @@ -403,6 +418,8 @@ mod test {

app.add_systems(Update, setup_physics);

app.finish();

let mut stepping = Stepping::new();

app.update();
Expand Down Expand Up @@ -478,7 +495,6 @@ mod test {
fn main() {
let mut app = App::new();
app.add_plugins((
HeadlessRenderPlugin,
TransformPlugin,
TimePlugin,
RapierPhysicsPlugin::<NoUserData>::default(),
Expand Down Expand Up @@ -526,6 +542,7 @@ mod test {
app.add_systems(Update, remove_rapier_entity);
app.add_systems(FixedUpdate, || println!("Fixed Update"));
app.add_systems(Update, || println!("Update"));
app.finish();
// startup
app.update();
// normal updates starting
Expand Down Expand Up @@ -559,7 +576,6 @@ mod test {
fn main() {
let mut app = App::new();
app.add_plugins((
HeadlessRenderPlugin,
TransformPlugin,
TimePlugin,
RapierPhysicsPlugin::<NoUserData>::default().in_fixed_schedule(),
Expand Down
14 changes: 8 additions & 6 deletions src/plugin/systems/collider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -589,11 +589,13 @@ pub mod test {
#[cfg(all(feature = "dim3", feature = "async-collider"))]
fn async_collider_initializes() {
use super::*;
use crate::plugin::systems::tests::HeadlessRenderPlugin;
use bevy::{render::mesh::MeshPlugin, scene::ScenePlugin};

let mut app = App::new();
app.add_plugins(HeadlessRenderPlugin)
.add_systems(Update, init_async_colliders);
app.add_plugins((AssetPlugin::default(), MeshPlugin, ScenePlugin));
app.add_systems(Update, init_async_colliders);

app.finish();

let mut meshes = app.world_mut().resource_mut::<Assets<Mesh>>();
let cube = meshes.add(Cuboid::default());
Expand All @@ -620,11 +622,11 @@ pub mod test {
#[cfg(all(feature = "dim3", feature = "async-collider"))]
fn async_scene_collider_initializes() {
use super::*;
use crate::plugin::systems::tests::HeadlessRenderPlugin;
use bevy::{render::mesh::MeshPlugin, scene::ScenePlugin};

let mut app = App::new();
app.add_plugins(HeadlessRenderPlugin)
.add_systems(PostUpdate, init_async_scene_colliders);
app.add_plugins((AssetPlugin::default(), MeshPlugin, ScenePlugin));
app.add_systems(PostUpdate, init_async_scene_colliders);

let mut meshes = app.world_mut().resource_mut::<Assets<Mesh>>();
let cube_handle = meshes.add(Cuboid::default());
Expand Down
2 changes: 1 addition & 1 deletion src/plugin/systems/joint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ pub fn apply_joint_user_changes(
// Re-parenting the joint isn’t supported yet.
for (link, handle, changed_joint) in changed_impulse_joints.iter() {
let mut context = context.get_mut(link.0).expect(RAPIER_CONTEXT_EXPECT_ERROR);
if let Some(joint) = context.impulse_joints.get_mut(handle.0) {
if let Some(joint) = context.impulse_joints.get_mut(handle.0, false) {
joint.data = changed_joint.data.as_ref().into_rapier();
}
}
Expand Down
Loading

0 comments on commit dc1d56e

Please sign in to comment.