-
-
Notifications
You must be signed in to change notification settings - Fork 208
BVH Broad Phase and Collider Trees #927
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
base: main
Are you sure you want to change the base?
Conversation
- The broad phase now emits new collision pairs and stores all pairs in a HashSet - Contact status and kind is now tracked with `ContactPairFlags` instead of booleans - The narrow phase adds new collision pairs, updates existing pairs, and responds to state changes separately instead of overwriting and doing extra work for persistent contact - State changes are tracked with bit vectors (bit sets), which are fast to iterate serially - The narrow phase is responsible for collision events instead of the `ContactReportingPlugin`
- Renamed `BroadCollisionPairs` to `BroadPhasePairSet` - Added `BroadPhasePairSet` for fast pair lookup with new `PairKey` - Improve broad phase docs
…pt-in - Removed `BroadPhaseAddedPairs` - Renamed `BroadPhasePairSet` to `BroadPhasePairs` - Moved contact creation to broad phase to improve persistence - Removed some graph querying overhead from contact pair removal by using the `EdgeIndex` directly - Made collision events opt-in with `CollisionEventsEnabled` component - Improved a lot of docs
|
I've got some issues with this branch (though not on main): -- I am using collision hooks, but get a panic at startup regarding conflicting schedule conflicts inside avian. Unfortunately I lost the info (since I was working inside where: -- after turning that off for now, when my -- unfortunately, after this stage, I can't rebuild anymore without It looks like (and more) (I see that last error appears in the Ubuntu build, so I guess you have a repro there) |
|
After doing with the top of the backtrace: |
|
Hi, thanks for trying it out! That collision hook crash should hopefully be fixed now if you run
Hmm the crash looks like it'd be unrelated to this PR, since it's about simulation islands and not the BVH stuff, but I'll see if I can reproduce this when I have time. Edit: Or hmm, I just fixed one bug where the broad phase wasn't setting some flags correctly for contact data, which could have been related? Not sure |

Objective
Implement a new broad phase algorithm using Bounding Volume Hierarchies (BVH) provided by OBVHS. This replaces our existing broad phase that uses Sweep and Prune (SAP).
The goal is to greatly reduce overhead for large scenes with lots of colliders. Updating and querying the acceleration structures should be efficient, and static or sleeping bodies should have minimal runtime cost. The existing SAP broad phase is very inefficient at this, and scales poorly even with only static geometry.
Additionally, we can reuse these BVHs for accelerating spatial queries. Currently, they just use Parry's BVH, which we update and manage very inefficiently. I will leave migrating spatial queries to the new BVHs for a follow-up however, to keep the diff more manageable.
Huge thanks to @DGriffin91 for implementing incremental leaf insertion and removal, partial rebuilds, and more for OBVHS to better suit our needs <3
Solution
ColliderTreetype that contains aBvh2, its collision proxies, and a workspace for reusing allocationsColliderTreesresource, containing a separateColliderTreefor dynamic, kinematic, static, and standalone (=no body) collidersColliderTreePluginthat managesColliderTreesfor a collider typeCColliderAabbs andEnlargedAabbs of collidersEnlargedAabb, or otherwise require updating the treeColliderTreeOptimizationsettings (default is an adaptive hybrid that switches between them)BroadPhaseCorePluginthat sets up the resources, system sets, and diagnostics required for the broad phaseBvhBroadPhasePluginthat implements a BVH-based broad phase algorithmTesting
Ran examples and tested adding/removing/enabling/disabling colliders and changing various different configurations.
Note for Reviewers
The commit history here is a bit borked for some reason, and contains some older commits that are unrelated. The first real commit is "Implement dynamic BVH broad phase with OBVHS (WIP)" (a603c5e).
Showcase
Below is a test scene with 10k dynamic bodies that cannot sleep, with approximately 25% of them being moved each frame. Spatial queries are disabled.
Before, with the SAP broad phase:
After, with the BVH broad phase:
Future Work
Todo