Toast Engine
Loading...
Searching...
No Matches
mesh.hpp
Go to the documentation of this file.
1
8
9#pragma once
10#include "core_types.hpp"
11
12#include <glm/glm.hpp>
13#include <memory>
14#include <toast/export.hpp>
15#include <toast/log.hpp>
17
18namespace renderer {
19class VulkanMesh;
20}
21
22namespace assets {
23
24namespace _detail {
32
33inline constexpr uint16_t mesh_format_version = 7;
34
42 std::array<uint8_t, 6> magic = {'T', 'M', 'E', 'S', 'H', '\0'};
43 // Defaulted from the constant rather than repeating the number: these two drifted apart once already
44 // (writer stamped 5, reader accepted only 4) and every mesh in the project silently failed to load
45 uint16_t version = mesh_format_version;
46 uint32_t vertex_count = 0;
47 uint32_t index_count = 0;
48};
49}
50
64TOAST_API void generateTangents(std::vector<renderer::Vertex>& vertices, const std::vector<uint32_t>& indices);
65
66class TOAST_API Mesh final : public Asset {
67public:
68 using Index = uint32_t;
69
70 explicit Mesh(const std::vector<uint8_t>& data);
71 Mesh(std::string_view name, std::vector<renderer::Vertex>&& vertices, std::vector<uint32_t>&& indices);
73 Mesh(
74 std::string_view name, std::vector<renderer::Vertex>&& vertices, std::vector<uint32_t>&& indices,
75 std::vector<renderer::SkinVertex>&& skin_vertices
76 );
77 ~Mesh() override;
78
79 [[nodiscard]]
80 auto type() const -> std::string_view override {
81 return "mesh";
82 }
83
84 [[nodiscard]]
85 auto vertices() const -> const std::vector<renderer::Vertex>& {
86 return m_vertices;
87 }
88
89 [[nodiscard]]
90 auto indices() const -> const std::vector<Index>& {
91 return m_indices;
92 }
93
95 [[nodiscard]]
96 auto skinVertices() const -> const std::vector<renderer::SkinVertex>& {
97 return m_skin_vertices;
98 }
99
100 [[nodiscard]]
101 auto isSkinned() const noexcept -> bool {
102 return !m_skin_vertices.empty();
103 }
104
114 [[nodiscard]]
115 auto boundingSphere() const -> const glm::vec4&;
116
117 [[nodiscard]]
118 auto gpuMesh() const -> const renderer::VulkanMesh&;
119
120 [[nodiscard]]
121 auto gpuMesh() -> renderer::VulkanMesh&;
122
123 [[nodiscard]]
124 auto name() const -> const std::string& {
125 return m_name;
126 }
127
128 [[nodiscard]]
129 auto toBinary() const -> std::vector<uint8_t>;
130
131private:
132 std::string m_name;
133 std::vector<renderer::Vertex> m_vertices;
134 std::vector<Index> m_indices;
135 std::vector<renderer::SkinVertex> m_skin_vertices;
136
137 mutable std::optional<glm::vec4> m_bounding_sphere;
138
139 std::unique_ptr<renderer::VulkanMesh> m_gpu_mesh;
140};
141
142}
auto skinVertices() const -> const std::vector< renderer::SkinVertex > &
Definition mesh.hpp:96
Definition vulkan_mesh.hpp:26
Base types for the asset system.
Public logging interface for the engine.
constexpr uint16_t mesh_format_version
Definition mesh.hpp:33
Fixed 16-byte .tmesh header.
Definition mesh.hpp:41