Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/release-6.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
jslee02 committed Oct 4, 2017
2 parents 5c0c014 + b8b4a14 commit cc34abd
Show file tree
Hide file tree
Showing 17 changed files with 402 additions and 40 deletions.
92 changes: 81 additions & 11 deletions dart/collision/CollisionFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,44 +38,114 @@ namespace dart {
namespace collision {

//==============================================================================
bool BodyNodeCollisionFilter::needCollision(
bool CollisionFilter::needCollision(
const CollisionObject* object1, const CollisionObject* object2) const
{
return !ignoresCollision(object1, object2);
}

//==============================================================================
void CompositeCollisionFilter::addCollisionFilter(const CollisionFilter* filter)
{
// nullptr is not an allowed filter
if (!filter)
return;

mFilters.insert(filter);
}

//==============================================================================
void CompositeCollisionFilter::removeCollisionFilter(
const CollisionFilter* filter)
{
mFilters.erase(filter);
}

//==============================================================================
void CompositeCollisionFilter::removeAllCollisionFilters()
{
mFilters.clear();
}

//==============================================================================
bool CompositeCollisionFilter::ignoresCollision(
const CollisionObject* object1, const CollisionObject* object2) const
{
for (const auto* filter : mFilters)
{
if (filter->ignoresCollision(object1, object2))
return true;
}

return false;
}

//==============================================================================
void BodyNodeCollisionFilter::addBodyNodePairToBlackList(
const dynamics::BodyNode* bodyNode1, const dynamics::BodyNode* bodyNode2)
{
mBodyNodeBlackList.addPair(bodyNode1, bodyNode2);
}

//==============================================================================
void BodyNodeCollisionFilter::removeBodyNodePairFromBlackList(
const dynamics::BodyNode* bodyNode1, const dynamics::BodyNode* bodyNode2)
{
mBodyNodeBlackList.removePair(bodyNode1, bodyNode2);
}

//==============================================================================
void BodyNodeCollisionFilter::removeAllBodyNodePairsFromBlackList()
{
mBodyNodeBlackList.removeAllPairs();
}

//==============================================================================
bool BodyNodeCollisionFilter::ignoresCollision(
const collision::CollisionObject* object1,
const collision::CollisionObject* object2) const
{
if (object1 == object2)
return false;
return true;

auto shapeNode1 = object1->getShapeFrame()->asShapeNode();
auto shapeNode2 = object2->getShapeFrame()->asShapeNode();

// We don't filter out for non-ShapeNode because this class shouldn't have the
// authority to make decisions about filtering any ShapeFrames that aren't
// attached to a BodyNode. So here we just return false. In order to decide
// whether the non-ShapeNode should be ignored, please use other collision
// filters.
if (!shapeNode1 || !shapeNode2)
return true;
// We assume that non-ShapeNode is always being checked collision.
return false;

auto bodyNode1 = shapeNode1->getBodyNodePtr();
auto bodyNode2 = shapeNode2->getBodyNodePtr();

if (bodyNode1 == bodyNode2)
return false;
return true;

if (!bodyNode1->isCollidable() || !bodyNode2->isCollidable())
return false;
return true;

if (bodyNode1->getSkeleton() == bodyNode2->getSkeleton())
{
auto skeleton = bodyNode1->getSkeleton();

if (!skeleton->isEnabledSelfCollisionCheck())
return false;
return true;

if (!skeleton->isEnabledAdjacentBodyCheck())
{
if (areAdjacentBodies(bodyNode1, bodyNode2))
return false;
return true;
}
}

return true;
if (mBodyNodeBlackList.contains(bodyNode1, bodyNode2))
return true;

return false;
}

//==============================================================================
Expand All @@ -93,5 +163,5 @@ bool BodyNodeCollisionFilter::areAdjacentBodies(
return false;
}

} // namespace collision
} // namespace dart
} // namespace collision
} // namespace dart
75 changes: 67 additions & 8 deletions dart/collision/CollisionFilter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
#ifndef DART_COLLISION_COLLISIONFILTER_HPP_
#define DART_COLLISION_COLLISIONFILTER_HPP_

#include "dart/common/Deprecated.hpp"
#include "dart/collision/detail/UnorderedPairs.hpp"

