From d78200b71b259b87f401b24906385af4e2553fbe Mon Sep 17 00:00:00 2001 From: ladevieq Date: Mon, 8 Aug 2022 23:38:19 +0200 Subject: Refactored gltf imported and mesh management --- include/gltf.hpp | 48 ++++++++++++++++++++---------------------------- 1 file changed, 20 insertions(+), 28 deletions(-) (limited to 'include/gltf.hpp') diff --git a/include/gltf.hpp b/include/gltf.hpp index 66fb6ec..2886dea 100644 --- a/include/gltf.hpp +++ b/include/gltf.hpp @@ -2,56 +2,48 @@ #define __GLTF_HPP_ #include -#include #include using json = nlohmann::json; #include "material.hpp" - -struct mesh_part { - std::vector indices; - std::vector positions; - std::vector normals; - std::vector uvs; - material mat; - uint32_t triangles_count = 0; - uint32_t vertices_count = 0; -}; - -struct mesh { - std::vector parts; - uint32_t triangles_count = 0; - uint32_t vertices_count = 0; -}; +#include "mesh.hpp" struct node { std::vector children; - std::optional mesh; + Mesh* mesh = nullptr; }; namespace std::filesystem { class path; } -class vkrenderer; class gltf { public: - static node load(std::filesystem::path &path, std::string &filename, vkrenderer &renderer); + gltf(const std::filesystem::path &filepath); + + node root_node; + +private: + + void load_node(uint32_t index, node &parent); + + void load_meshes(); - private: - static void load_node(json &gltf_json, uint32_t index, node &parent, std::vector &meshes); + Mesh::submesh load_primitive(const json &primitive); - static std::vector load_meshes( - json &gltf_json, std::vector> &buffers_content, std::vector &materials); + Mesh::attribute load_attribute(uint32_t accessor_index); - static std::vector load_textures(json &gltf_json, std::filesystem::path &path, vkrenderer &renderer); + void load_textures(const std::filesystem::path &path); - static std::vector load_materials(json &gltf_json, std::vector &textures); + void load_materials(); - static mesh_part load_primitive(json &gltf_json, json &primitive, - std::vector> &buffers_content, std::vector &materials); + json gltf_json; + std::vector meshes; + std::vector materials; + std::vector textures; + std::vector> buffers; }; #endif -- cgit v1.3