Skip to content

Commit

Permalink
Start experimenting with the bevy/glam versions of rapier/parry
Browse files Browse the repository at this point in the history
More wrapper removal
  • Loading branch information
sebcrozet committed Mar 17, 2024
1 parent 6aa960b commit eae6526
Show file tree
Hide file tree
Showing 57 changed files with 2,521 additions and 7,327 deletions.
174 changes: 139 additions & 35 deletions CHANGELOG.md

Large diffs are not rendered by default.

16 changes: 10 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,25 @@ 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]
#simba = { path = "../simba" }
#nalgebra = { path = "../nalgebra" }
#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" }
#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" }


simba = { git = "https://github.com/dimforge/simba", rev = "7b50b3eb568e9c551431286a95c913a7057de58f" }
nalgebra = { git = "https://github.com/dimforge/nalgebra", rev = "25032f089bb2e8a8bd2c1d419f1613911a042895" }
parry2d = { git = "https://github.com/dimforge/parry", rev = "c0e6f8032396396f93b5ad687504bed9d676aaee" }
parry3d = { git = "https://github.com/dimforge/parry", rev = "c0e6f8032396396f93b5ad687504bed9d676aaee" }
rapier2d = { git = "https://github.com/dimforge/rapier", rev = "ecd308338b189ab569816a38a03e3f8b89669dde" }
rapier3d = { git = "https://github.com/dimforge/rapier", rev = "ecd308338b189ab569816a38a03e3f8b89669dde" }
34 changes: 17 additions & 17 deletions bevy_rapier2d/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,44 +7,44 @@ documentation = "http://docs.rs/bevy_rapier2d"
homepage = "http://rapier.rs"
repository = "https://github.com/dimforge/bevy_rapier"
readme = "../README.md"
keywords = [ "physics", "dynamics", "rigid", "real-time", "joints" ]
keywords = ["physics", "dynamics", "rigid", "real-time", "joints"]
license = "Apache-2.0"
edition = "2021"


# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]
path = "../src/lib.rs"
required-features = [ "dim2" ]
required-features = ["dim2"]

[features]
default = [ "dim2", "async-collider", "debug-render-2d" ]
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" ]
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" ]
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"]
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" ]
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.18.0"
nalgebra = { version = "0.32.3", features = ["convert-glam025"] }
rapier2d = { version = "0.18", features = ["linalg-glam"] }
bitflags = "2.4"
log = "0.4"
serde = { version = "1", features = [ "derive" ], optional = true}
serde = { version = "1", features = ["derive"], optional = true }

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

[package.metadata.docs.rs]
# Enable all the features when building the docs on docs.rs
features = [ "debug-render-2d", "serde-serialize" ]
features = ["debug-render-2d", "serde-serialize"]
40 changes: 20 additions & 20 deletions bevy_rapier3d/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,44 +7,44 @@ documentation = "http://docs.rs/bevy_rapier3d"
homepage = "http://rapier.rs"
repository = "https://github.com/dimforge/bevy_rapier"
readme = "../README.md"
keywords = [ "physics", "dynamics", "rigid", "real-time", "joints" ]
keywords = ["physics", "dynamics", "rigid", "real-time", "joints"]
license = "Apache-2.0"
edition = "2021"


# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]
path = "../src/lib.rs"
required-features = [ "dim3" ]
required-features = ["dim3"]

[features]
default = [ "dim3", "async-collider", "debug-render-3d" ]
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" ]
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" ]
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"]
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"]

[dependencies]
bevy = { version = "0.13", default-features = false }
nalgebra = { version = "0.32.3", features = [ "convert-glam025" ] }
rapier3d = "0.18"
nalgebra = { version = "0.32.3", features = ["convert-glam025"] }
rapier3d = { version = "0.18", features = ["linalg-glam"] }
bitflags = "2.4"
log = "0.4"
serde = { version = "1", features = [ "derive" ], optional = true}
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" ] }
glam = { version = "0.25", features = ["approx"] }

[package.metadata.docs.rs]
# Enable all the features when building the docs on docs.rs
features = [ "debug-render-3d", "serde-serialize" ]
features = ["debug-render-3d", "serde-serialize"]
8 changes: 1 addition & 7 deletions bevy_rapier3d/examples/ray_casting3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,7 @@ pub fn cast_ray(
};

// Then cast the ray.
let hit = rapier_context.cast_ray(
ray.origin,
ray.direction.into(),
f32::MAX,
true,
QueryFilter::only_dynamic(),
);
let hit = rapier_context.cast_ray(ray, f32::MAX, true, QueryFilter::only_dynamic());

if let Some((entity, _toi)) = hit {
// Color in blue the entity we just hit.
Expand Down
2 changes: 1 addition & 1 deletion bevy_rapier3d/examples/static_trimesh3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ pub fn ball_spawner(mut commands: Commands, time: Res<Time>, mut ball_state: Res
)),
RigidBody::Dynamic,
Collider::ball(rad),
Restitution::new(0.5),
Restitution::coefficient(0.5),
));

