diff --git a/include/blt/gfx/loader/obj_loader.h b/include/blt/gfx/loader/obj_loader.h index e43614d..3072d77 100644 --- a/include/blt/gfx/loader/obj_loader.h +++ b/include/blt/gfx/loader/obj_loader.h @@ -80,6 +80,11 @@ namespace blt::gfx std::int32_t v[3]; }; + struct quad_t + { + std::int32_t v[4]; + }; + struct object_data { std::string object_name; @@ -127,6 +132,8 @@ namespace blt::gfx void parse_extra_line(char_tokenizer& tokenizer); void parse_face(char_tokenizer& tokenizer); + + void handle_face_vertex(const std::vector& face_list, std::int32_t* arr); public: obj_objects_t parseFile(std::string_view file); diff --git a/libraries/imgui b/libraries/imgui index 240ab58..a1b0682 160000 --- a/libraries/imgui +++ b/libraries/imgui @@ -1 +1 @@ -Subproject commit 240ab5890b2e8da294937a1710b021ac3f271472 +Subproject commit a1b06823fe2d964a62fda99385499b218cf5cea5 diff --git a/libraries/openal-soft b/libraries/openal-soft index cfab142..6675317 160000 --- a/libraries/openal-soft +++ b/libraries/openal-soft @@ -1 +1 @@ -Subproject commit cfab14287405a0d34f6a0fec1336f46415728fcf +Subproject commit 6675317107257c2cc16c947b359d557821d85bf2 diff --git a/src/blt/gfx/loader/obj_loader.cpp b/src/blt/gfx/loader/obj_loader.cpp index f48c32b..ddc7d72 100644 --- a/src/blt/gfx/loader/obj_loader.cpp +++ b/src/blt/gfx/loader/obj_loader.cpp @@ -172,38 +172,55 @@ namespace blt::gfx void obj_loader::parse_face(char_tokenizer& tokenizer) { - auto vertexes = blt::string::split(std::string(tokenizer.read_fully()), ' '); - if (vertexes.size() == 3) + auto faces = blt::string::split(std::string(tokenizer.read_fully()), ' '); + if (faces.size() == 3) { triangle_t triangle{}; - for (const auto& pair : blt::enumerate(vertexes)) - { - auto indices = blt::string::split(pair.second, '/'); - BLT_ASSERT(indices.size() == 3 && "Must have vertex, uv, and normal indices!!"); - - auto vi = get(indices[0]); - auto ui = get(indices[1]); - auto ni = get(indices[2]); - - face_t face{vi, ui, ni}; - - auto loc = vertex_map.find(face); - if (loc == vertex_map.end()) - { - auto index = static_cast(vertex_data.size()); - vertex_data.push_back({vertices[vi], uvs[ui], normals[ni]}); - vertex_map.insert({face, index}); - triangle.v[pair.first] = index; - } else - { - triangle.v[pair.first] = loc->second; - } - } + handle_face_vertex(faces, triangle.v); current_object.indices.push_back(triangle); - } else if (vertexes.size() == 4) + } else if (faces.size() == 4) { - BLT_WARN("Currently unable to process non-triangulated meshes!"); + quad_t quad{}; + handle_face_vertex(faces, quad.v); + triangle_t t1{}; + triangle_t t2{}; + + for (int i = 0; i < 3; i++) + t1.v[i] = quad.v[i]; + t2.v[0] = quad.v[0]; + t2.v[1] = quad.v[2]; + t2.v[2] = quad.v[3]; + + current_object.indices.push_back(t1); + current_object.indices.push_back(t2); } else - BLT_WARN("Unsupported vertex count! %d", vertexes.size()); + BLT_WARN("Unsupported vertex count! %d", faces.size()); + } + + void obj_loader::handle_face_vertex(const std::vector& face_list, int32_t* arr) + { + for (const auto& pair : blt::enumerate(face_list)) + { + auto indices = blt::string::split(pair.second, '/'); + BLT_ASSERT(indices.size() == 3 && "Must have vertex, uv, and normal indices!!"); + + auto vi = get(indices[0]); + auto ui = get(indices[1]); + auto ni = get(indices[2]); + + face_t face{vi, ui, ni}; + + auto loc = vertex_map.find(face); + if (loc == vertex_map.end()) + { + auto index = static_cast(vertex_data.size()); + vertex_data.push_back({vertices[vi], uvs[ui], normals[ni]}); + vertex_map.insert({face, index}); + arr[pair.first] = index; + } else + { + arr[pair.first] = loc->second; + } + } } } \ No newline at end of file