Skip to content

Commit c70bbdf

Browse files
committed
that's an oopsy.
1 parent 956a679 commit c70bbdf

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

BepuPhysics/CollisionDetection/MeshReduction.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,12 @@ public static void ReduceManifolds(ref Buffer<Triangle> continuationTriangles, r
445445
var contactQueryMin = meshSpaceContact - contactExpansion;
446446
var contactQueryMax = meshSpaceContact + contactExpansion;
447447
enumerator.List.Count = 0;
448-
mesh->Tree.GetOverlaps(contactQueryMin, contactQueryMax, pool, ref enumerator);
448+
//The contact and the cached TestTriangle data live in scaled mesh-local space (GetLocalChild applies the mesh's scale),
449+
//but the Tree was built from unscaled source triangles. Bring the query into the tree's space before traversing.
450+
//Take min/max after scaling to compensate for negative scales.
451+
var scaledQueryMin = contactQueryMin * mesh->inverseScale;
452+
var scaledQueryMax = contactQueryMax * mesh->inverseScale;
453+
mesh->Tree.GetOverlaps(Vector3.Min(scaledQueryMin, scaledQueryMax), Vector3.Max(scaledQueryMin, scaledQueryMax), pool, ref enumerator);
449454
//Note that the test triangles detected by querying may exceed the count in extremely rare cases, so it's not safe to use AllocateUnsafely without some extra work.
450455
//Resizing invalidates table indices, so do any that ahead of time.
451456
testTriangles.EnsureCapacity(testTriangles.Count + enumerator.List.Count, pool);

0 commit comments

Comments
 (0)