diff --git a/build/nphysics2d/Cargo.toml b/build/nphysics2d/Cargo.toml index a629e03ec..b2492e22b 100644 --- a/build/nphysics2d/Cargo.toml +++ b/build/nphysics2d/Cargo.toml @@ -25,11 +25,16 @@ either = "1.0" num-traits = "0.2" slab = "0.4" alga = "0.8" -nalgebra = { version = "0.17", features = [ "sparse" ] } approx = "0.3" downcast-rs = "1.0" bitflags = "1.0" ncollide2d = "0.18" +serde = { version = "1.0", optional = true, features = ["derive"]} + +[target.'cfg(feature = "serde")'.dependencies] +nalgebra = { version = "0.17", features = [ "sparse", "serde-serialize" ] } +[target.'cfg(not(feature = "serde"))'.dependencies] +nalgebra = { version = "0.17", features = [ "sparse" ] } [target.wasm32-unknown-unknown.dependencies] stdweb = {version = "0.4", optional = true} diff --git a/build/nphysics3d/Cargo.toml b/build/nphysics3d/Cargo.toml index a066b6c9c..c12904143 100644 --- a/build/nphysics3d/Cargo.toml +++ b/build/nphysics3d/Cargo.toml @@ -25,11 +25,16 @@ either = "1.0" num-traits = "0.2" slab = "0.4" alga = "0.8" -nalgebra = { version = "0.17", features = [ "sparse" ] } approx = "0.3" downcast-rs = "1.0" bitflags = "1.0" ncollide3d = "0.18" +serde = { version = "1.0", optional = true, features = ["derive"]} + +[target.'cfg(feature = "serde")'.dependencies] +nalgebra = { version = "0.17", features = [ "sparse", "serde-serialize" ] } +[target.'cfg(not(feature = "serde"))'.dependencies] +nalgebra = { version = "0.17", features = [ "sparse" ] } [target.wasm32-unknown-unknown.dependencies] stdweb = {version = "0.4", optional = true} diff --git a/nphysics_testbed3d/src/lib.rs b/nphysics_testbed3d/src/lib.rs index 4ae68fd43..7d9ce2e0d 100644 --- a/nphysics_testbed3d/src/lib.rs +++ b/nphysics_testbed3d/src/lib.rs @@ -10,11 +10,11 @@ extern crate time; #[macro_use] extern crate log; -pub use crate::engine::GraphicsManager; -pub use crate::testbed::Testbed; -pub use world_owner::WorldOwner; - mod engine; pub mod objects; mod testbed; -mod world_owner; \ No newline at end of file +mod world_owner; + +pub use crate::engine::GraphicsManager; +pub use crate::testbed::Testbed; +pub use crate::world_owner::WorldOwner; \ No newline at end of file diff --git a/src/algebra/force2.rs b/src/algebra/force2.rs index 42adacd75..d284a4a63 100644 --- a/src/algebra/force2.rs +++ b/src/algebra/force2.rs @@ -6,6 +6,7 @@ use std::ops::{Add, AddAssign, Mul, Neg, Sub, SubAssign}; /// A force with a linear and angular (torque) component. #[repr(C)] #[derive(Copy, Clone, Debug)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct Force2 { /// The linear force. pub linear: Vector2, diff --git a/src/algebra/force3.rs b/src/algebra/force3.rs index aabf5eb4a..aef4b3687 100644 --- a/src/algebra/force3.rs +++ b/src/algebra/force3.rs @@ -6,6 +6,7 @@ use std::ops::{Add, AddAssign, Mul, Neg, Sub, SubAssign}; /// A force with a linear and angular (torque) component. #[repr(C)] #[derive(Copy, Clone, Debug)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct Force3 { /// The linear force. pub linear: Vector3, diff --git a/src/algebra/inertia3.rs b/src/algebra/inertia3.rs index 036b32902..56ee4bc98 100644 --- a/src/algebra/inertia3.rs +++ b/src/algebra/inertia3.rs @@ -5,6 +5,7 @@ use crate::algebra::{Force3, Velocity3}; /// The inertia of a rigid body grouping both its mass and its angular inertia. #[derive(Clone, Copy, Debug)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct Inertia3 { /// The linear part (mass) of the inertia. pub linear: N, diff --git a/src/algebra/velocity2.rs b/src/algebra/velocity2.rs index 64369027a..3db95e1e6 100644 --- a/src/algebra/velocity2.rs +++ b/src/algebra/velocity2.rs @@ -6,6 +6,7 @@ use std::ops::{Add, AddAssign, Mul, Sub, SubAssign}; /// A velocity structure combining both the linear angular velocities of a point. #[repr(C)] #[derive(Copy, Clone, Debug)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct Velocity2 { /// The linear velocity. pub linear: Vector2, diff --git a/src/algebra/velocity3.rs b/src/algebra/velocity3.rs index 163113295..9a01735e9 100644 --- a/src/algebra/velocity3.rs +++ b/src/algebra/velocity3.rs @@ -6,6 +6,7 @@ use std::ops::{Add, AddAssign, Mul, Sub, SubAssign}; /// A velocity structure combining both the linear angular velocities of a point. #[repr(C)] #[derive(Copy, Clone, Debug)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct Velocity3 { /// The linear velocity. pub linear: Vector3, diff --git a/src/lib.rs b/src/lib.rs index 418a2ffec..a30776a3b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -89,6 +89,10 @@ extern crate num_traits as num; extern crate slab; extern crate either; +#[cfg(feature = "serde")] +#[macro_use] +extern crate serde; + /* * The two following crates are pulled-in for * measuring time. diff --git a/src/object/body.rs b/src/object/body.rs index 5c9d0896a..a8d29eaf8 100644 --- a/src/object/body.rs +++ b/src/object/body.rs @@ -22,6 +22,12 @@ pub enum BodyStatus { Kinematic, } +impl Default for BodyStatus { + fn default() -> Self { + BodyStatus::Dynamic + } +} + /// The activation status of a body. /// /// This controls whether a body is sleeping or not. diff --git a/src/world/collider_world.rs b/src/world/collider_world.rs index dd6746e5d..37a474bd7 100644 --- a/src/world/collider_world.rs +++ b/src/world/collider_world.rs @@ -87,6 +87,11 @@ impl ColliderWorld { pub fn as_collider_world(&self) -> &CollisionWorld> { &self.cworld } + + /// The underlying collision world from the ncollide crate. + pub fn as_collider_world_mut(&mut self) -> &mut CollisionWorld> { + &mut self.cworld + } /// Unwraps the underlying collision world from the ncollide crate. pub fn into_inner(self) -> CollisionWorld> { @@ -567,4 +572,4 @@ impl<'a, N: Real> Iterator for ColliderChain<'a, N> { self.curr = coll.next(); Some(coll) } -} \ No newline at end of file +}