Skip to content

Commit 5fb8a4e

Browse files
Update to Rapier 0.20 (#525)
1 parent 470cd9b commit 5fb8a4e

9 files changed

Lines changed: 79 additions & 51 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,14 @@
22

33
## Unreleased
44

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

711
- Renamed `has_any_active_contacts` to `has_any_active_contact` for better consistency with rapier.
12+
- Update to rapier `0.20`.
813

914
### Added
1015

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ codegen-units = 1
2020
#parry2d = { git = "https://github.com/dimforge/parry", branch = "master" }
2121
#parry3d = { git = "https://github.com/dimforge/parry", branch = "master" }
2222
#rapier2d = { git = "https://github.com/dimforge/rapier", branch = "character-controller" }
23-
#rapier3d = { git = "https://github.com/dimforge/rapier", branch = "character-controller" }
23+
#rapier3d = { git = "https://github.com/dimforge/rapier", branch = "character-controller" }

bevy_rapier2d/Cargo.toml

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,20 @@ required-features = ["dim2"]
2020
[features]
2121
default = ["dim2", "async-collider", "debug-render-2d"]
2222
dim2 = []
23-
debug-render-2d = ["bevy/bevy_core_pipeline", "bevy/bevy_sprite", "bevy/bevy_gizmos", "rapier2d/debug-render", "bevy/bevy_asset"]
24-
debug-render-3d = ["bevy/bevy_core_pipeline", "bevy/bevy_pbr", "bevy/bevy_gizmos", "rapier2d/debug-render", "bevy/bevy_asset"]
23+
debug-render-2d = [
24+
"bevy/bevy_core_pipeline",
25+
"bevy/bevy_sprite",
26+
"bevy/bevy_gizmos",
27+
"rapier2d/debug-render",
28+
"bevy/bevy_asset",
29+
]
30+
debug-render-3d = [
31+
"bevy/bevy_core_pipeline",
32+
"bevy/bevy_pbr",
33+
"bevy/bevy_gizmos",
34+
"rapier2d/debug-render",
35+
"bevy/bevy_asset",
36+
]
2537
parallel = ["rapier2d/parallel"]
2638
simd-stable = ["rapier2d/simd-stable"]
2739
simd-nightly = ["rapier2d/simd-nightly"]
@@ -34,7 +46,7 @@ async-collider = ["bevy/bevy_asset", "bevy/bevy_scene"]
3446
[dependencies]
3547
bevy = { version = "0.13", default-features = false }
3648
nalgebra = { version = "0.32.3", features = ["convert-glam025"] }
37-
rapier2d = "0.19.0"
49+
rapier2d = "0.20"
3850
bitflags = "2.4"
3951
log = "0.4"
4052
serde = { version = "1", features = ["derive"], optional = true }

bevy_rapier3d/Cargo.toml

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,20 @@ required-features = ["dim3"]
2121
default = ["dim3", "async-collider", "debug-render-3d"]
2222
dim3 = []
2323
debug-render = ["debug-render-3d"]
24-
debug-render-2d = ["bevy/bevy_core_pipeline", "bevy/bevy_sprite", "bevy/bevy_gizmos", "rapier3d/debug-render", "bevy/bevy_asset"]
25-
debug-render-3d = ["bevy/bevy_core_pipeline", "bevy/bevy_pbr", "bevy/bevy_gizmos", "rapier3d/debug-render", "bevy/bevy_asset"]
24+
debug-render-2d = [
25+
"bevy/bevy_core_pipeline",
26+
"bevy/bevy_sprite",
27+
"bevy/bevy_gizmos",
28+
"rapier3d/debug-render",
29+
"bevy/bevy_asset",
30+
]
31+
debug-render-3d = [
32+
"bevy/bevy_core_pipeline",
33+
"bevy/bevy_pbr",
34+
"bevy/bevy_gizmos",
35+
"rapier3d/debug-render",
36+
"bevy/bevy_asset",
37+
]
2638
parallel = ["rapier3d/parallel"]
2739
simd-stable = ["rapier3d/simd-stable"]
2840
simd-nightly = ["rapier3d/simd-nightly"]
@@ -35,13 +47,16 @@ async-collider = ["bevy/bevy_asset", "bevy/bevy_scene"]
3547
[dependencies]
3648
bevy = { version = "0.13", default-features = false }
3749
nalgebra = { version = "0.32.3", features = ["convert-glam025"] }
38-
rapier3d = "0.19"
50+
rapier3d = "0.20"
3951
bitflags = "2.4"
4052
log = "0.4"
4153
serde = { version = "1", features = ["derive"], optional = true }
4254

4355
[dev-dependencies]
44-
bevy = { version = "0.13", default-features = false, features = ["x11", "tonemapping_luts"] }
56+
bevy = { version = "0.13", default-features = false, features = [
57+
"x11",
58+
"tonemapping_luts",
59+
] }
4560
approx = "0.5.1"
4661
glam = { version = "0.25", features = ["approx"] }
4762

src/dynamics/prismatic_joint.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,19 +89,19 @@ impl PrismaticJoint {
8989
/// The motor affecting the joint’s translational degree of freedom.
9090
#[must_use]
9191
pub fn motor(&self) -> Option<&JointMotor> {
92-
self.data.motor(JointAxis::X)
92+
self.data.motor(JointAxis::LinX)
9393
}
9494

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

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

@@ -113,7 +113,7 @@ impl PrismaticJoint {
113113
damping: Real,
114114
) -> &mut Self {
115115
self.data
116-
.set_motor_position(JointAxis::X, target_pos, stiffness, damping);
116+
.set_motor_position(JointAxis::LinX, target_pos, stiffness, damping);
117117
self
118118
}
119119

@@ -126,25 +126,25 @@ impl PrismaticJoint {
126126
damping: Real,
127127
) -> &mut Self {
128128
self.data
129-
.set_motor(JointAxis::X, target_pos, target_vel, stiffness, damping);
129+
.set_motor(JointAxis::LinX, target_pos, target_vel, stiffness, damping);
130130
self
131131
}
132132

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

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

145145
/// Sets the `[min,max]` limit distances attached bodies can translate along the joint’s principal axis.
146146
pub fn set_limits(&mut self, limits: [Real; 2]) -> &mut Self {
147-
self.data.set_limits(JointAxis::X, limits);
147+
self.data.set_limits(JointAxis::LinX, limits);
148148
self
149149
}
150150
}

src/dynamics/rope_joint.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,14 @@ impl RopeJoint {
9393

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

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

@@ -112,7 +112,7 @@ impl RopeJoint {
112112
damping: Real,
113113
) -> &mut Self {
114114
self.data
115-
.set_motor_position(JointAxis::X, target_pos, stiffness, damping);
115+
.set_motor_position(JointAxis::LinX, target_pos, stiffness, damping);
116116
self
117117
}
118118

@@ -125,13 +125,13 @@ impl RopeJoint {
125125
damping: Real,
126126
) -> &mut Self {
127127
self.data
128-
.set_motor(JointAxis::X, target_pos, target_vel, stiffness, damping);
128+
.set_motor(JointAxis::LinX, target_pos, target_vel, stiffness, damping);
129129
self
130130
}
131131

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

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

152152
/// The maximum distance between the attached bodies.
153153
pub fn max_distance(&self) -> Real {
154154
self.data
155-
.limits(JointAxis::X)
155+
.limits(JointAxis::LinX)
156156
.map(|l| l.max)
157157
.unwrap_or(Real::MAX)
158158
}

src/dynamics/spring_joint.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ impl SpringJoint {
2222
pub fn new(rest_length: Real, stiffness: Real, damping: Real) -> Self {
2323
let data = GenericJointBuilder::new(JointAxesMask::empty())
2424
.coupled_axes(JointAxesMask::LIN_AXES)
25-
.motor_position(JointAxis::X, rest_length, stiffness, damping)
26-
.motor_model(JointAxis::X, MotorModel::ForceBased)
25+
.motor_position(JointAxis::LinX, rest_length, stiffness, damping)
26+
.motor_model(JointAxis::LinX, MotorModel::ForceBased)
2727
.build();
2828
Self { data }
2929
}
@@ -75,7 +75,7 @@ impl SpringJoint {
7575
/// `MotorModel::AccelerationBased`, the spring constants will be automatically scaled by the attached masses,
7676
/// making the spring more mass-independent.
7777
pub fn set_spring_model(&mut self, model: MotorModel) -> &mut Self {
78-
self.data.set_motor_model(JointAxis::X, model);
78+
self.data.set_motor_model(JointAxis::LinX, model);
7979
self
8080
}
8181
}

src/plugin/context.rs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ impl RapierContext {
338338
/// Updates the state of the query pipeline, based on the collider positions known
339339
/// from the last timestep or the last call to `self.propagate_modified_body_positions_to_colliders()`.
340340
pub fn update_query_pipeline(&mut self) {
341-
self.query_pipeline.update(&self.bodies, &self.colliders);
341+
self.query_pipeline.update(&self.colliders);
342342
}
343343

344344
/// The map from entities to rigid-body handles.
@@ -447,18 +447,16 @@ impl RapierContext {
447447
);
448448

449449
if options.apply_impulse_to_dynamic_bodies {
450-
for collision in &*collisions {
451-
controller.solve_character_collision_impulses(
452-
dt,
453-
bodies,
454-
colliders,
455-
query_pipeline,
456-
(&scaled_shape).into(),
457-
shape_mass,
458-
collision,
459-
filter,
460-
)
461-
}
450+
controller.solve_character_collision_impulses(
451+
dt,
452+
bodies,
453+
colliders,
454+
query_pipeline,
455+
(&scaled_shape).into(),
456+
shape_mass,
457+
collisions.iter().copied(),
458+
filter,
459+
)
462460
}
463461

464462
result

src/plugin/systems/character_controller.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -115,18 +115,16 @@ pub fn update_character_controls(
115115
);
116116

117117
if controller.apply_impulse_to_dynamic_bodies {
118-
for collision in &*collisions {
119-
raw_controller.solve_character_collision_impulses(
120-
context.integration_parameters.dt,
121-
&mut context.bodies,
122-
&context.colliders,
123-
&context.query_pipeline,
124-
character_shape,
125-
character_mass,
126-
collision,
127-
filter,
128-
)
129-
}
118+
raw_controller.solve_character_collision_impulses(
119+
context.integration_parameters.dt,
120+
&mut context.bodies,
121+
&context.colliders,
122+
&context.query_pipeline,
123+
character_shape,
124+
character_mass,
125+
collisions.iter().copied(),
126+
filter,
127+
)
130128
}
131129

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

0 commit comments

Comments
 (0)