.obj import error with mtllib name in quotes - regression from 2.79b #67266

Closed
opened 2019-07-19 23:34:38 +02:00 by Robert Guetzkow · 15 comments

System Information
Operating system: Windows 10 64 bit
Graphics card: GeForce GTX 1080 Ti

Blender Version
Broken: 2.80 c2e8e249acf9
Worked: 2.79b f4dc9f9d68b
Short description of error
Blender 2.8 can't import .obj files that contain an mtllib with quotes. While not mentioned in the .obj specification, it seems some software uses quotes when the filename contains blanks. These kind of .obj files could be imported by Blender 2.79b, but the current master branch of 2.8 throws a FileNotFoundError.

Excerpt of the problematic .obj file:

- Blender v2.80 (sub 74) OBJ File: ''
- www.blender.org
mtllib "name with blanks.mtl"

Exact steps for others to reproduce the error

**System Information** Operating system: Windows 10 64 bit Graphics card: GeForce GTX 1080 Ti **Blender Version** Broken: 2.80 c2e8e249acf9 Worked: 2.79b f4dc9f9d68b **Short description of error** Blender 2.8 can't import .obj files that contain an mtllib with quotes. While not mentioned in the .obj specification, it seems some software uses quotes when the filename contains blanks. These kind of .obj files could be imported by Blender 2.79b, but the current master branch of 2.8 throws a `FileNotFoundError`. Excerpt of the problematic .obj file: ``` - Blender v2.80 (sub 74) OBJ File: '' - www.blender.org mtllib "name with blanks.mtl" ``` **Exact steps for others to reproduce the error** - Download the attached files - Try to import .obj [name with blanks.mtl](https://archive.blender.org/developer/F7618853/name_with_blanks.mtl) [name with blanks.obj](https://archive.blender.org/developer/F7618854/name_with_blanks.obj)
Author
Member

Added subscriber: @rjg

Added subscriber: @rjg
Author
Member

Technically this isn't a bug, since Blender follows the spec. However it may still be useful to support this as it was in 2.79b. This issue was originally brought to my intention in this post on Blender StackExchange . The software that created the problematic .obj file was Agisoft Metashape.

Technically this isn't a bug, since Blender follows the spec. However it may still be useful to support this as it was in 2.79b. This issue was originally brought to my intention in this [post on Blender StackExchange ](https://blender.stackexchange.com/questions/145840/cannot-import-obj-into-blender-2-8-but-works-in-2-79). The software that created the problematic .obj file was Agisoft Metashape.
Author
Member

Looking at the code of import_obj.py from 2.79b it seems that this may not have been an intended feature.

If this is of interest, it could be easily fixed by changing line 1151 from:

material_libs |= {os.fsdecode(f) for f in filenames_group_by_ext(line.lstrip()[7:].strip(), b'.mtl')
                    }

to something like:

 material_libs |= {os.fsdecode(f) for f in filenames_group_by_ext(line.replace(b'"',b'').lstrip()[7:].strip(), b'.mtl')
                    }
Looking at the code of `import_obj.py` from 2.79b it seems that this may not have been an intended feature. If this is of interest, it could be easily fixed by changing [line 1151 ](https://developer.blender.org/diffusion/BA/browse/master/io_scene_obj/import_obj.py;aa3366b7805bbe4d1afee890bda81b6d91bd47be$1151) from: ``` material_libs |= {os.fsdecode(f) for f in filenames_group_by_ext(line.lstrip()[7:].strip(), b'.mtl') } ``` to something like: ``` material_libs |= {os.fsdecode(f) for f in filenames_group_by_ext(line.replace(b'"',b'').lstrip()[7:].strip(), b'.mtl') } ```
Author
Member

The same issue applies to .mtl files with map_Kd and a texture filename in quotes.

The same issue applies to .mtl files with `map_Kd` and a texture filename in quotes.

Added subscriber: @mont29

Added subscriber: @mont29
Bastien Montagne self-assigned this 2019-07-22 17:29:36 +02:00

Indeed, even though that’s not a bug, it does not cost much to support it either… Will commit, thanks for the initial report & investigations.

Indeed, even though that’s not a bug, it does not cost much to support it either… Will commit, thanks for the initial report & investigations.
Author
Member

You're very welcome. Always happy to help and contribute.

You're very welcome. Always happy to help and contribute.
Author
Member

Just noticed that this might be a bit more complex to solve in general because " could be a legitimate character in Linux and macOS file names.

Just noticed that this might be a bit more complex to solve in general because `"` could be a legitimate character in Linux and macOS file names.

I would not care much about that… having spaces in filenames is already a bad and annoying habit, but someone putting a quote (single or double) in a file name only deserves what they will get (and a good spanking on top of it ;) ).

I would not care much about that… having spaces in filenames is already a bad and annoying habit, but someone putting a quote (single or double) in a file name only deserves what they will get (and a good spanking on top of it ;) ).

This issue was referenced by 05dc8caa35

This issue was referenced by 05dc8caa35da9914a0c0da61bb0dd49aa292e9ce

Changed status from 'Open' to: 'Resolved'

Changed status from 'Open' to: 'Resolved'
Author
Member

Can't argue with that. Thank you!

Can't argue with that. Thank you!

Added subscriber: @darthhawk

Added subscriber: @darthhawk

The modeler I use doesn't put quotation marks in the OBJ file and Blender has issues importing OBJ files.

I get the following error on trying to import obj files. Other modelers I use don't have this problem.
BlendOBJProblem.jpg

The modeler I use doesn't put quotation marks in the OBJ file and Blender has issues importing OBJ files. I get the following error on trying to import obj files. Other modelers I use don't have this problem. ![BlendOBJProblem.jpg](https://archive.blender.org/developer/F8488427/BlendOBJProblem.jpg)
Author
Member

@darthhawk Please create a new ticket for your issue through Help > Report a Bug in Blender and generate a minimal .obj example file that results in the described problem when imported.

@darthhawk Please create a new ticket for your issue through *Help > Report a Bug* in Blender and generate a **minimal** .obj example file that results in the described problem when imported.
Sign in to join this conversation.
No Milestone
No project
No Assignees
4 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender-addons#67266
No description provided.