feat: rename collision_skin to contact_skin

This commit is contained in:
Sébastien Crozet
2024-04-28 15:53:49 +02:00
committed by Sébastien Crozet
parent 97f7c1b4b2
commit 929aa6b925
6 changed files with 26 additions and 26 deletions

View File

@@ -85,7 +85,7 @@ pub fn init_world(testbed: &mut Testbed) {
for k in 0..5 { for k in 0..5 {
let collider = ColliderBuilder::trimesh(vertices.clone(), indices.clone()) let collider = ColliderBuilder::trimesh(vertices.clone(), indices.clone())
.collision_skin(0.2); .contact_skin(0.2);
let rigid_body = RigidBodyBuilder::dynamic() let rigid_body = RigidBodyBuilder::dynamic()
.translation(vector![ith as f32 * 8.0 - 20.0, 20.0 + k as f32 * 11.0]) .translation(vector![ith as f32 * 8.0 - 20.0, 20.0 + k as f32 * 11.0])
.rotation(angle); .rotation(angle);

View File

@@ -36,8 +36,7 @@ pub fn do_init_world(testbed: &mut Testbed, use_convex_decomposition: bool) {
-(i as f32 * 40.0 / (nsubdivs as f32) / 2.0).cos() -(i as f32 * 40.0 / (nsubdivs as f32) / 2.0).cos()
- (j as f32 * 40.0 / (nsubdivs as f32) / 2.0).cos() - (j as f32 * 40.0 / (nsubdivs as f32) / 2.0).cos()
}); });
let heightfield = let heightfield = HeightField::new(heights, vector![100.0, 2.0, 100.0]);
HeightField::new(heights, vector![100.0, 2.0, 100.0]);
let mut trimesh = TriMesh::from(heightfield); let mut trimesh = TriMesh::from(heightfield);
trimesh.set_flags(TriMeshFlags::FIX_INTERNAL_EDGES); trimesh.set_flags(TriMeshFlags::FIX_INTERNAL_EDGES);
colliders.insert(ColliderBuilder::new(SharedShape::new(trimesh.clone()))); colliders.insert(ColliderBuilder::new(SharedShape::new(trimesh.clone())));
@@ -101,7 +100,8 @@ pub fn do_init_world(testbed: &mut Testbed, use_convex_decomposition: bool) {
// let compound = SharedShape::compound(compound_parts); // let compound = SharedShape::compound(compound_parts);
for k in 1..num_duplications + 1 { for k in 1..num_duplications + 1 {
let x = (igeom % width) as f32 * shift_xz - num_duplications as f32 * shift_xz / 2.0; let x =
(igeom % width) as f32 * shift_xz - num_duplications as f32 * shift_xz / 2.0;
let y = (igeom / width) as f32 * shift_y + 7.0; let y = (igeom / width) as f32 * shift_y + 7.0;
let z = k as f32 * shift_xz - num_duplications as f32 * shift_xz / 2.0; let z = k as f32 * shift_xz - num_duplications as f32 * shift_xz / 2.0;
@@ -109,7 +109,7 @@ pub fn do_init_world(testbed: &mut Testbed, use_convex_decomposition: bool) {
let handle = bodies.insert(body); let handle = bodies.insert(body);
for shape in &shapes { for shape in &shapes {
let collider = ColliderBuilder::new(shape.clone()).collision_skin(0.1); let collider = ColliderBuilder::new(shape.clone()).contact_skin(0.1);
colliders.insert_with_parent(collider, handle, &mut bodies); colliders.insert_with_parent(collider, handle, &mut bodies);
} }
} }

View File

@@ -362,7 +362,7 @@ impl BroadPhaseMultiSap {
let next_aabb = collider let next_aabb = collider
.shape .shape
.compute_aabb(next_position) .compute_aabb(next_position)
.loosened(collider.collision_skin() + prediction_distance / 2.0); .loosened(collider.contact_skin() + prediction_distance / 2.0);
aabb.merge(&next_aabb); aabb.merge(&next_aabb);
} }

View File

@@ -30,7 +30,7 @@ pub struct Collider {
pub(crate) material: ColliderMaterial, pub(crate) material: ColliderMaterial,
pub(crate) flags: ColliderFlags, pub(crate) flags: ColliderFlags,
pub(crate) bf_data: ColliderBroadPhaseData, pub(crate) bf_data: ColliderBroadPhaseData,
collision_skin: Real, contact_skin: Real,
contact_force_event_threshold: Real, contact_force_event_threshold: Real,
/// User-defined data associated to this collider. /// User-defined data associated to this collider.
pub user_data: u128, pub user_data: u128,
@@ -110,7 +110,7 @@ impl Collider {
bf_data: _bf_data, // Internal ids must not be overwritten. bf_data: _bf_data, // Internal ids must not be overwritten.
contact_force_event_threshold, contact_force_event_threshold,
user_data, user_data,
collision_skin, contact_skin,
} = other; } = other;
if self.parent.is_none() { if self.parent.is_none() {
@@ -125,7 +125,7 @@ impl Collider {
self.user_data = *user_data; self.user_data = *user_data;
self.flags = *flags; self.flags = *flags;
self.changes = ColliderChanges::all(); self.changes = ColliderChanges::all();
self.collision_skin = *collision_skin; self.contact_skin = *contact_skin;
} }
/// The physics hooks enabled for this collider. /// The physics hooks enabled for this collider.
@@ -159,13 +159,13 @@ impl Collider {
} }
/// The collision skin of this collider. /// The collision skin of this collider.
pub fn collision_skin(&self) -> Real { pub fn contact_skin(&self) -> Real {
self.collision_skin self.contact_skin
} }
/// Sets the collision skin of this collider. /// Sets the collision skin of this collider.
pub fn set_collision_skin(&mut self, skin_thickness: Real) { pub fn set_contact_skin(&mut self, skin_thickness: Real) {
self.collision_skin = skin_thickness; self.contact_skin = skin_thickness;
} }
/// The friction coefficient of this collider. /// The friction coefficient of this collider.
@@ -452,17 +452,17 @@ impl Collider {
/// Compute the axis-aligned bounding box of this collider. /// Compute the axis-aligned bounding box of this collider.
/// ///
/// This AABB doesnt take into account the colliders collision skin. /// This AABB doesnt take into account the colliders collision skin.
/// [`Collider::collision_skin`]. /// [`Collider::contact_skin`].
pub fn compute_aabb(&self) -> Aabb { pub fn compute_aabb(&self) -> Aabb {
self.shape.compute_aabb(&self.pos) self.shape.compute_aabb(&self.pos)
} }
/// Compute the axis-aligned bounding box of this collider, taking into account the /// Compute the axis-aligned bounding box of this collider, taking into account the
/// [`Collider::collision_skin`] and prediction distance. /// [`Collider::contact_skin`] and prediction distance.
pub fn compute_collision_aabb(&self, prediction: Real) -> Aabb { pub fn compute_collision_aabb(&self, prediction: Real) -> Aabb {
self.shape self.shape
.compute_aabb(&self.pos) .compute_aabb(&self.pos)
.loosened(self.collision_skin + prediction) .loosened(self.contact_skin + prediction)
} }
/// Compute the axis-aligned bounding box of this collider moving from its current position /// Compute the axis-aligned bounding box of this collider moving from its current position
@@ -520,7 +520,7 @@ pub struct ColliderBuilder {
/// The total force magnitude beyond which a contact force event can be emitted. /// The total force magnitude beyond which a contact force event can be emitted.
pub contact_force_event_threshold: Real, pub contact_force_event_threshold: Real,
/// An extract thickness around the collider shape to keep them further apart when in collision. /// An extract thickness around the collider shape to keep them further apart when in collision.
pub collision_skin: Real, pub contact_skin: Real,
} }
impl ColliderBuilder { impl ColliderBuilder {
@@ -543,7 +543,7 @@ impl ColliderBuilder {
active_events: ActiveEvents::empty(), active_events: ActiveEvents::empty(),
enabled: true, enabled: true,
contact_force_event_threshold: 0.0, contact_force_event_threshold: 0.0,
collision_skin: 0.0, contact_skin: 0.0,
} }
} }
@@ -982,8 +982,8 @@ impl ColliderBuilder {
/// it creates a small gap between colliding object (equal to the sum of their skin). If the /// it creates a small gap between colliding object (equal to the sum of their skin). If the
/// skin is sufficiently small, this might not be visually significant or can be hidden by the /// skin is sufficiently small, this might not be visually significant or can be hidden by the
/// rendering assets. /// rendering assets.
pub fn collision_skin(mut self, skin_thickness: Real) -> Self { pub fn contact_skin(mut self, skin_thickness: Real) -> Self {
self.collision_skin = skin_thickness; self.contact_skin = skin_thickness;
self self
} }
@@ -1034,7 +1034,7 @@ impl ColliderBuilder {
flags, flags,
coll_type, coll_type,
contact_force_event_threshold: self.contact_force_event_threshold, contact_force_event_threshold: self.contact_force_event_threshold,
collision_skin: self.collision_skin, contact_skin: self.contact_skin,
user_data: self.user_data, user_data: self.user_data,
} }
} }

