Skip to content

Commit

Permalink
chore: start updating to the latest rapier version
Browse files Browse the repository at this point in the history
  • Loading branch information
sebcrozet committed May 4, 2024
1 parent 6aa960b commit adfb741
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 26 deletions.
10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ members = ["bevy_rapier2d", "bevy_rapier3d"]
resolver = "2"

[profile.dev]
# Use slightly better optimization by default, as examples otherwise seem laggy.
# Use slightly better optimization by default, as examples otherwise seem laggy.
opt-level = 1

[profile.release]
codegen-units = 1

[patch.crates-io]
#nalgebra = { path = "../nalgebra" }
#parry2d = { path = "../parry/crates/parry2d" }
#parry3d = { path = "../parry/crates/parry3d" }
#rapier2d = { path = "../rapier/crates/rapier2d" }
#rapier3d = { path = "../rapier/crates/rapier3d" }
parry2d = { path = "../parry/crates/parry2d" }
parry3d = { path = "../parry/crates/parry3d" }
rapier2d = { path = "../rapier/crates/rapier2d" }
rapier3d = { path = "../rapier/crates/rapier3d" }

#nalgebra = { git = "https://github.com/dimforge/nalgebra", branch = "dev" }
#parry2d = { git = "https://github.com/dimforge/parry", branch = "master" }
Expand Down
21 changes: 21 additions & 0 deletions src/control/character_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,15 @@ pub struct MoveShapeOptions {
/// Should the character be automatically snapped to the ground if the distance between
/// the ground and its feet are smaller than the specified threshold?
pub snap_to_ground: Option<CharacterLength>,
/// Increase this number if your character appears to get stuck when sliding against surfaces.
///
/// This is a small distance applied to the movement toward the contact normals of shapes hit
/// by the character controller. This helps shape-casting not getting stuck in an alway-penetrating
/// state during the sliding calculation.
///
/// This value should remain fairly small since it can introduce artificial "bumps" when sliding
/// along a flat surface.
pub normal_nudge_factor: Real,
}

impl Default for MoveShapeOptions {
Expand All @@ -92,6 +101,7 @@ impl Default for MoveShapeOptions {
min_slope_slide_angle: def.min_slope_slide_angle,
apply_impulse_to_dynamic_bodies: true,
snap_to_ground: def.snap_to_ground,
normal_nudge_factor: def.normal_nudge_factor,
}
}
}
Expand Down Expand Up @@ -138,6 +148,15 @@ pub struct KinematicCharacterController {
/// Groups for filtering-out some colliders from the environment seen by the character
/// controller.
pub filter_groups: Option<CollisionGroups>,
/// Increase this number if your character appears to get stuck when sliding against surfaces.
///
/// This is a small distance applied to the movement toward the contact normals of shapes hit
/// by the character controller. This helps shape-casting not getting stuck in an alway-penetrating
/// state during the sliding calculation.
///
/// This value should remain fairly small since it can introduce artificial "bumps" when sliding
/// along a flat surface.
pub normal_nudge_factor: Real,
}

