Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add bevy-components feature #248

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ resolver = "2"
#ncollide3d = { git = "https://github.com/dimforge/ncollide" }
#nphysics2d = { git = "https://github.com/dimforge/nphysics" }
#nphysics3d = { git = "https://github.com/dimforge/nphysics" }
bevy = { path="../bevy" }

[profile.release]
#debug = true
Expand Down
2 changes: 2 additions & 0 deletions build/rapier2d-f64/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ simd-is-enabled = [ "vec_map" ]
wasm-bindgen = [ "instant/wasm-bindgen" ]
serde-serialize = [ "nalgebra/serde-serialize", "parry2d-f64/serde-serialize", "serde", "bit-vec/serde", "arrayvec/serde" ]
enhanced-determinism = [ "simba/libm_force", "parry2d-f64/enhanced-determinism", "indexmap" ]
bevy-components = ["bevy", "parry2d-f64/bevy-components"]

# Feature used for debugging only.
debug-disable-legitimate-fe-exceptions = [ ]
Expand Down Expand Up @@ -61,6 +62,7 @@ indexmap = { version = "1", features = [ "serde-1" ], optional = true }
downcast-rs = "1.2"
num-derive = "0.3"
bitflags = "1"
bevy = { version = "0.5", default-features=false, optional = true }

[dev-dependencies]
bincode = "1"
Expand Down
4 changes: 3 additions & 1 deletion build/rapier2d/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ simd-is-enabled = [ "vec_map" ]
wasm-bindgen = [ "instant/wasm-bindgen" ]
serde-serialize = [ "nalgebra/serde-serialize", "parry2d/serde-serialize", "serde", "bit-vec/serde", "arrayvec/serde" ]
enhanced-determinism = [ "simba/libm_force", "parry2d/enhanced-determinism", "indexmap" ]
bevy-components = ["bevy", "parry2d/bevy-components"]

# Feature used for debugging only.
debug-disable-legitimate-fe-exceptions = [ ]
Expand Down Expand Up @@ -61,7 +62,8 @@ indexmap = { version = "1", features = [ "serde-1" ], optional = true }
downcast-rs = "1.2"
num-derive = "0.3"
bitflags = "1"
bevy = { version = "0.5", default-features=false, optional = true }

[dev-dependencies]
bincode = "1"
serde = { version = "1", features = [ "derive" ] }
serde = { version = "1", features = [ "derive" ] }
2 changes: 2 additions & 0 deletions build/rapier3d-f64/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ simd-is-enabled = [ "vec_map" ]
wasm-bindgen = [ "instant/wasm-bindgen" ]
serde-serialize = [ "nalgebra/serde-serialize", "parry3d-f64/serde-serialize", "serde", "bit-vec/serde" ]
enhanced-determinism = [ "simba/libm_force", "parry3d-f64/enhanced-determinism" ]
bevy-components = ["bevy", "parry3d-f64/bevy-components"]

# Feature used for debugging only.
debug-disable-legitimate-fe-exceptions = [ ]
Expand Down Expand Up @@ -60,6 +61,7 @@ serde = { version = "1", features = [ "derive" ], optional = true }
downcast-rs = "1.2"
num-derive = "0.3"
bitflags = "1"
bevy = { version = "0.5", default-features=false, optional = true }

[dev-dependencies]
bincode = "1"
Expand Down
3 changes: 3 additions & 0 deletions build/rapier3d/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ simd-is-enabled = [ "vec_map" ]
wasm-bindgen = [ "instant/wasm-bindgen" ]
serde-serialize = [ "nalgebra/serde-serialize", "parry3d/serde-serialize", "serde", "bit-vec/serde" ]
enhanced-determinism = [ "simba/libm_force", "parry3d/enhanced-determinism" ]
bevy-components = ["bevy", "parry3d/bevy-components"]

# Feature used for debugging only.
debug-disable-legitimate-fe-exceptions = [ ]
Expand Down Expand Up @@ -60,6 +61,8 @@ serde = { version = "1", features = [ "derive" ], optional = true }
downcast-rs = "1.2"
num-derive = "0.3"
bitflags = "1"
bevy = { version = "0.5", default-features=false, optional = true }


[dev-dependencies]
bincode = "1"
Expand Down
16 changes: 16 additions & 0 deletions src/dynamics/rigid_body_components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@ use crate::parry::partitioning::IndexedData;
use crate::utils::{WCross, WDot};
use num::Zero;

#[cfg(feature = "bevy-components")]
use bevy::prelude::Component;

/// The unique handle of a rigid body added to a `RigidBodySet`.
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "bevy-components", derive(Component))]
#[repr(transparent)]
pub struct RigidBodyHandle(pub crate::data::arena::Index);

Expand Down Expand Up @@ -51,6 +55,7 @@ pub type BodyStatus = RigidBodyType;

