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 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
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
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
35 changes: 3 additions & 32 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 @@ -203,11 +194,11 @@ pub mod tests {
fn transform_propagation() {
let mut app = App::new();
app.add_plugins((
HeadlessRenderPlugin,
TransformPlugin,
TimePlugin,
RapierPhysicsPlugin::<NoUserData>::default(),
));
app.finish();

let zero = (Transform::default(), Transform::default());

Expand Down Expand Up @@ -260,11 +251,11 @@ pub mod tests {
fn transform_propagation2() {
let mut app = App::new();
app.add_plugins((
HeadlessRenderPlugin,
TransformPlugin,
TimePlugin,
RapierPhysicsPlugin::<NoUserData>::default(),
));
app.finish();

let zero = (Transform::default(), Transform::default());

Expand Down Expand Up @@ -342,24 +333,4 @@ pub mod tests {
approx::assert_relative_eq!(body_transform.scale, child_transform.scale,);
}
}

// Allows run tests for systems containing rendering related things without GPU
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(),
));
}
}
}
Loading
Loading