Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse file:// mesh prefix from mesh filepath #206

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions urdf2webots/parserURDF.py
Original file line number Diff line number Diff line change
Expand Up @@ -594,13 +594,16 @@ def getVisual(link, node, path, outputDirectory):
link.visual.append(visual)
elif hasElement(geometryElement, 'mesh'):
meshfile = geometryElement.getElementsByTagName('mesh')[0].getAttribute('filename')
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))
# hack for gazebo mesh database
if meshfile.count('package'):
idx0 = meshfile.find('package://')
meshfile = meshfile[idx0 + len('package://'):]
elif 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))
Comment on lines 598 to +606
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would seem clearer and cleaner to me:

Suggested change
if meshfile.count('package'):
idx0 = meshfile.find('package://')
meshfile = meshfile[idx0 + len('package://'):]
elif 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))
if meshfile.startswith('package://'):
idx0 = meshfile.find('package://')
meshfile = meshfile[idx0 + len('package://'):] # package relative path
elif meshfile.startswith('file:///'):
idx0 = meshfile.find('file:///')
meshfile = meshfile[idx0 + len('file://'):] # we keep the last slash for absolute path
elif 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))

if geometryElement.getElementsByTagName('mesh')[0].getAttribute('scale'):
meshScale = geometryElement.getElementsByTagName('mesh')[0].getAttribute('scale').split()
visual.scale[0] = float(meshScale[0])
Expand Down