Skip to content

Commit e0f2c4e

Browse files
authored
Fix plane collision handling for Bullet and FCL (#2246)
1 parent de21d44 commit e0f2c4e

File tree

3 files changed

+28
-19
lines changed

3 files changed

+28
-19
lines changed

dart/collision/bullet/BulletCollisionGroup.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
#include "dart/collision/bullet/BulletCollisionObject.hpp"
3737
#include "dart/collision/bullet/detail/BulletCollisionDispatcher.hpp"
3838

39+
#include <BulletCollision/Gimpact/btGImpactCollisionAlgorithm.h>
40+
3941
#if !defined(_WIN32)
4042
#include <LinearMath/btAlignedAllocator.h>
4143

@@ -180,7 +182,8 @@ BulletCollisionGroup::BulletCollisionGroup(
180182
mBulletCollisionConfiguration.get()))
181183
{
182184
ensureBulletAllocator();
183-
// Do nothing
185+
btGImpactCollisionAlgorithm::registerAlgorithm(
186+
static_cast<btCollisionDispatcher*>(mBulletDispatcher.get()));
184187
}
185188

186189
//==============================================================================

dart/collision/fcl/FCLCollisionDetector.cpp

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -985,21 +985,18 @@ FCLCollisionDetector::createFCLCollisionGeometry(
985985
// Use mesh since FCL doesn't support pyramid shape.
986986
geom = createPyramid<fcl::OBBRSS>(*pyramid, fcl::getTransform3Identity());
987987
} else if (PlaneShape::getStaticType() == shapeType) {
988-
if (FCLCollisionDetector::PRIMITIVE == type) {
989-
DART_ASSERT(dynamic_cast<const PlaneShape*>(shape.get()));
990-
auto plane = static_cast<const PlaneShape*>(shape.get());
991-
const Eigen::Vector3d normal = plane->getNormal();
992-
const double offset = plane->getOffset();
993-
994-
geom = new fcl::Halfspace(FCLTypes::convertVector3(normal), offset);
995-
} else {
996-
geom = createCube<fcl::OBBRSS>(1000.0, 0.0, 1000.0);
997-
998-
DART_WARN(
999-
"[FCLCollisionDetector] PlaneShape is not supported by "
1000-
"FCLCollisionDetector. We create a thin box mesh instead, where the "
1001-
"size is [1000 0 1000].");
1002-
}
988+
DART_ASSERT(dynamic_cast<const PlaneShape*>(shape.get()));
989+
const auto plane = static_cast<const PlaneShape*>(shape.get());
990+
const Eigen::Vector3d normal = plane->getNormal();
991+
const double offset = plane->getOffset();
992+
993+
geom = new fcl::Halfspace(FCLTypes::convertVector3(normal), offset);
994+
995+
DART_WARN_ONCE_IF(
996+
FCLCollisionDetector::MESH == type,
997+
"[FCLCollisionDetector] PlaneShape requested with primitive shape type "
998+
"MESH. Using analytic halfspace instead of the previous thin-box "
999+
"fallback to keep plane collisions reliable.");
10031000
} else if (MeshShape::getStaticType() == shapeType) {
10041001
DART_ASSERT(dynamic_cast<const MeshShape*>(shape.get()));
10051002

tests/integration/collision/test_PlaneShapeCollision.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include <dart/constraint/ConstraintSolver.hpp>
3838

3939
#include <dart/collision/bullet/BulletCollisionDetector.hpp>
40+
#include <dart/collision/fcl/FCLCollisionDetector.hpp>
4041
#include <dart/collision/ode/OdeCollisionDetector.hpp>
4142

4243
#include <dart/dynamics/All.hpp>
@@ -111,9 +112,6 @@ void runIssue1234Test(
111112
const auto box
112113
= std::make_shared<dart::dynamics::BoxShape>(bb.getMax() - bb.getMin());
113114

114-
const auto sphere = std::make_shared<dart::dynamics::SphereShape>(
115-
bb.getMax()[0] - bb.getMin()[0]);
116-
117115
std::size_t numTests = 0;
118116
std::size_t numPasses = 0;
119117

@@ -172,3 +170,14 @@ TEST(Issue1234, Ode)
172170
runIssue1234Test(
173171
[] { return dart::collision::OdeCollisionDetector::create(); });
174172
}
173+
174+
//==============================================================================
175+
TEST(Issue1234, Fcl)
176+
{
177+
runIssue1234Test([] {
178+
auto detector = dart::collision::FCLCollisionDetector::create();
179+
detector->setPrimitiveShapeType(
180+
dart::collision::FCLCollisionDetector::PRIMITIVE);
181+
return detector;
182+
});
183+
}

0 commit comments

Comments
 (0)