diff --git a/python/mujoco/specs_test.py b/python/mujoco/specs_test.py index d2f07eca..e92ddb59 100644 --- a/python/mujoco/specs_test.py +++ b/python/mujoco/specs_test.py @@ -479,6 +479,14 @@ class SpecsTest(absltest.TestCase): # Check that the state is the same. np.testing.assert_array_equal(state1, state2) + def test_parses_urdf(self): + file_path = epath.resource_path("mujoco") / "testdata" / "model.urdf" + filename = file_path.as_posix() + + # Load from file. + spec1 = mujoco.MjSpec.from_file(filename) + self.assertIsNotNone(spec1) + def test_make_mesh(self): spec = mujoco.MjSpec() diff --git a/python/mujoco/testdata/model.urdf b/python/mujoco/testdata/model.urdf new file mode 100644 index 00000000..f4b2793f --- /dev/null +++ b/python/mujoco/testdata/model.urdf @@ -0,0 +1,4 @@ + + + + diff --git a/python/pyproject.toml b/python/pyproject.toml index 85106596..f8ca2c2c 100644 --- a/python/pyproject.toml +++ b/python/pyproject.toml @@ -58,6 +58,7 @@ mujoco = [ "testdata/*.msh", "testdata/*.usda", "testdata/*.zip", + "testdata/*.urdf", ] [project.optional-dependencies] diff --git a/src/user/user_api.cc b/src/user/user_api.cc index 4dbf3b0e..ad93f468 100644 --- a/src/user/user_api.cc +++ b/src/user/user_api.cc @@ -72,7 +72,9 @@ mjSpec* mj_parse(const char* filename, const char* content_type, // early exit for existing XML workflow auto filepath = mujoco::user::FilePath(filename); - if (filepath.Ext() == ".xml" || (content_type && std::strcmp(content_type, "text/xml") == 0)) { + if (filepath.Ext() == ".xml" || + filepath.Ext() == ".urdf" || + (content_type && std::strcmp(content_type, "text/xml") == 0)) { return mj_parseXML(filename, vfs, error, error_sz); }