Skip to content

Commit

Permalink
Merge pull request #424 from Aceeri/bitflags-2.4
Browse files Browse the repository at this point in the history
Update bitflags to 2.4
  • Loading branch information
sebcrozet authored Sep 30, 2023
2 parents a149ff5 + cec116e commit eb6a8d7
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 36 deletions.
2 changes: 1 addition & 1 deletion bevy_rapier2d/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
4 changes: 2 additions & 2 deletions bevy_rapier3d/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
8 changes: 6 additions & 2 deletions bevy_rapier3d/examples/ray_casting3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
14 changes: 8 additions & 6 deletions src/dynamics/rigid_body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,27 +239,29 @@ 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.
const TRANSLATION_LOCKED_Y = 1 << 1;
/// 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.
const ROTATION_LOCKED_Y = 1 << 4;
/// 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();
}
}

Expand Down
56 changes: 32 additions & 24 deletions src/geometry/collider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -245,17 +247,19 @@ impl Default for ActiveCollisionTypes {

impl From<ActiveCollisionTypes> 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.
Expand Down Expand Up @@ -410,12 +414,14 @@ impl From<SolverGroups> 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.
Expand All @@ -427,17 +433,19 @@ bitflags::bitflags! {

impl From<ActiveHooks> 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;
Expand All @@ -449,7 +457,7 @@ bitflags::bitflags! {

impl From<ActiveEvents> 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.")
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/geometry/collider_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Self> {
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)
Expand Down

0 comments on commit eb6a8d7

Please sign in to comment.