syoyo / tinyobjloader-c

Header only tiny wavefront .obj loader in pure C99
412 stars 60 forks source link

Add functionality to find mtl file in-library #51

Closed geckor14 closed 2 years ago

geckor14 commented 2 years ago

Hi Syoyo, Up until now, the callback function written by the client was responsible for finding and loading the material file for the respective obj file. This commit changes this and allows the library to find the material file based on the mtllib listing in the OBJ file, then pass that name through to the callback to load the file.

The benefit of this is as follows: 1. the client library does not need to worry about extracting the material file's name from the obj name anymore. 2. The functions are written carefully so that the location of the material file is calculated relative to the OBJ file, so the MTL and OBJ files can live in seperate directories if the user chooses, as long as the mtllib line of the OBJ file has the path, relative to itself. 3. Client callbacks can be simplified to merely extract the file, making client integration easier.

With the above said, it should be noted that this is a breaking change, because if the client tries to manipulate the MTL file path, there is a risk it will not be able to find the file. Thus, I would prefer a discussion on whether this approach would be a good one or not, for the project's future and how it wants to approach MTL file discovery and loading.

Thank you for your time and consideration.

syoyo commented 2 years ago

@geckor14 Good! Let me give some time review the changes(ping me again if there is no response from me after 2~3 weeks)

geckor14 commented 2 years ago

Hi @syoyo, have you had a chance to look at the code yet?

syoyo commented 2 years ago

@geckor14 Thank you for the reminder! Code become simple and looks good, so merged!

how it wants to approach MTL file discovery and loading

I think it'd be possible to do custom MTL file discovery and handling under current callback API(e.g. providing ctx). Still it would be better to provide example code such custom MTL handling situation. (Also we need to update the documentation of callback API: https://github.com/syoyo/tinyobjloader-c/blob/5cd6dfd25c28b426e80ce5150248911b7acba97b/tinyobj_loader_c.h#L98 )