diff --git a/bevy_rapier2d/Cargo.toml b/bevy_rapier2d/Cargo.toml index feb88221..f8193a72 100644 --- a/bevy_rapier2d/Cargo.toml +++ b/bevy_rapier2d/Cargo.toml @@ -64,15 +64,15 @@ async-collider = [ to-bevy-mesh = ["bevy/bevy_render", "bevy/bevy_asset"] [dependencies] -bevy = { version = "0.18.0", default-features = false, features = ["std"] } -nalgebra = { version = "0.34.1", features = ["convert-glam030"] } -rapier2d = "0.31.0" +bevy = { version = "0.18.1", default-features = false, features = ["std"] } +nalgebra = { version = "0.34.2", features = ["convert-glam030"] } +rapier2d = "0.32.0" bitflags = "2.10.0" log = "0.4" serde = { version = "1", features = ["derive"], optional = true } [dev-dependencies] -bevy = { version = "0.18.0", default-features = false, features = [ +bevy = { version = "0.18.1", default-features = false, features = [ "x11", "bevy_state", "bevy_window", @@ -94,7 +94,7 @@ oorandom = "11" approx = "0.5.1" glam = { version = "0.30.9", features = ["approx"] } bevy-inspector-egui = "0.36.0" -bevy_egui = "0.39.0" +bevy_egui = "0.39.1" bevy_mod_debugdump = "0.15.0" serde_json = "1.0" diff --git a/bevy_rapier3d/Cargo.toml b/bevy_rapier3d/Cargo.toml index 6616acf7..ba9cc46d 100644 --- a/bevy_rapier3d/Cargo.toml +++ b/bevy_rapier3d/Cargo.toml @@ -65,15 +65,15 @@ async-collider = [ to-bevy-mesh = ["bevy/bevy_render", "bevy/bevy_asset"] [dependencies] -bevy = { version = "0.18.0", default-features = false, features = ["std"] } -nalgebra = { version = "0.34.1", features = ["convert-glam030"] } -rapier3d = "0.31.0" +bevy = { version = "0.18.1", default-features = false, features = ["std"] } +nalgebra = { version = "0.34.2", features = ["convert-glam030"] } +rapier3d = "0.32.0" bitflags = "2.10.0" log = "0.4" serde = { version = "1", features = ["derive"], optional = true } [dev-dependencies] -bevy = { version = "0.18.0", default-features = false, features = [ +bevy = { version = "0.18.1", default-features = false, features = [ "bevy_window", "x11", "tonemapping_luts", @@ -88,7 +88,7 @@ bevy = { version = "0.18.0", default-features = false, features = [ approx = "0.5.1" glam = { version = "0.30.9", features = ["approx"] } bevy-inspector-egui = "0.36.0" -bevy_egui = "0.39.0" +bevy_egui = "0.39.1" bevy_mod_debugdump = "0.15.0" [package.metadata.docs.rs] diff --git a/bevy_rapier3d/examples/voxels3.rs b/bevy_rapier3d/examples/voxels3.rs index 5ce534e5..0c09291f 100644 --- a/bevy_rapier3d/examples/voxels3.rs +++ b/bevy_rapier3d/examples/voxels3.rs @@ -1,6 +1,6 @@ use bevy::prelude::*; use bevy_rapier3d::prelude::*; -use rapier3d::math::Isometry; +use rapier3d::math::Pose; fn main() { App::new() @@ -58,7 +58,7 @@ pub fn setup_physics(mut commands: Commands) { } let collider = Collider::voxels_from_points(voxel_size, &samples); let ground_position = Vec3::new(voxel_size.x / 2f32, 0.0, voxel_size.z / 2f32); - let floor_aabb = collider.raw.compute_aabb(&Isometry::identity()); + let floor_aabb = collider.raw.compute_aabb(&Pose::IDENTITY); commands.spawn((Transform::from_translation(ground_position), collider)); /* diff --git a/bevy_rapier_benches3d/Cargo.toml b/bevy_rapier_benches3d/Cargo.toml index 390b09d2..20a92089 100644 --- a/bevy_rapier_benches3d/Cargo.toml +++ b/bevy_rapier_benches3d/Cargo.toml @@ -9,9 +9,9 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -rapier3d = "0.31.0" +rapier3d = "0.32.0" bevy_rapier3d = { version = "0.33", path = "../bevy_rapier3d" } -bevy = { version = "0.18.0", default-features = false } +bevy = { version = "0.18.1", default-features = false } [dev-dependencies] divan = "0.1" diff --git a/ci/Cargo.toml b/ci/Cargo.toml index 425c467b..430ca038 100644 --- a/ci/Cargo.toml +++ b/ci/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" edition = "2021" [dependencies] -bevy = "0.18.0" +bevy = "0.18.1" bevy_rapier3d = { version = "0.33", path = "../bevy_rapier3d" } bevy_rapier2d = { version = "0.33", path = "../bevy_rapier2d" } diff --git a/src/control/character_controller.rs b/src/control/character_controller.rs index 7d76c206..c51241bf 100644 --- a/src/control/character_controller.rs +++ b/src/control/character_controller.rs @@ -40,13 +40,13 @@ impl CharacterCollision { RapierContextColliders::collider_entity_with_set(colliders, c.handle).map(|entity| { CharacterCollision { entity, - character_translation: c.character_pos.translation.vector.into(), + character_translation: c.character_pos.translation, #[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.into(), - translation_remaining: c.translation_remaining.into(), + character_rotation: c.character_pos.rotation, + translation_applied: c.translation_applied, + translation_remaining: c.translation_remaining, hit: ShapeCastHit::from_rapier(c.hit, details_always_computed), } }) @@ -93,7 +93,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, @@ -167,8 +167,12 @@ impl KinematicCharacterController { include_dynamic_bodies: autostep.include_dynamic_bodies, }); + if self.up.length_squared() < 1.0e-12 { + return None; + } + Some(rapier::control::KinematicCharacterController { - up: self.up.try_into().ok()?, + up: self.up.normalize(), offset: self.offset, slide: self.slide, autostep, @@ -187,7 +191,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, diff --git a/src/dynamics/generic_joint.rs b/src/dynamics/generic_joint.rs index 833dbc72..ec58c309 100644 --- a/src/dynamics/generic_joint.rs +++ b/src/dynamics/generic_joint.rs @@ -55,18 +55,18 @@ impl GenericJoint { #[cfg(feature = "dim2")] return self.raw.local_frame1.rotation.angle(); #[cfg(feature = "dim3")] - return self.raw.local_frame1.rotation.into(); + return self.raw.local_frame1.rotation; } /// Sets the joint’s frame, expressed in the first rigid-body’s local-space. pub fn set_local_basis1(&mut self, local_basis: Rot) -> &mut Self { #[cfg(feature = "dim2")] { - self.raw.local_frame1.rotation = na::UnitComplex::new(local_basis); + self.raw.local_frame1.rotation = rapier::math::Rot2::new(local_basis); } #[cfg(feature = "dim3")] { - self.raw.local_frame1.rotation = local_basis.into(); + self.raw.local_frame1.rotation = local_basis; } self } @@ -77,18 +77,18 @@ impl GenericJoint { #[cfg(feature = "dim2")] return self.raw.local_frame2.rotation.angle(); #[cfg(feature = "dim3")] - return self.raw.local_frame2.rotation.into(); + return self.raw.local_frame2.rotation; } /// Sets the joint’s frame, expressed in the second rigid-body’s local-space. pub fn set_local_basis2(&mut self, local_basis: Rot) -> &mut Self { #[cfg(feature = "dim2")] { - self.raw.local_frame2.rotation = na::UnitComplex::new(local_basis); + self.raw.local_frame2.rotation = rapier::math::Rot2::new(local_basis); } #[cfg(feature = "dim3")] { - self.raw.local_frame2.rotation = local_basis.into(); + self.raw.local_frame2.rotation = local_basis; } self } @@ -96,48 +96,48 @@ impl GenericJoint { /// The principal (local X) axis of this joint, expressed in the first rigid-body’s local-space. #[must_use] pub fn local_axis1(&self) -> Vect { - (*self.raw.local_axis1()).into() + self.raw.local_axis1() } /// Sets the principal (local X) axis of this joint, expressed in the first rigid-body’s local-space. pub fn set_local_axis1(&mut self, local_axis: Vect) -> &mut Self { - self.raw.set_local_axis1(local_axis.try_into().unwrap()); + self.raw.set_local_axis1(local_axis.normalize()); self } /// The principal (local X) axis of this joint, expressed in the second rigid-body’s local-space. #[must_use] pub fn local_axis2(&self) -> Vect { - (*self.raw.local_axis2()).into() + self.raw.local_axis2() } /// Sets the principal (local X) axis of this joint, expressed in the second rigid-body’s local-space. pub fn set_local_axis2(&mut self, local_axis: Vect) -> &mut Self { - self.raw.set_local_axis2(local_axis.try_into().unwrap()); + self.raw.set_local_axis2(local_axis.normalize()); self } /// The anchor of this joint, expressed in the first rigid-body’s local-space. #[must_use] pub fn local_anchor1(&self) -> Vect { - self.raw.local_anchor1().into() + self.raw.local_anchor1() } /// Sets anchor of this joint, expressed in the first rigid-body’s local-space. pub fn set_local_anchor1(&mut self, anchor1: Vect) -> &mut Self { - self.raw.set_local_anchor1(anchor1.into()); + self.raw.set_local_anchor1(anchor1); self } /// The anchor of this joint, expressed in the second rigid-body’s local-space. #[must_use] pub fn local_anchor2(&self) -> Vect { - self.raw.local_anchor2().into() + self.raw.local_anchor2() } /// Sets anchor of this joint, expressed in the second rigid-body’s local-space. pub fn set_local_anchor2(&mut self, anchor2: Vect) -> &mut Self { - self.raw.set_local_anchor2(anchor2.into()); + self.raw.set_local_anchor2(anchor2); self } diff --git a/src/dynamics/rigid_body.rs b/src/dynamics/rigid_body.rs index 87ff4f4b..221a998b 100644 --- a/src/dynamics/rigid_body.rs +++ b/src/dynamics/rigid_body.rs @@ -1,7 +1,7 @@ use crate::math::Vect; use bevy::prelude::*; use rapier::prelude::{ - Isometry, LockedAxes as RapierLockedAxes, RigidBodyActivation, RigidBodyHandle, RigidBodyType, + LockedAxes as RapierLockedAxes, Pose, RigidBodyActivation, RigidBodyHandle, RigidBodyType, }; use std::ops::{Add, AddAssign, Sub, SubAssign}; @@ -244,7 +244,7 @@ impl MassProperties { #[cfg(feature = "dim2")] pub fn into_rapier(self) -> rapier::dynamics::MassProperties { rapier::dynamics::MassProperties::new( - self.local_center_of_mass.into(), + self.local_center_of_mass, self.mass, #[allow(clippy::useless_conversion)] // Need to convert if dim3 enabled self.principal_inertia.into(), @@ -255,10 +255,10 @@ impl MassProperties { #[cfg(feature = "dim3")] pub fn into_rapier(self) -> rapier::dynamics::MassProperties { rapier::dynamics::MassProperties::with_principal_inertia_frame( - self.local_center_of_mass.into(), + self.local_center_of_mass, self.mass, - self.principal_inertia.into(), - self.principal_inertia_local_frame.into(), + self.principal_inertia, + self.principal_inertia_local_frame, ) } @@ -588,16 +588,16 @@ impl Default for Damping { #[derive(Copy, Clone, Debug, Default, PartialEq, Component)] pub struct TransformInterpolation { /// The starting point of the interpolation. - pub start: Option>, + pub start: Option, /// The end point of the interpolation. - pub end: Option>, + pub end: Option, } impl TransformInterpolation { /// Interpolates between the start and end positions with `t` in the range `[0..1]`. - pub fn lerp_slerp(&self, t: f32) -> Option> { + pub fn lerp_slerp(&self, t: f32) -> Option { if let (Some(start), Some(end)) = (self.start, self.end) { - Some(start.lerp_slerp(&end, t)) + Some(start.lerp(&end, t)) } else { None } diff --git a/src/geometry/collider_impl.rs b/src/geometry/collider_impl.rs index c3ef018a..a1d3383b 100644 --- a/src/geometry/collider_impl.rs +++ b/src/geometry/collider_impl.rs @@ -1,5 +1,3 @@ -#[cfg(feature = "dim2")] -use na::DVector; #[cfg(all(feature = "dim3", feature = "async-collider"))] use { bevy::mesh::{Indices, VertexAttributeValues}, @@ -8,7 +6,7 @@ use { use rapier::{ parry::transformation::voxelization::FillMode, - prelude::{FeatureId, Point, Ray, SharedShape, Vector, Voxels, DIM}, + prelude::{FeatureId, Ray, SharedShape, Vector, Voxels, DIM}, }; use super::{get_snapped_scale, shape_views::*}; @@ -37,7 +35,7 @@ impl Collider { pub fn compound(shapes: Vec<(Vect, Rot, Collider)>) -> Self { let shapes = shapes .into_iter() - .map(|(t, r, s)| ((t, r).into(), s.raw)) + .map(|(t, r, s)| (crate::utils::pose_from(t, r), s.raw)) .collect(); SharedShape::compound(shapes).into() } @@ -50,9 +48,11 @@ impl Collider { /// Initialize a new collider build with a half-space shape defined by the outward normal /// of its planar boundary. pub fn halfspace(outward_normal: Vect) -> Option { - use rapier::na::Unit; let normal = Vector::from(outward_normal); - Unit::try_new(normal, 1.0e-6).map(|n| SharedShape::halfspace(n).into()) + if normal.length_squared() < 1.0e-12 { + return None; + } + Some(SharedShape::halfspace(normal.normalize()).into()) } /// Initialize a new collider with a cylindrical shape defined by its half-height @@ -100,25 +100,25 @@ impl Collider { /// Initialize a new collider with a capsule shape. pub fn capsule(start: Vect, end: Vect, radius: Real) -> Self { - SharedShape::capsule(start.into(), end.into(), radius).into() + SharedShape::capsule(start, end, radius).into() } /// Initialize a new collider with a capsule shape aligned with the `x` axis. pub fn capsule_x(half_height: Real, radius: Real) -> Self { - let p = Point::from(Vector::x() * half_height); + let p = Vector::X * half_height; SharedShape::capsule(-p, p, radius).into() } /// Initialize a new collider with a capsule shape aligned with the `y` axis. pub fn capsule_y(half_height: Real, radius: Real) -> Self { - let p = Point::from(Vector::y() * half_height); + let p = Vector::Y * half_height; SharedShape::capsule(-p, p, radius).into() } /// Initialize a new collider with a capsule shape aligned with the `z` axis. #[cfg(feature = "dim3")] pub fn capsule_z(half_height: Real, radius: Real) -> Self { - let p = Point::from(Vector::z() * half_height); + let p = Vector::Z * half_height; SharedShape::capsule(-p, p, radius).into() } @@ -137,41 +137,25 @@ impl Collider { /// Initializes a collider with a segment shape. pub fn segment(a: Vect, b: Vect) -> Self { - SharedShape::segment(a.into(), b.into()).into() + SharedShape::segment(a, b).into() } /// Initializes a collider with a triangle shape. pub fn triangle(a: Vect, b: Vect, c: Vect) -> Self { - SharedShape::triangle(a.into(), b.into(), c.into()).into() + SharedShape::triangle(a, b, c).into() } /// Initializes a collider with a triangle shape with round corners. pub fn round_triangle(a: Vect, b: Vect, c: Vect, border_radius: Real) -> Self { - SharedShape::round_triangle(a.into(), b.into(), c.into(), border_radius).into() + SharedShape::round_triangle(a, b, c, border_radius).into() } - fn ivec_array_from_point_int_array(points: &[IVect]) -> Vec> { - points - .iter() - .map(|p| { - #[cfg(feature = "dim3")] - return Point::new(p.x, p.y, p.z); - #[cfg(feature = "dim2")] - return Point::new(p.x, p.y); - }) - .collect::>() + fn ivec_array_from_point_int_array(points: &[IVect]) -> Vec { + points.to_vec() } - fn vec_array_from_point_float_array(points: &[Vect]) -> Vec> { - points - .iter() - .map(|p| { - #[cfg(feature = "dim3")] - return Point::new(p.x, p.y, p.z); - #[cfg(feature = "dim2")] - return Point::new(p.x, p.y); - }) - .collect::>() + fn vec_array_from_point_float_array(points: &[Vect]) -> Vec { + points.to_vec() } /// Initializes a shape made of voxels. @@ -185,7 +169,7 @@ impl Collider { /// [`Self::voxelized_convex_decomposition`]. pub fn voxels(voxel_size: Vect, grid_coordinates: &[IVect]) -> Self { let shape = Voxels::new( - voxel_size.into(), + voxel_size, &Self::ivec_array_from_point_int_array(grid_coordinates), ); SharedShape::new(shape).into() @@ -196,11 +180,8 @@ impl Collider { /// Each voxel has the size `voxel_size` and contains at least one point from `centers`. /// The `primitive_geometry` controls the behavior of collision detection at voxels boundaries. pub fn voxels_from_points(voxel_size: Vect, points: &[Vect]) -> Self { - SharedShape::voxels_from_points( - voxel_size.into(), - &Self::vec_array_from_point_float_array(points), - ) - .into() + SharedShape::voxels_from_points(voxel_size, &Self::vec_array_from_point_float_array(points)) + .into() } /// Initializes a voxels shape obtained from the decomposition of the given trimesh (in 3D) @@ -244,7 +225,7 @@ impl Collider { /// Initializes a collider with a polyline shape defined by its vertex and index buffers. pub fn polyline(vertices: Vec, indices: Option>) -> Self { - let vertices = vertices.into_iter().map(|v| v.into()).collect(); + let vertices = vertices.into_iter().collect(); SharedShape::polyline(vertices, indices).into() } @@ -253,7 +234,7 @@ impl Collider { vertices: Vec, indices: Vec<[u32; 3]>, ) -> Result { - let vertices = vertices.into_iter().map(|v| v.into()).collect(); + let vertices = vertices.into_iter().collect(); Ok(SharedShape::trimesh(vertices, indices)?.into()) } @@ -264,7 +245,7 @@ impl Collider { indices: Vec<[u32; 3]>, flags: TriMeshFlags, ) -> Result { - let vertices = vertices.into_iter().map(|v| v.into()).collect(); + let vertices = vertices.into_iter().collect(); Ok(SharedShape::trimesh_with_flags(vertices, indices, flags)?.into()) } @@ -293,7 +274,7 @@ impl Collider { /// Initializes a collider with a compound shape obtained from the decomposition of /// the given trimesh (in 3D) or polyline (in 2D) into convex parts. pub fn convex_decomposition(vertices: &[Vect], indices: &[[u32; DIM]]) -> Self { - let vertices: Vec<_> = vertices.iter().map(|v| (*v).into()).collect(); + let vertices: Vec<_> = vertices.to_vec(); SharedShape::convex_decomposition(&vertices, indices).into() } @@ -304,7 +285,7 @@ impl Collider { indices: &[[u32; DIM]], border_radius: Real, ) -> Self { - let vertices: Vec<_> = vertices.iter().map(|v| (*v).into()).collect(); + let vertices: Vec<_> = vertices.to_vec(); SharedShape::round_convex_decomposition(&vertices, indices, border_radius).into() } @@ -315,7 +296,7 @@ impl Collider { indices: &[[u32; DIM]], params: &VHACDParameters, ) -> Self { - let vertices: Vec<_> = vertices.iter().map(|v| (*v).into()).collect(); + let vertices: Vec<_> = vertices.to_vec(); SharedShape::convex_decomposition_with_params(&vertices, indices, params).into() } @@ -327,7 +308,7 @@ impl Collider { params: &VHACDParameters, border_radius: Real, ) -> Self { - let vertices: Vec<_> = vertices.iter().map(|v| (*v).into()).collect(); + let vertices: Vec<_> = vertices.to_vec(); SharedShape::round_convex_decomposition_with_params( &vertices, indices, @@ -340,7 +321,7 @@ impl Collider { /// Initializes a new collider with a 2D convex polygon or 3D convex polyhedron /// obtained after computing the convex-hull of the given points. pub fn convex_hull(points: &[Vect]) -> Option { - let points: Vec<_> = points.iter().map(|v| (*v).into()).collect(); + let points: Vec<_> = points.to_vec(); SharedShape::convex_hull(&points).map(Into::into) } @@ -348,7 +329,7 @@ impl Collider { /// obtained after computing the convex-hull of the given points. The shape is dilated /// by a sphere of radius `border_radius`. pub fn round_convex_hull(points: &[Vect], border_radius: Real) -> Option { - let points: Vec<_> = points.iter().map(|v| (*v).into()).collect(); + let points: Vec<_> = points.to_vec(); SharedShape::round_convex_hull(&points, border_radius).map(Into::into) } @@ -357,7 +338,6 @@ impl Collider { /// computed). #[cfg(feature = "dim2")] pub fn convex_polyline(points: Vec) -> Option { - let points = points.into_iter().map(|v| v.into()).collect(); SharedShape::convex_polyline(points).map(Into::into) } @@ -366,7 +346,6 @@ impl Collider { /// computed). The polygon shape is dilated by a sphere of radius `border_radius`. #[cfg(feature = "dim2")] pub fn round_convex_polyline(points: Vec, border_radius: Real) -> Option { - let points = points.into_iter().map(|v| v.into()).collect(); SharedShape::round_convex_polyline(points, border_radius).map(Into::into) } @@ -375,7 +354,7 @@ impl Collider { /// computed). #[cfg(feature = "dim3")] pub fn convex_mesh(points: Vec, indices: &[[u32; 3]]) -> Option { - let points = points.into_iter().map(|v| v.into()).collect(); + let points = points.into_iter().collect(); SharedShape::convex_mesh(points, indices).map(Into::into) } @@ -388,7 +367,7 @@ impl Collider { indices: &[[u32; 3]], border_radius: Real, ) -> Option { - let points = points.into_iter().map(|v| v.into()).collect(); + let points = points.into_iter().collect(); SharedShape::round_convex_mesh(points, indices, border_radius).map(Into::into) } @@ -396,7 +375,7 @@ impl Collider { /// factor along each coordinate axis. #[cfg(feature = "dim2")] pub fn heightfield(heights: Vec, scale: Vect) -> Self { - SharedShape::heightfield(DVector::from_vec(heights), scale.into()).into() + SharedShape::heightfield(heights, scale).into() } /// Initializes a collider with a heightfield shape defined by its set of height (in @@ -408,8 +387,8 @@ impl Collider { num_rows * num_cols, "Invalid number of heights provided." ); - let heights = rapier::na::DMatrix::from_vec(num_rows, num_cols, heights); - SharedShape::heightfield(heights, scale.into()).into() + let heights = rapier::parry::utils::Array2::new(num_rows, num_cols, heights); + SharedShape::heightfield(heights, scale).into() } /// Takes a strongly typed reference of this collider. @@ -671,7 +650,7 @@ impl Collider { max_dist: Real, ) -> Option { self.raw - .project_local_point_with_max_dist(&point.into(), solid, max_dist) + .project_local_point_with_max_dist(point, solid, max_dist) .map(Into::into) } @@ -684,9 +663,9 @@ impl Collider { solid: bool, max_dist: Real, ) -> Option { - let pos = (translation, rotation).into(); + let pos = crate::utils::pose_from(translation, rotation); self.raw - .project_point_with_max_dist(&pos, &point.into(), solid, max_dist) + .project_point_with_max_dist(&pos, point, solid, max_dist) .map(Into::into) } @@ -694,24 +673,24 @@ impl Collider { /// /// The point is assumed to be expressed in the local-space of `self`. pub fn project_local_point(&self, point: Vect, solid: bool) -> PointProjection { - self.raw.project_local_point(&point.into(), solid).into() + self.raw.project_local_point(point, solid).into() } /// Projects a point on the boundary of `self` and returns the id of the /// feature the point was projected on. pub fn project_local_point_and_get_feature(&self, point: Vect) -> (PointProjection, FeatureId) { - let (proj, feat) = self.raw.project_local_point_and_get_feature(&point.into()); + let (proj, feat) = self.raw.project_local_point_and_get_feature(point); (proj.into(), feat) } /// Computes the minimal distance between a point and `self`. pub fn distance_to_local_point(&self, point: Vect, solid: bool) -> Real { - self.raw.distance_to_local_point(&point.into(), solid) + self.raw.distance_to_local_point(point, solid) } /// Tests if the given point is inside of `self`. pub fn contains_local_point(&self, point: Vect) -> bool { - self.raw.contains_local_point(&point.into()) + self.raw.contains_local_point(point) } /// Projects a point on `self` transformed by `m`. @@ -722,8 +701,8 @@ impl Collider { point: Vect, solid: bool, ) -> PointProjection { - let pos = (translation, rotation).into(); - self.raw.project_point(&pos, &point.into(), solid).into() + let pos = crate::utils::pose_from(translation, rotation); + self.raw.project_point(&pos, point, solid).into() } /// Computes the minimal distance between a point and `self` transformed by `m`. @@ -735,8 +714,8 @@ impl Collider { point: Vect, solid: bool, ) -> Real { - let pos = (translation, rotation).into(); - self.raw.distance_to_point(&pos, &point.into(), solid) + let pos = crate::utils::pose_from(translation, rotation); + self.raw.distance_to_point(&pos, point, solid) } /// Projects a point on the boundary of `self` transformed by `m` and returns the id of the @@ -747,15 +726,15 @@ impl Collider { rotation: Rot, point: Vect, ) -> (PointProjection, FeatureId) { - let pos = (translation, rotation).into(); - let (proj, feat) = self.raw.project_point_and_get_feature(&pos, &point.into()); + let pos = crate::utils::pose_from(translation, rotation); + let (proj, feat) = self.raw.project_point_and_get_feature(&pos, point); (proj.into(), feat) } /// Tests if the given point is inside of `self` transformed by `m`. pub fn contains_point(&self, translation: Vect, rotation: Rot, point: Vect) -> bool { - let pos = (translation, rotation).into(); - self.raw.contains_point(&pos, &point.into()) + let pos = crate::utils::pose_from(translation, rotation); + self.raw.contains_point(&pos, point) } /// Computes the time of impact between this transform shape and a ray. @@ -766,7 +745,7 @@ impl Collider { max_time_of_impact: Real, solid: bool, ) -> Option { - let ray = Ray::new(ray_origin.into(), ray_dir.into()); + let ray = Ray::new(ray_origin, ray_dir); self.raw.cast_local_ray(&ray, max_time_of_impact, solid) } @@ -778,7 +757,7 @@ impl Collider { max_time_of_impact: Real, solid: bool, ) -> Option { - let ray = Ray::new(ray_origin.into(), ray_dir.into()); + let ray = Ray::new(ray_origin, ray_dir); self.raw .cast_local_ray_and_get_normal(&ray, max_time_of_impact, solid) .map(|inter| RayIntersection::from_rapier(inter, ray_origin, ray_dir)) @@ -791,7 +770,7 @@ impl Collider { ray_dir: Vect, max_time_of_impact: Real, ) -> bool { - let ray = Ray::new(ray_origin.into(), ray_dir.into()); + let ray = Ray::new(ray_origin, ray_dir); self.raw.intersects_local_ray(&ray, max_time_of_impact) } @@ -805,8 +784,8 @@ impl Collider { max_time_of_impact: Real, solid: bool, ) -> Option { - let pos = (translation, rotation).into(); - let ray = Ray::new(ray_origin.into(), ray_dir.into()); + let pos = crate::utils::pose_from(translation, rotation); + let ray = Ray::new(ray_origin, ray_dir); self.raw.cast_ray(&pos, &ray, max_time_of_impact, solid) } @@ -820,8 +799,8 @@ impl Collider { max_time_of_impact: Real, solid: bool, ) -> Option { - let pos = (translation, rotation).into(); - let ray = Ray::new(ray_origin.into(), ray_dir.into()); + let pos = crate::utils::pose_from(translation, rotation); + let ray = Ray::new(ray_origin, ray_dir); self.raw .cast_ray_and_get_normal(&pos, &ray, max_time_of_impact, solid) .map(|inter| RayIntersection::from_rapier(inter, ray_origin, ray_dir)) @@ -836,8 +815,8 @@ impl Collider { ray_dir: Vect, max_time_of_impact: Real, ) -> bool { - let pos = (translation, rotation).into(); - let ray = Ray::new(ray_origin.into(), ray_dir.into()); + let pos = crate::utils::pose_from(translation, rotation); + let ray = Ray::new(ray_origin, ray_dir); self.raw.intersects_ray(&pos, &ray, max_time_of_impact) } } @@ -850,21 +829,19 @@ impl Default for Collider { #[cfg(all(feature = "dim3", feature = "async-collider"))] #[allow(clippy::type_complexity)] -fn extract_mesh_vertices_indices(mesh: &Mesh) -> Option<(Vec>, Vec<[u32; 3]>)> { - use rapier::na::point; - +fn extract_mesh_vertices_indices(mesh: &Mesh) -> Option<(Vec, Vec<[u32; 3]>)> { let vertices = mesh.attribute(Mesh::ATTRIBUTE_POSITION)?; let indices = mesh.indices()?; - let vtx: Vec<_> = match vertices { + let vtx: Vec = match vertices { VertexAttributeValues::Float32(vtx) => Some( vtx.chunks(3) - .map(|v| point![v[0] as Real, v[1] as Real, v[2] as Real]) + .map(|v| Vector::new(v[0] as Real, v[1] as Real, v[2] as Real)) .collect(), ), VertexAttributeValues::Float32x3(vtx) => Some( vtx.iter() - .map(|v| point![v[0] as Real, v[1] as Real, v[2] as Real]) + .map(|v| Vector::new(v[0] as Real, v[1] as Real, v[2] as Real)) .collect(), ), _ => None, diff --git a/src/geometry/mod.rs b/src/geometry/mod.rs index 4a862d18..a8aab4eb 100644 --- a/src/geometry/mod.rs +++ b/src/geometry/mod.rs @@ -28,7 +28,7 @@ impl PointProjection { pub(crate) fn from_rapier(raw: rapier::parry::query::PointProjection) -> Self { Self { is_inside: raw.is_inside, - point: raw.point.into(), + point: raw.point, } } } @@ -36,7 +36,7 @@ impl From for PointProjection { fn from(projection: rapier::parry::query::PointProjection) -> PointProjection { PointProjection { is_inside: projection.is_inside, - point: projection.point.into(), + point: projection.point, } } } @@ -70,7 +70,7 @@ impl RayIntersection { Self { time_of_impact: inter.time_of_impact, point: unscaled_origin + unscaled_dir * inter.time_of_impact, - normal: inter.normal.into(), + normal: inter.normal, feature: inter.feature, } } @@ -113,10 +113,10 @@ impl ShapeCastHit { (_, ShapeCastStatus::Failed) => None, (false, ShapeCastStatus::PenetratingOrWithinTargetDist) => None, _ => Some(ShapeCastHitDetails { - witness1: hit.witness1.into(), - witness2: hit.witness2.into(), - normal1: hit.normal1.into(), - normal2: hit.normal2.into(), + witness1: hit.witness1, + witness2: hit.witness2, + normal1: hit.normal1, + normal2: hit.normal2, }), }; Self { diff --git a/src/geometry/shape_views/capsule.rs b/src/geometry/shape_views/capsule.rs index 5a5169c9..7a238a24 100644 --- a/src/geometry/shape_views/capsule.rs +++ b/src/geometry/shape_views/capsule.rs @@ -42,7 +42,11 @@ macro_rules! impl_ref_methods( /// The transformation such that `t * Y` is collinear with `b - a` and `t * origin` equals /// the capsule's center. pub fn canonical_transform(&self) -> (Vect, Rot) { - self.raw.canonical_transform().into() + let pose = self.raw.canonical_transform(); + #[cfg(feature = "dim2")] + return (pose.translation, pose.rotation.angle()); + #[cfg(feature = "dim3")] + return (pose.translation, pose.rotation); } /// The rotation `r` such that `r * Y` is collinear with `b - a`. @@ -54,12 +58,16 @@ macro_rules! impl_ref_methods( /// The rotation `r` such that `r * Y` is collinear with `b - a`. #[cfg(feature = "dim3")] pub fn rotation_wrt_y(&self) -> Rot { - self.raw.rotation_wrt_y().into() + self.raw.rotation_wrt_y() } /// The transform `t` such that `t * Y` is collinear with `b - a` and such that `t * origin = (b + a) / 2.0`. pub fn transform_wrt_y(&self) -> (Vect, Rot) { - self.raw.transform_wrt_y().into() + let pose = self.raw.transform_wrt_y(); + #[cfg(feature = "dim2")] + return (pose.translation, pose.rotation.angle()); + #[cfg(feature = "dim3")] + return (pose.translation, pose.rotation); } } } @@ -78,8 +86,8 @@ impl_ref_methods!(CapsuleViewMut); impl CapsuleViewMut<'_> { /// Set the segment of this capsule. pub fn set_segment(&mut self, start: Vect, end: Vect) { - self.raw.segment.a = start.into(); - self.raw.segment.b = end.into(); + self.raw.segment.a = start; + self.raw.segment.b = end; } /// Set the radius of this capsule. diff --git a/src/geometry/shape_views/collider_view.rs b/src/geometry/shape_views/collider_view.rs index ce7ab9ec..8617f271 100644 --- a/src/geometry/shape_views/collider_view.rs +++ b/src/geometry/shape_views/collider_view.rs @@ -256,12 +256,12 @@ impl<'a> ColliderView<'a> { /// Compute the scaled version of `self.raw`. pub fn raw_scale_by(&self, scale: Vect, num_subdivisions: u32) -> Option { let result = match self { - ColliderView::Cuboid(s) => SharedShape::new(s.raw.scaled(&scale.into())), + ColliderView::Cuboid(s) => SharedShape::new(s.raw.scaled(scale)), ColliderView::RoundCuboid(s) => SharedShape::new(RoundShape { border_radius: s.raw.border_radius, - inner_shape: s.raw.inner_shape.scaled(&scale.into()), + inner_shape: s.raw.inner_shape.scaled(scale), }), - ColliderView::Capsule(c) => match c.raw.scaled(&scale.into(), num_subdivisions) { + ColliderView::Capsule(c) => match c.raw.scaled(scale, num_subdivisions) { None => { log::error!("Failed to apply scale {scale} to Capsule shape."); SharedShape::ball(0.0) @@ -269,7 +269,7 @@ impl<'a> ColliderView<'a> { Some(Either::Left(b)) => SharedShape::new(b), Some(Either::Right(b)) => SharedShape::new(b), }, - ColliderView::Ball(b) => match b.raw.scaled(&scale.into(), num_subdivisions) { + ColliderView::Ball(b) => match b.raw.scaled(scale, num_subdivisions) { None => { log::error!("Failed to apply scale {scale} to Ball shape."); SharedShape::ball(0.0) @@ -277,25 +277,25 @@ impl<'a> ColliderView<'a> { Some(Either::Left(b)) => SharedShape::new(b), Some(Either::Right(b)) => SharedShape::new(b), }, - ColliderView::Segment(s) => SharedShape::new(s.raw.scaled(&scale.into())), - ColliderView::Triangle(t) => SharedShape::new(t.raw.scaled(&scale.into())), - ColliderView::Voxels(cp) => SharedShape::new(cp.raw.clone().scaled(&scale.into())), + ColliderView::Segment(s) => SharedShape::new(s.raw.scaled(scale)), + ColliderView::Triangle(t) => SharedShape::new(t.raw.scaled(scale)), + ColliderView::Voxels(cp) => SharedShape::new(cp.raw.clone().scaled(scale)), ColliderView::RoundTriangle(t) => SharedShape::new(RoundShape { border_radius: t.raw.border_radius, - inner_shape: t.raw.inner_shape.scaled(&scale.into()), + inner_shape: t.raw.inner_shape.scaled(scale), }), - ColliderView::TriMesh(t) => SharedShape::new(t.raw.clone().scaled(&scale.into())), - ColliderView::Polyline(p) => SharedShape::new(p.raw.clone().scaled(&scale.into())), - ColliderView::HalfSpace(h) => match h.raw.scaled(&scale.into()) { + ColliderView::TriMesh(t) => SharedShape::new(t.raw.clone().scaled(scale)), + ColliderView::Polyline(p) => SharedShape::new(p.raw.clone().scaled(scale)), + ColliderView::HalfSpace(h) => match h.raw.scaled(scale) { None => { log::error!("Failed to apply scale {scale} to HalfSpace shape."); SharedShape::ball(0.0) } Some(scaled) => SharedShape::new(scaled), }, - ColliderView::HeightField(h) => SharedShape::new(h.raw.clone().scaled(&scale.into())), + ColliderView::HeightField(h) => SharedShape::new(h.raw.clone().scaled(scale)), #[cfg(feature = "dim2")] - ColliderView::ConvexPolygon(cp) => match cp.raw.clone().scaled(&scale.into()) { + ColliderView::ConvexPolygon(cp) => match cp.raw.clone().scaled(scale) { None => { log::error!("Failed to apply scale {scale} to ConvexPolygon shape."); SharedShape::ball(0.0) @@ -304,7 +304,7 @@ impl<'a> ColliderView<'a> { }, #[cfg(feature = "dim2")] ColliderView::RoundConvexPolygon(cp) => { - match cp.raw.inner_shape.clone().scaled(&scale.into()) { + match cp.raw.inner_shape.clone().scaled(scale) { None => { log::error!("Failed to apply scale {scale} to RoundConvexPolygon shape."); SharedShape::ball(0.0) @@ -316,7 +316,7 @@ impl<'a> ColliderView<'a> { } } #[cfg(feature = "dim3")] - ColliderView::ConvexPolyhedron(cp) => match cp.raw.clone().scaled(&scale.into()) { + ColliderView::ConvexPolyhedron(cp) => match cp.raw.clone().scaled(scale) { None => { log::error!("Failed to apply scale {scale} to ConvexPolyhedron shape."); SharedShape::ball(0.0) @@ -325,7 +325,7 @@ impl<'a> ColliderView<'a> { }, #[cfg(feature = "dim3")] ColliderView::RoundConvexPolyhedron(cp) => { - match cp.raw.clone().inner_shape.scaled(&scale.into()) { + match cp.raw.clone().inner_shape.scaled(scale) { None => { log::error!( "Failed to apply scale {scale} to RoundConvexPolyhedron shape." @@ -339,7 +339,7 @@ impl<'a> ColliderView<'a> { } } #[cfg(feature = "dim3")] - ColliderView::Cylinder(c) => match c.raw.scaled(&scale.into(), num_subdivisions) { + ColliderView::Cylinder(c) => match c.raw.scaled(scale, num_subdivisions) { None => { log::error!("Failed to apply scale {scale} to Cylinder shape."); SharedShape::ball(0.0) @@ -349,7 +349,7 @@ impl<'a> ColliderView<'a> { }, #[cfg(feature = "dim3")] ColliderView::RoundCylinder(c) => { - match c.raw.inner_shape.scaled(&scale.into(), num_subdivisions) { + match c.raw.inner_shape.scaled(scale, num_subdivisions) { None => { log::error!("Failed to apply scale {scale} to RoundCylinder shape."); SharedShape::ball(0.0) @@ -365,7 +365,7 @@ impl<'a> ColliderView<'a> { } } #[cfg(feature = "dim3")] - ColliderView::Cone(c) => match c.raw.scaled(&scale.into(), num_subdivisions) { + ColliderView::Cone(c) => match c.raw.scaled(scale, num_subdivisions) { None => { log::error!("Failed to apply scale {scale} to Cone shape."); SharedShape::ball(0.0) @@ -374,28 +374,26 @@ impl<'a> ColliderView<'a> { Some(Either::Right(b)) => SharedShape::new(b), }, #[cfg(feature = "dim3")] - ColliderView::RoundCone(c) => { - match c.raw.inner_shape.scaled(&scale.into(), num_subdivisions) { - None => { - log::error!("Failed to apply scale {scale} to RoundCone shape."); - SharedShape::ball(0.0) - } - Some(Either::Left(scaled)) => SharedShape::new(RoundShape { - border_radius: c.raw.border_radius, - inner_shape: scaled, - }), - Some(Either::Right(scaled)) => SharedShape::new(RoundShape { - border_radius: c.raw.border_radius, - inner_shape: scaled, - }), + ColliderView::RoundCone(c) => match c.raw.inner_shape.scaled(scale, num_subdivisions) { + None => { + log::error!("Failed to apply scale {scale} to RoundCone shape."); + SharedShape::ball(0.0) } - } + Some(Either::Left(scaled)) => SharedShape::new(RoundShape { + border_radius: c.raw.border_radius, + inner_shape: scaled, + }), + Some(Either::Right(scaled)) => SharedShape::new(RoundShape { + border_radius: c.raw.border_radius, + inner_shape: scaled, + }), + }, ColliderView::Compound(c) => { let mut scaled = Vec::with_capacity(c.shapes().len()); for (tra, rot, shape) in c.shapes() { scaled.push(( - (tra * scale, rot).into(), + crate::utils::pose_from(tra * scale, rot), shape.raw_scale_by(scale, num_subdivisions)?, )); } diff --git a/src/geometry/shape_views/compound.rs b/src/geometry/shape_views/compound.rs index 2f0a47b3..90f9c56b 100644 --- a/src/geometry/shape_views/compound.rs +++ b/src/geometry/shape_views/compound.rs @@ -14,8 +14,11 @@ impl CompoundView<'_> { #[inline] pub fn shapes(&self) -> impl ExactSizeIterator)> { self.raw.shapes().iter().map(|(pos, shape)| { - let (tra, rot) = (*pos).into(); - (tra, rot, shape.as_typed_shape().into()) + #[cfg(feature = "dim2")] + let rot = pos.rotation.angle(); + #[cfg(feature = "dim3")] + let rot = pos.rotation; + (pos.translation, rot, shape.as_typed_shape().into()) }) } } diff --git a/src/geometry/shape_views/convex_polygon.rs b/src/geometry/shape_views/convex_polygon.rs index 06c084ca..b03d4f70 100644 --- a/src/geometry/shape_views/convex_polygon.rs +++ b/src/geometry/shape_views/convex_polygon.rs @@ -11,12 +11,12 @@ pub struct ConvexPolygonView<'a> { impl ConvexPolygonView<'_> { /// The vertices of this convex polygon. pub fn points(&self) -> impl ExactSizeIterator + '_ { - self.raw.points().iter().map(|pt| (*pt).into()) + self.raw.points().iter().copied() } /// The normals of the edges of this convex polygon. pub fn normals(&self) -> impl ExactSizeIterator + '_ { - self.raw.normals().iter().map(|n| (**n).into()) + self.raw.normals().iter().copied() } } @@ -29,12 +29,12 @@ pub struct ConvexPolygonViewMut<'a> { impl ConvexPolygonViewMut<'_> { /// The vertices of this convex polygon. pub fn points(&self) -> impl ExactSizeIterator + '_ { - self.raw.points().iter().map(|pt| (*pt).into()) + self.raw.points().iter().copied() } /// The normals of the edges of this convex polygon. pub fn normals(&self) -> impl ExactSizeIterator + '_ { - self.raw.normals().iter().map(|n| (**n).into()) + self.raw.normals().iter().copied() } // TODO: add modifications. diff --git a/src/geometry/shape_views/convex_polyhedron.rs b/src/geometry/shape_views/convex_polyhedron.rs index 48a39ad9..a354b6f8 100644 --- a/src/geometry/shape_views/convex_polyhedron.rs +++ b/src/geometry/shape_views/convex_polyhedron.rs @@ -11,7 +11,7 @@ pub struct ConvexPolyhedronView<'a> { impl ConvexPolyhedronView<'_> { /// The vertices of this convex polygon. pub fn points(&self) -> impl ExactSizeIterator + '_ { - self.raw.points().iter().map(|pt| (*pt).into()) + self.raw.points().iter().copied() } // TODO: add retrieval of topology information. @@ -26,7 +26,7 @@ pub struct ConvexPolyhedronViewMut<'a> { impl ConvexPolyhedronViewMut<'_> { /// The vertices of this convex polygon. pub fn points(&self) -> impl ExactSizeIterator + '_ { - self.raw.points().iter().map(|pt| (*pt).into()) + self.raw.points().iter().copied() } // TODO: add retrieval of topology information and modification. diff --git a/src/geometry/shape_views/cuboid.rs b/src/geometry/shape_views/cuboid.rs index 058b03d8..523da39b 100644 --- a/src/geometry/shape_views/cuboid.rs +++ b/src/geometry/shape_views/cuboid.rs @@ -32,6 +32,6 @@ impl_ref_methods!(CuboidViewMut); impl CuboidViewMut<'_> { /// Set the half-extents of the cuboid. pub fn set_half_extents(&mut self, half_extents: Vect) { - self.raw.half_extents = half_extents.into(); + self.raw.half_extents = half_extents; } } diff --git a/src/geometry/shape_views/halfspace.rs b/src/geometry/shape_views/halfspace.rs index 864e61da..4ddce2b6 100644 --- a/src/geometry/shape_views/halfspace.rs +++ b/src/geometry/shape_views/halfspace.rs @@ -13,7 +13,7 @@ macro_rules! impl_ref_methods( impl<'a> $View<'a> { /// The halfspace planar boundary's outward normal. pub fn normal(&self) -> Vect { - (*self.raw.normal).into() + self.raw.normal } } } @@ -32,9 +32,9 @@ impl_ref_methods!(HalfSpaceViewMut); impl HalfSpaceViewMut<'_> { /// Set the normal of the half-space. pub fn set_normal(&mut self, normal: Vect) { - let normal: rapier::math::Vector<_> = normal.into(); - if let Some(unit_normal) = na::Unit::try_new(normal, 1.0e-6) { - self.raw.normal = unit_normal; + let normal: rapier::math::Vector = normal; + if normal.length_squared() >= 1.0e-12 { + self.raw.normal = normal.normalize(); } } } diff --git a/src/geometry/shape_views/heightfield.rs b/src/geometry/shape_views/heightfield.rs index 4f9a4fe7..d9e4bb91 100644 --- a/src/geometry/shape_views/heightfield.rs +++ b/src/geometry/shape_views/heightfield.rs @@ -25,7 +25,7 @@ macro_rules! impl_ref_methods( /// The scale factor applied to this heightfield. pub fn scale(&self) -> Vect { - (*self.raw.scale()).into() + self.raw.scale() } /// The width of a single cell of this heightfield. @@ -40,19 +40,17 @@ macro_rules! impl_ref_methods( /// Index of the cell a point is on after vertical projection. pub fn cell_at_point(&self, point: Vect) -> Option { - self.raw.cell_at_point(&point.into()) + self.raw.cell_at_point(point) } /// Iterator through all the segments of this heightfield. pub fn segments(&self) -> impl Iterator + '_ { - self.raw.segments().map(|seg| (seg.a.into(), seg.b.into())) + self.raw.segments().map(|seg| (seg.a, seg.b)) } /// The i-th segment of the heightfield if it has not been removed. pub fn segment_at(&self, i: usize) -> Option<(Vect, Vect)> { - self.raw - .segment_at(i) - .map(|seg| (seg.a.into(), seg.b.into())) + self.raw.segment_at(i).map(|seg| (seg.a, seg.b)) } /// Is the i-th segment of this heightfield removed? @@ -75,12 +73,12 @@ macro_rules! impl_ref_methods( /// The height at each cell endpoint. pub fn heights(&self) -> &[Real] { - self.raw.heights().as_slice() + self.raw.heights().data() } /// The scale factor applied to this heightfield. pub fn scale(&self) -> Vect { - (*self.raw.scale()).into() + self.raw.scale() } /// The width (extent along its local `x` axis) of each cell of this heightmap, including the scale factor. @@ -105,14 +103,12 @@ macro_rules! impl_ref_methods( /// Index of the cell a point is on after vertical projection. pub fn cell_at_point(&self, point: Vect) -> Option<(usize, usize)> { - self.raw.cell_at_point(&point.into()) + self.raw.cell_at_point(point) } /// Iterator through all the triangles of this heightfield. pub fn triangles(&self) -> impl Iterator + '_ { - self.raw - .triangles() - .map(|tri| (tri.a.into(), tri.b.into(), tri.c.into())) + self.raw.triangles().map(|tri| (tri.a, tri.b, tri.c)) } /// The two triangles at the cell (i, j) of this heightfield. @@ -126,8 +122,8 @@ macro_rules! impl_ref_methods( ) -> (Option<(Vect, Vect, Vect)>, Option<(Vect, Vect, Vect)>) { let (tri1, tri2) = self.raw.triangles_at(i, j); ( - tri1.map(|tri| (tri.a.into(), tri.b.into(), tri.c.into())), - tri2.map(|tri| (tri.a.into(), tri.b.into(), tri.c.into())), + tri1.map(|tri| (tri.a, tri.b, tri.c)), + tri2.map(|tri| (tri.a, tri.b, tri.c)), ) } @@ -138,7 +134,7 @@ macro_rules! impl_ref_methods( /// The statuses of all the cells of this heightfield, in column-major order. pub fn cells_statuses(&self) -> &[HeightFieldCellStatus] { - self.raw.cells_statuses().as_slice() + self.raw.cells_statuses().data() } } } @@ -171,6 +167,6 @@ impl HeightFieldViewMut<'_> { /// The mutable statuses of all the cells of this heightfield. pub fn cells_statuses_mut(&mut self) -> &mut [HeightFieldCellStatus] { - self.raw.cells_statuses_mut().as_mut_slice() + self.raw.cells_statuses_mut().data_mut() } } diff --git a/src/geometry/shape_views/segment.rs b/src/geometry/shape_views/segment.rs index 338990af..33b4c0eb 100644 --- a/src/geometry/shape_views/segment.rs +++ b/src/geometry/shape_views/segment.rs @@ -38,39 +38,39 @@ macro_rules! impl_ref_methods( /// Points from `self.a()` toward `self.b()`. /// Returns `None` is both points are equal. pub fn direction(&self) -> Option { - self.raw.direction().map(|dir| (*dir).into()) + self.raw.direction() } /// In 2D, the not-normalized counterclockwise normal of this segment. #[cfg(feature = "dim2")] pub fn scaled_normal(&self) -> Vect { - self.raw.scaled_normal().into() + self.raw.scaled_normal() } /// The not-normalized counterclockwise normal of this segment, assuming it lies on the plane /// with the normal collinear to the given axis (0 = X, 1 = Y, 2 = Z). #[cfg(feature = "dim3")] pub fn scaled_planar_normal(&self, plane_axis: u8) -> Vect { - self.raw.scaled_planar_normal(plane_axis).into() + self.raw.scaled_planar_normal(plane_axis) } /// In 2D, the normalized counterclockwise normal of this segment. #[cfg(feature = "dim2")] pub fn normal(&self) -> Option { - self.raw.normal().map(|n| (*n).into()) + self.raw.normal() } /// Returns `None`. Exists only for API similarity with the 2D parry. #[cfg(feature = "dim3")] pub fn normal(&self) -> Option { - self.raw.normal().map(|n| (*n).into()) + self.raw.normal() } /// The normalized counterclockwise normal of this segment, assuming it lies on the plane /// with the normal collinear to the given axis (0 = X, 1 = Y, 2 = Z). #[cfg(feature = "dim3")] pub fn planar_normal(&self, plane_axis: u8) -> Option { - self.raw.planar_normal(plane_axis).map(|n| (*n).into()) + self.raw.planar_normal(plane_axis) } } } @@ -89,11 +89,11 @@ impl_ref_methods!(SegmentViewMut); impl SegmentViewMut<'_> { /// Set the first point of the segment. pub fn set_a(&mut self, a: Vect) { - self.raw.a = a.into(); + self.raw.a = a; } /// Set the second point of the segment. pub fn set_b(&mut self, b: Vect) { - self.raw.b = b.into(); + self.raw.b = b; } } diff --git a/src/geometry/shape_views/triangle.rs b/src/geometry/shape_views/triangle.rs index 242a3c82..619a66c3 100644 --- a/src/geometry/shape_views/triangle.rs +++ b/src/geometry/shape_views/triangle.rs @@ -40,7 +40,7 @@ macro_rules! impl_ref_methods( #[cfg(feature = "dim3")] #[inline] pub fn normal(&self) -> Option { - self.raw.normal().map(|n| (*n).into()) + self.raw.normal() } /// A vector normal of this triangle. @@ -93,16 +93,16 @@ impl_ref_methods!(TriangleViewMut); impl TriangleViewMut<'_> { /// Set the first point of the segment. pub fn set_a(&mut self, a: Vect) { - self.raw.a = a.into(); + self.raw.a = a; } /// Set the second point of the segment. pub fn set_b(&mut self, b: Vect) { - self.raw.b = b.into(); + self.raw.b = b; } /// Set the third point of the segment. pub fn set_c(&mut self, c: Vect) { - self.raw.c = c.into(); + self.raw.c = c; } } diff --git a/src/geometry/shape_views/voxels.rs b/src/geometry/shape_views/voxels.rs index e12d0342..986e7c23 100644 --- a/src/geometry/shape_views/voxels.rs +++ b/src/geometry/shape_views/voxels.rs @@ -7,10 +7,25 @@ use bevy::math::bounding::Aabb2d as BevyAabb; #[cfg(feature = "dim3")] use bevy::math::bounding::Aabb3d as BevyAabb; +#[cfg(feature = "dim2")] +fn aabb_na_from_bevy(aabb: &BevyAabb) -> Aabb { + rapier::parry::bounding_volume::Aabb::new(aabb.min, aabb.max) +} + +#[cfg(feature = "dim3")] fn aabb_na_from_bevy(aabb: &BevyAabb) -> Aabb { rapier::parry::bounding_volume::Aabb::new(aabb.min.into(), aabb.max.into()) } +#[cfg(feature = "dim2")] +fn aabb_bevy_from_na(aabb: &Aabb) -> BevyAabb { + BevyAabb { + min: aabb.mins, + max: aabb.maxs, + } +} + +#[cfg(feature = "dim3")] fn aabb_bevy_from_na(aabb: &Aabb) -> BevyAabb { BevyAabb { min: aabb.mins.into(), @@ -41,12 +56,12 @@ macro_rules! impl_ref_methods( /// Shortcut to [`Voxels::local_aabb`]. pub fn extents(&self) -> Vect { - self.raw.local_aabb().extents().into() + self.raw.local_aabb().extents() } /// Shortcut to [`Voxels::local_aabb`]. pub fn domain_center(&self) -> Vect { - self.raw.local_aabb().center().coords.into() + self.raw.local_aabb().center() } /// Shortcut to [`Voxels::domain`]. @@ -79,15 +94,7 @@ macro_rules! impl_ref_methods( /// Shortcut to [`Voxels::voxel_at_point`]. pub fn voxel_at_point_unchecked(&self, point: Vect) -> IVect { - let p = self.raw.voxel_at_point(point.into()); - #[cfg(feature = "dim2")] - { - IVect::new(p.x, p.y) - } - #[cfg(feature = "dim3")] - { - IVect::new(p.x, p.y, p.z) - } + self.raw.voxel_at_point(point) } /// Shortcut to [`Voxels::voxel_at_point`]. @@ -184,7 +191,7 @@ impl<'a> VoxelsViewMut<'a> { /// Shortcut to set voxel state with bounds checking. pub fn try_set_voxel(&mut self, key: IVect, is_filled: bool) -> Option { if self.is_voxel_in_bounds(key) { - Some(self.raw.set_voxel(key.into(), is_filled)) + Some(self.raw.set_voxel(key, is_filled)) } else { None } @@ -192,11 +199,11 @@ impl<'a> VoxelsViewMut<'a> { /// Shortcut to to [`Voxels::set_voxel`]. pub fn set_voxel(&mut self, key: IVect, is_filled: bool) -> VoxelState { - self.raw.set_voxel(key.into(), is_filled) + self.raw.set_voxel(key, is_filled) } /// Shortcut to [`Voxels::crop`]. pub fn crop(&mut self, domain_mins: IVect, domain_maxs: IVect) { - self.raw.crop(domain_mins.into(), domain_maxs.into()); + self.raw.crop(domain_mins, domain_maxs); } } diff --git a/src/geometry/to_bevy_mesh.rs b/src/geometry/to_bevy_mesh.rs index 5ad2ec6e..edf679cb 100644 --- a/src/geometry/to_bevy_mesh.rs +++ b/src/geometry/to_bevy_mesh.rs @@ -45,9 +45,9 @@ pub fn typed_shape_to_mesh(typed_shape: &TypedShape) -> Option { } TypedShape::Triangle(triangle) => { // FIXME: bevy 0.16 will expose a builder for triangles: https://github.com/bevyengine/bevy/pull/17454 - let a = triangle.a.coords; - let b = triangle.b.coords; - let c = triangle.c.coords; + let a = triangle.a; + let b = triangle.b; + let c = triangle.c; #[cfg(feature = "dim2")] let mesh = bevy::prelude::Triangle3d::new( bevy::prelude::Vec3::new(a.x, a.y, 0.0), @@ -55,7 +55,7 @@ pub fn typed_shape_to_mesh(typed_shape: &TypedShape) -> Option { bevy::prelude::Vec3::new(c.x, c.y, 0.0), ); #[cfg(feature = "dim3")] - let mesh = bevy::prelude::Triangle3d::new(a.into(), b.into(), c.into()); + let mesh = bevy::prelude::Triangle3d::new(a, b, c); mesh.into() } @@ -272,7 +272,7 @@ impl ToMeshBuilder for &rapier3d::prelude::HalfSpace { fn mesh_builder(&self) -> Self::MeshBuilder { PlaneMeshBuilder::new( - bevy::prelude::Dir3::new(self.normal.into()).unwrap_or(bevy::prelude::Dir3::Y), + bevy::prelude::Dir3::new(self.normal).unwrap_or(bevy::prelude::Dir3::Y), bevy::prelude::Vec2::ONE, ) } diff --git a/src/pipeline/events.rs b/src/pipeline/events.rs index e587a6c9..0a7a26ec 100644 --- a/src/pipeline/events.rs +++ b/src/pipeline/events.rs @@ -112,9 +112,9 @@ impl EventHandler for EventQueue<'_> { let event = ContactForceEvent { collider1: self.collider2entity(colliders, rapier_event.collider1), collider2: self.collider2entity(colliders, rapier_event.collider2), - total_force: rapier_event.total_force.into(), + total_force: rapier_event.total_force, total_force_magnitude: rapier_event.total_force_magnitude, - max_force_direction: rapier_event.max_force_direction.into(), + max_force_direction: rapier_event.max_force_direction, max_force_magnitude: rapier_event.max_force_magnitude, }; diff --git a/src/plugin/context/mod.rs b/src/plugin/context/mod.rs index aadd35e1..69dc4949 100644 --- a/src/plugin/context/mod.rs +++ b/src/plugin/context/mod.rs @@ -309,7 +309,7 @@ impl<'a> RapierQueryPipeline<'a> { max_toi: Real, solid: bool, ) -> Option<(Entity, Real)> { - let ray = Ray::new(ray_origin.into(), ray_dir.into()); + let ray = Ray::new(ray_origin, ray_dir); let (h, toi) = self.query_pipeline.cast_ray(&ray, max_toi, solid)?; @@ -333,7 +333,7 @@ impl<'a> RapierQueryPipeline<'a> { max_toi: Real, solid: bool, ) -> Option<(Entity, RayIntersection)> { - let ray = Ray::new(ray_origin.into(), ray_dir.into()); + let ray = Ray::new(ray_origin, ray_dir); let (h, result) = self .query_pipeline @@ -363,7 +363,7 @@ impl<'a> RapierQueryPipeline<'a> { max_toi: Real, solid: bool, ) -> impl Iterator + 'a { - let ray = Ray::new(ray_origin.into(), ray_dir.into()); + let ray = Ray::new(ray_origin, ray_dir); self.query_pipeline.intersect_ray(ray, max_toi, solid).map( move |(collider_handle, _, intersection)| { @@ -386,7 +386,7 @@ impl<'a> RapierQueryPipeline<'a> { shape_rot: Rot, shape: &'a dyn Shape, ) -> impl Iterator + 'a { - let scaled_transform = (shape_pos, shape_rot).into(); + let scaled_transform = crate::utils::pose_from(shape_pos, shape_rot); self.query_pipeline .intersect_shape(scaled_transform, shape) @@ -408,9 +408,7 @@ impl<'a> RapierQueryPipeline<'a> { max_dist: Real, solid: bool, ) -> Option<(Entity, PointProjection)> { - let (h, result) = self - .query_pipeline - .project_point(&point.into(), max_dist, solid)?; + let (h, result) = self.query_pipeline.project_point(point, max_dist, solid)?; Some(( self.collider_entity(h), @@ -424,7 +422,7 @@ impl<'a> RapierQueryPipeline<'a> { /// * `point` - The point used for the containment test. pub fn intersect_point(&'a self, point: Vect) -> impl Iterator + 'a { self.query_pipeline - .intersect_point(point.into()) + .intersect_point(point) .map(move |(collider_handle, _)| self.collider_entity(collider_handle)) } @@ -443,9 +441,7 @@ impl<'a> RapierQueryPipeline<'a> { &self, point: Vect, ) -> Option<(Entity, PointProjection, FeatureId)> { - let (h, proj, fid) = self - .query_pipeline - .project_point_and_get_feature(&point.into())?; + let (h, proj, fid) = self.query_pipeline.project_point_and_get_feature(point)?; Some(( self.collider_entity(h), @@ -463,6 +459,12 @@ impl<'a> RapierQueryPipeline<'a> { #[cfg(feature = "dim2")] aabb: bevy::math::bounding::Aabb2d, #[cfg(feature = "dim3")] aabb: bevy::math::bounding::Aabb3d, ) -> impl Iterator + 'a { + #[cfg(feature = "dim2")] + let scaled_aabb = Aabb { + mins: aabb.min, + maxs: aabb.max, + }; + #[cfg(feature = "dim3")] let scaled_aabb = Aabb { mins: aabb.min.into(), maxs: aabb.max.into(), @@ -501,11 +503,11 @@ impl<'a> RapierQueryPipeline<'a> { shape: &dyn Shape, options: ShapeCastOptions, ) -> Option<(Entity, ShapeCastHit)> { - let scaled_transform = (shape_pos, shape_rot).into(); + let scaled_transform = crate::utils::pose_from(shape_pos, shape_rot); let (h, result) = self.query_pipeline - .cast_shape(&scaled_transform, &shape_vel.into(), shape, options)?; + .cast_shape(&scaled_transform, shape_vel, shape, options)?; Some(( self.collider_entity(h), @@ -759,7 +761,7 @@ impl RapierContextSimulation { for _ in 0..substeps { self.pipeline.step( - &gravity.into(), + gravity, &substep_integration_parameters, &mut self.islands, &mut self.broad_phase, @@ -790,7 +792,7 @@ impl RapierContextSimulation { for _ in 0..substeps { self.pipeline.step( - &gravity.into(), + gravity, &substep_integration_parameters, &mut self.islands, &mut self.broad_phase, @@ -814,7 +816,7 @@ impl RapierContextSimulation { for _ in 0..substeps { self.pipeline.step( - &gravity.into(), + gravity, &substep_integration_parameters, &mut self.islands, &mut self.broad_phase, @@ -883,10 +885,11 @@ impl RapierContextSimulation { options: &MoveShapeOptions, mut events: impl FnMut(CharacterCollision), ) -> MoveShapeOutput { - let up = options - .up - .try_into() - .expect("The up vector must be non-zero."); + assert!( + options.up.length_squared() > 0.0, + "The up vector must be non-zero." + ); + let up = options.up.normalize(); let autostep = options.autostep.map(|autostep| CharacterAutostep { max_height: autostep.max_height, min_width: autostep.min_width, @@ -916,8 +919,8 @@ impl RapierContextSimulation { dt, &rapier_query_pipeline.query_pipeline.as_ref(), shape, - &(shape_translation, shape_rotation).into(), - movement.into(), + &crate::utils::pose_from(shape_translation, shape_rotation), + movement, |c| { if let Some(collision) = CharacterCollision::from_raw_with_set(colliders, &c, true) { @@ -938,7 +941,7 @@ impl RapierContextSimulation { }; MoveShapeOutput { - effective_translation: result.translation.into(), + effective_translation: result.translation, grounded: result.grounded, is_sliding_down_slope: result.is_sliding_down_slope, } diff --git a/src/plugin/narrow_phase.rs b/src/plugin/narrow_phase.rs index f37ea577..4870360c 100644 --- a/src/plugin/narrow_phase.rs +++ b/src/plugin/narrow_phase.rs @@ -155,12 +155,12 @@ impl ContactManifoldView<'_> { /// The contact normal of all the contacts of this manifold, expressed in the local space of the first shape. pub fn local_n1(&self) -> Vect { - self.raw.local_n1.into() + self.raw.local_n1 } /// The contact normal of all the contacts of this manifold, expressed in the local space of the second shape. pub fn local_n2(&self) -> Vect { - self.raw.local_n2.into() + self.raw.local_n2 } /// The first subshape involved in this contact manifold. @@ -200,7 +200,7 @@ impl ContactManifoldView<'_> { /// The world-space contact normal shared by all the contact in this contact manifold. pub fn normal(&self) -> Vect { - self.raw.data.normal.into() + self.raw.data.normal } /// The contacts that will be seen by the constraints solver for computing forces. @@ -255,12 +255,12 @@ pub struct ContactView<'a> { impl ContactView<'_> { /// The contact point in the local-space of the first shape. pub fn local_p1(&self) -> Vect { - self.raw.local_p1.into() + self.raw.local_p1 } /// The contact point in the local-space of the second shape. pub fn local_p2(&self) -> Vect { - self.raw.local_p2.into() + self.raw.local_p2 } /// The distance between the two contact points. @@ -309,7 +309,7 @@ pub struct SolverContactView<'a> { impl SolverContactView<'_> { /// The world-space contact point. pub fn point(&self) -> Vect { - self.raw.point.into() + self.raw.point } /// The distance between the two original contacts points along the contact normal. /// If negative, this is measures the penetration depth. @@ -329,7 +329,7 @@ impl SolverContactView<'_> { /// This is set to zero by default. Set to a non-zero value to /// simulate, e.g., conveyor belts. pub fn tangent_velocity(&self) -> Vect { - self.raw.tangent_velocity.into() + self.raw.tangent_velocity } /// Whether or not this contact existed during the last timestep. pub fn is_new(&self) -> bool { @@ -379,7 +379,7 @@ impl ContactPairView<'_> { /// Is there any active contact in this contact pair? pub fn has_any_active_contact(&self) -> bool { - self.raw.has_any_active_contact + self.raw.has_any_active_contact() } /// Finds the contact with the smallest signed distance. diff --git a/src/plugin/systems/character_controller.rs b/src/plugin/systems/character_controller.rs index 9d10f9e0..f722c589 100644 --- a/src/plugin/systems/character_controller.rs +++ b/src/plugin/systems/character_controller.rs @@ -11,8 +11,7 @@ use crate::prelude::KinematicCharacterController; use crate::prelude::KinematicCharacterControllerOutput; use crate::utils; use bevy::prelude::*; -use rapier::math::Isometry; -use rapier::math::Real; +use rapier::math::Pose; use rapier::parry::query::DefaultQueryDispatcher; use rapier::pipeline::QueryFilter; @@ -83,7 +82,7 @@ pub fn update_character_controls( let (character_shape, character_pos) = if let Some((scaled_shape, tra, rot)) = &scaled_custom_shape { - let mut shape_pos: Isometry = (*tra, *rot).into(); + let mut shape_pos: Pose = utils::pose_from(*tra, *rot); if let Some(body) = body_handle.and_then(|h| rigidbody_set.bodies.get(h.0)) { shape_pos = body.position() * shape_pos @@ -142,7 +141,7 @@ pub fn update_character_controls( &query_pipeline.as_ref(), &*character_shape, &character_pos, - translation.into(), + translation, |c| collisions.push(c), ); @@ -173,7 +172,7 @@ pub fn update_character_controls( if let Some(mut output) = output { output.desired_translation = controller.translation.unwrap(); - output.effective_translation = movement.translation.into(); + output.effective_translation = movement.translation; output.grounded = movement.grounded; output.collisions.clear(); output.collisions.extend(converted_collisions); @@ -183,7 +182,7 @@ pub fn update_character_controls( .entity(entity) .insert(KinematicCharacterControllerOutput { desired_translation: controller.translation.unwrap(), - effective_translation: movement.translation.into(), + effective_translation: movement.translation, grounded: movement.grounded, collisions: converted_collisions.collect(), is_sliding_down_slope: movement.is_sliding_down_slope, diff --git a/src/plugin/systems/rigid_body.rs b/src/plugin/systems/rigid_body.rs index e5401d8b..646549fc 100644 --- a/src/plugin/systems/rigid_body.rs +++ b/src/plugin/systems/rigid_body.rs @@ -264,7 +264,7 @@ pub fn apply_rigid_body_user_changes( .expect(RAPIER_CONTEXT_EXPECT_ERROR) .into_inner(); if let Some(rb) = rigidbody_set.bodies.get_mut(handle.0) { - rb.set_linvel(velocity.linvel.into(), true); + rb.set_linvel(velocity.linvel, true); #[allow(clippy::useless_conversion)] // Need to convert if dim3 enabled rb.set_angvel(velocity.angvel.into(), true); } @@ -317,7 +317,7 @@ pub fn apply_rigid_body_user_changes( if let Some(rb) = rigidbody_set.bodies.get_mut(handle.0) { rb.reset_forces(true); rb.reset_torques(true); - rb.add_force(forces.force.into(), true); + rb.add_force(forces.force, true); #[allow(clippy::useless_conversion)] // Need to convert if dim3 enabled rb.add_torque(forces.torque.into(), true); } @@ -329,7 +329,7 @@ pub fn apply_rigid_body_user_changes( .expect(RAPIER_CONTEXT_EXPECT_ERROR) .into_inner(); if let Some(rb) = rigidbody_set.bodies.get_mut(handle.0) { - rb.apply_impulse(impulses.impulse.into(), true); + rb.apply_impulse(impulses.impulse, true); #[allow(clippy::useless_conversion)] // Need to convert if dim3 enabled rb.apply_torque_impulse(impulses.torque_impulse.into(), true); impulses.reset(); @@ -532,9 +532,9 @@ pub fn writeback_rigid_bodies( if let Some(velocity) = &mut velocity { let new_vel = Velocity { - linvel: (*rb.linvel()).into(), + linvel: rb.linvel(), #[cfg(feature = "dim3")] - angvel: (*rb.angvel()).into(), + angvel: rb.angvel(), #[cfg(feature = "dim2")] angvel: rb.angvel(), }; @@ -719,7 +719,7 @@ pub fn apply_initial_rigid_body_impulses( // Make sure the mass-properties are computed. rb.recompute_mass_properties_from_colliders(&context_colliders.colliders); // Apply the impulse. - rb.apply_impulse(impulse.impulse.into(), false); + rb.apply_impulse(impulse.impulse, false); #[allow(clippy::useless_conversion)] // Need to convert if dim3 enabled rb.apply_torque_impulse(impulse.torque_impulse.into(), false); diff --git a/src/render/mod.rs b/src/render/mod.rs index 1b2fdce5..26aa110a 100644 --- a/src/render/mod.rs +++ b/src/render/mod.rs @@ -3,7 +3,7 @@ use crate::plugin::context::{ }; use bevy::prelude::*; use bevy::transform::TransformSystems; -use rapier::math::{Point, Real}; +use rapier::math::Vector; use rapier::pipeline::{DebugRenderBackend, DebugRenderObject, DebugRenderPipeline}; pub use rapier::pipeline::{DebugRenderMode, DebugRenderStyle}; use std::fmt::Debug; @@ -175,13 +175,7 @@ impl<'world, 'state, 'world2, 'state2, 'a, 'c, 'd, 'v, 'p> DebugRenderBackend for BevyLinesRenderBackend<'world, 'state, 'world2, 'state2, 'a, 'c, 'd, 'v, 'p> { #[cfg(feature = "dim2")] - fn draw_line( - &mut self, - object: DebugRenderObject, - a: Point, - b: Point, - color: [f32; 4], - ) { + fn draw_line(&mut self, object: DebugRenderObject, a: Vector, b: Vector, color: [f32; 4]) { if !self.drawing_enabled(object) { return; } @@ -195,13 +189,7 @@ impl<'world, 'state, 'world2, 'state2, 'a, 'c, 'd, 'v, 'p> DebugRenderBackend } #[cfg(feature = "dim3")] - fn draw_line( - &mut self, - object: DebugRenderObject, - a: Point, - b: Point, - color: [f32; 4], - ) { + fn draw_line(&mut self, object: DebugRenderObject, a: Vector, b: Vector, color: [f32; 4]) { if !self.drawing_enabled(object) { return; } diff --git a/src/utils/mod.rs b/src/utils/mod.rs index 19b970f6..0efd2abb 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -1,40 +1,53 @@ +use crate::math::{Rot, Vect}; use bevy::prelude::Transform; -use rapier::math::{Isometry, Real}; +use rapier::math::Pose; -/// Converts a Rapier isometry to a Bevy transform. +/// Builds a Rapier [`Pose`] from a translation/rotation pair using bevy_rapier's [`Vect`] / [`Rot`] aliases. #[cfg(feature = "dim2")] -pub fn iso_to_transform(iso: &Isometry) -> Transform { +pub(crate) fn pose_from(translation: Vect, rotation: Rot) -> Pose { + Pose::new(translation, rotation) +} + +/// Builds a Rapier [`Pose`] from a translation/rotation pair using bevy_rapier's [`Vect`] / [`Rot`] aliases. +#[cfg(feature = "dim3")] +pub(crate) fn pose_from(translation: Vect, rotation: Rot) -> Pose { + Pose::from_parts(translation, rotation) +} + +/// Converts a Rapier pose to a Bevy transform. +#[cfg(feature = "dim2")] +pub fn iso_to_transform(iso: &Pose) -> Transform { Transform { - translation: iso.translation.vector.push(0.0).into(), + translation: iso.translation.extend(0.0), rotation: bevy::prelude::Quat::from_rotation_z(iso.rotation.angle()), ..Default::default() } } -/// Converts a Rapier isometry to a Bevy transform. +/// Converts a Rapier pose to a Bevy transform. #[cfg(feature = "dim3")] -pub fn iso_to_transform(iso: &Isometry) -> Transform { +pub fn iso_to_transform(iso: &Pose) -> Transform { Transform { - translation: iso.translation.vector.into(), - rotation: iso.rotation.into(), + translation: iso.translation, + rotation: iso.rotation, ..Default::default() } } -/// Converts a Bevy transform to a Rapier isometry. +/// Converts a Bevy transform to a Rapier pose. #[cfg(feature = "dim2")] -pub(crate) fn transform_to_iso(transform: &Transform) -> Isometry { +pub(crate) fn transform_to_iso(transform: &Transform) -> Pose { use bevy::math::Vec3Swizzles; - Isometry::new( - transform.translation.xy().into(), + Pose::new( + transform.translation.xy(), transform.rotation.to_scaled_axis().z, ) } -/// Converts a Bevy transform to a Rapier isometry. +/// Converts a Bevy transform to a Rapier pose. #[cfg(feature = "dim3")] -pub(crate) fn transform_to_iso(transform: &Transform) -> Isometry { - Isometry::from_parts(transform.translation.into(), transform.rotation.into()) +pub(crate) fn transform_to_iso(transform: &Transform) -> Pose { + Pose::from_parts(transform.translation, transform.rotation) } #[cfg(test)]