Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update rapier to 0.23 #625

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ jobs:
run: cargo test --verbose -p bevy_rapier2d
- name: Test for bevy_rapier3d
run: cargo test --verbose -p bevy_rapier3d
- name: Unit Tests for bevy_rapier3d without default features
run: cargo test -p bevy_rapier3d --no-default-features --features dim3 --lib
- name: Unit Tests for bevy_rapier3d without default features
run: cargo test -p bevy_rapier3d --no-default-features --features dim3 --lib
Vrixyz marked this conversation as resolved.
Show resolved Hide resolved
test-wasm:
runs-on: ubuntu-latest
env:
Expand All @@ -72,6 +76,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
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
8 changes: 6 additions & 2 deletions bevy_rapier_benches3d/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ 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>()
Expand All @@ -34,7 +34,11 @@ pub fn custom_bencher(steps: usize, setup: impl Fn(&mut App)) {
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_millis() 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;
Expand Down
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
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
31 changes: 8 additions & 23 deletions src/plugin/systems/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,7 @@ pub fn step_simulation<Hooks>(
#[cfg(test)]
#[allow(missing_docs)]
pub mod tests {
use bevy::{
asset::AssetPlugin,
ecs::event::Events,
render::{
settings::{RenderCreation, WgpuSettings},
RenderPlugin,
},
scene::ScenePlugin,
time::TimePlugin,
};
use bevy::{ecs::event::Events, time::TimePlugin};
use rapier::geometry::CollisionEventFlags;
use std::f32::consts::PI;

Expand Down Expand Up @@ -347,19 +338,13 @@ pub mod tests {
pub struct HeadlessRenderPlugin;

impl Plugin for HeadlessRenderPlugin {
fn build(&self, app: &mut App) {
app.add_plugins((
AssetPlugin::default(),
ScenePlugin,
RenderPlugin {
render_creation: RenderCreation::Automatic(WgpuSettings {
backends: None,
..Default::default()
}),
..Default::default()
},
ImagePlugin::default(),
));
fn build(&self, _app: &mut App) {
#[cfg(feature = "async-collider")]
{
use bevy::{asset::AssetPlugin, render::mesh::MeshPlugin, scene::ScenePlugin};
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might want to add those directly within RapierPhysicsPlugin when we use the feature async-collider.


_app.add_plugins((AssetPlugin::default(), MeshPlugin, ScenePlugin));
}
}
}
}
Loading