/* * * Copyright (C) 2024 Brett Terpstra * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifndef BLT_WITH_GRAPHICS_OBJ_LOADER_H #define BLT_WITH_GRAPHICS_OBJ_LOADER_H #include "blt/math/vectors.h" #include "blt/std/hashmap.h" #include #include #include namespace blt::gfx { typedef blt::vec3 vertex_t; typedef blt::vec2 uv_t; typedef blt::vec3 normal_t; struct face_t { std::int32_t vertex, uv, normal; }; struct constructed_vertex_t { vertex_t vertex; uv_t uv; normal_t normal; }; struct triangle_t { std::int32_t v1, v2, v3; }; class obj_loader; class obj_object_t { friend obj_loader; private: // TODO: shared VBO? std::string object_name; std::vector vertices_; std::vector indices_; obj_object_t(std::string_view name, std::vector vertices, std::vector indices): object_name(name), vertices_(std::move(vertices)), indices_(std::move(indices)) {} public: inline const std::vector& vertices() { return vertices_; }; inline const std::vector& indices() { return indices_; }; }; class obj_loader { private: std::vector vertices; std::vector uvs; std::vector normals; struct object_data { std::string object_name; // maps between vertex indices -> face (constructed vertex) HASHMAP vertex_data; std::vector indices; }; private: void parse_face(std::string_view line); public: void parseFile(std::string_view file); }; std::vector quick_load(std::string_view file); } #endif //BLT_WITH_GRAPHICS_OBJ_LOADER_H