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/mesh.hpp | 93 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 include/mesh.hpp (limited to 'include/mesh.hpp') diff --git a/include/mesh.hpp b/include/mesh.hpp new file mode 100644 index 0000000..34f2df8 --- /dev/null +++ b/include/mesh.hpp @@ -0,0 +1,93 @@ +#pragma once + +#include +#include +#include + +#include "vk-renderer.hpp" + +enum ATTRIBUTE_TYPE { + POSITION, + NORMAL, + TANGENT, + UV_0, + MAX_ATTRIBUTE, +}; + +struct material; + +class Mesh { + struct submesh_info { + uint32_t vertex_offset; + uint32_t index_offset; + size_t element_count; + uint32_t mat_id; + }; + +public: + struct mesh_instance { + const Mesh& mesh; + // transform a transform matrice for the instance + }; + + struct attribute { + uint8_t* data = nullptr; + size_t length = 0; + }; + + struct submesh { + attribute indices; + std::array attributes; + uint32_t vertex_count = 0; + uint32_t index_count = 0; + // material& mat; + }; + + Mesh() = default; + + [[nodiscard]] mesh_instance instantiate () const; + + void add_submesh(const submesh& submesh); + + static inline uint32_t attribute_components(enum ATTRIBUTE_TYPE attribute_type) { + switch(attribute_type) { + case ATTRIBUTE_TYPE::POSITION: + case ATTRIBUTE_TYPE::NORMAL: + return 3; + case ATTRIBUTE_TYPE::UV_0: + return 2; + default: + return 0; + } + } + + static inline size_t attribute_size(enum ATTRIBUTE_TYPE attribute_type) { + return sizeof(float) * attribute_components(attribute_type); + } + + [[nodiscard]] inline uint32_t triangle_count() const { return index_count / 3; }; + [[nodiscard]] inline uint32_t vertices_count() const { return vertex_count; }; + + + static void register_mesh(const Mesh& mesh); + +private: + + uint32_t vertex_count; + uint32_t index_count; + + std::array, ATTRIBUTE_TYPE::MAX_ATTRIBUTE> attributes; + std::vector indices; + + std::vector submeshes; + + struct gpu_mesh { + std::array attributes; + Buffer* indices; + Buffer* submeshes; + }; + + // allocate gpu mesh upon instanciation + // static std::vector gpu_meshes; + // static std::vector instances; +}; -- cgit v1.3