Skip to content

Commit

Permalink
Merge pull request bevyengine#54 from dimforge/rapier_up
Browse files Browse the repository at this point in the history
Update to the latest version of Rapier.
  • Loading branch information
sebcrozet authored Jan 29, 2021
2 parents a838854 + e99341e commit 7b5974f
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 38 deletions.
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ members = ["bevy_rapier2d", "bevy_rapier3d"]
codegen-units = 1

[patch.crates-io]
#parry2d = { path = "../parry/build/parry2d" }
#parry3d = { path = "../parry/build/parry3d" }
#rapier2d = { path = "../rapier/build/rapier2d" }
#rapier3d = { path = "../rapier/build/rapier3d" }
4 changes: 2 additions & 2 deletions bevy_rapier2d/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ enhanced-determinism = [ "rapier2d/enhanced-determinism" ]

[dependencies]
bevy = { version = "0.4", default-features = false }
nalgebra = "0.23"
rapier2d = "0.4"
nalgebra = "0.24"
rapier2d = "0.5"
concurrent-queue = "1"

[dev-dependencies]
Expand Down
4 changes: 2 additions & 2 deletions bevy_rapier2d/examples/events2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ fn setup_graphics(commands: &mut Commands, mut configuration: ResMut<RapierConfi
}

fn display_events(events: Res<EventQueue>) {
while let Ok(proximity_event) = events.proximity_events.pop() {
println!("Received proximity event: {:?}", proximity_event);
while let Ok(intersection_event) = events.intersection_events.pop() {
println!("Received intersection event: {:?}", intersection_event);
}

while let Ok(contact_event) = events.contact_events.pop() {
Expand Down
4 changes: 2 additions & 2 deletions bevy_rapier3d/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ enhanced-determinism = [ "rapier3d/enhanced-determinism" ]

[dependencies]
bevy = { version = "0.4", default-features = false }
nalgebra = "0.23"
rapier3d = "0.4"
nalgebra = "0.24"
rapier3d = "0.5"
concurrent-queue = "1"

[dev-dependencies]
Expand Down
4 changes: 2 additions & 2 deletions bevy_rapier3d/examples/events3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ fn setup_graphics(commands: &mut Commands) {
}

fn display_events(events: Res<EventQueue>) {
while let Ok(proximity_event) = events.proximity_events.pop() {
println!("Received proximity event: {:?}", proximity_event);
while let Ok(intersection_event) = events.intersection_events.pop() {
println!("Received intersection event: {:?}", intersection_event);
}

while let Ok(contact_event) = events.contact_events.pop() {
Expand Down
2 changes: 1 addition & 1 deletion bevy_rapier3d/examples/locked_rotations3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ pub fn setup_physics(commands: &mut Commands) {
let rigid_body = RigidBodyBuilder::new_dynamic()
.translation(0.0, 3.0, 0.0)
.lock_translations()
.principal_angular_inertia(Vector3::zeros(), Vector3::new(true, false, false));
.restrict_rotations(true, false, false);
let collider = ColliderBuilder::cuboid(0.2, 0.6, 2.0);
commands.spawn((rigid_body, collider));

Expand Down
14 changes: 7 additions & 7 deletions bevy_rapier3d/examples/static_trimesh3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ pub fn setup_physics(commands: &mut Commands) {

// Create the ramp.
let mut vertices: Vec<Point3<f32>> = Vec::new();
let mut indices: Vec<Point3<u32>> = Vec::new();
let mut indices: Vec<[u32; 3]> = Vec::new();
let segments = 32;
let ramp_size = ramp_size();
for i in 0..=segments {
Expand All @@ -77,8 +77,8 @@ pub fn setup_physics(commands: &mut Commands) {
}
for i in 0..segments {
// Two triangles making up a flat quad for each segment of the ramp.
indices.push(Point3::new(2 * i + 0, 2 * i + 1, 2 * i + 2));
indices.push(Point3::new(2 * i + 2, 2 * i + 1, 2 * i + 3));
indices.push([2 * i + 0, 2 * i + 1, 2 * i + 2]);
indices.push([2 * i + 2, 2 * i + 1, 2 * i + 3]);
}
let rigid_body = RigidBodyBuilder::new_static().translation(0.0, 0.0, 0.0);
let collider = ColliderBuilder::trimesh(vertices, indices);
Expand All @@ -88,7 +88,7 @@ pub fn setup_physics(commands: &mut Commands) {
// so that we can join the end of the ramp smoothly
// to the lip of the bowl.
let mut vertices: Vec<Point3<f32>> = Vec::new();
let mut indices: Vec<Point3<u32>> = Vec::new();
let mut indices: Vec<[u32; 3]> = Vec::new();
let segments = 32;
let bowl_size = Vec3::new(10.0, 3.0, 10.0);
for ix in 0..=segments {
Expand All @@ -110,8 +110,8 @@ pub fn setup_physics(commands: &mut Commands) {
let row0 = ix * (segments + 1);
let row1 = (ix + 1) * (segments + 1);
// Two triangles making up a not-very-flat quad for each segment of the bowl.
indices.push(Point3::new(row0 + iz + 0, row0 + iz + 1, row1 + iz + 0));
indices.push(Point3::new(row1 + iz + 0, row0 + iz + 1, row1 + iz + 1));
indices.push([row0 + iz + 0, row0 + iz + 1, row1 + iz + 0]);
indices.push([row1 + iz + 0, row0 + iz + 1, row1 + iz + 1]);
}
}
// Position so ramp connects smoothly
Expand Down Expand Up @@ -154,7 +154,7 @@ fn ball_spawner(

// NOTE: The timing here only works properly with `time_dependent_number_of_timesteps`
// disabled, as it is for examples.
ball_state.seconds_until_next_spawn -= integration_parameters.dt();
ball_state.seconds_until_next_spawn -= integration_parameters.dt;
if ball_state.seconds_until_next_spawn > 0.0 {
return;
}
Expand Down
30 changes: 15 additions & 15 deletions src/physics/resources.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::rapier::{
dynamics::{JointHandle, RigidBodyHandle},
geometry::{
ColliderHandle, ContactEvent, ContactPairFilter, ProximityEvent, ProximityPairFilter,
ColliderHandle, ContactEvent, ContactPairFilter, IntersectionEvent, IntersectionPairFilter,
},
pipeline::EventHandler,
};
Expand Down Expand Up @@ -47,8 +47,8 @@ impl Default for RapierConfiguration {
pub struct EventQueue {
/// The unbounded contact event queue.
pub contact_events: ConcurrentQueue<ContactEvent>,
/// The unbounded proximity event queue.
pub proximity_events: ConcurrentQueue<ProximityEvent>,
/// The unbounded intersection event queue.
pub intersection_events: ConcurrentQueue<IntersectionEvent>,
/// Are these queues automatically cleared before each simulation timestep?
pub auto_clear: bool,
}
Expand All @@ -58,21 +58,21 @@ impl EventQueue {
pub fn new(auto_clear: bool) -> Self {
Self {
contact_events: ConcurrentQueue::unbounded(),
proximity_events: ConcurrentQueue::unbounded(),
intersection_events: ConcurrentQueue::unbounded(),
auto_clear,
}
}

/// Removes all events contained by this queue.
pub fn clear(&self) {
while let Ok(_) = self.contact_events.pop() {}
while let Ok(_) = self.proximity_events.pop() {}
while let Ok(_) = self.intersection_events.pop() {}
}
}

impl EventHandler for EventQueue {
fn handle_proximity_event(&self, event: ProximityEvent) {
let _ = self.proximity_events.push(event);
fn handle_intersection_event(&self, event: IntersectionEvent) {
let _ = self.intersection_events.push(event);
}

fn handle_contact_event(&self, event: ContactEvent) {
Expand All @@ -87,19 +87,19 @@ pub struct SimulationToRenderTime {
pub diff: f32,
}

/// Custom filters for proximity and contact pairs.
/// Custom filters for intersection and contact pairs.
pub struct InteractionPairFilters {
/// Custom proximity pair filter.
pub proximity_filter: Option<Box<dyn ProximityPairFilter>>,
/// Custom intersection pair filter.
pub intersection_filter: Option<Box<dyn IntersectionPairFilter>>,
/// Custom contact pair filter.
pub contact_filter: Option<Box<dyn ContactPairFilter>>,
}

impl InteractionPairFilters {
/// A new interaction pair filter with no custom proximity and contact pair filters.
/// A new interaction pair filter with no custom intersection and contact pair filters.
pub fn new() -> Self {
Self {
proximity_filter: None,
intersection_filter: None,
contact_filter: None,
}
}
Expand All @@ -110,9 +110,9 @@ impl InteractionPairFilters {
self
}

/// Sets the custom proximity pair filter.
pub fn proximity_filter(mut self, filter: impl ProximityPairFilter + 'static) -> Self {
self.proximity_filter = Some(Box::new(filter) as Box<dyn ProximityPairFilter>);
/// Sets the custom intersection pair filter.
pub fn intersection_filter(mut self, filter: impl IntersectionPairFilter + 'static) -> Self {
self.intersection_filter = Some(Box::new(filter) as Box<dyn IntersectionPairFilter>);
self
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/physics/systems.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ pub fn step_world_system(
if configuration.time_dependent_number_of_timesteps {
sim_to_render_time.diff += time.delta_seconds();

let sim_dt = integration_parameters.dt();
let sim_dt = integration_parameters.dt;
while sim_to_render_time.diff >= sim_dt {
if configuration.physics_pipeline_active {
// NOTE: in this comparison we do the same computations we
Expand All @@ -217,7 +217,7 @@ pub fn step_world_system(
&mut colliders,
&mut joints,
filter.contact_filter.as_deref(),
filter.proximity_filter.as_deref(),
filter.intersection_filter.as_deref(),
&*events,
);
}
Expand All @@ -233,7 +233,7 @@ pub fn step_world_system(
&mut colliders,
&mut joints,
filter.contact_filter.as_deref(),
filter.proximity_filter.as_deref(),
filter.intersection_filter.as_deref(),
&*events,
);
}
Expand Down Expand Up @@ -285,7 +285,7 @@ pub fn sync_transform_system(
>,
) {
let dt = sim_to_render_time.diff;
let sim_dt = integration_parameters.dt();
let sim_dt = integration_parameters.dt;
let alpha = dt / sim_dt;
for (rigid_body, previous_pos, mut transform) in interpolation_query.iter_mut() {
if let Some(rb) = bodies.get(rigid_body.handle()) {
Expand Down
6 changes: 3 additions & 3 deletions src/render/systems.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ pub fn create_collider_renders_system(
radius: 1.0,
}),
#[cfg(feature = "dim2")]
ShapeType::Trimesh => {
ShapeType::TriMesh => {
let mut mesh =
Mesh::new(bevy::render::pipeline::PrimitiveTopology::TriangleList);
let trimesh = shape.as_trimesh().unwrap();
Expand All @@ -102,7 +102,7 @@ pub fn create_collider_renders_system(
mesh
}
#[cfg(feature = "dim3")]
ShapeType::Trimesh => {
ShapeType::TriMesh => {
let mut mesh =
Mesh::new(bevy::render::pipeline::PrimitiveTopology::TriangleList);
let trimesh = shape.as_trimesh().unwrap();
Expand Down Expand Up @@ -182,7 +182,7 @@ pub fn create_collider_renders_system(
let b = shape.as_ball().unwrap();
Vec3::new(b.radius, b.radius, b.radius)
}
ShapeType::Trimesh => Vec3::one(),
ShapeType::TriMesh => Vec3::one(),
_ => unimplemented!(),
} * configuration.scale;

Expand Down

0 comments on commit 7b5974f

Please sign in to comment.