Skip to content

Commit

Permalink
Update to Rapier 0.20 (#525)
Browse files Browse the repository at this point in the history
  • Loading branch information
Vrixyz authored Jun 14, 2024
1 parent 470cd9b commit 5fb8a4e
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 51 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@

## Unreleased

**This is an update to Rapier 0.20 which includes several stability improvements
and new features. Please have a look at the
[0.20 changelog](https://github.com/dimforge/rapier/blob/master/CHANGELOG.md) of Rapier.**

### Modified

- Renamed `has_any_active_contacts` to `has_any_active_contact` for better consistency with rapier.
- Update to rapier `0.20`.

### Added

Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ codegen-units = 1
#parry2d = { git = "https://github.com/dimforge/parry", branch = "master" }
#parry3d = { git = "https://github.com/dimforge/parry", branch = "master" }
#rapier2d = { git = "https://github.com/dimforge/rapier", branch = "character-controller" }
#rapier3d = { git = "https://github.com/dimforge/rapier", branch = "character-controller" }
#rapier3d = { git = "https://github.com/dimforge/rapier", branch = "character-controller" }
18 changes: 15 additions & 3 deletions bevy_rapier2d/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,20 @@ required-features = ["dim2"]
[features]
default = ["dim2", "async-collider", "debug-render-2d"]
dim2 = []
debug-render-2d = ["bevy/bevy_core_pipeline", "bevy/bevy_sprite", "bevy/bevy_gizmos", "rapier2d/debug-render", "bevy/bevy_asset"]
debug-render-3d = ["bevy/bevy_core_pipeline", "bevy/bevy_pbr", "bevy/bevy_gizmos", "rapier2d/debug-render", "bevy/bevy_asset"]
debug-render-2d = [
"bevy/bevy_core_pipeline",
"bevy/bevy_sprite",
"bevy/bevy_gizmos",
"rapier2d/debug-render",
"bevy/bevy_asset",
]
debug-render-3d = [
"bevy/bevy_core_pipeline",
"bevy/bevy_pbr",
"bevy/bevy_gizmos",
"rapier2d/debug-render",
"bevy/bevy_asset",
]
parallel = ["rapier2d/parallel"]
simd-stable = ["rapier2d/simd-stable"]
simd-nightly = ["rapier2d/simd-nightly"]
Expand All @@ -34,7 +46,7 @@ async-collider = ["bevy/bevy_asset", "bevy/bevy_scene"]
[dependencies]
bevy = { version = "0.13", default-features = false }
nalgebra = { version = "0.32.3", features = ["convert-glam025"] }
rapier2d = "0.19.0"
rapier2d = "0.20"
bitflags = "2.4"
log = "0.4"
serde = { version = "1", features = ["derive"], optional = true }
Expand Down
23 changes: 19 additions & 4 deletions bevy_rapier3d/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,20 @@ required-features = ["dim3"]
default = ["dim3", "async-collider", "debug-render-3d"]
dim3 = []
debug-render = ["debug-render-3d"]
debug-render-2d = ["bevy/bevy_core_pipeline", "bevy/bevy_sprite", "bevy/bevy_gizmos", "rapier3d/debug-render", "bevy/bevy_asset"]
debug-render-3d = ["bevy/bevy_core_pipeline", "bevy/bevy_pbr", "bevy/bevy_gizmos", "rapier3d/debug-render", "bevy/bevy_asset"]
debug-render-2d = [
"bevy/bevy_core_pipeline",
"bevy/bevy_sprite",
"bevy/bevy_gizmos",
"rapier3d/debug-render",
"bevy/bevy_asset",
]
debug-render-3d = [
"bevy/bevy_core_pipeline",
"bevy/bevy_pbr",
"bevy/bevy_gizmos",
"rapier3d/debug-render",
"bevy/bevy_asset",
]
parallel = ["rapier3d/parallel"]
simd-stable = ["rapier3d/simd-stable"]
simd-nightly = ["rapier3d/simd-nightly"]
Expand All @@ -35,13 +47,16 @@ async-collider = ["bevy/bevy_asset", "bevy/bevy_scene"]
[dependencies]
bevy = { version = "0.13", default-features = false }
nalgebra = { version = "0.32.3", features = ["convert-glam025"] }
rapier3d = "0.19"
rapier3d = "0.20"
bitflags = "2.4"
log = "0.4"
serde = { version = "1", features = ["derive"], optional = true }

[dev-dependencies]
bevy = { version = "0.13", default-features = false, features = ["x11", "tonemapping_luts"] }
bevy = { version = "0.13", default-features = false, features = [
"x11",
"tonemapping_luts",
] }
approx = "0.5.1"
glam = { version = "0.25", features = ["approx"] }

Expand Down
16 changes: 8 additions & 8 deletions src/dynamics/prismatic_joint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,19 +89,19 @@ impl PrismaticJoint {
/// The motor affecting the joint’s translational degree of freedom.
#[must_use]
pub fn motor(&self) -> Option<&JointMotor> {
self.data.motor(JointAxis::X)
self.data.motor(JointAxis::LinX)
}

/// Set the spring-like model used by the motor to reach the desired target velocity and position.
pub fn set_motor_model(&mut self, model: MotorModel) -> &mut Self {
self.data.set_motor_model(JointAxis::X, model);
self.data.set_motor_model(JointAxis::LinX, model);
self
}

/// Sets the target velocity this motor needs to reach.
pub fn set_motor_velocity(&mut self, target_vel: Real, factor: Real) -> &mut Self {
self.data
.set_motor_velocity(JointAxis::X, target_vel, factor);
.set_motor_velocity(JointAxis::LinX, target_vel, factor);
self
}

Expand All @@ -113,7 +113,7 @@ impl PrismaticJoint {
damping: Real,
) -> &mut Self {
self.data
.set_motor_position(JointAxis::X, target_pos, stiffness, damping);
.set_motor_position(JointAxis::LinX, target_pos, stiffness, damping);
self
}

Expand All @@ -126,25 +126,25 @@ impl PrismaticJoint {
damping: Real,
) -> &mut Self {
self.data
.set_motor(JointAxis::X, target_pos, target_vel, stiffness, damping);
.set_motor(JointAxis::LinX, target_pos, target_vel, stiffness, damping);
self
}

/// Sets the maximum force the motor can deliver.
pub fn set_motor_max_force(&mut self, max_force: Real) -> &mut Self {
self.data.set_motor_max_force(JointAxis::X, max_force);
self.data.set_motor_max_force(JointAxis::LinX, max_force);
self
}

/// The limit distance attached bodies can translate along the joint’s principal axis.
#[must_use]
pub fn limits(&self) -> Option<&JointLimits<Real>> {
self.data.limits(JointAxis::X)
self.data.limits(JointAxis::LinX)
}

/// Sets the `[min,max]` limit distances attached bodies can translate along the joint’s principal axis.
pub fn set_limits(&mut self, limits: [Real; 2]) -> &mut Self {
self.data.set_limits(JointAxis::X, limits);
self.data.set_limits(JointAxis::LinX, limits);
self
}
}
Expand Down
14 changes: 7 additions & 7 deletions src/dynamics/rope_joint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,14 @@ impl RopeJoint {

/// Set the spring-like model used by the motor to reach the desired target velocity and position.
pub fn set_motor_model(&mut self, model: MotorModel) -> &mut Self {
self.data.set_motor_model(JointAxis::X, model);
self.data.set_motor_model(JointAxis::LinX, model);
self
}

/// Sets the target velocity this motor needs to reach.
pub fn set_motor_velocity(&mut self, target_vel: Real, factor: Real) -> &mut Self {
self.data
.set_motor_velocity(JointAxis::X, target_vel, factor);
.set_motor_velocity(JointAxis::LinX, target_vel, factor);
self
}

Expand All @@ -112,7 +112,7 @@ impl RopeJoint {
damping: Real,
) -> &mut Self {
self.data
.set_motor_position(JointAxis::X, target_pos, stiffness, damping);
.set_motor_position(JointAxis::LinX, target_pos, stiffness, damping);
self
}

Expand All @@ -125,13 +125,13 @@ impl RopeJoint {
damping: Real,
) -> &mut Self {
self.data
.set_motor(JointAxis::X, target_pos, target_vel, stiffness, damping);
.set_motor(JointAxis::LinX, target_pos, target_vel, stiffness, damping);
self
}

/// Sets the maximum force the motor can deliver.
pub fn set_motor_max_force(&mut self, max_force: Real) -> &mut Self {
self.data.set_motor_max_force(JointAxis::X, max_force);
self.data.set_motor_max_force(JointAxis::LinX, max_force);
self
}

Expand All @@ -145,14 +145,14 @@ impl RopeJoint {
///
/// The `max_dist` must be strictly greater than 0.0.
pub fn set_max_distance(&mut self, max_dist: Real) -> &mut Self {
self.data.set_limits(JointAxis::X, [0.0, max_dist]);
self.data.set_limits(JointAxis::LinX, [0.0, max_dist]);
self
}

/// The maximum distance between the attached bodies.
pub fn max_distance(&self) -> Real {
self.data
.limits(JointAxis::X)
.limits(JointAxis::LinX)
.map(|l| l.max)
.unwrap_or(Real::MAX)
}
Expand Down
6 changes: 3 additions & 3 deletions src/dynamics/spring_joint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ impl SpringJoint {
pub fn new(rest_length: Real, stiffness: Real, damping: Real) -> Self {
let data = GenericJointBuilder::new(JointAxesMask::empty())
.coupled_axes(JointAxesMask::LIN_AXES)
.motor_position(JointAxis::X, rest_length, stiffness, damping)
.motor_model(JointAxis::X, MotorModel::ForceBased)
.motor_position(JointAxis::LinX, rest_length, stiffness, damping)
.motor_model(JointAxis::LinX, MotorModel::ForceBased)
.build();
Self { data }
}
Expand Down Expand Up @@ -75,7 +75,7 @@ impl SpringJoint {
/// `MotorModel::AccelerationBased`, the spring constants will be automatically scaled by the attached masses,
/// making the spring more mass-independent.
pub fn set_spring_model(&mut self, model: MotorModel) -> &mut Self {
self.data.set_motor_model(JointAxis::X, model);
self.data.set_motor_model(JointAxis::LinX, model);
self
}
}
Expand Down
24 changes: 11 additions & 13 deletions src/plugin/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ impl RapierContext {
/// Updates the state of the query pipeline, based on the collider positions known
/// from the last timestep or the last call to `self.propagate_modified_body_positions_to_colliders()`.
pub fn update_query_pipeline(&mut self) {
self.query_pipeline.update(&self.bodies, &self.colliders);
self.query_pipeline.update(&self.colliders);
}

/// The map from entities to rigid-body handles.
Expand Down Expand Up @@ -447,18 +447,16 @@ impl RapierContext {
);

if options.apply_impulse_to_dynamic_bodies {
for collision in &*collisions {
controller.solve_character_collision_impulses(
dt,
bodies,
colliders,
query_pipeline,
(&scaled_shape).into(),
shape_mass,
collision,
filter,
)
}
controller.solve_character_collision_impulses(
dt,
bodies,
colliders,
query_pipeline,
(&scaled_shape).into(),
shape_mass,
collisions.iter().copied(),
filter,
)
}

result
Expand Down
22 changes: 10 additions & 12 deletions src/plugin/systems/character_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,18 +115,16 @@ pub fn update_character_controls(
);

if controller.apply_impulse_to_dynamic_bodies {
for collision in &*collisions {
raw_controller.solve_character_collision_impulses(
context.integration_parameters.dt,
&mut context.bodies,
&context.colliders,
&context.query_pipeline,
character_shape,
character_mass,
collision,
filter,
)
}
raw_controller.solve_character_collision_impulses(
context.integration_parameters.dt,
&mut context.bodies,
&context.colliders,
&context.query_pipeline,
character_shape,
character_mass,
collisions.iter().copied(),
filter,
)
}

if let Ok(mut transform) = transforms.get_mut(entity_to_move) {
Expand Down

0 comments on commit 5fb8a4e

Please sign in to comment.