cyberbotics / urdf2webots

Utility to convert URDF files to Webots PROTO nodes
Apache License 2.0
127 stars 43 forks source link

Missing parsing of ROS mesh filename 'file://' prefix #204

Open IDavGal opened 1 year ago

IDavGal commented 1 year ago

The file:// prefix is not being parsed out of the mesh filename in the URDF definition.

I'm thinking this can be fixed by modifying the code in parserURDF.py in a similar manner to how the package:// prefix is addressed there, although both checks should be done before the absolute path checking, since filenames with any of these prefixes would be categorized as relative paths and therefore be affected by the os.path.normpath() method, collapsing all consecutive backslashes into a single one. The modified code would look like this:

elif hasElement(geometryElement, 'mesh'):
    meshfile = geometryElement.getElementsByTagName('mesh')[0].getAttribute('filename')
    # hack for gazebo mesh database
    if meshfile.count('package'):
        idx0 = meshfile.find('package://')
        meshfile = meshfile[idx0 + len('package://'):]
    if meshfile.count('file'):
        idx0 = meshfile.find('file://')
        meshfile = meshfile[idx0 + len('file://'):]
    if not os.path.isabs(meshfile):
        # Use the path relative to the output file
        meshfile = os.path.normpath(os.path.relpath(os.path.join(path, meshfile), outputDirectory))
omichel commented 1 year ago

Thank you for this contribution. Can you please create a new pull request for proposing this change?