64 lines
1.4 KiB
C++
64 lines
1.4 KiB
C++
#ifndef MODEL_COMPONENT_H
|
|
#define MODEL_COMPONENT_H
|
|
|
|
#include <glm/glm.hpp>
|
|
#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;
|
|
};
|
|
|
|
// Structure representing a sub-mesh (a group of faces sharing the same material)
|
|
struct SubMesh {
|
|
std::vector<Vertex> vertices;
|
|
std::vector<GLuint> indices;
|
|
glm::vec3 diffuseColor;
|
|
glm::vec3 specularColor;
|
|
float shininess;
|
|
GLuint diffuseTexture;
|
|
GLuint VAO, VBO, EBO;
|
|
|
|
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)
|
|
{}
|
|
};
|
|
|
|
class ModelComponent {
|
|
public:
|
|
ModelComponent();
|
|
~ModelComponent();
|
|
|
|
// Base model path.
|
|
std::string modelPath;
|
|
// Submeshes
|
|
std::vector<SubMesh> meshes;
|
|
|
|
// Functions.
|
|
bool LoadModel(const std::string &filepath);
|
|
void Draw();
|
|
|
|
// 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;
|
|
};
|
|
|
|
#endif // MODEL_COMPONENT_H
|