ball_state.balls_spawned += 1;
Expand Down
76 changes: 11 additions & 65 deletions src/control/character_controller.rs
Original file line number Diff line number Diff line change
@@ -1,57 +1,12 @@
use crate::geometry::{Collider, CollisionGroups, Toi};
use crate::math::{Real, Rot, Vect};
use crate::geometry::{Collider, CollisionGroups};
use crate::math::{Isometry, Real, Vect};
use bevy::prelude::*;

use crate::plugin::RapierContext;
pub use rapier::control::CharacterAutostep;
pub use rapier::control::CharacterCollision;
pub use rapier::control::CharacterLength;
use rapier::prelude::{ColliderSet, QueryFilterFlags};

/// A collision between the character and its environment during its movement.
#[derive(Copy, Clone, PartialEq, Debug)]
pub struct CharacterCollision {
/// The entity hit by the character.
pub entity: Entity,
/// The position of the character when the collider was hit.
pub character_translation: Vect,
/// The rotation of the character when the collider was hit.
pub character_rotation: Rot,
/// The translation that was already applied to the character when the hit happens.
pub translation_applied: Vect,
/// The translations that was still waiting to be applied to the character when the hit happens.
pub translation_remaining: Vect,
/// Geometric information about the hit.
pub toi: Toi,
}

impl CharacterCollision {
pub(crate) fn from_raw(
ctxt: &RapierContext,
c: &rapier::control::CharacterCollision,
) -> Option<Self> {
Self::from_raw_with_set(ctxt.physics_scale, &ctxt.colliders, c)
}

pub(crate) fn from_raw_with_set(
physics_scale: Real,
colliders: &ColliderSet,
c: &rapier::control::CharacterCollision,
) -> Option<Self> {
RapierContext::collider_entity_with_set(colliders, c.handle).map(|entity| {
CharacterCollision {
entity,
character_translation: (c.character_pos.translation.vector * physics_scale).into(),
#[cfg(feature = "dim2")]
character_rotation: c.character_pos.rotation.angle(),
#[cfg(feature = "dim3")]
character_rotation: c.character_pos.rotation.into(),
translation_applied: (c.translation_applied * physics_scale).into(),
translation_remaining: (c.translation_remaining * physics_scale).into(),
toi: Toi::from_rapier(physics_scale, c.toi),
}
})
}
}
use rapier::prelude::{ColliderSet, QueryFilterFlags, TOI};

/// Options for moving a shape using `RapierContext::move_shape`.
#[derive(Clone, Debug, Copy, PartialEq)]
Expand Down Expand Up @@ -84,7 +39,7 @@ impl Default for MoveShapeOptions {
fn default() -> Self {
let def = rapier::control::KinematicCharacterController::default();
Self {
up: def.up.into(),
up: def.up,
offset: def.offset,
slide: def.slide,
autostep: def.autostep,
Expand All @@ -103,7 +58,7 @@ pub struct KinematicCharacterController {
pub translation: Option<Vect>,
/// The shape, and its position, to be used instead of the shape of the collider attached to
/// the same entity is this `KinematicCharacterController`.
pub custom_shape: Option<(Collider, Vect, Rot)>,
pub custom_shape: Option<(Collider, Isometry)>,
/// The mass to be used for impulse of dynamic bodies. This replaces the mass of the rigid-body
/// potentially associated to the collider attached to the same entity as this
/// `KinematicCharacterController`.
Expand Down Expand Up @@ -141,26 +96,17 @@ pub struct KinematicCharacterController {
}

impl KinematicCharacterController {
pub(crate) fn to_raw(
&self,
physics_scale: Real,
) -> Option<rapier::control::KinematicCharacterController> {
let autostep = self.autostep.map(|autostep| CharacterAutostep {
max_height: autostep.max_height.map_absolute(|x| x / physics_scale),
min_width: autostep.min_width.map_absolute(|x| x / physics_scale),
include_dynamic_bodies: autostep.include_dynamic_bodies,
});
pub(crate) fn to_raw(&self) -> Option<rapier::control::KinematicCharacterController> {
let autostep = self.autostep;

Some(rapier::control::KinematicCharacterController {
up: self.up.try_into().ok()?,
offset: self.offset.map_absolute(|x| x / physics_scale),
offset: self.offset,
slide: self.slide,
autostep,
max_slope_climb_angle: self.max_slope_climb_angle,
min_slope_slide_angle: self.min_slope_slide_angle,
snap_to_ground: self
.snap_to_ground
.map(|x| x.map_absolute(|x| x / physics_scale)),
snap_to_ground: self.snap_to_ground,
})
}
}
Expand All @@ -172,7 +118,7 @@ impl Default for KinematicCharacterController {
translation: None,
custom_shape: None,
custom_mass: None,
up: def.up.into(),
up: def.up,
offset: def.offset,
slide: def.slide,
autostep: def.autostep,
Expand Down
Loading

0 comments on commit eae6526

Please sign in to comment.