From 471adf8357e0489bd2c0f7a9248b18e5c127648e Mon Sep 17 00:00:00 2001 From: Cedric Guillemet Date: Fri, 1 Apr 2022 11:00:21 +0200 Subject: [PATCH 1/2] Added a new flag for checking double sided mesh in collision detection (disable by default) --- packages/dev/core/src/Collisions/collider.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/packages/dev/core/src/Collisions/collider.ts b/packages/dev/core/src/Collisions/collider.ts index c3fb895a1b4..6ab779e9a23 100644 --- a/packages/dev/core/src/Collisions/collider.ts +++ b/packages/dev/core/src/Collisions/collider.ts @@ -85,6 +85,11 @@ export class Collider { */ public collidedMesh: Nullable; + /** + * If true, it check for double sided faces and only returns 1 collision instead of 2 + */ + public static DoubleSidedCheck = false; + private _collisionPoint = Vector3.Zero(); private _planeIntersectionPoint = Vector3.Zero(); private _tempVector = Vector3.Zero(); @@ -248,6 +253,12 @@ export class Collider { const signedDistToTrianglePlane = trianglePlane.signedDistanceTo(this._basePoint); const normalDotVelocity = Vector3.Dot(trianglePlane.normal, this._velocity); + // if DoubleSidedCheck is false(default), a double sided face will be consided 2 times. + // if true, it discard the faces having normal not facing velocity + if (Collider.DoubleSidedCheck && normalDotVelocity > 0.0001) { + return; + } + if (normalDotVelocity == 0) { if (Math.abs(signedDistToTrianglePlane) >= 1.0) { return; From adb55450f76f7a31f123573b5e9a59849edbeaae Mon Sep 17 00:00:00 2001 From: Cedric Guillemet Date: Fri, 1 Apr 2022 12:04:44 +0200 Subject: [PATCH 2/2] code format --- packages/dev/core/src/Collisions/collider.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/dev/core/src/Collisions/collider.ts b/packages/dev/core/src/Collisions/collider.ts index 6ab779e9a23..617a07a1b61 100644 --- a/packages/dev/core/src/Collisions/collider.ts +++ b/packages/dev/core/src/Collisions/collider.ts @@ -253,7 +253,7 @@ export class Collider { const signedDistToTrianglePlane = trianglePlane.signedDistanceTo(this._basePoint); const normalDotVelocity = Vector3.Dot(trianglePlane.normal, this._velocity); - // if DoubleSidedCheck is false(default), a double sided face will be consided 2 times. + // if DoubleSidedCheck is false(default), a double sided face will be consided 2 times. // if true, it discard the faces having normal not facing velocity if (Collider.DoubleSidedCheck && normalDotVelocity > 0.0001) { return;