#include "CModel.hpp"

CModel::CModel(std::vector<CMesh*> meshes) :
	m_meshes(meshes),
	m_loaded(false) {
}

CModel::~CModel(void) {
	for (unsigned int i = 0; i < m_meshes.size(); i++)
	{
		delete m_meshes[i];
	}
}

void CModel::load(void) {
	// For each meshes of the model.
	for (unsigned int i = 0; i < m_meshes.size(); i++) {
		m_meshes[i]->load();
	}

	m_loaded = true;
}

void CModel::draw(glm::mat4 model, glm::mat4 view, glm::mat4 projection, glm::vec3 lightPos, float intensity) {
	// For each meshes of the model.
	for (unsigned int i = 0; i < m_meshes.size(); i++) {
		m_meshes[i]->draw(model, view, projection, lightPos, intensity);
	}
}

std::vector<CMesh*>& CModel::getMeshes()
{
	return m_meshes;
}

void CModel::setMeshes(std::vector<CMesh*> meshes)
{
	m_meshes = meshes;
}

bool CModel::isLoaded()
{
	return m_loaded;
}
