Skip to content

Commit

Permalink
Dart doesn't like Devo, needs "mesh pit".
Browse files Browse the repository at this point in the history
Signed-off-by: Benjamin Perseghetti <[email protected]>
  • Loading branch information
bperseghetti committed May 14, 2024
1 parent fa0b698 commit 078395d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 15 deletions.
25 changes: 16 additions & 9 deletions dartsim/src/SDFFeatures.cc
Original file line number Diff line number Diff line change
Expand Up @@ -258,14 +258,6 @@ static ShapeAndTransform ConstructBox(
math::eigen3::convert(_box.Size()))};
}

/////////////////////////////////////////////////
static ShapeAndTransform ConstructCone(
const ::sdf::Cone &_cone)
{
return {std::make_shared<dart::dynamics::ConeShape>(
_cone.Radius(), _cone.Length())};
}

/////////////////////////////////////////////////
static ShapeAndTransform ConstructCylinder(
const ::sdf::Cylinder &_cylinder)
Expand Down Expand Up @@ -352,7 +344,22 @@ static ShapeAndTransform ConstructGeometry(
}
else if (_geometry.ConeShape())
{
return ConstructCone(*_geometry.ConeShape());
// TODO(anyone): Replace this code when Cone is supported by DART
common::MeshManager *meshMgr = common::MeshManager::Instance();
std::string coneMeshName = std::string("cone_mesh")
+ "_" + std::to_string(_geometry.ConeShape()->Radius())
+ "_" + std::to_string(_geometry.ConeShape()->Length());
meshMgr->CreateCone(
coneMeshName,
_geometry.ConeShape()->Radius(),
_geometry.ConeShape()->Length(),
3, 40);
const gz::common::Mesh * _mesh =
meshMgr->MeshByName(coneMeshName);

auto mesh = std::make_shared<CustomMeshShape>(*_mesh, Vector3d(1, 1, 1));
auto mesh2 = std::dynamic_pointer_cast<dart::dynamics::MeshShape>(mesh);
return {mesh2};
}
else if (_geometry.CylinderShape())
{
Expand Down
2 changes: 1 addition & 1 deletion dartsim/src/SDFFeatures_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -975,7 +975,7 @@ TEST_P(SDFFeatures_TEST, Shapes)
ASSERT_EQ(5u, dartWorld->getNumSkeletons());

int count{0};
for (auto name : {"sphere", "box", "cylinder", "capsule", "ellipsoid"})
for (auto name : {"sphere", "box", "cylinder", "capsule", "cone", "ellipsoid"})
{
const auto skeleton = dartWorld->getSkeleton(count++);
ASSERT_NE(nullptr, skeleton);
Expand Down
16 changes: 11 additions & 5 deletions dartsim/src/ShapeFeatures.cc
Original file line number Diff line number Diff line change
Expand Up @@ -208,17 +208,23 @@ Identity ShapeFeatures::AttachConeShape(
const double _height,
const Pose3d &_pose)
{
auto cone = std::make_shared<dart::dynamics::ConeShape>(
_radius, _height);
common::MeshManager *meshMgr = common::MeshManager::Instance();
std::string coneMeshName = _name + "_cone_mesh"
+ "_" + std::to_string(_radius)
+ "_" + std::to_string(_height);
meshMgr->CreateCone(coneMeshName,_radius, _height,
3, 40);
const gz::common::Mesh * _mesh = meshMgr->MeshByName(coneMeshName);

auto bn = this->ReferenceInterface<LinkInfo>(_linkID)->link;
auto mesh = std::make_shared<CustomMeshShape>(*_mesh, Vector3d(1, 1, 1));

DartBodyNode *bn = this->ReferenceInterface<LinkInfo>(_linkID)->link.get();
dart::dynamics::ShapeNode *sn =
bn->createShapeNodeWith<dart::dynamics::CollisionAspect,
dart::dynamics::DynamicsAspect>(
cone, bn->getName() + ":" + _name);
mesh, bn->getName() + ":" + _name);

sn->setRelativeTransform(_pose);

const std::size_t shapeID = this->AddShape({sn, _name});
return this->GenerateIdentity(shapeID, this->shapes.at(shapeID));
}
Expand Down

0 comments on commit 078395d

Please sign in to comment.