Struct Mesh¶
Defined in File Mesh.hpp
Struct Documentation¶
-
struct Mesh¶
Represents a 3D mesh with associated vertex and index data, OpenGL buffers, and optional texture.
The Mesh class encapsulates the data and operations required to render a 3D mesh using OpenGL. It manages the Vertex Array Object (VAO), Vertex Buffer Object (VBO), and Element Buffer Object (EBO), as well as the mesh’s vertices, indices, and an optional texture. The mesh is identified by a name.
Note
Copying of Mesh objects is disabled to prevent resource duplication.
Public Functions
-
Mesh() = default¶
Constructs a Mesh object with the given name, vertices, and indices.
- Parameters:
name – The name of the mesh.
vv – A unique pointer to a vector containing the mesh’s vertices.
vi – A unique pointer to a vector containing the mesh’s indices.
- Throws:
std::runtime_error – if the vertices or indices are empty.
-
~Mesh()¶
-
bool Init(const std::string &name, std::unique_ptr<std::vector<Vertex>> vv, std::unique_ptr<std::vector<unsigned int>> vi)¶
-
inline const std::string &GetName() const¶
Sets the texture for the mesh.
Associates the given texture with this mesh, replacing any previously set texture.
- Parameters:
t – A shared pointer to the Texture to be applied to the mesh.
-
void Draw(ShaderProgram &shader, const glm::mat4 &modelMatrix, Camera &camera) const¶
Renders the mesh using the specified shader and transformation matrices.
This function draws the mesh by applying the given model, view, and projection matrices, and using the provided shader program for rendering.
- Parameters:
shader – Reference to the ShaderProgram used for rendering the mesh.
modelMatrix – The model transformation matrix to position, scale, and rotate the mesh in world space.
view – The view matrix representing the camera’s transformation.
projection – The projection matrix defining the camera’s lens. (screen space)
Friends
-
inline friend std::ostream &operator<<(std::ostream &os, const Mesh &mesh)¶
Overloads the stream insertion operator to output the contents of a Mesh.
This function prints all vertices and indices of the given Mesh object to the provided output stream. Each vertex is printed on a separate line, followed by the mesh indices in groups of three per line.
- Parameters:
os – The output stream to write to.
mesh – The Mesh object whose contents are to be printed.
- Returns:
Reference to the output stream after writing.
-
Mesh() = default¶