Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: force a complete QBVH rebuild when it gets too imbalanced. #185

Merged
merged 2 commits into from
Mar 23, 2024

Conversation

sebcrozet
Copy link
Member

@sebcrozet sebcrozet commented Mar 23, 2024

In many situations (see linked issues), especially at the first simulation frame, but also if many objects are inserted at once during the simulation, the QBVH incremental update algorithm could lead to a degenerate tree. Ideally the fix would improve the incremental update to lower risks of imbalance, but this is a very difficult problem.

A way simpler, but less efficient, fix (that is implemented in this PR) is to force a complete tree rebuild if it reaches a certain depth, indicating degeneracy. That depth is set to 15, which for a perfectly balanced QBVH, can hold 4^15 = 1.073.741.824 leaves (meaning that past that number of object in the tree you are guaranteed to trigger a forced rebuild at every update. But this is a very unlikely number to reach in practical games).

Fix #146
Close #169
Fix dimforge/rapier#466
Fix dimforge/rapier#532
Fix dimforge/rapier#558
Fix dimforge/rapier#450

@sebcrozet sebcrozet merged commit e19f9f0 into master Mar 23, 2024
4 of 5 checks passed
@sebcrozet sebcrozet deleted the qbvh-refit branch March 23, 2024 20:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment