|
12 | 12 |
|
13 | 13 | class TestROSPackagesCli(ConverterTestCase): |
14 | 14 | def test_do_not_specify_ros_package_name(self): |
15 | | - # If the `package` argument is not specified in `converter.convert`. |
16 | | - # In this case, if the mesh or texture URI specifies "package://PackageName/foo/test.png", |
17 | | - # this will be removed and treated as a relative path "foo/test.png". |
| 15 | + """ |
| 16 | + If the `package` argument is not specified in `converter.convert`. |
| 17 | + In this case, if the mesh or texture URI specifies "package://PackageName/foo/test.png", |
| 18 | + and the relative path "foo/test.png" exists, PackageName="" is assigned and automatically resolved. |
| 19 | + """ |
18 | 20 | input_path = "tests/data/ros_packages.urdf" |
19 | 21 | output_dir = self.tmpDir() |
20 | 22 |
|
21 | 23 | with patch("sys.argv", ["urdf_usd_converter", input_path, output_dir]): |
22 | 24 | self.assertEqual(run(), 0, f"Failed to convert {input_path}") |
23 | 25 |
|
| 26 | + # Check the USD file after converting ros_packages.urdf. |
24 | 27 | output_path = pathlib.Path(output_dir) / "ros_packages.usda" |
25 | | - self.assertTrue(output_path.exists()) |
26 | | - |
27 | | - self.stage: Usd.Stage = Usd.Stage.Open(str(output_path)) |
28 | | - self.assertIsValidUsd(self.stage) |
29 | | - |
30 | | - # Check geometry. |
31 | | - default_prim = self.stage.GetDefaultPrim() |
32 | | - geometry_scope_prim = self.stage.GetPrimAtPath(default_prim.GetPath().AppendChild("Geometry")) |
33 | | - self.assertTrue(geometry_scope_prim.IsValid()) |
34 | | - |
35 | | - link_mesh_stl_path = geometry_scope_prim.GetPath().AppendChild("BaseLink").AppendChild("link_mesh_stl") |
36 | | - link_stl_prim = self.stage.GetPrimAtPath(link_mesh_stl_path) |
37 | | - self.assertTrue(link_stl_prim.IsValid()) |
38 | | - self.assertTrue(link_stl_prim.IsA(UsdGeom.Xform)) |
39 | | - |
40 | | - stl_mesh_prim = self.stage.GetPrimAtPath(link_mesh_stl_path.AppendChild("box")) |
41 | | - self.assertTrue(stl_mesh_prim.IsValid()) |
42 | | - self.assertTrue(stl_mesh_prim.IsA(UsdGeom.Mesh)) |
43 | | - self.assertTrue(stl_mesh_prim.HasAuthoredReferences()) |
44 | | - |
45 | | - # Check material texture. |
46 | | - # TODO: Here we need to make sure that the reference to the usd file is correct after the texture is loaded. |
| 28 | + self.check_usd_converted_from_urdf(output_path) |
47 | 29 |
|
48 | 30 | def test_specify_ros_package_names(self): |
49 | 31 | """ |
@@ -82,10 +64,65 @@ def test_specify_ros_package_names(self): |
82 | 64 | ): |
83 | 65 | self.assertEqual(run(), 0, f"Failed to convert {input_path}") |
84 | 66 |
|
| 67 | + # Check the USD file after converting ros_packages.urdf. |
85 | 68 | output_path = pathlib.Path(output_dir) / "ros_packages.usda" |
86 | | - self.assertTrue(output_path.exists()) |
| 69 | + self.check_usd_converted_from_urdf(output_path) |
| 70 | + |
| 71 | + def test_do_not_specify_ros_package_with_relative_path(self): |
| 72 | + """ |
| 73 | + If the `package` argument is not specified in `converter.convert`. |
| 74 | + ROS package name resolution is performed automatically. |
| 75 | +
|
| 76 | + Search for each mesh and texture from the relative path one directory up from the current directory, |
| 77 | + starting from `ros_packages.urdf` within the following directory structure. |
| 78 | +
|
| 79 | + [temp] |
| 80 | + [urdf] |
| 81 | + ros_packages.urdf |
| 82 | + [assets] |
| 83 | + box.stl |
| 84 | + grid.png |
| 85 | + """ |
| 86 | + temp_path = pathlib.Path(self.tmpDir()) |
| 87 | + urdf_dir = temp_path / "urdf" |
| 88 | + mesh_dir = temp_path / "assets" |
| 89 | + texture_dir = temp_path / "assets" |
| 90 | + output_dir = temp_path / "output" |
| 91 | + input_path = urdf_dir / "ros_packages.urdf" |
| 92 | + |
| 93 | + urdf_dir.mkdir(parents=True, exist_ok=True) |
| 94 | + mesh_dir.mkdir(parents=True, exist_ok=True) |
| 95 | + texture_dir.mkdir(parents=True, exist_ok=True) |
| 96 | + output_dir.mkdir(parents=True, exist_ok=True) |
| 97 | + |
| 98 | + shutil.copy("tests/data/ros_packages.urdf", urdf_dir) |
| 99 | + shutil.copy("tests/data/assets/box.stl", mesh_dir) |
| 100 | + shutil.copy("tests/data/assets/grid.png", texture_dir) |
| 101 | + |
| 102 | + with patch( |
| 103 | + "sys.argv", |
| 104 | + [ |
| 105 | + "urdf_usd_converter", |
| 106 | + str(input_path), |
| 107 | + str(output_dir), |
| 108 | + ], |
| 109 | + ): |
| 110 | + self.assertEqual(run(), 0, f"Failed to convert {input_path}") |
| 111 | + |
| 112 | + # Check the USD file after converting ros_packages.urdf. |
| 113 | + output_path = output_dir / "ros_packages.usda" |
| 114 | + self.check_usd_converted_from_urdf(output_path) |
| 115 | + |
| 116 | + def check_usd_converted_from_urdf(self, usd_path: pathlib.Path): |
| 117 | + """ |
| 118 | + Perform checks on the USD file after converting ros_packages.urdf. |
| 119 | +
|
| 120 | + Args: |
| 121 | + usd_path: The path to the USD file. |
| 122 | + """ |
| 123 | + self.assertTrue(usd_path.exists()) |
87 | 124 |
|
88 | | - self.stage: Usd.Stage = Usd.Stage.Open(str(output_path)) |
| 125 | + self.stage: Usd.Stage = Usd.Stage.Open(str(usd_path)) |
89 | 126 | self.assertIsValidUsd(self.stage) |
90 | 127 |
|
91 | 128 | # Check geometry. |
|
0 commit comments