From 06b6ecf7c2d45d9cfd33d401e7d5a1808664be71 Mon Sep 17 00:00:00 2001 From: Jonathan Cornaz Date: Mon, 8 Mar 2021 22:59:17 +0100 Subject: [PATCH 01/11] Introduce rotation contraints --- core/src/lib.rs | 39 +++++++++++++++++++++++++++++++++++++++ rapier/src/body.rs | 23 +++++++++++++++++++++-- 2 files changed, 60 insertions(+), 2 deletions(-) diff --git a/core/src/lib.rs b/core/src/lib.rs index 7b5c6f36..50f2efea 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -79,6 +79,7 @@ impl Plugin for CorePlugin { .register_type::() .register_type::() .register_type::() + .register_type::() .add_stage_after(bevy::app::stage::UPDATE, crate::stage::ROOT, { let mut schedule = Schedule::default(); @@ -218,6 +219,7 @@ impl BodyType { /// } /// } /// } +/// ``` #[derive(Debug, Copy, Clone, PartialEq)] pub enum CollisionEvent { /// The two entities started to collide @@ -276,3 +278,40 @@ impl Default for PhysicMaterial { } } } + +/// Component that restrict the rotations caused by forces +/// +/// Note that angular velocity may still be applied programmatically. +#[derive(Debug, Copy, Clone, Reflect)] +pub struct RotationConstraints { + /// Set to true to prevent rotations around the x axis + pub allow_x: bool, + + /// Set to true to prevent rotations around the y axis + pub allow_y: bool, + + /// Set to true to prevent rotations around the Z axis + pub allow_z: bool, +} + +impl Default for RotationConstraints { + fn default() -> Self { + Self { + allow_x: true, + allow_y: true, + allow_z: true, + } + } +} + +impl RotationConstraints { + /// Lock rotations around all axes + #[must_use] + pub fn lock() -> Self { + Self { + allow_x: false, + allow_y: false, + allow_z: false, + } + } +} diff --git a/rapier/src/body.rs b/rapier/src/body.rs index 3219b271..424aa9a0 100644 --- a/rapier/src/body.rs +++ b/rapier/src/body.rs @@ -3,7 +3,7 @@ use bevy::math::prelude::*; use bevy::transform::prelude::*; use fnv::FnvHashMap; -use heron_core::{Body, BodyType, PhysicMaterial, Velocity}; +use heron_core::{Body, BodyType, PhysicMaterial, RotationConstraints, Velocity}; use crate::convert::{IntoBevy, IntoRapier}; use crate::rapier::dynamics::{ @@ -29,17 +29,36 @@ pub(crate) fn create( Option<&BodyType>, Option<&Velocity>, Option<&PhysicMaterial>, + Option<&RotationConstraints>, ), Without, >, ) { - for (entity, body, transform, body_type, velocity, material) in query.iter() { + for (entity, body, transform, body_type, velocity, material, restrict_rotation) in query.iter() + { let body_type = body_type.cloned().unwrap_or_default(); let mut builder = RigidBodyBuilder::new(body_status(body_type)) .user_data(entity.to_bits().into()) .position((transform.translation, transform.rotation).into_rapier()); + #[allow(unused_variables)] + if let Some(RotationConstraints { + allow_x, + allow_y, + allow_z, + }) = restrict_rotation.cloned() + { + #[cfg(feature = "2d")] + if !allow_z { + builder = builder.lock_rotations(); + } + #[cfg(feature = "3d")] + { + builder = builder.restrict_rotations(allow_x, allow_y, allow_z); + } + } + if let Some(v) = velocity { #[cfg(feature = "2d")] { From fb218fde1d50162b47eef6c9de1d75242d0e4b31 Mon Sep 17 00:00:00 2001 From: Jonathan Cornaz Date: Tue, 9 Mar 2021 19:35:31 +0100 Subject: [PATCH 02/11] Refine component API --- core/src/constraints.rs | 74 +++++++++++++++++++++++++++++++++++++++++ core/src/lib.rs | 39 ++-------------------- 2 files changed, 76 insertions(+), 37 deletions(-) create mode 100644 core/src/constraints.rs diff --git a/core/src/constraints.rs b/core/src/constraints.rs new file mode 100644 index 00000000..004712fa --- /dev/null +++ b/core/src/constraints.rs @@ -0,0 +1,74 @@ +use bevy::reflect::Reflect; + +/// Component that restrict the rotations caused by forces +/// +/// Note that angular velocity may still be applied programmatically. +#[derive(Debug, Copy, Clone, Reflect)] +pub struct RotationConstraints { + /// Set to true to prevent rotations around the x axis + pub allow_x: bool, + + /// Set to true to prevent rotations around the y axis + pub allow_y: bool, + + /// Set to true to prevent rotations around the Z axis + pub allow_z: bool, +} + +impl Default for RotationConstraints { + fn default() -> Self { + Self::allow() + } +} + +impl RotationConstraints { + /// Lock rotations around all axes + #[must_use] + pub fn lock() -> Self { + Self { + allow_x: false, + allow_y: false, + allow_z: false, + } + } + + /// Allow rotations around all axes + #[must_use] + pub fn allow() -> Self { + Self { + allow_x: true, + allow_y: true, + allow_z: true, + } + } + + /// Allow rotation around the x axis only (and prevent rotating around the other axes) + #[must_use] + pub fn restrict_to_x_only() -> Self { + Self { + allow_x: true, + allow_y: false, + allow_z: false, + } + } + + /// Allow rotation around the y axis only (and prevent rotating around the other axes) + #[must_use] + pub fn restrict_to_y_only() -> Self { + Self { + allow_x: false, + allow_y: true, + allow_z: false, + } + } + + /// Allow rotation around the z axis only (and prevent rotating around the other axes) + #[must_use] + pub fn restrict_to_z_only() -> Self { + Self { + allow_x: false, + allow_y: false, + allow_z: true, + } + } +} diff --git a/core/src/lib.rs b/core/src/lib.rs index 50f2efea..5b3fa060 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -6,10 +6,12 @@ use bevy::core::FixedTimestep; use bevy::prelude::*; +pub use constraints::RotationConstraints; pub use ext::*; pub use gravity::Gravity; pub use velocity::{AxisAngle, Velocity}; +mod constraints; pub mod ext; mod gravity; pub mod utils; @@ -278,40 +280,3 @@ impl Default for PhysicMaterial { } } } - -/// Component that restrict the rotations caused by forces -/// -/// Note that angular velocity may still be applied programmatically. -#[derive(Debug, Copy, Clone, Reflect)] -pub struct RotationConstraints { - /// Set to true to prevent rotations around the x axis - pub allow_x: bool, - - /// Set to true to prevent rotations around the y axis - pub allow_y: bool, - - /// Set to true to prevent rotations around the Z axis - pub allow_z: bool, -} - -impl Default for RotationConstraints { - fn default() -> Self { - Self { - allow_x: true, - allow_y: true, - allow_z: true, - } - } -} - -impl RotationConstraints { - /// Lock rotations around all axes - #[must_use] - pub fn lock() -> Self { - Self { - allow_x: false, - allow_y: false, - allow_z: false, - } - } -} From 23086fb62ff58ac7b777aada7375b0c378475990 Mon Sep 17 00:00:00 2001 From: Jonathan Cornaz Date: Tue, 9 Mar 2021 20:33:02 +0100 Subject: [PATCH 03/11] Test default case --- rapier/tests/constraints.rs | 65 +++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 rapier/tests/constraints.rs diff --git a/rapier/tests/constraints.rs b/rapier/tests/constraints.rs new file mode 100644 index 00000000..74a725d2 --- /dev/null +++ b/rapier/tests/constraints.rs @@ -0,0 +1,65 @@ +#![cfg(all( + any(feature = "2d", feature = "3d"), + not(all(feature = "2d", feature = "3d")), +))] + +use bevy::core::CorePlugin; +use bevy::prelude::*; +use bevy::reflect::TypeRegistryArc; + +use heron_core::{Body, PhysicMaterial}; +use heron_rapier::convert::IntoBevy; +use heron_rapier::rapier::dynamics::{IntegrationParameters, RigidBodySet}; +use heron_rapier::rapier::math::AngVector; +use heron_rapier::{BodyHandle, RapierPlugin}; + +fn test_app() -> App { + let mut builder = App::build(); + builder + .init_resource::() + .add_plugin(CorePlugin) + .add_plugin(RapierPlugin { + step_per_second: None, + parameters: IntegrationParameters::default(), + }); + builder.app +} + +#[test] +fn rotation_is_not_constrained_without_the_component() { + let mut app = test_app(); + + let entity = app + .world + .spawn((GlobalTransform::default(), Body::Sphere { radius: 10.0 })); + + app.update(); + + let bodies = app.resources.get::().unwrap(); + let body = bodies + .get(app.world.get::(entity).unwrap().rigid_body()) + .unwrap(); + + let inv_angular_inertia: Vec3 = + vec3_from_angle_vector(body.mass_properties().inv_principal_inertia_sqrt); + + let inv_angular_inertia: Vec3 = inv_angular_inertia.into(); + + #[cfg(feature = "3d")] + assert!(inv_angular_inertia.x > 0.0); + + #[cfg(feature = "3d")] + assert!(inv_angular_inertia.y > 0.0); + + assert!(inv_angular_inertia.z > 0.0); +} + +#[cfg(feature = "2d")] +fn vec3_from_angle_vector(vector: AngVector) -> Vec3 { + Vec3::unit_z() * vector +} + +#[cfg(feature = "3d")] +fn vec3_from_angle_vector(vector: AngVector) -> Vec3 { + vector.into_bevy() +} From d1aed271526f49f9a0bf12529169f0f5cd8b6204 Mon Sep 17 00:00:00 2001 From: Jonathan Cornaz Date: Tue, 9 Mar 2021 20:44:52 +0100 Subject: [PATCH 04/11] Test locking at creation --- rapier/src/body.rs | 5 ++-- rapier/tests/constraints.rs | 49 +++++++++++++++++++++---------------- 2 files changed, 31 insertions(+), 23 deletions(-) diff --git a/rapier/src/body.rs b/rapier/src/body.rs index 424aa9a0..75692dda 100644 --- a/rapier/src/body.rs +++ b/rapier/src/body.rs @@ -34,7 +34,8 @@ pub(crate) fn create( Without, >, ) { - for (entity, body, transform, body_type, velocity, material, restrict_rotation) in query.iter() + for (entity, body, transform, body_type, velocity, material, rotation_constraints) in + query.iter() { let body_type = body_type.cloned().unwrap_or_default(); @@ -47,7 +48,7 @@ pub(crate) fn create( allow_x, allow_y, allow_z, - }) = restrict_rotation.cloned() + }) = rotation_constraints.cloned() { #[cfg(feature = "2d")] if !allow_z { diff --git a/rapier/tests/constraints.rs b/rapier/tests/constraints.rs index 74a725d2..32f523df 100644 --- a/rapier/tests/constraints.rs +++ b/rapier/tests/constraints.rs @@ -7,7 +7,7 @@ use bevy::core::CorePlugin; use bevy::prelude::*; use bevy::reflect::TypeRegistryArc; -use heron_core::{Body, PhysicMaterial}; +use heron_core::{Body, PhysicMaterial, RotationConstraints}; use heron_rapier::convert::IntoBevy; use heron_rapier::rapier::dynamics::{IntegrationParameters, RigidBodySet}; use heron_rapier::rapier::math::AngVector; @@ -26,6 +26,7 @@ fn test_app() -> App { } #[test] +#[cfg(feature = "2d")] fn rotation_is_not_constrained_without_the_component() { let mut app = test_app(); @@ -36,30 +37,36 @@ fn rotation_is_not_constrained_without_the_component() { app.update(); let bodies = app.resources.get::().unwrap(); - let body = bodies - .get(app.world.get::(entity).unwrap().rigid_body()) - .unwrap(); - - let inv_angular_inertia: Vec3 = - vec3_from_angle_vector(body.mass_properties().inv_principal_inertia_sqrt); - let inv_angular_inertia: Vec3 = inv_angular_inertia.into(); + assert!( + bodies + .get(app.world.get::(entity).unwrap().rigid_body()) + .unwrap() + .effective_world_inv_inertia_sqrt + > 0.0 + ); +} - #[cfg(feature = "3d")] - assert!(inv_angular_inertia.x > 0.0); +#[test] +#[cfg(feature = "2d")] +fn rotation_can_be_locked_on_creation() { + let mut app = test_app(); - #[cfg(feature = "3d")] - assert!(inv_angular_inertia.y > 0.0); + let entity = app.world.spawn(( + GlobalTransform::default(), + Body::Sphere { radius: 10.0 }, + RotationConstraints::lock(), + )); - assert!(inv_angular_inertia.z > 0.0); -} + app.update(); -#[cfg(feature = "2d")] -fn vec3_from_angle_vector(vector: AngVector) -> Vec3 { - Vec3::unit_z() * vector -} + let bodies = app.resources.get::().unwrap(); -#[cfg(feature = "3d")] -fn vec3_from_angle_vector(vector: AngVector) -> Vec3 { - vector.into_bevy() + assert_eq!( + bodies + .get(app.world.get::(entity).unwrap().rigid_body()) + .unwrap() + .effective_world_inv_inertia_sqrt, + 0.0 + ); } From 8a03dea8d4c927a088a184c4987b14eed4dffe8d Mon Sep 17 00:00:00 2001 From: Jonathan Cornaz Date: Tue, 9 Mar 2021 20:49:21 +0100 Subject: [PATCH 05/11] Write case for locking after creation (not implemented) --- rapier/tests/constraints.rs | 41 ++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/rapier/tests/constraints.rs b/rapier/tests/constraints.rs index 32f523df..26337b57 100644 --- a/rapier/tests/constraints.rs +++ b/rapier/tests/constraints.rs @@ -1,16 +1,11 @@ -#![cfg(all( - any(feature = "2d", feature = "3d"), - not(all(feature = "2d", feature = "3d")), -))] +#![cfg(feature = "2d")] use bevy::core::CorePlugin; use bevy::prelude::*; use bevy::reflect::TypeRegistryArc; -use heron_core::{Body, PhysicMaterial, RotationConstraints}; -use heron_rapier::convert::IntoBevy; +use heron_core::{Body, RotationConstraints}; use heron_rapier::rapier::dynamics::{IntegrationParameters, RigidBodySet}; -use heron_rapier::rapier::math::AngVector; use heron_rapier::{BodyHandle, RapierPlugin}; fn test_app() -> App { @@ -26,7 +21,6 @@ fn test_app() -> App { } #[test] -#[cfg(feature = "2d")] fn rotation_is_not_constrained_without_the_component() { let mut app = test_app(); @@ -48,8 +42,7 @@ fn rotation_is_not_constrained_without_the_component() { } #[test] -#[cfg(feature = "2d")] -fn rotation_can_be_locked_on_creation() { +fn rotation_can_be_locked_at_creation() { let mut app = test_app(); let entity = app.world.spawn(( @@ -70,3 +63,31 @@ fn rotation_can_be_locked_on_creation() { 0.0 ); } + +#[test] +#[ignore] +fn rotation_can_be_locked_after_creation() { + let mut app = test_app(); + + let entity = app + .world + .spawn((GlobalTransform::default(), Body::Sphere { radius: 10.0 })); + + app.update(); + + app.world + .insert_one(entity, RotationConstraints::lock()) + .unwrap(); + + app.update(); + + let bodies = app.resources.get::().unwrap(); + + assert_eq!( + bodies + .get(app.world.get::(entity).unwrap().rigid_body()) + .unwrap() + .effective_world_inv_inertia_sqrt, + 0.0 + ); +} From 0413ea75c436cf4581a3b51748f9086336f0a814 Mon Sep 17 00:00:00 2001 From: Jonathan Cornaz Date: Tue, 9 Mar 2021 21:29:24 +0100 Subject: [PATCH 06/11] Unlock if component is removed --- rapier/src/body.rs | 21 +++++++++++++++++++++ rapier/src/lib.rs | 4 ++++ rapier/tests/constraints.rs | 28 +++++++++++++++++++++++++++- 3 files changed, 52 insertions(+), 1 deletion(-) diff --git a/rapier/src/body.rs b/rapier/src/body.rs index 75692dda..a81ea7a3 100644 --- a/rapier/src/body.rs +++ b/rapier/src/body.rs @@ -95,6 +95,27 @@ pub(crate) fn create( } } +pub(crate) fn remove_invalid_bodies( + commands: &mut Commands, + mut bodies: ResMut<'_, RigidBodySet>, + mut colliders: ResMut<'_, ColliderSet>, + mut joints: ResMut<'_, JointSet>, + changed: Query<'_, (Entity, &BodyHandle), Changed>, + removed: Query<'_, (Entity, &BodyHandle), Without>, +) { + for (entity, handle) in changed.iter() { + bodies.remove(handle.rigid_body, &mut colliders, &mut joints); + commands.remove_one::(entity); + } + + for entity in removed.removed::() { + if let Some((entity, handle)) = removed.get(*entity).ok() { + bodies.remove(handle.rigid_body, &mut colliders, &mut joints); + commands.remove_one::(entity); + } + } +} + #[allow(clippy::type_complexity)] pub(crate) fn recreate_collider( mut bodies: ResMut<'_, RigidBodySet>, diff --git a/rapier/src/lib.rs b/rapier/src/lib.rs index a9cc1412..de6fa6ea 100644 --- a/rapier/src/lib.rs +++ b/rapier/src/lib.rs @@ -115,6 +115,10 @@ impl Plugin for RapierPlugin { .add_resource(JointSet::new()) .stage(heron_core::stage::ROOT, |schedule: &mut Schedule| { schedule + .add_stage( + "heron-remove-invalid-bodies", + SystemStage::serial().with_system(body::remove_invalid_bodies.system()), + ) .add_stage( "heron-pre-step", SystemStage::serial() diff --git a/rapier/tests/constraints.rs b/rapier/tests/constraints.rs index 26337b57..f133fa03 100644 --- a/rapier/tests/constraints.rs +++ b/rapier/tests/constraints.rs @@ -65,7 +65,6 @@ fn rotation_can_be_locked_at_creation() { } #[test] -#[ignore] fn rotation_can_be_locked_after_creation() { let mut app = test_app(); @@ -91,3 +90,30 @@ fn rotation_can_be_locked_after_creation() { 0.0 ); } + +#[test] +fn rotation_is_unlocked_if_component_is_removed() { + let mut app = test_app(); + + let entity = app.world.spawn(( + GlobalTransform::default(), + Body::Sphere { radius: 10.0 }, + RotationConstraints::lock(), + )); + + app.update(); + + app.world.remove_one::(entity).unwrap(); + + app.update(); + + let bodies = app.resources.get::().unwrap(); + + assert!( + bodies + .get(app.world.get::(entity).unwrap().rigid_body()) + .unwrap() + .effective_world_inv_inertia_sqrt + > 0.0 + ); +} From f78aff39c689bcaf4b604bdfc3c3ac759d0314c8 Mon Sep 17 00:00:00 2001 From: Jonathan Cornaz Date: Tue, 9 Mar 2021 21:32:17 +0100 Subject: [PATCH 07/11] Update changelog and root documentation --- CHANGELOG.md | 8 +++++++- src/lib.rs | 3 ++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bc26400a..89cbb654 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,13 @@ The format is inspired from [Keep a Changelog], and this project adheres to [Sem ## [Unreleased] -The default color for debug shape is less transparent. That should make easier to see the debug shapes. +### RotationConstraints component + +A new `RotationConstraints` component make possible to prevent rotation around the given axes (incl. fully lock rotation) + +### Others + +* The opacity has been increased for the default color of debug shapes. ## [0.2.0] - 2021-03-07 diff --git a/src/lib.rs b/src/lib.rs index 1d1e797f..1af5d2e9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -128,6 +128,7 @@ //! * How to define the world's [`Gravity`] //! * How to define the [`PhysicMaterial`] //! * How to listen to [`CollisionEvent`] +//! * How to define [`RotationConstraints`] use bevy::app::{AppBuilder, Plugin}; @@ -146,7 +147,7 @@ pub mod rapier_plugin { pub mod prelude { pub use crate::{ ext::*, stage, AxisAngle, Body, BodyType, CollisionEvent, Gravity, PhysicMaterial, - PhysicsPlugin, Velocity, + PhysicsPlugin, RotationConstraints, Velocity, }; } From b4b395f14ab27e28214b8a9ea29b4ea285601c28 Mon Sep 17 00:00:00 2001 From: Jonathan Cornaz Date: Tue, 9 Mar 2021 21:43:07 +0100 Subject: [PATCH 08/11] Add example to RotationConstraints component --- core/src/constraints.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/core/src/constraints.rs b/core/src/constraints.rs index 004712fa..b69932d8 100644 --- a/core/src/constraints.rs +++ b/core/src/constraints.rs @@ -1,8 +1,22 @@ use bevy::reflect::Reflect; -/// Component that restrict the rotations caused by forces +/// Component that restrict what rotations can be caused by forces. /// -/// Note that angular velocity may still be applied programmatically. +/// Note that angular velocity may still be applied programmatically. This only restrict how rotation +/// can change when force/torques are applied. +/// +/// # Example +/// +/// ``` +/// # use bevy::prelude::*; +/// # use heron_core::*; +/// +/// fn spawn(commands: &mut Commands) { +/// commands.spawn(todo!("Spawn your sprite/mesh, incl. at least a GlobalTransform")) +/// .with(Body::Sphere { radius: 1.0 }) +/// .with(RotationConstraints::lock()); // Prevent rotation caused by forces +/// } +/// ``` #[derive(Debug, Copy, Clone, Reflect)] pub struct RotationConstraints { /// Set to true to prevent rotations around the x axis From cd6caeaeb0ca69930045c6b96887cf82f26ff1bc Mon Sep 17 00:00:00 2001 From: Jonathan Cornaz Date: Tue, 9 Mar 2021 21:45:24 +0100 Subject: [PATCH 09/11] Address clippy reports --- core/src/ext.rs | 2 -- core/src/lib.rs | 1 + rapier/src/body.rs | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/core/src/ext.rs b/core/src/ext.rs index eac7d852..2e4cbb6e 100644 --- a/core/src/ext.rs +++ b/core/src/ext.rs @@ -1,5 +1,3 @@ -#![allow(clippy::module_name_repetitions)] - //! Extensions to bevy API use bevy::app::AppBuilder; diff --git a/core/src/lib.rs b/core/src/lib.rs index 5b3fa060..3df77b57 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -1,5 +1,6 @@ #![deny(future_incompatible, nonstandard_style)] #![warn(missing_docs, rust_2018_idioms, clippy::pedantic)] +#![allow(clippy::module_name_repetitions)] //! Core components and resources to use Heron diff --git a/rapier/src/body.rs b/rapier/src/body.rs index a81ea7a3..75ff8390 100644 --- a/rapier/src/body.rs +++ b/rapier/src/body.rs @@ -109,7 +109,7 @@ pub(crate) fn remove_invalid_bodies( } for entity in removed.removed::() { - if let Some((entity, handle)) = removed.get(*entity).ok() { + if let Ok((entity, handle)) = removed.get(*entity) { bodies.remove(handle.rigid_body, &mut colliders, &mut joints); commands.remove_one::(entity); } From 3c048133c66bdc5bf75a2f9a6b6715614b69c1f0 Mon Sep 17 00:00:00 2001 From: Jonathan Cornaz Date: Tue, 9 Mar 2021 22:02:43 +0100 Subject: [PATCH 10/11] Simplify existing code --- rapier/src/body.rs | 45 ++++++++++++--------------------------------- rapier/src/lib.rs | 3 +-- 2 files changed, 13 insertions(+), 35 deletions(-) diff --git a/rapier/src/body.rs b/rapier/src/body.rs index 75ff8390..37362b6d 100644 --- a/rapier/src/body.rs +++ b/rapier/src/body.rs @@ -95,12 +95,22 @@ pub(crate) fn create( } } -pub(crate) fn remove_invalid_bodies( +#[allow(clippy::type_complexity)] +pub(crate) fn remove_bodies( commands: &mut Commands, mut bodies: ResMut<'_, RigidBodySet>, mut colliders: ResMut<'_, ColliderSet>, mut joints: ResMut<'_, JointSet>, - changed: Query<'_, (Entity, &BodyHandle), Changed>, + changed: Query< + '_, + (Entity, &BodyHandle), + Or<( + Mutated, + Changed, + Changed, + Changed, + )>, + >, removed: Query<'_, (Entity, &BodyHandle), Without>, ) { for (entity, handle) in changed.iter() { @@ -116,37 +126,6 @@ pub(crate) fn remove_invalid_bodies( } } -#[allow(clippy::type_complexity)] -pub(crate) fn recreate_collider( - mut bodies: ResMut<'_, RigidBodySet>, - mut colliders: ResMut<'_, ColliderSet>, - mut query: Query< - '_, - ( - Entity, - &Body, - &mut BodyHandle, - Option<&BodyType>, - Option<&PhysicMaterial>, - ), - Or<(Mutated, Changed, Changed)>, - >, -) { - for (entity, body_def, mut handle, body_type, material) in query.iter_mut() { - colliders.remove(handle.collider, &mut bodies, true); - handle.collider = colliders.insert( - build_collider( - entity, - &body_def, - body_type.cloned().unwrap_or_default(), - material.cloned().unwrap_or_default(), - ), - handle.rigid_body, - &mut bodies, - ); - } -} - pub(crate) fn update_rapier_status( mut bodies: ResMut<'_, RigidBodySet>, with_type_changed: Query<'_, (&BodyType, &BodyHandle), Changed>, diff --git a/rapier/src/lib.rs b/rapier/src/lib.rs index de6fa6ea..784525c5 100644 --- a/rapier/src/lib.rs +++ b/rapier/src/lib.rs @@ -117,7 +117,7 @@ impl Plugin for RapierPlugin { schedule .add_stage( "heron-remove-invalid-bodies", - SystemStage::serial().with_system(body::remove_invalid_bodies.system()), + SystemStage::serial().with_system(body::remove_bodies.system()), ) .add_stage( "heron-pre-step", @@ -127,7 +127,6 @@ impl Plugin for RapierPlugin { .system(), ) .with_system(body::remove.system()) - .with_system(body::recreate_collider.system()) .with_system(body::update_rapier_position.system()) .with_system(velocity::update_rapier_velocity.system()) .with_system(body::update_rapier_status.system()) From 2a266fb255c898af9a465a5c3a05c2a2e7d0125f Mon Sep 17 00:00:00 2001 From: Jonathan Cornaz Date: Tue, 9 Mar 2021 22:05:42 +0100 Subject: [PATCH 11/11] Reword changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 89cbb654..2e4fffbb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,7 +12,7 @@ The format is inspired from [Keep a Changelog], and this project adheres to [Sem ### RotationConstraints component -A new `RotationConstraints` component make possible to prevent rotation around the given axes (incl. fully lock rotation) +A new `RotationConstraints` component make possible to prevent rotation around the given axes. ### Others