#[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "bevy-components", derive(Component))]
/// The status of a body, governing the way it is affected by external forces.
pub enum RigidBodyType {
/// A `RigidBodyType::Dynamic` body can be affected by all external forces.
Expand Down Expand Up @@ -95,6 +100,7 @@ impl RigidBodyType {

bitflags::bitflags! {
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "bevy-components", derive(Component))]
/// Flags describing how the rigid-body has been modified by the user.
pub struct RigidBodyChanges: u32 {
/// Flag indicating that any component of this rigid-body has been modified.
Expand All @@ -117,6 +123,7 @@ impl Default for RigidBodyChanges {
}

#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "bevy-components", derive(Component))]
#[derive(Clone, Debug, Copy, PartialEq)]
/// The position of this rigid-body.
pub struct RigidBodyPosition {
Expand Down Expand Up @@ -214,6 +221,7 @@ bitflags::bitflags! {

// TODO: split this into "LocalMassProps" and `WorldMassProps"?
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "bevy-components", derive(Component))]
#[derive(Clone, Debug, Copy, PartialEq)]
/// The mass properties of this rigid-bodies.
pub struct RigidBodyMassProps {
Expand Down Expand Up @@ -330,6 +338,7 @@ impl RigidBodyMassProps {
}

#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "bevy-components", derive(Component))]
#[derive(Clone, Debug, Copy, PartialEq)]
/// The velocities of this rigid-body.
pub struct RigidBodyVelocity {
Expand Down Expand Up @@ -470,6 +479,7 @@ impl RigidBodyVelocity {
}

#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "bevy-components", derive(Component))]
#[derive(Clone, Debug, Copy, PartialEq)]
/// Damping factors to progressively slow down a rigid-body.
pub struct RigidBodyDamping {
Expand All @@ -489,6 +499,7 @@ impl Default for RigidBodyDamping {
}

#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "bevy-components", derive(Component))]
#[derive(Clone, Debug, Copy, PartialEq)]
/// The user-defined external forces applied to this rigid-body.
pub struct RigidBodyForces {
Expand Down Expand Up @@ -549,6 +560,7 @@ impl RigidBodyForces {
}

#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "bevy-components", derive(Component))]
#[derive(Clone, Debug, Copy, PartialEq)]
/// Information used for Continuous-Collision-Detection.
pub struct RigidBodyCcd {
Expand Down Expand Up @@ -621,6 +633,7 @@ impl RigidBodyCcd {
}

#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "bevy-components", derive(Component))]
#[derive(Clone, Debug, Copy, PartialEq, Eq, Hash)]
/// Internal identifiers used by the physics engine.
pub struct RigidBodyIds {
Expand All @@ -642,6 +655,7 @@ impl Default for RigidBodyIds {
}

#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "bevy-components", derive(Component))]
#[derive(Clone, Debug, PartialEq, Eq)]
/// The set of colliders attached to this rigid-bodies.
///
Expand Down Expand Up @@ -739,6 +753,7 @@ impl RigidBodyColliders {
}

#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "bevy-components", derive(Component))]
#[derive(Clone, Debug, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
/// The dominance groups of a rigid-body.
pub struct RigidBodyDominance(pub i8);
Expand Down Expand Up @@ -766,6 +781,7 @@ impl RigidBodyDominance {
/// If the threshold is negative, the body never sleeps.
#[derive(Copy, Clone, Debug, PartialEq)]
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "bevy-components", derive(Component))]
pub struct RigidBodyActivation {
/// The threshold pseudo-kinetic energy bellow which the body can fall asleep.
pub threshold: Real,
Expand Down
11 changes: 11 additions & 0 deletions src/geometry/collider_components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ use crate::math::{Isometry, Real};
use crate::parry::partitioning::IndexedData;
use crate::pipeline::{ActiveEvents, ActiveHooks};
use std::ops::{Deref, DerefMut};
#[cfg(feature = "bevy-components")]
use bevy::prelude::Component;

/// The unique identifier of a collider added to a collider set.
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "bevy-components", derive(Component))]
#[repr(transparent)]
pub struct ColliderHandle(pub crate::data::arena::Index);

Expand Down Expand Up @@ -43,6 +46,7 @@ impl IndexedData for ColliderHandle {

bitflags::bitflags! {
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "bevy-components", derive(Component))]
/// Flags describing how the collider has been modified by the user.
pub struct ColliderChanges: u32 {
/// Flag indicating that any component of the collider has been modified.
Expand Down Expand Up @@ -82,6 +86,7 @@ impl ColliderChanges {

#[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "bevy-components", derive(Component))]
/// The type of collider.
pub enum ColliderType {
/// A collider that can generate contacts and contact events.
Expand All @@ -99,6 +104,7 @@ impl ColliderType {

#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "bevy-components", derive(Component))]
/// Data associated to a collider that takes part to a broad-phase algorithm.
pub struct ColliderBroadPhaseData {
pub(crate) proxy_index: SAPProxyIndex,
Expand All @@ -117,6 +123,7 @@ pub type ColliderShape = SharedShape;

#[derive(Clone, PartialEq)]
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "bevy-components", derive(Component))]
/// The mass-properties of a collider.
pub enum ColliderMassProps {
/// The collider is given a density.
Expand Down Expand Up @@ -157,6 +164,7 @@ impl ColliderMassProps {

#[derive(Copy, Clone, Debug, PartialEq)]
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "bevy-components", derive(Component))]
/// Information about the rigid-body this collider is attached to.
pub struct ColliderParent {
/// Handle of the rigid-body this collider is attached to.
Expand All @@ -167,6 +175,7 @@ pub struct ColliderParent {

#[derive(Copy, Clone, Debug, PartialEq)]
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "bevy-components", derive(Component))]
/// The position of a collider.
pub struct ColliderPosition(pub Isometry<Real>);

Expand Down Expand Up @@ -222,6 +231,7 @@ where

#[derive(Copy, Clone, Debug, PartialEq)]
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "bevy-components", derive(Component))]
/// The constraints solver-related properties of this collider (friction, restitution, etc.)
pub struct ColliderMaterial {
/// The friction coefficient of this collider.
Expand Down Expand Up @@ -343,6 +353,7 @@ impl Default for ActiveCollisionTypes {

#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "bevy-components", derive(Component))]
/// A set of flags for controlling collision/intersection filtering, modification, and events.
pub struct ColliderFlags {
/// Controls whether collision-detection happens between two colliders depending on
Expand Down