thisistherk / fast_obj

Fast C OBJ parser
MIT License
616 stars 46 forks source link

Support both Unix and Windows style paths #20

Closed righier closed 3 years ago

righier commented 3 years ago

I noticed that if I'm loading a model on Windows and I use Unix style paths, the library cannot find the .mtl file related to my .obj file, this happens because string_find_last only searches for one type of slash inside the original path in order to generate the base path.

I suggest the following edit at line 1338:

    /* Find base path for materials/textures */
    const char *sep, *sep2;
    int found_sep;

    sep = sep2 = 0;
    found_sep = string_find_last(path, FAST_OBJ_SEPARATOR, &sep);
    found_sep = found_sep || string_find_last(path, FAST_OBJ_OTHER_SEP, &sep2);
    if (sep2 > sep) sep = sep2;
    if (found_sep)
        data.base = string_substr(path, 0, sep + 1);
thisistherk commented 3 years ago

Yep, that makes sense. Just checked something in that should fix. If you could give it a quick try when you get chance, that'd be great (I don't have a Windows machine to test on) - thanks!

righier commented 3 years ago

Just tried it, works great!