From 0b21f15bb623c30a9adc3bde59175c7d8431802a Mon Sep 17 00:00:00 2001 From: Aceeri Date: Thu, 24 Aug 2023 17:54:30 -0700 Subject: [PATCH 1/2] Update bitflags to 2.4 --- bevy_rapier2d/Cargo.toml | 2 +- bevy_rapier3d/Cargo.toml | 4 +-- src/dynamics/rigid_body.rs | 14 ++++++---- src/geometry/collider.rs | 56 ++++++++++++++++++++++---------------- 4 files changed, 43 insertions(+), 33 deletions(-) diff --git a/bevy_rapier2d/Cargo.toml b/bevy_rapier2d/Cargo.toml index a691f05a..f72a84ce 100644 --- a/bevy_rapier2d/Cargo.toml +++ b/bevy_rapier2d/Cargo.toml @@ -36,7 +36,7 @@ bevy = { version = "0.11", default-features = false } nalgebra = { version = "0.32.3", features = [ "convert-glam024" ] } # Don't enable the default features because we don't need the ColliderSet/RigidBodySet rapier2d = "0.17.0" -bitflags = "1" +bitflags = "2.4" #bevy_prototype_debug_lines = { version = "0.6", optional = true } log = "0.4" serde = { version = "1", features = [ "derive" ], optional = true} diff --git a/bevy_rapier3d/Cargo.toml b/bevy_rapier3d/Cargo.toml index 1082f501..6f7cd941 100644 --- a/bevy_rapier3d/Cargo.toml +++ b/bevy_rapier3d/Cargo.toml @@ -36,8 +36,8 @@ async-collider = [ "bevy/bevy_asset", "bevy/bevy_scene" ] bevy = { version = "0.11", default-features = false } nalgebra = { version = "0.32.3", features = [ "convert-glam024" ] } # Don't enable the default features because we don't need the ColliderSet/RigidBodySet -rapier3d = "0.17.0" -bitflags = "1" +rapier3d = "0.17" +bitflags = "2.4" #bevy_prototype_debug_lines = { version = "0.6", features = ["3d"], optional = true } log = "0.4" serde = { version = "1", features = [ "derive" ], optional = true} diff --git a/src/dynamics/rigid_body.rs b/src/dynamics/rigid_body.rs index f2be60ec..61b89c80 100644 --- a/src/dynamics/rigid_body.rs +++ b/src/dynamics/rigid_body.rs @@ -239,11 +239,13 @@ impl MassProperties { } } +#[derive(Default, Component, Reflect, Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash)] +#[reflect(Component, PartialEq)] +/// Flags affecting the behavior of the constraints solver for a given contact manifold. +pub struct LockedAxes(u8); + bitflags::bitflags! { - #[derive(Default, Component, Reflect)] - #[reflect(Component, PartialEq)] - /// Flags affecting the behavior of the constraints solver for a given contact manifold. - pub struct LockedAxes: u8 { + impl LockedAxes: u8 { /// Flag indicating that the rigid-body cannot translate along the `X` axis. const TRANSLATION_LOCKED_X = 1 << 0; /// Flag indicating that the rigid-body cannot translate along the `Y` axis. @@ -251,7 +253,7 @@ bitflags::bitflags! { /// Flag indicating that the rigid-body cannot translate along the `Z` axis. const TRANSLATION_LOCKED_Z = 1 << 2; /// Flag indicating that the rigid-body cannot translate along any direction. - const TRANSLATION_LOCKED = Self::TRANSLATION_LOCKED_X.bits | Self::TRANSLATION_LOCKED_Y.bits | Self::TRANSLATION_LOCKED_Z.bits; + const TRANSLATION_LOCKED = Self::TRANSLATION_LOCKED_X.bits() | Self::TRANSLATION_LOCKED_Y.bits() | Self::TRANSLATION_LOCKED_Z.bits(); /// Flag indicating that the rigid-body cannot rotate along the `X` axis. const ROTATION_LOCKED_X = 1 << 3; /// Flag indicating that the rigid-body cannot rotate along the `Y` axis. @@ -259,7 +261,7 @@ bitflags::bitflags! { /// Flag indicating that the rigid-body cannot rotate along the `Z` axis. const ROTATION_LOCKED_Z = 1 << 5; /// Combination of flags indicating that the rigid-body cannot rotate along any axis. - const ROTATION_LOCKED = Self::ROTATION_LOCKED_X.bits | Self::ROTATION_LOCKED_Y.bits | Self::ROTATION_LOCKED_Z.bits; + const ROTATION_LOCKED = Self::ROTATION_LOCKED_X.bits() | Self::ROTATION_LOCKED_Y.bits() | Self::ROTATION_LOCKED_Z.bits(); } } diff --git a/src/geometry/collider.rs b/src/geometry/collider.rs index a7dd2384..4e08f484 100644 --- a/src/geometry/collider.rs +++ b/src/geometry/collider.rs @@ -206,13 +206,15 @@ impl Default for Restitution { } } +#[derive(Component, Reflect, Debug, Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash)] +#[reflect(Component, Hash, PartialEq)] +#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))] +/// Flags affecting whether or not collision-detection happens between two colliders +/// depending on the type of rigid-bodies they are attached to. +pub struct ActiveCollisionTypes(u16); + bitflags::bitflags! { - #[derive(Component, Reflect)] - #[reflect(Component, Hash, PartialEq)] - #[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))] - /// Flags affecting whether or not collision-detection happens between two colliders - /// depending on the type of rigid-bodies they are attached to. - pub struct ActiveCollisionTypes: u16 { + impl ActiveCollisionTypes: u16 { /// Enable collision-detection between a collider attached to a dynamic body /// and another collider attached to a dynamic body. const DYNAMIC_DYNAMIC = 0b0000_0000_0000_0001; @@ -245,17 +247,19 @@ impl Default for ActiveCollisionTypes { impl From for rapier::geometry::ActiveCollisionTypes { fn from(collision_types: ActiveCollisionTypes) -> rapier::geometry::ActiveCollisionTypes { - rapier::geometry::ActiveCollisionTypes::from_bits(collision_types.bits) + rapier::geometry::ActiveCollisionTypes::from_bits(collision_types.bits()) .expect("Internal error: invalid active events conversion.") } } +/// A bit mask identifying groups for interaction. +#[derive(Component, Reflect, Copy, Clone, Debug, PartialEq, Eq, Hash)] +#[reflect(Component, Hash, PartialEq)] +#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))] +pub struct Group(u32); + bitflags::bitflags! { - /// A bit mask identifying groups for interaction. - #[derive(Component, Reflect)] - #[reflect(Component, Hash, PartialEq)] - #[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))] - pub struct Group: u32 { + impl Group: u32 { /// The group n°1. const GROUP_1 = 1 << 0; /// The group n°2. @@ -410,12 +414,14 @@ impl From for InteractionGroups { } } +#[derive(Default, Component, Reflect, Debug, Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash)] +#[reflect(Component)] +#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))] +/// Flags affecting the behavior of the constraints solver for a given contact manifold. +pub struct ActiveHooks(u32); + bitflags::bitflags! { - #[derive(Default, Component, Reflect)] - #[reflect(Component)] - #[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))] - /// Flags affecting the behavior of the constraints solver for a given contact manifold. - pub struct ActiveHooks: u32 { + impl ActiveHooks: u32 { /// If set, Rapier will call `PhysicsHooks::filter_contact_pair` whenever relevant. const FILTER_CONTACT_PAIRS = 0b0001; /// If set, Rapier will call `PhysicsHooks::filter_intersection_pair` whenever relevant. @@ -427,17 +433,19 @@ bitflags::bitflags! { impl From for rapier::pipeline::ActiveHooks { fn from(active_hooks: ActiveHooks) -> rapier::pipeline::ActiveHooks { - rapier::pipeline::ActiveHooks::from_bits(active_hooks.bits) + rapier::pipeline::ActiveHooks::from_bits(active_hooks.bits()) .expect("Internal error: invalid active events conversion.") } } +#[derive(Default, Component, Reflect, Debug, Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash)] +#[reflect(Component)] +#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))] +/// Flags affecting the events generated for this collider. +pub struct ActiveEvents(u32); + bitflags::bitflags! { - #[derive(Default, Component, Reflect)] - #[reflect(Component)] - #[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))] - /// Flags affecting the events generated for this collider. - pub struct ActiveEvents: u32 { + impl ActiveEvents: u32 { /// If set, Rapier will call `EventHandler::handle_collision_event` /// whenever relevant for this collider. const COLLISION_EVENTS = 0b0001; @@ -449,7 +457,7 @@ bitflags::bitflags! { impl From for rapier::pipeline::ActiveEvents { fn from(active_events: ActiveEvents) -> rapier::pipeline::ActiveEvents { - rapier::pipeline::ActiveEvents::from_bits(active_events.bits) + rapier::pipeline::ActiveEvents::from_bits(active_events.bits()) .expect("Internal error: invalid active events conversion.") } } From cec116ea396deb2d3353bed2cce6819097a69d46 Mon Sep 17 00:00:00 2001 From: Aceeri Date: Mon, 28 Aug 2023 00:38:24 -0700 Subject: [PATCH 2/2] Formatting --- bevy_rapier3d/examples/ray_casting3.rs | 8 ++++++-- src/geometry/collider_impl.rs | 4 +++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/bevy_rapier3d/examples/ray_casting3.rs b/bevy_rapier3d/examples/ray_casting3.rs index 50a27a4c..c6068117 100644 --- a/bevy_rapier3d/examples/ray_casting3.rs +++ b/bevy_rapier3d/examples/ray_casting3.rs @@ -80,12 +80,16 @@ fn cast_ray( ) { let window = windows.single(); - let Some(cursor_position) = window.cursor_position() else { return; }; + let Some(cursor_position) = window.cursor_position() else { + return; + }; // We will color in read the colliders hovered by the mouse. for (camera, camera_transform) in &cameras { // First, compute a ray from the mouse position. - let Some(ray) = camera.viewport_to_world(camera_transform, cursor_position) else { return; }; + let Some(ray) = camera.viewport_to_world(camera_transform, cursor_position) else { + return; + }; // Then cast the ray. let hit = rapier_context.cast_ray( diff --git a/src/geometry/collider_impl.rs b/src/geometry/collider_impl.rs index f526ecd8..212a77f7 100644 --- a/src/geometry/collider_impl.rs +++ b/src/geometry/collider_impl.rs @@ -172,7 +172,9 @@ impl Collider { /// Returns `None` if the index buffer or vertex buffer of the mesh are in an incompatible format. #[cfg(all(feature = "dim3", feature = "async-collider"))] pub fn from_bevy_mesh(mesh: &Mesh, collider_shape: &ComputedColliderShape) -> Option { - let Some((vtx, idx)) = extract_mesh_vertices_indices(mesh) else { return None; }; + let Some((vtx, idx)) = extract_mesh_vertices_indices(mesh) else { + return None; + }; match collider_shape { ComputedColliderShape::TriMesh => Some( SharedShape::trimesh_with_flags(vtx, idx, TriMeshFlags::MERGE_DUPLICATE_VERTICES)