1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
#include "o3d/mesh.hpp"
#include <vector>
#include <array>
#include <cstdint>
#include <cstddef>
#include <tuple>
#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<engine::vk::Vertex>, std::vector<uint16_t>> Mesh::linearize_indices() const & {
std::vector<engine::vk::Vertex> linearized_vertices;
std::vector<uint16_t> 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 };
}
|