ThreeLab/Engine/Components/ModelComponent.h

64 lines
1.4 KiB
C
Raw Normal View History

2025-04-01 20:03:18 +00:00
#ifndef MODEL_COMPONENT_H
#define MODEL_COMPONENT_H
#include <glm/glm.hpp>
2025-04-01 20:19:00 +00:00
#include <string>
#include <vector>
#include <GL/glew.h>
// Structure representing a single vertex.
struct Vertex {
glm::vec3 Position;
glm::vec3 Normal;
glm::vec2 TexCoords;
glm::vec3 Tangent;
};
2025-04-01 20:03:18 +00:00
2025-04-01 22:28:45 +00:00
// Structure representing a sub-mesh (a group of faces sharing the same material)
struct SubMesh {
std::vector<Vertex> vertices;
std::vector<GLuint> indices;
2025-04-01 20:03:18 +00:00
glm::vec3 diffuseColor;
glm::vec3 specularColor;
float shininess;
2025-04-01 22:28:45 +00:00
GLuint diffuseTexture;
2025-04-01 20:19:00 +00:00
GLuint VAO, VBO, EBO;
2025-04-01 22:28:45 +00:00
SubMesh()
: diffuseColor(1.0f,1.0f,1.0f),
specularColor(1.0f,1.0f,1.0f),
shininess(32.0f),
diffuseTexture(0),
VAO(0), VBO(0), EBO(0)
{}
};
2025-04-01 20:19:00 +00:00
2025-04-01 22:28:45 +00:00
class ModelComponent {
public:
ModelComponent();
~ModelComponent();
2025-04-01 20:19:00 +00:00
2025-04-01 22:28:45 +00:00
// Base model path.
std::string modelPath;
// Submeshes
std::vector<SubMesh> meshes;
2025-04-01 20:19:00 +00:00
2025-04-01 22:28:45 +00:00
// Functions.
bool LoadModel(const std::string &filepath);
2025-04-01 20:19:00 +00:00
void Draw();
2025-04-01 22:28:45 +00:00
// Texture loading.
bool LoadDiffuseTexture(const std::string &filepath, GLuint &textureID);
bool LoadNormalTexture(const std::string &filepath);
// Setup mesh for a submesh.
void SetupMesh(SubMesh &mesh);
// (Optional) Global material properties if needed.
glm::vec3 diffuseColor;
glm::vec3 specularColor;
float shininess;
2025-04-01 20:03:18 +00:00
};
#endif // MODEL_COMPONENT_H