107 lines
3.1 KiB
C++
107 lines
3.1 KiB
C++
#ifndef MESH_H
|
|
#define MESH_H
|
|
|
|
#include <cstdint>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include <glm/vec2.hpp>
|
|
#include <glm/vec3.hpp>
|
|
#include <glm/vec4.hpp>
|
|
|
|
#include <destrum/Graphics/Resources/Buffer.h>
|
|
|
|
struct CPUMesh {
|
|
std::vector<std::uint32_t> indices;
|
|
|
|
struct Vertex {
|
|
glm::vec3 position;
|
|
float uv_x{};
|
|
glm::vec3 normal;
|
|
float uv_y{};
|
|
glm::vec4 tangent;
|
|
};
|
|
std::vector<Vertex> vertices;
|
|
|
|
std::string name;
|
|
|
|
glm::vec3 minPos;
|
|
glm::vec3 maxPos;
|
|
};
|
|
|
|
|
|
struct GPUMesh {
|
|
GPUBuffer vertexBuffer;
|
|
GPUBuffer indexBuffer;
|
|
|
|
std::uint32_t numVertices{0};
|
|
std::uint32_t numIndices{0};
|
|
|
|
// AABB
|
|
glm::vec3 minPos;
|
|
glm::vec3 maxPos;
|
|
// math::Sphere boundingSphere;
|
|
};
|
|
|
|
static std::vector<CPUMesh::Vertex> vertices = {
|
|
// =======================
|
|
// +Z (Front)
|
|
// =======================
|
|
{{-0.5f, -0.5f, 0.5f}, 0.0f, {0, 0, 1}, 0.0f, {1, 0, 0, 1}},
|
|
{{ 0.5f, -0.5f, 0.5f}, 1.0f, {0, 0, 1}, 0.0f, {1, 0, 0, 1}},
|
|
{{ 0.5f, 0.5f, 0.5f}, 1.0f, {0, 0, 1}, 1.0f, {1, 0, 0, 1}},
|
|
{{-0.5f, 0.5f, 0.5f}, 0.0f, {0, 0, 1}, 1.0f, {1, 0, 0, 1}},
|
|
|
|
// =======================
|
|
// -Z (Back)
|
|
// =======================
|
|
{{ 0.5f, -0.5f, -0.5f}, 0.0f, {0, 0, -1}, 0.0f, {-1, 0, 0, 1}},
|
|
{{-0.5f, -0.5f, -0.5f}, 1.0f, {0, 0, -1}, 0.0f, {-1, 0, 0, 1}},
|
|
{{-0.5f, 0.5f, -0.5f}, 1.0f, {0, 0, -1}, 1.0f, {-1, 0, 0, 1}},
|
|
{{ 0.5f, 0.5f, -0.5f}, 0.0f, {0, 0, -1}, 1.0f, {-1, 0, 0, 1}},
|
|
|
|
// =======================
|
|
// +X (Right)
|
|
// =======================
|
|
{{ 0.5f, -0.5f, 0.5f}, 0.0f, {1, 0, 0}, 0.0f, {0, 0, -1, 1}},
|
|
{{ 0.5f, -0.5f, -0.5f}, 1.0f, {1, 0, 0}, 0.0f, {0, 0, -1, 1}},
|
|
{{ 0.5f, 0.5f, -0.5f}, 1.0f, {1, 0, 0}, 1.0f, {0, 0, -1, 1}},
|
|
{{ 0.5f, 0.5f, 0.5f}, 0.0f, {1, 0, 0}, 1.0f, {0, 0, -1, 1}},
|
|
|
|
// =======================
|
|
// -X (Left)
|
|
// =======================
|
|
{{-0.5f, -0.5f, -0.5f}, 0.0f, {-1, 0, 0}, 0.0f, {0, 0, 1, 1}},
|
|
{{-0.5f, -0.5f, 0.5f}, 1.0f, {-1, 0, 0}, 0.0f, {0, 0, 1, 1}},
|
|
{{-0.5f, 0.5f, 0.5f}, 1.0f, {-1, 0, 0}, 1.0f, {0, 0, 1, 1}},
|
|
{{-0.5f, 0.5f, -0.5f}, 0.0f, {-1, 0, 0}, 1.0f, {0, 0, 1, 1}},
|
|
|
|
// =======================
|
|
// +Y (Top)
|
|
// =======================
|
|
{{-0.5f, 0.5f, 0.5f}, 0.0f, {0, 1, 0}, 0.0f, {1, 0, 0, 1}},
|
|
{{ 0.5f, 0.5f, 0.5f}, 1.0f, {0, 1, 0}, 0.0f, {1, 0, 0, 1}},
|
|
{{ 0.5f, 0.5f, -0.5f}, 1.0f, {0, 1, 0}, 1.0f, {1, 0, 0, 1}},
|
|
{{-0.5f, 0.5f, -0.5f}, 0.0f, {0, 1, 0}, 1.0f, {1, 0, 0, 1}},
|
|
|
|
// =======================
|
|
// -Y (Bottom)
|
|
// =======================
|
|
{{-0.5f, -0.5f, -0.5f}, 0.0f, {0, -1, 0}, 0.0f, {1, 0, 0, 1}},
|
|
{{ 0.5f, -0.5f, -0.5f}, 1.0f, {0, -1, 0}, 0.0f, {1, 0, 0, 1}},
|
|
{{ 0.5f, -0.5f, 0.5f}, 1.0f, {0, -1, 0}, 1.0f, {1, 0, 0, 1}},
|
|
{{-0.5f, -0.5f, 0.5f}, 0.0f, {0, -1, 0}, 1.0f, {1, 0, 0, 1}},
|
|
};
|
|
|
|
static std::vector<uint32_t> indices = {
|
|
0, 1, 2, 2, 3, 0, // Front
|
|
4, 5, 6, 6, 7, 4, // Back
|
|
8, 9,10, 10,11, 8, // Right
|
|
12,13,14, 14,15,12, // Left
|
|
16,17,18, 18,19,16, // Top
|
|
20,21,22, 22,23,20 // Bottom
|
|
};
|
|
|
|
|
|
#endif //MESH_H
|