-
Notifications
You must be signed in to change notification settings - Fork 97
Check pair margin AABB before narrow phase check #1208
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: master
Are you sure you want to change the base?
Check pair margin AABB before narrow phase check #1208
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1208 +/- ##
==========================================
- Coverage 93.53% 93.53% -0.01%
==========================================
Files 272 272
Lines 18796 18823 +27
==========================================
+ Hits 17581 17606 +25
- Misses 1215 1217 +2
🚀 New features to boost your workflow:
|
I'll try and test this next week and report back with the differences compared to before any of the recent collision updates |
838f23d
to
a30cd7c
Compare
results_callback_.collisions_.collision_margin_data.getCollisionMargin(cow0->getName(), cow1->getName()); | ||
btVector3 min_aabb[2], max_aabb[2]; // NOLINT | ||
cow0->getAABB(min_aabb[0], max_aabb[0], contact_threshold / 2.0); | ||
cow1->getAABB(min_aabb[1], max_aabb[1], contact_threshold / 2.0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using no and full threshold instead of half twice would save one set of expansion calculations, but we'd need a getAABB_noexpand() function without expansion.
TesseractBroadphaseBridgedManifoldResult contactPointResult(&obj0Wrap, &obj1Wrap, results_callback_); | ||
contactPointResult.m_closestPointDistanceThreshold = | ||
results_callback_.collisions_.collision_margin_data.getCollisionMargin(cow0->getName(), cow1->getName()); | ||
const bool aabb_check = (min_aabb[0][0] <= max_aabb[1][0] && max_aabb[0][0] >= min_aabb[1][0]) && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use Bullet function TestAabbAgainstAabb2(min_aabb[0], max_aabb[0], min_aabb[1], max_aabb[1])
contact_test_data_.collision_margin_data.getCollisionMargin(cow1->getName(), cow2->getName()); | ||
cow2->getAABB(min_aabb[1], max_aabb[1], contact_threshold); | ||
|
||
bool aabb_check = (min_aabb[0][0] <= max_aabb[1][0] && max_aabb[0][0] >= min_aabb[1][0]) && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use Bullet function TestAabbAgainstAabb2(min_aabb[0], max_aabb[0], min_aabb[1], max_aabb[1])
contact_test_data_.collision_margin_data.getCollisionMargin(cow1->getName(), cow2->getName()); | ||
cow2->getAABB(min_aabb[1], max_aabb[1], contact_threshold); | ||
|
||
bool aabb_check = (min_aabb[0][0] <= max_aabb[1][0] && max_aabb[0][0] >= min_aabb[1][0]) && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use Bullet function TestAabbAgainstAabb2(min_aabb[0], max_aabb[0], min_aabb[1], max_aabb[1])
pair.m_algorithm->processCollision(&obj0Wrap, &obj1Wrap, dispatch_info_, &contactPointResult); | ||
} | ||
|
||
// Should this return true? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it should not return true here. We might return true if needsCollision is false above, see Bullet source, where it mentions that returning true allows removal of the pair.
TesseractBroadphaseBridgedManifoldResult contactPointResult(&obj0Wrap, &obj1Wrap, results_callback_); | ||
contactPointResult.m_closestPointDistanceThreshold = | ||
results_callback_.collisions_.collision_margin_data.getCollisionMargin(cow0->getName(), cow1->getName()); | ||
const bool aabb_check = (min_aabb[0][0] <= max_aabb[1][0] && max_aabb[0][0] >= min_aabb[1][0]) && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could add an additional check here: if (contact_threshold < (cow0->getContactProcessingThreshold() + cow1->getContactProcessingThreshold()) then do the extra aabb_check.
{ | ||
btCollisionObjectWrapper obj0Wrap(nullptr, cow0->getCollisionShape(), cow0, cow0->getWorldTransform(), -1, -1); | ||
btCollisionObjectWrapper obj1Wrap(nullptr, cow1->getCollisionShape(), cow1, cow1->getWorldTransform(), -1, -1); | ||
if (!results_callback_.needsCollision(cow0, cow1)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're basically replicating the broadphase AABB check here, but with the actual margin between the objects. In the scenario where all margins are the same, this would lead to completely superfluous duplicate AABB checking. When margins vary, the cost of duplicate AABB checks is most likely compensated for by the reduced number of narrowphase collide calls. I just looked into the Bullet source, and maybe it is possible to override the original broadphase AABB check. Then we could insert the actual pair margin there, which would be ideal. I don't have time to dive into this right now, but I can look into it next week.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this callback.
(aabb1.min_[2] <= aabb2.max_[2] && aabb1.max_[2] >= aabb2.min_[2]); | ||
|
||
// Check if ABB are overlapping | ||
if (!aabb_check) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can add the same check as suggested above: first check if the sum of the object margins is smaller than the pair margin before doing the extra aabb check.
(aabb1.min_[2] <= aabb2.max_[2] && aabb1.max_[2] >= aabb2.min_[2]); | ||
|
||
// Check if ABB are overlapping | ||
if (!aabb_check) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can add the same check as suggested above: first check if the sum of the object margins is smaller than the pair margin before doing the extra aabb check.
I know this isn't ready to merge yet, but I ran some tests on my application that go through a bunch of various plans with several unique collision pairs, although none exceed the default collision margin, just reduce it. On commit 53ad1b4 (before @rjoomen's recent changes): averaged 6 min 43 sec This was only 2 trials each, but this PR didn't show improvement for me, basically the same as the current master, which did for sure show improvement from the previous version |
@marrts