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 collision from bounding box #423

Merged
merged 22 commits into from
Jan 21, 2020
Merged

Conversation

aclegg3
Copy link
Contributor

@aclegg3 aclegg3 commented Jan 10, 2020

Motivation and Context

Primitive box shapes are much more efficient and stable than meshes for collision.

This PR enables the use of an object's accumulated mesh bounding box to serve as its collision shape. It also allows this option to be configured in an object's physics config file. This option will override other options such as choice of collision mesh and mesh joining.

TODO in future PR:

  • Add an option to build a compound of component bounding boxes for approximate concavity.

How Has This Been Tested

C++ CI test.

Local testing in viewer:
sphere_mesh_vs_bb

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.

… to default.phys_scene_config.json. Modified inertia computation for bounding box objects.
… test confirming bug in margin setting between joined and unjoined objects.
…e to margin test. Fixed margin setting bugs.
…entation assertion to account for jittering.
@aclegg3 aclegg3 self-assigned this Jan 10, 2020
@facebook-github-bot facebook-github-bot added the CLA Signed Do not delete this pull request or issue due to inactivity. label Jan 10, 2020
@codecov-io
Copy link

codecov-io commented Jan 10, 2020

Codecov Report

Merging #423 into master will increase coverage by 0.2%.
The diff coverage is 92.5%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master     #423     +/-   ##
=========================================
+ Coverage   56.63%   56.83%   +0.2%     
=========================================
  Files         155      156      +1     
  Lines        6832     6872     +40     
  Branches       84       84             
=========================================
+ Hits         3869     3906     +37     
- Misses       2963     2966      +3
Flag Coverage Δ
#CPP 51.15% <94.73%> (+0.42%) ⬆️
#JavaScript 10% <ø> (ø) ⬆️
#Python 78.8% <50%> (-0.03%) ⬇️
Impacted Files Coverage Δ
src/esp/gfx/Simulator.h 100% <ø> (ø) ⬆️
src/esp/physics/PhysicsManager.h 31.81% <0%> (-3.19%) ⬇️
src/tests/PhysicsTest.cpp 100% <100%> (ø) ⬆️
src/esp/physics/bullet/BulletPhysicsManager.cpp 54.46% <100%> (+2.12%) ⬆️
src/esp/physics/bullet/BulletRigidObject.h 100% <100%> (ø)
src/esp/physics/bullet/BulletRigidObject.cpp 69.36% <100%> (+0.43%) ⬆️
habitat_sim/simulator.py 93.83% <50%> (-0.39%) ⬇️

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 640729c...5c16431. Read the comment docs.

src/esp/physics/bullet/BulletRigidObject.cpp Outdated Show resolved Hide resolved
src/esp/physics/bullet/BulletRigidObject.h Outdated Show resolved Hide resolved
src/esp/physics/bullet/BulletRigidObject.cpp Outdated Show resolved Hide resolved
btVector3 dim(cumulativeBB_.size() / 2.0);
bObjectShape_->removeChildShape(bGenericShapes_.back().get());
bGenericShapes_.clear();
bGenericShapes_.emplace_back(std::make_unique<btBoxShape>(dim));
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is bGenericShapes needed? Couldn't a local variable have been used instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We need to store the collision shapes since Bullet does not replicate them internally, this is also consistent with how we handle other collision shapes.

Copy link
Contributor

Choose a reason for hiding this comment

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

Why is bGenericShapes_ a vector? I can't seem to find anywhere else that adds something to it, i.e. bGenericShapes_.size() == 1 is always true.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Next step is to enable component level bounding box hierarchies for approximate concavities. This will be used soon.

Copy link
Contributor

Choose a reason for hiding this comment

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

We need to store the collision shapes since Bullet does not replicate them internally, this is also consistent with how we handle other collision shapes.

Understand. But bGenericShape is only ever added as a ChildShape to bObjectShape. From your later comment it sounds like bGenericShape is needed for future work.

src/esp/physics/bullet/BulletRigidObject.cpp Outdated Show resolved Hide resolved

setInertiaVector(Magnum::Vector3(bInertia));
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

The logic above is now duplicated. Could it be put into its own function?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These two instances are different enough that this wouldn't give us much. Since one is before initialization of the bObjectRigidBody_ and the other is after, most of the get/set code would still need to stay for each.

// Then set the collision shape to the cumulativeBB_ if necessary
if (objID != ID_UNDEFINED) {
BulletRigidObject* bro =
static_cast<BulletRigidObject*>(existingObjects_.at(objID));
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we ever expect to have multiple types of rigid objects in existingObjects_? (i.e. some objects are bullet objects, others are simple kinematic ones?). If so, a dynamic cast would be safer here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Current design is to set the MotionType of the object to specify kinematic, dynamic or static. To enable collisions between all types, they must still be BulletRigidObject type, so I think this is fine. If the user has enabled the BulletPhysicsManager then all objects in this list are BulletRigidObject. Will likely setup a different PhysicsManager type for dealing with multi-bodies.

btVector3 dim(cumulativeBB_.size() / 2.0);
bObjectShape_->removeChildShape(bGenericShapes_.back().get());
bGenericShapes_.clear();
bGenericShapes_.emplace_back(std::make_unique<btBoxShape>(dim));
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is bGenericShapes_ a vector? I can't seem to find anywhere else that adds something to it, i.e. bGenericShapes_.size() == 1 is always true.

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.

LGTM. Will let Erik approve.

btVector3 dim(cumulativeBB_.size() / 2.0);
bObjectShape_->removeChildShape(bGenericShapes_.back().get());
bGenericShapes_.clear();
bGenericShapes_.emplace_back(std::make_unique<btBoxShape>(dim));
Copy link
Contributor

Choose a reason for hiding this comment

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

We need to store the collision shapes since Bullet does not replicate them internally, this is also consistent with how we handle other collision shapes.

Understand. But bGenericShape is only ever added as a ChildShape to bObjectShape. From your later comment it sounds like bGenericShape is needed for future work.

@aclegg3 aclegg3 merged commit 2684f62 into master Jan 21, 2020
@aclegg3 aclegg3 deleted the bullet-collision-from-bounding-box branch January 21, 2020 23:48
Ram81 pushed a commit to Ram81/habitat-web-sim that referenced this pull request Dec 10, 2020
* Enabled bounding box collision for BulletRigidObjects

* Added bounding box C++ test and test asset sphere.glb.
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.

None yet

5 participants