Merge shape pair contacts into body-pair contacts - #64
Open
ZehMatt wants to merge 3 commits into
Open
Conversation
ZehMatt
marked this pull request as draft
July 11, 2026 03:23
ZehMatt
force-pushed
the
contact-reduction
branch
from
July 11, 2026 06:42
d1774b5 to
76cbfb2
Compare
ZehMatt
marked this pull request as ready for review
July 11, 2026 06:42
ZehMatt
force-pushed
the
contact-reduction
branch
from
July 11, 2026 06:48
76cbfb2 to
4d3bb5b
Compare
Owner
Owner
|
Sorry, didn't mean to close this. Meant to close the issue. The PR is still interesting. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Source Engine props are convex decompositions, the metal_wheel1 model from the issue is 37 hulls on one body. When two of these stack, every touching hull pair makes its own manifold, so a single body pair ends up with hundreds of near coplanar contact points. The solver has to push all of them through TGS soft and they fight each other: the stack never manages to sleep, restitution can add energy (a slab bounces higher than it was dropped from), and solve dominates the step.
This PR changes the contact to represent a body pair. Broadphase still works on shape pairs, but overlapping pairs between two bodies merge into one contact as sub contacts. The narrowphase collects a local manifold from every sub and
clusters them by normal into a few manifolds with up to 4 points each, warm started by feature id. This is the same clustering the mesh contact path already does per triangle, generalized so a sub collision can be a hull pair or a mesh. Contacts with a single shape pair take exactly the same path as before, the SIMD solver path and the existing determinism hashes are untouched, so scenes without compounds are bit identical.
Benchmarks
The trees and joint_grid wins come from recycling: one cached transform check per body pair instead of one per shape pair, so a 22 hull tree does 1 check instead of 22. Washer is the one real cost, debris against the 36 hull drum merges onto the scalar solver path and loses the SIMD lanes. The -1, +1 are tolerance, I re-ran it a couple times and it flip-flops.
The new wheel_stack benchmark (30 stacked wheels, 1110 hulls) has no counterpart on main to compare against, on this PR it runs 0.095ms per step with collide at 0.006ms, and the whole stack is 30 contacts, one per body pair. The stack settles and goes to sleep.
There is a new determinism test that hashes the wheel stack across worker counts, baked for float and double builds. Behavior tests cover stacking, restitution, mesh contacts, high mass ratio, rolling, events, curved contacts and sliding friction, plus a benchmark and a sample built from the actual .phy hull data.
Something to note: hit events on a merged contact report the first sub contacts shapes, and pre solve events are not delivered for multi sub contacts (mesh contacts already behave this way). The snapshot image version was bumped, old
recordings dont replay since the sim results changed anyway.
Closes #57