From 67b78f24a9ec8c823bbb8ff091ccd6bb4144a435 Mon Sep 17 00:00:00 2001 From: Frederico Linhares Date: Tue, 16 Aug 2022 16:25:02 -0300 Subject: feat Simplify the 3d model structure --- src/vk/graphics_pipeline.cpp | 13 ++++--------- src/vk/model.cpp | 46 ++++++-------------------------------------- src/vk/vertex.hpp | 1 - 3 files changed, 10 insertions(+), 50 deletions(-) (limited to 'src') diff --git a/src/vk/graphics_pipeline.cpp b/src/vk/graphics_pipeline.cpp index bd0406c..de08945 100644 --- a/src/vk/graphics_pipeline.cpp +++ b/src/vk/graphics_pipeline.cpp @@ -533,7 +533,7 @@ load_pipeline(void *obj) vertex_input_binding.stride = sizeof(VK::Vertex); vertex_input_binding.inputRate = VK_VERTEX_INPUT_RATE_VERTEX; - std::array vertex_attribute{}; + std::array vertex_attribute{}; // Position. vertex_attribute[0].location = 0; vertex_attribute[0].binding = 0; @@ -544,16 +544,11 @@ load_pipeline(void *obj) vertex_attribute[1].binding = 0; vertex_attribute[1].format = VK_FORMAT_R32G32B32_SFLOAT; vertex_attribute[1].offset = offsetof(VK::Vertex, normal); - // Color. + // Texture coordinate. vertex_attribute[2].location = 2; vertex_attribute[2].binding = 0; - vertex_attribute[2].format = VK_FORMAT_R32G32B32_SFLOAT; - vertex_attribute[2].offset = offsetof(VK::Vertex, color); - // Texture coordinate. - vertex_attribute[3].location = 3; - vertex_attribute[3].binding = 0; - vertex_attribute[3].format = VK_FORMAT_R32G32_SFLOAT; - vertex_attribute[3].offset = offsetof(VK::Vertex, texture_coord); + vertex_attribute[2].format = VK_FORMAT_R32G32_SFLOAT; + vertex_attribute[2].offset = offsetof(VK::Vertex, texture_coord); VkPipelineVertexInputStateCreateInfo vertex_input_info = {}; vertex_input_info.sType = diff --git a/src/vk/model.cpp b/src/vk/model.cpp index d47db8a..5cf96b6 100644 --- a/src/vk/model.cpp +++ b/src/vk/model.cpp @@ -48,16 +48,6 @@ ModelBuilder::ModelBuilder(VK::Model *m, const char *mp): { } -struct MeshData -{ - glm::vec3 color; - - uint32_t vertex_base; - uint32_t vertex_count; - uint32_t index_base; - uint32_t index_count; -}; - uint32_t read_uint32_from_file(std::ifstream &input_file) { uint32_t data{}; @@ -90,42 +80,20 @@ load_mesh(void *obj) std::ifstream input_file{self->model_path}; if(!input_file.is_open()) throw CommandError{"Failed to open file."}; - std::vector meshes{}; - self->model->queue_family = cg_core.vk_device_with_swapchain->get_queue_family_with_graphics(); VK::Queue transfer_queue{self->model->queue_family->get_queue()}; - // Load meshes. - { - uint32_t meshes_count{read_uint32_from_file(input_file)}; - meshes.resize(meshes_count); - - for(uint32_t i{0}; i < meshes_count; i++) - { - meshes[i].color = read_vec3_from_file(input_file); - - meshes[i].vertex_base = read_uint32_from_file(input_file); - meshes[i].vertex_count = read_uint32_from_file(input_file); - meshes[i].index_base = read_uint32_from_file(input_file); - meshes[i].index_count = read_uint32_from_file(input_file); - } - } - // Load vertexes. { - uint32_t vertex_count{read_uint32_from_file(input_file)}; + auto vertex_count{read_uint32_from_file(input_file)}; std::vector vertexes{vertex_count}; - for(auto mesh: meshes) + for(auto i{0}; i < vertex_count; i++) { - for(uint32_t i{mesh.vertex_base}; i < mesh.vertex_count; i++) - { - vertexes[i].position = read_vec3_from_file(input_file); - vertexes[i].normal = read_vec3_from_file(input_file); - vertexes[i].texture_coord = read_vec2_from_file(input_file); - vertexes[i].color = mesh.color; - } + vertexes[i].position = read_vec3_from_file(input_file); + vertexes[i].normal = read_vec3_from_file(input_file); + vertexes[i].texture_coord = read_vec2_from_file(input_file); } void *vertexes_data{vertexes.data()}; @@ -142,10 +110,8 @@ load_mesh(void *obj) self->model->index_count = read_uint32_from_file(input_file); std::vector indexes(self->model->index_count); - for(uint32_t i{0}; i < self->model->index_count; i++) - { + for(auto i{0}; i < self->model->index_count; i++) indexes[i] = read_uint32_from_file(input_file); - } void *indexes_data{indexes.data()}; size_t indexes_size{sizeof(indexes[0]) * indexes.size()}; diff --git a/src/vk/vertex.hpp b/src/vk/vertex.hpp index 735d0a7..07332a8 100644 --- a/src/vk/vertex.hpp +++ b/src/vk/vertex.hpp @@ -26,7 +26,6 @@ struct Vertex { glm::vec3 position; glm::vec3 normal; - glm::vec3 color; glm::vec2 texture_coord; }; -- cgit v1.2.3