impl KinematicCharacterController {
Expand All @@ -161,6 +180,7 @@ impl KinematicCharacterController {
snap_to_ground: self
.snap_to_ground
.map(|x| x.map_absolute(|x| x / physics_scale)),
normal_nudge_factor: self.normal_nudge_factor,
})
}
}
Expand All @@ -182,6 +202,7 @@ impl Default for KinematicCharacterController {
snap_to_ground: def.snap_to_ground,
filter_flags: QueryFilterFlags::default() | QueryFilterFlags::EXCLUDE_SENSORS,
filter_groups: None,
normal_nudge_factor: def.normal_nudge_factor,
}
}
}
Expand Down
9 changes: 6 additions & 3 deletions src/dynamics/rigid_body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,10 @@ impl Dominance {
#[reflect(Component, PartialEq)]
pub struct Sleeping {
/// The linear velocity below which the body can fall asleep.
pub linear_threshold: f32,
///
/// The effictive threshold is obtained by multpilying this value by the
/// [`IntegrationParameters::length_unit`].
pub normalized_linear_threshold: f32,
/// The angular velocity below which the body can fall asleep.
pub angular_threshold: f32,
/// Is this body sleeping?
Expand All @@ -517,7 +520,7 @@ impl Sleeping {
/// Creates a components that disables sleeping for the associated [`RigidBody`].
pub fn disabled() -> Self {
Self {
linear_threshold: -1.0,
normalized_linear_threshold: -1.0,
angular_threshold: -1.0,
sleeping: false,
}
Expand All @@ -527,7 +530,7 @@ impl Sleeping {
impl Default for Sleeping {
fn default() -> Self {
Self {
linear_threshold: RigidBodyActivation::default_linear_threshold(),
normalized_linear_threshold: RigidBodyActivation::default_normalized_linear_threshold(),
angular_threshold: RigidBodyActivation::default_angular_threshold(),
sleeping: false,
}
Expand Down
14 changes: 7 additions & 7 deletions src/geometry/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pub use self::collider::*;
pub use self::shape_views::ColliderView;
pub use rapier::geometry::SolverFlags;
pub use rapier::parry::query::TOIStatus;
pub use rapier::parry::query::{ShapeCastOptions, ShapeCastStatus};
pub use rapier::parry::shape::TriMeshFlags;
pub use rapier::parry::transformation::{vhacd::VHACDParameters, voxelization::FillMode};

Expand Down Expand Up @@ -69,8 +69,8 @@ impl RayIntersection {
unscaled_dir: Vect,
) -> Self {
Self {
toi: inter.toi,
point: unscaled_origin + unscaled_dir * inter.toi,
toi: inter.time_of_impact,
point: unscaled_origin + unscaled_dir * inter.time_of_impact,
normal: inter.normal.into(),
feature: inter.feature,
}
Expand All @@ -87,7 +87,7 @@ pub struct Toi {
/// `None` if `status` is `Penetrating`.
pub details: Option<ToiDetails>,
/// The way the time-of-impact computation algorithm terminated.
pub status: TOIStatus,
pub status: ShapeCastStatus,
}

/// In depth information about a time-of-impact (TOI) computation.
Expand All @@ -105,8 +105,8 @@ pub struct ToiDetails {

impl Toi {
/// Convert from internal `rapier::Toi`.
pub fn from_rapier(physics_scale: Real, toi: rapier::parry::query::TOI) -> Self {
let details = if toi.status != TOIStatus::Penetrating {
pub fn from_rapier(physics_scale: Real, toi: rapier::parry::query::ShapeCastHit) -> Self {
let details = if toi.status != ShapeCastStatus::PenetratingOrWithinTargetDist {
Some(ToiDetails {
witness1: (toi.witness1 * physics_scale).into(),
witness2: (toi.witness2 * physics_scale).into(),
Expand All @@ -117,7 +117,7 @@ impl Toi {
None
};
Self {
toi: toi.toi,
toi: toi.time_of_impact,
status: toi.status,
details,
}
Expand Down
19 changes: 10 additions & 9 deletions src/plugin/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ use bevy::prelude::{Entity, EventWriter, GlobalTransform, Query};

use crate::control::{CharacterCollision, MoveShapeOptions, MoveShapeOutput};
use crate::dynamics::TransformInterpolation;
use crate::parry::query::details::ShapeCastOptions;
use crate::plugin::configuration::{SimulationToRenderTime, TimestepMode};
use crate::prelude::{CollisionGroups, RapierRigidBodyHandle};
use rapier::control::CharacterAutostep;
use rapier::geometry::DefaultBroadPhase;

/// The Rapier context, containing all the state of the physics engine.
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
Expand All @@ -28,7 +30,7 @@ pub struct RapierContext {
/// (not moving much) to reduce computations.
pub islands: IslandManager,
/// The broad-phase, which detects potential contact pairs.
pub broad_phase: BroadPhase,
pub broad_phase: Box<dyn BroadPhase>,
/// The narrow-phase, which computes contact points, tests intersections,
/// and maintain the contact and intersection graphs.
pub narrow_phase: NarrowPhase,
Expand Down Expand Up @@ -76,7 +78,7 @@ impl Default for RapierContext {
fn default() -> Self {
Self {
islands: IslandManager::new(),
broad_phase: BroadPhase::new(),
broad_phase: Box::new(DefaultBroadPhase::new()),
narrow_phase: NarrowPhase::new(),
bodies: RigidBodySet::new(),
colliders: ColliderSet::new(),
Expand Down Expand Up @@ -264,7 +266,7 @@ impl RapierContext {
&(gravity / self.physics_scale).into(),
&substep_integration_parameters,
&mut self.islands,
&mut self.broad_phase,
&mut *self.broad_phase,
&mut self.narrow_phase,
&mut self.bodies,
&mut self.colliders,
Expand Down Expand Up @@ -295,7 +297,7 @@ impl RapierContext {
&(gravity / self.physics_scale).into(),
&substep_integration_parameters,
&mut self.islands,
&mut self.broad_phase,
&mut *self.broad_phase,
&mut self.narrow_phase,
&mut self.bodies,
&mut self.colliders,
Expand All @@ -319,7 +321,7 @@ impl RapierContext {
&(gravity / self.physics_scale).into(),
&substep_integration_parameters,
&mut self.islands,
&mut self.broad_phase,
&mut *self.broad_phase,
&mut self.narrow_phase,
&mut self.bodies,
&mut self.colliders,
Expand Down Expand Up @@ -417,6 +419,7 @@ impl RapierContext {
snap_to_ground: options
.snap_to_ground
.map(|x| x.map_absolute(|x| x / physics_scale)),
normal_nudge_factor: options.normal_nudge_factor,
};

self.character_collisions_collector.clear();
Expand Down Expand Up @@ -786,8 +789,7 @@ impl RapierContext {
shape_rot: Rot,
shape_vel: Vect,
shape: &Collider,
max_toi: Real,
stop_at_penetration: bool,
options: ShapeCastOptions,
filter: QueryFilter,
) -> Option<(Entity, Toi)> {
let scaled_transform = (shape_pos / self.physics_scale, shape_rot).into();
Expand All @@ -803,8 +805,7 @@ impl RapierContext {
&scaled_transform,
&(shape_vel / self.physics_scale).into(),
&*scaled_shape.raw,
max_toi,
stop_at_penetration,
options,
filter,
)
})?;
Expand Down
4 changes: 2 additions & 2 deletions src/plugin/systems.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ pub fn apply_rigid_body_user_changes(
for (handle, sleeping) in changed_sleeping.iter() {
if let Some(rb) = context.bodies.get_mut(handle.0) {
let activation = rb.activation_mut();
activation.linear_threshold = sleeping.linear_threshold;
activation.normalized_linear_threshold = sleeping.normalized_linear_threshold;
activation.angular_threshold = sleeping.angular_threshold;

if !sleeping.sleeping && activation.sleeping {
Expand Down Expand Up @@ -1068,7 +1068,7 @@ pub fn init_rigid_bodies(

if let Some(sleep) = sleep {
let activation = rb.activation_mut();
activation.linear_threshold = sleep.linear_threshold;
activation.normalized_linear_threshold = sleep.normalized_linear_threshold;
activation.angular_threshold = sleep.angular_threshold;
}

Expand Down

0 comments on commit adfb741

Please sign in to comment.