Skip to content

Commit

Permalink
Add parser test.
Browse files Browse the repository at this point in the history
  • Loading branch information
mitiguy committed Oct 3, 2024
1 parent e4fa5a8 commit 4e2af39
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
12 changes: 12 additions & 0 deletions multibody/parsing/test/detail_mujoco_parser_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -823,6 +823,18 @@ TEST_F(MujocoParserTest, BadMeshSpatialInertiaFallback) {
// that we're using it (and not choking).
}

// Ensure an exception is thrown for the mesh in bad_geometry_volume_zero.obj
// since its calculated volume is zero (volume = 0).
TEST_F(MujocoParserTest, BadMeshShouldThrowException) {
std::string filename = "drake/geometry/test/bad_geometry_volume_zero.obj";
std::string geometry_file_path = FindResourceOrThrow(filename);
const geometry::Mesh bad_geometry_volume_zero(geometry_file_path, 1.0);
DRAKE_EXPECT_THROWS_MESSAGE(
CalcSpatialInertia(bad_geometry_volume_zero, /* density = */ 1.0),
".*volume of a triangle surface mesh is.* whereas a reasonable "
"positive value was expected. The mesh may have bad geometry.*");
}

TEST_F(MujocoParserTest, MeshFileRelativePathFromFile) {
const std::string file = FindResourceOrThrow(
"drake/multibody/parsing/test/box_package/mjcfs/box.xml");
Expand Down
4 changes: 2 additions & 2 deletions multibody/tree/geometry_spatial_inertia.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ SpatialInertia<double> CalcSpatialInertia(const geometry::Shape& shape,
- All triangles must be "wound" such that their normals point outward
(according to the right-hand rule based on vertex winding).
In the rare situation that we detect unmet requirements, an exception is thrown
(no value is returned). Otherwise, the returned SpatialInertia is meaningless.
If `mesh` does not meet these requirements, then either an exception is thrown
(no value is returned) or the returned SpatialInertia may be meaningless.
@throws std::exception if the volume of `mesh` is negative or nearly zero.
@pydrake_mkdoc_identifier{mesh} */
SpatialInertia<double> CalcSpatialInertia(
Expand Down

0 comments on commit 4e2af39

Please sign in to comment.