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

Bullet margin fix and Aabb query #399

Merged
merged 8 commits into from
Jan 17, 2020
Merged

Bullet margin fix and Aabb query #399

merged 8 commits into from
Jan 17, 2020

Conversation

aclegg3
Copy link
Contributor

@aclegg3 aclegg3 commented Dec 20, 2019

Motivation and Context

Bullet collision shapes have a default margin on 0.04.

We allow the user to assign a single collision margin value for each rigid body. We assign this to the root of the btCompoundShape object which holds all sub-components of the collision shape. We have not been explicitly overriding the default margins for these sub-objects. This caused a difference between joined and component hierarchy objects in the actual collision margins of the whole, as sub-component margins are accumulated additively (i.e. default margins (0.04) on sub-components would be added to the user defined margin).

This PR fixes said issue.

Sub-thesis:

  • Fix PhysicsTest.cpp build without --bullet issue. (identified by @matthewjmay ).
  • Added here to avoid git churn because this PR contains the first functionality which requires the linking and better fix on master would be to remove the broken include.

How Has This Been Tested

This PR introduces a test to be sure that different collision shape modes (scene, joined, hierarchal) will result in the correct margin. To do so, we add functionality for querying collision Aabb from Bullet and check this against ground truth for a known test asset composed of multiple parts. This test will be extended to encompass additional collision modes such as bounding boxes when added.

Types of changes

  • Docs change / refactoring / dependency upgrade
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have completed my CLA (see CONTRIBUTING)
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@aclegg3 aclegg3 self-assigned this Dec 20, 2019
@facebook-github-bot facebook-github-bot added the CLA Signed Do not delete this pull request or issue due to inactivity. label Dec 20, 2019
@aclegg3
Copy link
Contributor Author

aclegg3 commented Jan 8, 2020

Ready for review.

@codecov-io
Copy link

codecov-io commented Jan 8, 2020

Codecov Report

Merging #399 into master will increase coverage by 0.56%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #399      +/-   ##
==========================================
+ Coverage   56.97%   57.53%   +0.56%     
==========================================
  Files         175      175              
  Lines        8153     8181      +28     
  Branches       84       84              
==========================================
+ Hits         4645     4707      +62     
+ Misses       3508     3474      -34
Flag Coverage Δ
#CPP 53.65% <100%> (+0.89%) ⬆️
#JavaScript 10% <ø> (ø) ⬆️
#Python 78.82% <ø> (ø) ⬆️
Impacted Files Coverage Δ
src/esp/bindings/GfxBindings.cpp 93.65% <ø> (-0.2%) ⬇️
src/esp/physics/bullet/BulletPhysicsManager.cpp 49% <100%> (ø) ⬆️
src/esp/physics/bullet/BulletRigidObject.cpp 62.93% <100%> (ø) ⬆️
src/esp/gfx/RenderCamera.h 100% <100%> (ø) ⬆️
src/esp/sensor/PinholeCamera.cpp 41.02% <100%> (ø) ⬆️
src/tests/SimTest.cpp 100% <100%> (ø) ⬆️
src/tests/PhysicsTest.cpp 100% <100%> (ø) ⬆️
src/esp/gfx/RenderCamera.cpp 75% <100%> (+9.78%) ⬆️
src/esp/sensor/Sensor.h 56.66% <0%> (+6.66%) ⬆️
src/esp/scene/ObjectControls.cpp 26.92% <0%> (+26.92%) ⬆️
... and 2 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d71406d...3ac5379. Read the comment docs.

@aclegg3 aclegg3 mentioned this pull request Jan 10, 2020
11 tasks
@aclegg3 aclegg3 mentioned this pull request Jan 14, 2020
11 tasks
Copy link
Contributor

@msbaines msbaines left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm looking at this code for the first time so my knowledge is currently shallow.

src/esp/physics/bullet/BulletPhysicsManager.cpp Outdated Show resolved Hide resolved
@@ -177,6 +177,8 @@ bool BulletRigidObject::initializeObject(
if (joinCollisionMeshes) {
btTransform t;
t.setIdentity();
bObjectConvexShapes_.back()->setMargin(0.0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't dug too deep in the physics code yet but why is this here and not in constructBulletCompoundFromMeshes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

constructBulletCompoundFromMeshes is a recursive function.

With the join flag, as in this case, it is building up a single convex shape from all components. This will not be complete until after the recursion is done.

Without the join flag, each level of recursion builds a new object, so it makes sense to set margin upon construction in that case.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The constructBulletCompoundFromMeshes code might be easier to read with two functions. A top-level function and a recursive helper. It feels like functionality that should be part of constructBulletCompoundFromMeshes is part of initializeObject.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair point. 👍
A refactor like this should probably be a separate PR after this bug fix is merged.

src/tests/PhysicsTest.cpp Outdated Show resolved Hide resolved
@@ -177,6 +177,8 @@ bool BulletRigidObject::initializeObject(
if (joinCollisionMeshes) {
btTransform t;
t.setIdentity();
bObjectConvexShapes_.back()->setMargin(0.0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The constructBulletCompoundFromMeshes code might be easier to read with two functions. A top-level function and a recursive helper. It feels like functionality that should be part of constructBulletCompoundFromMeshes is part of initializeObject.

src/esp/physics/bullet/BulletPhysicsManager.cpp Outdated Show resolved Hide resolved
src/tests/PhysicsTest.cpp Outdated Show resolved Hide resolved
@aclegg3 aclegg3 requested a review from msbaines January 17, 2020 17:46
@aclegg3 aclegg3 merged commit 94f0c53 into master Jan 17, 2020
@aclegg3 aclegg3 deleted the bullet-margin-fix branch January 17, 2020 18:15
eundersander pushed a commit to eundersander/habitat-sim that referenced this pull request Aug 6, 2020
Cleaned up agent state checks as np.close method can cause issues and possible breaks. As well as logic changed: we tolerate that new agent's position can differ from the one requested by user as the agent should stand on the plane and can't intersect with other meshes.
Ram81 pushed a commit to Ram81/habitat-web-sim that referenced this pull request Dec 10, 2020
* Added Aabb query to BulletPhysicsManager and BulletRigidObject. 

* Added C++ test for margin setting between joined and unjoined objects and the scene.

* Fixed margin setting bugs.

* Bug fix: make PhysicsTest.cpp build without --bullet
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Do not delete this pull request or issue due to inactivity.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants