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
Merged
Show file tree
Hide file tree
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
12 changes: 10 additions & 2 deletions geometry/meshcat.cc
Original file line number Diff line number Diff line change
Expand Up @@ -406,8 +406,16 @@ class MeshcatShapeReifier : public ShapeReifier {

// Scan .mtl file for map_ lines. For each, load the file and add
// the contents to geometry.resources.
// TODO(russt): Make this parsing more robust.
std::regex map_regex("map_[^\\s]+\\s+([^\\s]+)");
// The syntax (http://paulbourke.net/dataformats/mtl/) is e.g.
// map_Ka -options args filename
// 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,
// - "\s" matches one whitespace (before the filename),
// - "[^\s]+" matches the filename, and
// - "[$\r\n]" matches the end of string or end of line.
// TODO(russt): This parsing could still be more robust.
std::regex map_regex(R"""(map_.+\s([^\s]+)[$\r\n])""");
for (std::sregex_iterator iter(meshfile_object.mtl_library.begin(),
meshfile_object.mtl_library.end(),
map_regex);
Expand Down
2 changes: 1 addition & 1 deletion geometry/render/test/meshes/box.obj.mtl
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ Ks 1.000000 1.000000 1.000000
d 1.000000
illum 2
Ns 0.000000
map_Kd box.png
map_Kd -s 1 1 1 box.png