View File

@@ -117,7 +117,7 @@ pub struct ContactPair {
/// ///
/// All contact manifold contain themselves contact points between the colliders. /// All contact manifold contain themselves contact points between the colliders.
/// Note that contact points in the contact manifold do not take into account the /// Note that contact points in the contact manifold do not take into account the
/// [`Collider::collision_skin`] which only affects the constraint solver and the /// [`Collider::contact_skin`] which only affects the constraint solver and the
/// [`SolverContact`]. /// [`SolverContact`].
pub manifolds: Vec<ContactManifold>, pub manifolds: Vec<ContactManifold>,
/// Is there any active contact in this contact pair? /// Is there any active contact in this contact pair?

View File

@@ -898,7 +898,7 @@ impl NarrowPhase {
let pos12 = co1.pos.inv_mul(&co2.pos); let pos12 = co1.pos.inv_mul(&co2.pos);
let collision_skin_sum = co1.collision_skin() + co2.collision_skin(); let contact_skin_sum = co1.contact_skin() + co2.contact_skin();
let soft_ccd_prediction1 = rb1.map(|rb| rb.soft_ccd_prediction()).unwrap_or(0.0); let soft_ccd_prediction1 = rb1.map(|rb| rb.soft_ccd_prediction()).unwrap_or(0.0);
let soft_ccd_prediction2 = rb2.map(|rb| rb.soft_ccd_prediction()).unwrap_or(0.0); let soft_ccd_prediction2 = rb2.map(|rb| rb.soft_ccd_prediction()).unwrap_or(0.0);
let effective_prediction_distance = if soft_ccd_prediction1 > 0.0 || soft_ccd_prediction2 > 0.0 { let effective_prediction_distance = if soft_ccd_prediction1 > 0.0 || soft_ccd_prediction2 > 0.0 {
@@ -918,9 +918,9 @@ impl NarrowPhase {
prediction_distance.max( prediction_distance.max(
dt * (linvel1 - linvel2).norm()) + collision_skin_sum dt * (linvel1 - linvel2).norm()) + contact_skin_sum
} else { } else {
prediction_distance + collision_skin_sum prediction_distance + contact_skin_sum
}; };
let _ = query_dispatcher.contact_manifolds( let _ = query_dispatcher.contact_manifolds(
@@ -969,7 +969,7 @@ impl NarrowPhase {
break; break;
} }
let effective_contact_dist = contact.dist - co1.collision_skin() - co2.collision_skin(); let effective_contact_dist = contact.dist - co1.contact_skin() - co2.contact_skin();
let keep_solver_contact = effective_contact_dist < prediction_distance || { let keep_solver_contact = effective_contact_dist < prediction_distance || {
let world_pt1 = world_pos1 * contact.local_p1; let world_pt1 = world_pos1 * contact.local_p1;