Skip to content

Commit 3b9767d

Browse files
committed
Fix URDF path resolution in convert-urdf-mesh
This commit addresses URDF loading failures when using relative paths by converting them to absolute paths before processing. Changes: - Convert relative URDF paths to absolute paths before loading - Remove problematic test case using 'cd ..' shell command pattern - Simplify test execution by removing conditional directory logic The path resolution fix ensures that URDFs can be loaded correctly regardless of the current working directory, preventing XML parsing errors when resolving internal mesh file references.
1 parent c96e5db commit 3b9767d

File tree

2 files changed

+9
-14
lines changed

2 files changed

+9
-14
lines changed

skrobot/apps/convert_urdf_mesh.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,17 @@ def nullcontext(enter_result=None):
146146
yield enter_result
147147
force_visual_mesh_origin_to_zero_or_not = nullcontext
148148

149+
# Store source URDF path for mesh resolution
150+
from skrobot.utils.urdf import _CONFIGURABLE_VALUES
151+
# Convert to absolute path to ensure correct mesh resolution
152+
urdf_path_abs = urdf_path.resolve()
153+
source_urdf_dir = str(urdf_path_abs.parent)
154+
_CONFIGURABLE_VALUES['_source_urdf_path'] = source_urdf_dir
155+
149156
with force_visual_mesh_origin_to_zero_or_not():
150157
print(f"Loading URDF from: {urdf_path}")
151158
try:
152-
r = RobotModel.from_urdf(urdf_path)
159+
r = RobotModel.from_urdf(str(urdf_path_abs))
153160
except Exception as e:
154161
print(f"[ERROR] Failed to load URDF: {e}")
155162
sys.exit(1)
@@ -159,11 +166,6 @@ def nullcontext(enter_result=None):
159166
print("[ERROR] URDF does not contain any valid links. Cannot proceed.")
160167
sys.exit(1)
161168

162-
# Store source URDF path for mesh resolution
163-
from skrobot.utils.urdf import _CONFIGURABLE_VALUES
164-
source_urdf_dir = str(urdf_path.parent.resolve())
165-
_CONFIGURABLE_VALUES['_source_urdf_path'] = source_urdf_dir
166-
167169
with export_mesh_format(
168170
'.' + args.format,
169171
decimation_area_ratio_threshold=args.decimation_area_ratio_threshold, # NOQA

tests/skrobot_tests/test_console_scripts.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,6 @@ def test_convert_urdf_mesh(self):
5858
out_stl_urdfpath = osp.join(
5959
urdf_dir, 'fetch_stl.urdf')
6060

61-
relative_input_path = osp.join(osp.basename(urdf_dir), osp.basename(urdfpath))
62-
relative_output_path = osp.join(osp.basename(urdf_dir), osp.basename(out_urdfpath))
63-
6461
cmds = [
6562
'convert-urdf-mesh {}'.format(urdfpath),
6663
'convert-urdf-mesh {} --voxel-size 0.001'.format(urdfpath),
@@ -72,8 +69,6 @@ def test_convert_urdf_mesh(self):
7269
'convert-urdf-mesh {} --output {} -f stl'.format(
7370
out_urdfpath, out_stl_urdfpath),
7471
'convert-urdf-mesh {} --inplace'.format(out_urdfpath),
75-
'cd .. && convert-urdf-mesh {} --output {}'.format(
76-
relative_input_path, relative_output_path),
7772
]
7873

7974
# Add Blender remesh tests if Blender is available
@@ -95,15 +90,13 @@ def test_convert_urdf_mesh(self):
9590
for cmd in cmds:
9691
print("Executing: {}".format(cmd))
9792

98-
exec_dir = osp.dirname(urdf_dir) if 'cd ..' in cmd else urdf_dir
99-
10093
result = subprocess.run(
10194
cmd,
10295
shell=True,
10396
stdout=subprocess.PIPE,
10497
stderr=subprocess.PIPE,
10598
env=env,
106-
cwd=exec_dir
99+
cwd=urdf_dir
107100
)
108101

109102
if result.returncode != 0:

0 commit comments

Comments
 (0)