namespace dart {

namespace dynamics {
Expand All @@ -42,22 +45,78 @@ namespace collision {

class CollisionObject;

struct CollisionFilter
class CollisionFilter
{
virtual bool needCollision(const CollisionObject* object1,
const CollisionObject* object2) const = 0;
public:
/// Returns true if the given two CollisionObjects should be checked by the
/// collision detector, false otherwise.
/// \deprecated Deprecated in 6.3.0. Please use ignoreCollision instead. Note
/// that ignoreCollision returns logically opposite to what needCollision
/// returns.
DART_DEPRECATED(6.3)
bool needCollision(
const CollisionObject* object1, const CollisionObject* object2) const;

/// Returns true if the given two CollisionObjects should be checked by the
/// collision detector, false otherwise.
virtual bool ignoresCollision(
const CollisionObject* object1, const CollisionObject* object2) const = 0;
};

struct BodyNodeCollisionFilter : CollisionFilter
class CompositeCollisionFilter : public CollisionFilter
{
bool needCollision(const CollisionObject* object1,
const CollisionObject* object2) const override;
public:
/// Adds a collision filter to this CompositeCollisionFilter.
void addCollisionFilter(const CollisionFilter* filter);

/// Removes a collision filter from this CompositeCollisionFilter.
void removeCollisionFilter(const CollisionFilter* filter);

/// Removes all the collision filters from this CompositeCollisionFilter.
void removeAllCollisionFilters();

// Documentation inherited
bool ignoresCollision(
const CollisionObject* object1,
const CollisionObject* object2) const override;

protected:
/// Collision filters
std::unordered_set<const CollisionFilter*> mFilters;
};

class BodyNodeCollisionFilter : public CollisionFilter
{
public:
/// Add a BodyNode pair to the blacklist.
void addBodyNodePairToBlackList(
const dynamics::BodyNode* bodyNode1,
const dynamics::BodyNode* bodyNode2);

/// Remove a BodyNode pair from the blacklist.
void removeBodyNodePairFromBlackList(
const dynamics::BodyNode* bodyNode1,
const dynamics::BodyNode* bodyNode2);

/// Remove all the BodyNode pairs from the blacklist.
void removeAllBodyNodePairsFromBlackList();

// Documentation inherited
bool ignoresCollision(
const CollisionObject* object1,
const CollisionObject* object2) const override;

private:
/// Returns true if the two BodyNodes are adjacent BodyNodes (i.e., the two
/// BodyNodes are connected by a Joint).
bool areAdjacentBodies(const dynamics::BodyNode* bodyNode1,
const dynamics::BodyNode* bodyNode2) const;

/// List of pairs to be ignored in the collision detection.
detail::UnorderedPairs<dynamics::BodyNode> mBodyNodeBlackList;
};

} // namespace collision
} // namespace dart
} // namespace collision
} // namespace dart

#endif // DART_COLLISION_COLLISIONFILTER_HPP_
2 changes: 1 addition & 1 deletion dart/collision/bullet/BulletCollisionDetector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ void filterOutCollisions(btCollisionWorld* world)
const auto collObj0 = static_cast<BulletCollisionObject*>(userPtr0);
const auto collObj1 = static_cast<BulletCollisionObject*>(userPtr1);

if (!filter->needCollision(collObj0, collObj1))
if (filter->ignoresCollision(collObj0, collObj1))
manifoldsToRelease.push_back(contactManifold);
}

Expand Down
2 changes: 1 addition & 1 deletion dart/collision/bullet/detail/BulletCollisionDispatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ bool BulletCollisionDispatcher::needsCollision(
const auto collObj1
= static_cast<BulletCollisionObject*>(body1->getUserPointer());

if (mFilter && !mFilter->needCollision(collObj0, collObj1))
if (mFilter && mFilter->ignoresCollision(collObj0, collObj1))
return false;

return btCollisionDispatcher::needsCollision(body0, body1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ bool BulletOverlapFilterCallback::needBroadphaseCollision(
const auto collObj0 = static_cast<BulletCollisionObject*>(userPtr0);
const auto collObj1 = static_cast<BulletCollisionObject*>(userPtr1);

return filter->needCollision(collObj0, collObj1);
return !filter->ignoresCollision(collObj0, collObj1);
}

return collide;
Expand Down
4 changes: 2 additions & 2 deletions dart/collision/dart/DARTCollisionDetector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ bool DARTCollisionDetector::collide(
{
auto* collObj2 = objects[j];

if (filter && !filter->needCollision(collObj1, collObj2))
if (filter && filter->ignoresCollision(collObj1, collObj2))
continue;

collisionFound = checkPair(collObj1, collObj2, option, result);
Expand Down Expand Up @@ -207,7 +207,7 @@ bool DARTCollisionDetector::collide(
{
auto* collObj2 = objects2[j];

if (filter && !filter->needCollision(collObj1, collObj2))
if (filter && filter->ignoresCollision(collObj1, collObj2))
continue;

collisionFound = checkPair(collObj1, collObj2, option, result);
Expand Down
Loading

0 comments on commit cc34abd

Please sign in to comment.