OBJ importer cannot deal with texture names with spaces #49357
Labels
No Label
Interest
Animation & Rigging
Interest
Blender Cloud
Interest
Collada
Interest
Core
Interest
Documentation
Interest
Eevee & Viewport
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
Import and Export
Interest
Modeling
Interest
Modifiers
Interest
Nodes & Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds, Tests & Devices
Interest
Python API
Interest
Rendering & Cycles
Interest
Sculpt, Paint & Texture
Interest
Translations
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Meta
Good First Issue
Meta
Papercut
Module
Add-ons (BF-Blender)
Module
Add-ons (Community)
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
3 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender-addons#49357
Loading…
Reference in New Issue
No description provided.
Delete Branch "%!s(<nil>)"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
System Information
Not relevant
Blender Version
Latest (2.78)
Short description of error
The OBJ importer, when processing the MTL cannot deal with material images cannot parse filenames with spaces.
Exact steps for others to reproduce the error
Load any OBJ with textures with spaces on the filename.
On the code: https://developer.blender.org/diffusion/BA/browse/master/io_scene_obj/import_obj.py
This line of code only uses the last separated-by-space part of the MTL line content. If the filename is (without quotes) "blue 3.jpg" the imagepath will be "3.jpg" instead of "blue 3.jpg". Just a bad parse.
This will result in Blender trying to load an image that does not exist.
Thank you for any effort to resolve this.
Changed status to: 'Open'
Added subscriber: @tiago.cardoso
Added subscriber: @mont29
Changed status from 'Open' to: 'Archived'
Thanks for the report, but no bug here, MTL does not support filenames with spaces, which is quite obvious since it uses spaces to separate options… Some programs are not smart enough to cope with this limitation when exporting, but we cannot do anything about it.
I haven't seen any indication on MTL specifications that prohibits spaces in the filename.
All the args options and parameters are well defined on the specs and could be taken in account, eg. after that code line, the last token is getting too much parameters (the begining of the filename) with no need. All options have a set number of parameters.
Just need to do a regular expression to eliminate options as it's parameters and you can get the complete filename.
It's not simple, but I think, very feasable and would be a great improvement :D
Thank you
Changed status from 'Archived' to: 'Open'
^\S+(\s-(((blenu|blenv|bm|boost|cc|clamp|imfchan|texres)\s[^-]\S+)|(mm(\s[^-]\S+){2})|(s(\s[^-]\S+){3})))*\s
If I've not made a mistake somewhere, this regex should work. Just remove what it grab and you have the filename, with or without spaces.
Could you test and commit it (if correct) ? :) It would be great.
Thank you!
That won't work in all cases, see e.g. the
-o
/-s
/-t
options, which can have optionalv
/w
values (ref MTL doc). So how to you handle e.g.map_Ka -o 1 2 3 foo.png
? Is it file"2 3 foo.png"
?Short answer/fix: do not use spaces in your filenames in OBJ context, this is not designed to support it, and will always make things harder, whatever solution is hacked around.
Will try some workaround though (like going backward adding items to 'potential' filename until we find an existing match), but this won't probably cover all cases anyway.
My regex is missing some options:
^\S+(\s-(((blenu|blenv|bm|boost|cc|clamp|imfchan|texres)\s[^-]\S+)|(mm(\s[^-]\S+){2})|((s|o|t)(\s[^-]\S+){3})))*\s
This should be it. Options like -o, -s or -t always have 3 parameters, so the regex accounts for that and the name should be just foo.png.
As the number of parameters is static for each option. A regex should be able to parse it, no ?
Can you see another case that wouldn't work ?
Thank you
Read the specs, v and w are optional, so there is no guarantee you'll have three params here…
You're right.
But we could use :
!!^\S+(\s-(((blenu|blenv|bm|boost|cc|clamp|imfchan|texres)\s[^-]\S+)|(mm(\s[^-]\S+){2})|((s|o|t)(\s\d(.\d+)?){1,3})))*\s!!
This would take in account those optional parameters. It will check only for number as parameters (specs) and never "eat" the texture filename.
The only (I think) time this could be wrong is in similar cases to the one that you provides, but it would return !!foo.png!! that is what you are already returning. So we do not had any more wrong cases and resolve a lot a cases that now don't work.
For example, for !!map_Ka -o 1.0 2 bar foo.png!! it would leave !!bar foo.png!! that might not be the correct filename but is way better guess than just !!foo.png!! that is what is happening right now.
I think this would improve much the situation we have right now. It's a perfect build on what there is now as it reduces the number of times it gets the wrong filename and doesn't add any more wrong filename that it already gets.
For my use case, this is very importing, as we are using Blender to render files and a lot of files (in OBJ) appear with spaces (and we cannot change it as we do not control the files that we get.
Do you agree that this would just reduce the amount of wrong file_paths without getting any other side effects ?
Once again, thank you!
This issue was referenced by
d98fc12f8d
This issue was referenced by
959f9d28d2
Changed status from 'Open' to: 'Resolved'
+1 Thanks!