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

[rmodels] Fails to load mtl file in obj file with crlf line terminator #3126

Closed
futu2 opened this issue Jun 20, 2023 · 3 comments
Closed

[rmodels] Fails to load mtl file in obj file with crlf line terminator #3126

futu2 opened this issue Jun 20, 2023 · 3 comments
Labels
external This issue depends on external lib

Comments

@futu2
Copy link

futu2 commented Jun 20, 2023

Issue description

loadModel works well for most obj, but for obj file with crlf line terminator, model loader will use wrong file name to find mtl file, and finally cannot find mtl file.

for example,

INFO: FILEIO: [CamoStellarJet.obj] Text file loaded successfully
': No such file or directory (2)oStellarJet.mtl
': -3BJ: Failed to parse material file 'CamoStellarJet.mtl

after changing clrf to normal line terminator,

INFO: FILEIO: [CamoStellarJet.obj] Text file loaded successfully
INFO: MODEL: [CamoStellarJet.obj] OBJ data loaded successfully: 1 meshes/1 materials
INFO: MODEL: model has 1 material meshes
INFO: FILEIO: [CamoStellarJet.png] File loaded successfully

every thing works well.

My crlf obj file is generated by magical voxel in windows, but it can be loaded successfully in blender.

@raysan5 raysan5 changed the title [rrmodule] Fails to load mtl file in obj file with crlf line terminator [rmodels] Fails to load mtl file in obj file with crlf line terminator Jun 21, 2023
@raysan5
Copy link
Owner

raysan5 commented Jun 21, 2023

@futu2 I'm afraid the issue resides in tinyobj_loader_c.h external library, it uses fp = fopen(filename, "r"); to load the material file and consequently the EOL are not properly translated to the OS.

@raysan5 raysan5 added the external This issue depends on external lib label Jun 21, 2023
@Peter0x44
Copy link
Contributor

As a quick test, would changing "r" to "rb" not be a solution?

@raysan5
Copy link
Owner

raysan5 commented Aug 4, 2023

@futu2 @Peter0x44 Just pushed a possible fix for the issue but please note that it belongs to an external library (tinyobj_loader_c.h) and this fix could be overwritten when library gets updated. Feel free to comment if issue persists.

@raysan5 raysan5 closed this as completed Aug 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
external This issue depends on external lib
Projects
None yet
Development

No branches or pull requests

3 participants