#include "o3d/mesh.hpp" #include #include #include #include #include #include "math/vector.hpp" #include "vulkan_utils.hpp" using namespace engine::o3d; Mesh Mesh::plane(float width, float height) { const float w2 = width / 2, h2 = height / 2; return { { { -w2 / 2, 0.f, -h2 / 2 }, { +w2 / 2, 0.f, -h2 / 2 }, { +w2 / 2, 0.f, +h2 / 2 }, { -w2 / 2, 0.f, +h2 / 2 }, }, { { 0.f, -1.f, 0.f }, { 0.f, +1.f, 0.f }, }, { {{ {{ 0, 0 }}, {{ 1, 0 }}, {{ 2, 0 }} }}, {{ {{ 2, 0 }}, {{ 3, 0 }}, {{ 0, 0 }} }}, {{ {{ 0, 1 }}, {{ 3, 1 }}, {{ 2, 1 }} }}, {{ {{ 2, 1 }}, {{ 1, 1 }}, {{ 0, 1 }} }}, } }; } std::tuple, std::vector> Mesh::linearize_indices() const & { std::vector linearized_vertices; std::vector linearized_indices; size_t n = 0; for (const auto& triangle_indices : this->indices) { for (const auto& vertex_indices : triangle_indices) { linearized_vertices.emplace_back(this->vertices[vertex_indices[0]], this->normals[vertex_indices[1]]); linearized_indices.emplace_back(n++); } } // TODO: I'm not sure if passing vectors like that makes a copy or not, because they are passed // to a structured which is instantly returned. I think that copy-ellision catches that return std::tuple { linearized_vertices, linearized_indices }; }