From e6812d2df6bd8a0a71375096abe46f8039d8c570 Mon Sep 17 00:00:00 2001 From: Mel Date: Tue, 11 Jul 2023 04:13:18 +0200 Subject: Create MeshBuilder utility for comfy mesh building --- src/GFX/Util/MeshBuilder.hpp | 65 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 src/GFX/Util/MeshBuilder.hpp (limited to 'src/GFX/Util') diff --git a/src/GFX/Util/MeshBuilder.hpp b/src/GFX/Util/MeshBuilder.hpp new file mode 100644 index 0000000..e3caa8c --- /dev/null +++ b/src/GFX/Util/MeshBuilder.hpp @@ -0,0 +1,65 @@ +#pragma once + +#include "../../Common/Sizes.hpp" +#include "../../Math/Common.hpp" +#include + +namespace MC::GFX::Util { + +template +class MeshBuilder { + using AttributeTuple = std::tuple...>; + + template + using EnableIfCorrectAttributeIndex = + std::enable_if_t::value_type, + typename AttributeContainer::value_type>, Bool>; + + template + std::vector& get() { + return std::get(m_attributes); + } + + template + Mesh mesh(std::index_sequence) { + return { + {m_positions, std::get(m_attributes)...}, + m_indices, + }; + } + + std::vector> m_positions{}; + std::vector m_indices{}; + AttributeTuple m_attributes; +public: + static constexpr UInt AttributesN = sizeof...(Attributes); + + MeshBuilder() = default; + + template = true> + void attributes(const AC& from) { + auto& attribute_list = get(); + attribute_list.insert(attribute_list.end(), from.begin(), from.end()); + } + + template + void positions(const AC& from) { + m_positions.insert(m_positions.end(), from.begin(), from.end()); + } + + template + void indices(const AC& from) { + m_indices.insert(m_indices.end(), from.begin(), from.end()); + } + + Mesh mesh() { + return mesh(std::make_index_sequence{}); + } + + USize vertex_count() const { + return m_positions.size(); + } +}; + +} -- cgit 1.4.1