From 83f6ea026dc64f89a5a9bfb9d83dfa52d0b9a6a2 Mon Sep 17 00:00:00 2001 From: sneakyevil Date: Sun, 29 Sep 2024 16:05:14 +0200 Subject: [PATCH 1/2] add fix --- fast_obj.h | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/fast_obj.h b/fast_obj.h index a884472..ad53745 100644 --- a/fast_obj.h +++ b/fast_obj.h @@ -1004,6 +1004,23 @@ const char* read_map(fastObjData* data, const char* ptr, unsigned int* idx) ptr = skip_name(ptr); e = ptr; + /* Find any separator in the name */ + const char* sep = 0; + for (const char* p = s; p != e; ++p) + { + if (*p == FAST_OBJ_SEPARATOR || *p == FAST_OBJ_OTHER_SEP) { + sep = p; + } + } + + /* Set path if separator found in the name */ + const char* path = 0; + if (sep) + { + path = s; + s = &sep[1]; + } + /* Try to find an existing texture map with the same name */ *idx = 1; /* skip dummy at index 0 */ while (*idx < array_size(data->mesh->textures)) @@ -1019,8 +1036,16 @@ const char* read_map(fastObjData* data, const char* ptr, unsigned int* idx) if (*idx == array_size(data->mesh->textures)) { fastObjTexture new_map = map_default(); - new_map.name = string_copy(s, e); - new_map.path = string_concat(data->base, s, e); + if (path) + { + new_map.name = string_copy(s, e); + new_map.path = string_copy(path, e); + } + else + { + new_map.name = string_copy(s, e); + new_map.path = string_concat(data->base, s, e); + } string_fix_separators(new_map.path); array_push(data->mesh->textures, new_map); } From 52e8b8226cc204838fc8216bc098642666b16c97 Mon Sep 17 00:00:00 2001 From: sneakyevil Date: Sun, 29 Sep 2024 16:16:30 +0200 Subject: [PATCH 2/2] Small if check change. --- fast_obj.h | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/fast_obj.h b/fast_obj.h index ad53745..3331c37 100644 --- a/fast_obj.h +++ b/fast_obj.h @@ -1036,14 +1036,12 @@ const char* read_map(fastObjData* data, const char* ptr, unsigned int* idx) if (*idx == array_size(data->mesh->textures)) { fastObjTexture new_map = map_default(); - if (path) - { - new_map.name = string_copy(s, e); + new_map.name = string_copy(s, e); + + if (path) { new_map.path = string_copy(path, e); } - else - { - new_map.name = string_copy(s, e); + else { new_map.path = string_concat(data->base, s, e); } string_fix_separators(new_map.path);