Skip to content

Commit

Permalink
Add collision group filter for models
Browse files Browse the repository at this point in the history
Signed-off-by: Jorge Perez <[email protected]>
  • Loading branch information
Blast545 committed Feb 12, 2021
1 parent 3fbf8a8 commit 3629cb8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
10 changes: 10 additions & 0 deletions bullet/src/Base.hh
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,18 @@ inline Eigen::Vector3d convert(btVector3 vec)
class Base : public Implements3d<FeatureList<Feature>>
{
public: std::size_t entityCount = 0;
public: std::size_t collisionGroup = 1;

public: inline std::size_t GetNextEntity()
{
return entityCount++;
}

public: inline std::size_t GetNextCollisionGroup()
{
return collisionGroup++;
}

public: inline Identity InitiateEngine(std::size_t /*_engineID*/) override
{
const auto id = this->GetNextEntity();
Expand All @@ -150,6 +156,9 @@ class Base : public Implements3d<FeatureList<Feature>>
const auto id = this->GetNextEntity();
this->models[id] = std::make_shared<ModelInfo>(_modelInfo);

// A collision mask for each different model
this->collisionGroups[id] = 1 << GetNextCollisionGroup();

return this->GenerateIdentity(id, this->models.at(id));
}

Expand Down Expand Up @@ -190,6 +199,7 @@ class Base : public Implements3d<FeatureList<Feature>>
public: std::unordered_map<std::size_t, LinkInfoPtr> links;
public: std::unordered_map<std::size_t, CollisionInfoPtr> collisions;
public: std::unordered_map<std::size_t, JointInfoPtr> joints;
public: std::unordered_map<std::size_t, std::size_t> collisionGroups;

public: int internalTicksDivider = 0;

Expand Down
7 changes: 6 additions & 1 deletion bullet/src/SDFFeatures.cc
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,12 @@ Identity SDFFeatures::ConstructSdfLink(
body->setActivationState(DISABLE_DEACTIVATION);

const auto &world = this->worlds.at(modelInfo->world)->world;
world->addRigidBody(body);

// Models collide with everything except themselves
const int modelCollisionGroup = 1 << this->collisionGroups.at(_modelID);
const int collisionMask = 0xFFFFFFFF & ~modelCollisionGroup;
world->addRigidBody(body, modelCollisionGroup, collisionMask);
//world->addRigidBody(body);

// Generate an identity for it
const auto linkIdentity = this->AddLink({name, body, _modelID, pose, mass, linkInertiaDiag});
Expand Down

0 comments on commit 3629cb8

Please sign in to comment.