35#include <assimp/Importer.hpp>
36#include <assimp/scene.h>
37#include <assimp/postprocess.h>
42#include <raftel/global_macros.hpp>
44#include <raftel/engine.hpp>
74 bool operator==(
const Vertex& other)
const {
105 MOVABLE_BUT_NOT_COPYABLE(
Mesh)
113 static std::shared_ptr<
Mesh>
Create(const std::
string& filePath,
bool multithread);
119 Mesh(const std::
string& filePath);
128 std::vector<std::vector<
unsigned int>> indicesPerSubmesh,
129 std::vector<std::shared_ptr<
Material>> mats);
137 std::vector<std::vector<
unsigned int>> indicesPerSubmesh);
151 materials = newMaterials;
160 materials.push_back(mat);
168 materials.push_back(mat);
204 void setName(std::string n_) { nameMesh = n_; }
229 std::vector<GLuint>
GetVAOs() {
return VAOs; }
244 bool loadFromFile(
const std::string& filePath);
251 bool loadFromAssimp(
const std::string& filePath);
258 void processNode(aiNode* node,
const aiScene* scene);
265 void processAssimpMesh(aiMesh* mesh,
const aiScene* scene);
272 void setError(
const std::string& errorMessage,
const char* file,
int line);
274 std::vector<std::shared_ptr<Material>> materials;
281 std::shared_ptr<Raftel::Material> convertAssimpMaterial(aiMaterial* material);
283 std::vector<GLuint> VBOs;
284 std::vector<GLuint> EBOs;
285 std::vector<GLuint> VAOs;
286 std::vector<std::vector<unsigned int>> submeshIndices;
287 std::vector<std::vector<Vertex>> submeshVertex;
289 std::string nameMesh;
291 std::string lastError;
315 static std::shared_ptr<Mesh>
createPlane(
float width,
float height);
343 float heightMultiplier,
362 static std::shared_ptr<Raftel::Mesh>
createCone(
float radius,
float height,
int segments);
Represents a material with textures and physical properties.
A factory class for creating and loading meshes.
static std::shared_ptr< Mesh > createCube(float size)
Creates a cube mesh with the given size.
static std::shared_ptr< Mesh > createSphere(float radius, int segments)
Creates a sphere mesh with the given radius and number of segments.
static std::shared_ptr< Mesh > createPlane(float width, float height)
Creates a plane mesh with the given width and height.
static std::shared_ptr< Raftel::Mesh > createCone(float radius, float height, int segments)
Creates a 3D cone mesh.
static std::shared_ptr< Mesh > createTerrain(const char *heightMapFile, float size, float heightMultiplier, bool isCentered)
Creates a terrain mesh from a heightmap image.
Mesh()=default
Default constructor for the Mesh class.
void addMaterial(const std::shared_ptr< Material > &mat)
Adds a material to the mesh.
void setupMesh()
Initializes OpenGL buffers for the mesh (VAO, VBO, EBO).
void setMaterial(const std::shared_ptr< Material > &mat)
Sets a single material for the mesh.
std::vector< std::vector< unsigned int > > GetSubMeshIndex()
Retrieves all submesh indices.
static std::shared_ptr< Mesh > Create(const std::string &filePath, bool multithread)
Move constructor for the Mesh class.
void draw(ShaderProgram &shader)
Renders the mesh using a specified shader.
std::vector< GLuint > GetVAOs()
Retrieves all VAOs associated with the mesh.
void setUniforms(GLuint shaderProgramID)
Sets the uniform variables for the shader program.
~Mesh()
Destructor for the Mesh class.
void setMaterials(const std::vector< std::shared_ptr< Material > > &newMaterials)
Sets the materials for the mesh.
std::string getName()
Retrieves the name of the mesh.
std::vector< std::shared_ptr< Material > > & GetAllMaterials()
Retrieves all materials associated with the mesh.
std::shared_ptr< Material > GetMaterialByIndex(int index)
Retrieves a material by its index.
void setName(std::string n_)
Sets the name of the mesh.
const std::string & getLastError() const
Retrieves the last error encountered during mesh loading.
void renderMaterial(ShaderProgram &shader)
Renders the material of the mesh.
bool loadMesh(const std::string &filePath)
Loads a mesh from a file.
A class to represent an OpenGL shader program, combining vertex and fragment shaders.
Defines the Material class for handling surface properties and textures.
Defines the Shader and ShaderProgram classes for managing shaders in OpenGL.
Represents a 3D vertex with attributes like position, normal, and texture coordinates.
glm::vec3 position
The position of the vertex in 3D space.
glm::vec2 texCoord
The texture coordinates of the vertex.
Vertex()=default
Default constructor for the Vertex structure.
Vertex(const glm::vec3 &position, const glm::vec3 &normal, const glm::vec2 &texCoord)
Constructor for the Vertex structure.
glm::vec3 normal
The normal vector of the vertex for lighting calculations.