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

[meshcat] More robust parsing of .mtl texture map filenames #17550

Merged

Conversation

RussTedrake
Copy link
Contributor

@RussTedrake RussTedrake commented Jul 12, 2022

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

@RussTedrake RussTedrake added priority: medium component: geometry illustration What and how geometry gets communicated to external visualizers release notes: fix This pull request contains fixes (no new features) labels Jul 12, 2022
Copy link
Contributor Author

@RussTedrake RussTedrake left a 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)

Copy link
Contributor

@SeanCurtis-TRI SeanCurtis-TRI left a 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.

:LGTM:

+@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:

  1. Use proper regex tokens in the comment.
  2. Use a raw string literal below (so the tokens match).
std::regex map_regex(R"""(map_.+\s([^\s]+)[$\r\n])""");

Copy link
Contributor

@rpoyner-tri rpoyner-tri left a comment

Choose a reason for hiding this comment

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

:lgtm: concur with Sean's comments.

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.
@RussTedrake RussTedrake force-pushed the meshcat_mtl_options branch from fc189a7 to 56ef30d Compare July 13, 2022 00:50
Copy link
Contributor Author

@RussTedrake RussTedrake left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: 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:

  1. Use proper regex tokens in the comment.
  2. Use a raw string literal below (so the tokens match).
std::regex map_regex(R"""(map_.+\s([^\s]+)[$\r\n])""");

Done.

@jwnimmer-tri jwnimmer-tri merged commit afd32b5 into RobotLocomotion:master Jul 13, 2022
@RussTedrake RussTedrake deleted the meshcat_mtl_options branch July 14, 2022 10:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: geometry illustration What and how geometry gets communicated to external visualizers priority: medium release notes: fix This pull request contains fixes (no new features)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants