From babcab0bed23fadd23181ccc58aae34fb80d01d8 Mon Sep 17 00:00:00 2001 From: Crozet Sébastien Date: Tue, 23 Feb 2021 15:49:23 +0100 Subject: Update the testbed to use PhysicsHooks. --- src/geometry/collider.rs | 17 ++++++++++++++++- src/geometry/contact_pair.rs | 11 +++++++++-- src/geometry/mod.rs | 2 -- src/geometry/narrow_phase.rs | 16 ++++++++-------- src/pipeline/collision_pipeline.rs | 6 ++---- src/pipeline/mod.rs | 4 ++++ 6 files changed, 39 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/geometry/collider.rs b/src/geometry/collider.rs index ce263f8..4be6d29 100644 --- a/src/geometry/collider.rs +++ b/src/geometry/collider.rs @@ -1,5 +1,5 @@ use crate::dynamics::{CoefficientCombineRule, MassProperties, RigidBodyHandle}; -use crate::geometry::{InteractionGroups, SharedShape}; +use crate::geometry::{InteractionGroups, SharedShape, SolverFlags}; use crate::math::{AngVector, Isometry, Point, Real, Rotation, Vector, DIM}; use crate::parry::transformation::vhacd::VHACDParameters; use parry::bounding_volume::AABB; @@ -50,6 +50,7 @@ pub struct Collider { shape: SharedShape, density: Real, pub(crate) flags: ColliderFlags, + pub(crate) solver_flags: SolverFlags, pub(crate) parent: RigidBodyHandle, pub(crate) delta: Isometry, pub(crate) position: Isometry, @@ -159,6 +160,9 @@ pub struct ColliderBuilder { pub delta: Isometry, /// Is this collider a sensor? pub is_sensor: bool, + /// Do we have to always call the contact modifier + /// on this collider? + pub modify_contacts: bool, /// The user-data of the collider being built. pub user_data: u128, /// The collision groups for the collider being built. @@ -182,6 +186,7 @@ impl ColliderBuilder { solver_groups: InteractionGroups::all(), friction_combine_rule: CoefficientCombineRule::Average, restitution_combine_rule: CoefficientCombineRule::Average, + modify_contacts: false, } } @@ -456,6 +461,13 @@ impl ColliderBuilder { self } + /// If set to `true` then the physics hooks will always run to modify + /// contacts involving this collider. + pub fn modify_contacts(mut self, modify_contacts: bool) -> Self { + self.modify_contacts = modify_contacts; + self + } + /// Sets the friction coefficient of the collider this builder will build. pub fn friction(mut self, friction: Real) -> Self { self.friction = friction; @@ -534,6 +546,8 @@ impl ColliderBuilder { flags = flags .with_friction_combine_rule(self.friction_combine_rule) .with_restitution_combine_rule(self.restitution_combine_rule); + let mut solver_flags = SolverFlags::default(); + solver_flags.set(SolverFlags::MODIFY_SOLVER_CONTACTS, self.modify_contacts); Collider { shape: self.shape.clone(), @@ -542,6 +556,7 @@ impl ColliderBuilder { restitution: self.restitution, delta: self.delta, flags, + solver_flags, parent: RigidBodyHandle::invalid(), position: Isometry::identity(), predicted_position: Isometry::identity(), diff --git a/src/geometry/contact_pair.rs b/src/geometry/contact_pair.rs index 11e0188..50094ca 100644 --- a/src/geometry/contact_pair.rs +++ b/src/geometry/contact_pair.rs @@ -16,6 +16,12 @@ bitflags::bitflags! { } } +impl Default for SolverFlags { + fn default() -> Self { + SolverFlags::COMPUTE_IMPULSES + } +} + #[derive(Copy, Clone, Debug)] #[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))] /// A single contact between two collider. @@ -126,10 +132,11 @@ pub struct SolverContact { pub friction: Real, /// The effective restitution coefficient at this contact point. pub restitution: Real, - /// The artificially add relative velocity at the contact point. + /// The desired tangent relative velocity at the contact point. + /// /// This is set to zero by default. Set to a non-zero value to /// simulate, e.g., conveyor belts. - pub surface_velocity: Vector, + pub tangent_velocity: Vector, /// Associated contact data used to warm-start the constraints /// solver. pub data: ContactData, diff --git a/src/geometry/mod.rs b/src/geometry/mod.rs index 2997e24..ab04b25 100644 --- a/src/geometry/mod.rs +++ b/src/geometry/mod.rs @@ -10,7 +10,6 @@ pub use self::interaction_graph::{ }; pub use self::interaction_groups::InteractionGroups; pub use self::narrow_phase::NarrowPhase; -pub use self::pair_filter::{PairFilterContext, PhysicsHooks}; pub use parry::query::TrackedContact; @@ -109,4 +108,3 @@ mod contact_pair; mod interaction_graph; mod interaction_groups; mod narrow_phase; -mod pair_filter; diff --git a/src/geometry/narrow_phase.rs b/src/geometry/narrow_phase.rs index e929e0f..d05b19a 100644 --- a/src/geometry/narrow_phase.rs +++ b/src/geometry/narrow_phase.rs @@ -4,15 +4,15 @@ use rayon::prelude::*; use crate::data::pubsub::Subscription; use crate::data::Coarena; use crate::dynamics::{BodyPair, CoefficientCombineRule, RigidBodySet}; -use crate::geometry::pair_filter::{ContactModificationContext, PhysicsHooksFlags}; use crate::geometry::{ - BroadPhasePairEvent, ColliderGraphIndex, ColliderHandle, ContactData, ContactEvent, - ContactManifoldData, IntersectionEvent, PairFilterContext, PhysicsHooks, RemovedCollider, - SolverContact, SolverFlags, + BroadPhasePairEvent, ColliderGraphIndex, ColliderHandle, ColliderSet, ContactData, + ContactEvent, ContactManifold, ContactManifoldData, ContactPair, InteractionGraph, + IntersectionEvent, RemovedCollider, SolverContact, SolverFlags, }; -use crate::geometry::{ColliderSet, ContactManifold, ContactPair, InteractionGraph}; use crate::math::{Real, Vector}; -use crate::pipeline::EventHandler; +use crate::pipeline::{ + ContactModificationContext, EventHandler, PairFilterContext, PhysicsHooks, PhysicsHooksFlags, +}; use parry::query::{DefaultQueryDispatcher, PersistentQueryDispatcher}; use parry::utils::IsometryOpt; use std::collections::HashMap; @@ -518,7 +518,7 @@ impl NarrowPhase { return; } } else { - SolverFlags::COMPUTE_IMPULSES + co1.solver_flags | co2.solver_flags }; if !co1.solver_groups.test(co2.solver_groups) { @@ -573,7 +573,7 @@ impl NarrowPhase { dist: contact.dist, friction, restitution, - surface_velocity: Vector::zeros(), + tangent_velocity: Vector::zeros(), data: contact.data, }; diff --git a/src/pipeline/collision_pipeline.rs b/src/pipeline/collision_pipeline.rs index 6f02d98..a74a6e5 100644 --- a/src/pipeline/collision_pipeline.rs +++ b/src/pipeline/collision_pipeline.rs @@ -1,11 +1,9 @@ //! Physics pipeline structures. use crate::dynamics::{JointSet, RigidBodySet}; -use crate::geometry::{ - BroadPhase, BroadPhasePairEvent, ColliderPair, ColliderSet, NarrowPhase, PhysicsHooks, -}; +use crate::geometry::{BroadPhase, BroadPhasePairEvent, ColliderPair, ColliderSet, NarrowPhase}; use crate::math::Real; -use crate::pipeline::EventHandler; +use crate::pipeline::{EventHandler, PhysicsHooks}; /// The collision pipeline, responsible for performing collision detection between colliders. /// diff --git a/src/pipeline/mod.rs b/src/pipeline/mod.rs index 287de9d..fd85cfa 100644 --- a/src/pipeline/mod.rs +++ b/src/pipeline/mod.rs @@ -2,10 +2,14 @@ pub use collision_pipeline::CollisionPipeline; pub use event_handler::{ChannelEventCollector, EventHandler}; +pub use physics_hooks::{ + ContactModificationContext, PairFilterContext, PhysicsHooks, PhysicsHooksFlags, +}; pub use physics_pipeline::PhysicsPipeline; pub use query_pipeline::QueryPipeline; mod collision_pipeline; mod event_handler; +mod physics_hooks; mod physics_pipeline; mod query_pipeline; -- cgit