Rendu
A lightweight rendering engine for experimentations
Loading...
Searching...
No Matches
Mesh.hpp
1#pragma once
2#include "resources/Bounds.hpp"
3#include "resources/Buffer.hpp"
4#include "graphics/GPUTypes.hpp"
5#include "Common.hpp"
6
7class GPUMesh;
8
15class Mesh {
16public:
17
19 enum class Load {
20 Expanded,
21 Points,
22 Indexed
23 };
24
26 struct Metrics {
27 size_t vertices = 0;
28 size_t normals = 0;
29 size_t tangents = 0;
30 size_t bitangents = 0;
31 size_t colors = 0;
32 size_t texcoords = 0;
33 size_t indices = 0;
34 };
35
39 Mesh(const std::string & name);
40
46 Mesh(std::istream & in, Mesh::Load mode, const std::string & name);
47
49 void upload();
50
52 void clearGeometry();
53
55 void clean();
56
62
65 void computeNormals();
66
70 void computeTangentsAndBitangents(bool force);
71
77 int saveAsObj(const std::string & path, bool defaultUVs);
78
82 const std::string & name() const;
83
87 bool hadNormals() const;
88
92 bool hadTexcoords() const;
93
97 bool hadColors() const;
98
100 const Metrics & metrics() const;
101
105 Mesh & operator=(const Mesh &) = delete;
106
108 Mesh(const Mesh &) = delete;
109
114
117
120
125
126 std::vector<glm::vec3> positions;
127 std::vector<glm::vec3> normals;
128 std::vector<glm::vec3> tangents;
129 std::vector<glm::vec3> bitangents;
130 std::vector<glm::vec3> colors;
131 std::vector<glm::vec2> texcoords;
132 std::vector<unsigned int> indices;
133
135 std::unique_ptr<GPUMesh> gpu;
136
137private:
138
140 void updateMetrics();
141
143 std::string _name;
144
145};
Represent the smallest axis-aligne box containing a given object or region of space.
Definition: Bounds.hpp:28
General purpose GPU buffer, with different use types determining its memory type, visibility and acce...
Definition: Buffer.hpp:10
Store vertices and triangles data on the GPU, linked by an array object.
Definition: GPUObjects.hpp:125
Represents a geometric mesh composed of vertices, other attributes and triangles.
Definition: Mesh.hpp:15
int saveAsObj(const std::string &path, bool defaultUVs)
Definition: Mesh.cpp:510
BoundingBox computeBoundingBox()
Definition: Mesh.cpp:310
const Metrics & metrics() const
Definition: Mesh.cpp:570
bool hadNormals() const
Definition: Mesh.cpp:558
BoundingBox bbox
The mesh bounding box in model space.
Definition: Mesh.hpp:134
void clearGeometry()
Definition: Mesh.cpp:279
std::vector< unsigned int > indices
The triangular faces indices.
Definition: Mesh.hpp:132
void clean()
Definition: Mesh.cpp:289
std::unique_ptr< GPUMesh > gpu
The GPU buffers infos (optional).
Definition: Mesh.hpp:135
std::vector< glm::vec3 > colors
The vertex colors.
Definition: Mesh.hpp:130
const std::string & name() const
Definition: Mesh.cpp:554
std::vector< glm::vec3 > normals
The surface normals.
Definition: Mesh.hpp:127
bool hadColors() const
Definition: Mesh.cpp:566
Mesh(Mesh &&)
std::string _name
Resource name.
Definition: Mesh.hpp:143
std::vector< glm::vec3 > positions
The 3D positions.
Definition: Mesh.hpp:126
Buffer & indexBuffer()
Definition: Mesh.cpp:305
Mesh & operator=(Mesh &&)
std::vector< glm::vec3 > bitangents
The surface bitangents.
Definition: Mesh.hpp:129
void updateMetrics()
Definition: Mesh.cpp:574
Mesh & operator=(const Mesh &)=delete
Buffer & vertexBuffer()
Definition: Mesh.cpp:300
void computeTangentsAndBitangents(bool force)
Definition: Mesh.cpp:356
void upload()
Definition: Mesh.cpp:274
void computeNormals()
Definition: Mesh.cpp:327
std::vector< glm::vec3 > tangents
The surface tangents.
Definition: Mesh.hpp:128
Load
The mesh loading preprocessing mode.
Definition: Mesh.hpp:19
@ Expanded
Duplicate vertices for every face.
@ Points
Load the vertices without any connectivity.
@ Indexed
Duplicate only vertices that are shared between faces with attributes with different values.
bool hadTexcoords() const
Definition: Mesh.cpp:562
Mesh(const Mesh &)=delete
Metrics _metrics
Resource stats.
Definition: Mesh.hpp:142
std::vector< glm::vec2 > texcoords
The texture coordinates.
Definition: Mesh.hpp:131
Detailed operation to perform when binding a texture (starting a renderpass).
Definition: GPUTypes.hpp:278
Information on a geometric mesh.
Definition: Mesh.hpp:26
size_t indices
Index count.
Definition: Mesh.hpp:33
size_t vertices
Vertex count.
Definition: Mesh.hpp:27
size_t colors
Color count.
Definition: Mesh.hpp:31
size_t texcoords
UV count.
Definition: Mesh.hpp:32
size_t normals
Normal count.
Definition: Mesh.hpp:28
size_t tangents
Tangent count.
Definition: Mesh.hpp:29
size_t bitangents
Bitangent count.
Definition: Mesh.hpp:30