-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
[meshcat] More robust parsing of .mtl texture map filenames #17550
[meshcat] More robust parsing of .mtl texture map filenames #17550
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+@SeanCurtis-TRI for feature review, please.
Reviewable status: LGTM missing from assignee SeanCurtis-TRI(platform), needs at least two assigned reviewers (waiting on @SeanCurtis-TRI)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My single greatest regret is that this is untested. :( This is meaningful logic for parsing the file and it would be good if it were supported by test. Right now the test passes, regardless of what the regular expression looks like. However, I'm too rusty on Meshcat
to recommend any specific solution to this. The correctness of this parsing wasn't tested before, so it's no worse now.
+@rpoyner-tri for platform review.
Reviewed 2 of 2 files at r1, all commit messages.
Reviewable status: 2 unresolved discussions, LGTM missing from assignee rpoyner-tri(platform) (waiting on @rpoyner-tri and @RussTedrake)
geometry/meshcat.cc
line 413 at r1 (raw file):
// Here we ignore the options and only extract the filename (by // extracting the last word before the end of line/string). // - "map_.+"" matches the map_ plus any options,
nit: Extra ". ("map_.+"" <--)
geometry/meshcat.cc
line 414 at r1 (raw file):
// extracting the last word before the end of line/string). // - "map_.+"" matches the map_ plus any options, // - "\s" matches one whitespace (before the filename),
BTW Here in this comment, sometimes you use proper reg ex tokens (\s
and sometimes you use escaped tokens (\\s
). I'd recommend the following:
- Use proper regex tokens in the comment.
- Use a raw string literal below (so the tokens match).
std::regex map_regex(R"""(map_.+\s([^\s]+)[$\r\n])""");
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 2 of 2 files at r1, all commit messages.
Reviewable status: 2 unresolved discussions (waiting on @RussTedrake)
In RobotLocomotion/models#18 (homecart_basecart.mtl) I ran into a texture map specification that specified a scale option in the map_Kd line. This defeated the simple regex expression that I had implemented in meschat.cc. meshcat.cc doesn't need to parse these options properly; it only needs to successfully extract the filename so that the file can be shipped over the websocket. I've updated the parsing line according to the mtl specification to ignore options. To reproduce the problem, run meshcat_manual_test with the change to box.obj.mtl but without the fix to meshcat.cc. You will see that the box appears in meshcat without a texture and a warning from meshcat.cc is printed to the console. The change to meshcat.cc resolves the problem.
fc189a7
to
56ef30d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status:
complete! all discussions resolved, LGTM from assignees rpoyner-tri(platform),SeanCurtis-TRI(platform) (waiting on @rpoyner-tri and @SeanCurtis-TRI)
geometry/meshcat.cc
line 414 at r1 (raw file):
Previously, SeanCurtis-TRI (Sean Curtis) wrote…
BTW Here in this comment, sometimes you use proper reg ex tokens (
\s
and sometimes you use escaped tokens (\\s
). I'd recommend the following:
- Use proper regex tokens in the comment.
- Use a raw string literal below (so the tokens match).
std::regex map_regex(R"""(map_.+\s([^\s]+)[$\r\n])""");
Done.
In RobotLocomotion/models#18
(homecart_basecart.mtl) I ran into a texture map specification that
specified a scale option in the map_Kd line. This defeated the simple
regex expression that I had implemented in meschat.cc.
meshcat.cc doesn't need to parse these options properly; it only needs
to successfully extract the filename so that the file can be shipped
over the websocket. I've updated the parsing line according to the
mtl specification to ignore options.
To reproduce the problem, run meshcat_manual_test with the change to
box.obj.mtl but without the fix to meshcat.cc. You will see that the
box appears in meshcat without a texture and a warning from meshcat.cc
is printed to the console. The change to meshcat.cc resolves the
problem.
This change is![Reviewable](https://camo.githubusercontent.com/1541c4039185914e83657d3683ec25920c672c6c5c7ab4240ee7bff601adec0b/68747470733a2f2f72657669657761626c652e696f2f7265766965775f627574746f6e2e737667)