Any collision meshes we have should be working, and RawModels should be released after being loaded.
This commit is contained in:
@@ -2,12 +2,10 @@
|
||||
|
||||
Model::Model(std::string fileName)
|
||||
{
|
||||
//fileName = "Models/Core/ScreenQuad.mesh";
|
||||
//Try loading the model asyncronously, if it throws any exceptions then let it propagate back to caller.
|
||||
auto m_RawModel = ResourceManager::Load<RawModel, true>(fileName);
|
||||
//throw FailedLoadingException("Test");
|
||||
auto rawModel = ResourceManager::Load<RawModel, true>(fileName);
|
||||
|
||||
for (auto& materialProperty : m_RawModel->m_Materials) {
|
||||
for (auto& materialProperty : rawModel->m_Materials) {
|
||||
switch (materialProperty.type) {
|
||||
case RawModel::MaterialType::SingleTextures:
|
||||
{
|
||||
@@ -48,11 +46,11 @@ Model::Model(std::string fileName)
|
||||
glGenBuffers(1, &buffer);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, buffer);
|
||||
|
||||
glBufferData(GL_ARRAY_BUFFER, m_RawModel->NumVertices() * m_RawModel->VertexSize(), m_RawModel->Vertices(), GL_STATIC_DRAW);
|
||||
glBufferData(GL_ARRAY_BUFFER, rawModel->NumVertices() * rawModel->VertexSize(), rawModel->Vertices(), GL_STATIC_DRAW);
|
||||
|
||||
glGenBuffers(1, &ElementBuffer);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ElementBuffer);
|
||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, m_RawModel->Indices().size() * sizeof(unsigned int), m_RawModel->Indices().data(), GL_STATIC_DRAW);
|
||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, rawModel->Indices().size() * sizeof(unsigned int), rawModel->Indices().data(), GL_STATIC_DRAW);
|
||||
|
||||
glGenVertexArrays(1, &VAO);
|
||||
glBindVertexArray(VAO);
|
||||
@@ -60,7 +58,7 @@ Model::Model(std::string fileName)
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, buffer);
|
||||
std::vector<int> structSizes;
|
||||
if (m_RawModel->IsSkinned()) {
|
||||
if (rawModel->IsSkinned()) {
|
||||
structSizes = { 3, 3, 3, 3, 2, 4, 4 };
|
||||
} else {
|
||||
structSizes = { 3, 3, 3, 3, 2 };
|
||||
@@ -79,7 +77,7 @@ Model::Model(std::string fileName)
|
||||
glVertexAttribPointer(element, structSizes[element], GL_FLOAT, GL_FALSE, stride, (GLvoid*)(sizeof(GLfloat) * (offset += structSizes[element - 1]))); element++;
|
||||
glVertexAttribPointer(element, structSizes[element], GL_FLOAT, GL_FALSE, stride, (GLvoid*)(sizeof(GLfloat) * (offset += structSizes[element - 1]))); element++;
|
||||
glVertexAttribPointer(element, structSizes[element], GL_FLOAT, GL_FALSE, stride, (GLvoid*)(sizeof(GLfloat) * (offset += structSizes[element - 1]))); element++;
|
||||
if (m_RawModel->IsSkinned()) {
|
||||
if (rawModel->IsSkinned()) {
|
||||
glVertexAttribPointer(element, structSizes[element], GL_FLOAT, GL_FALSE, stride, (GLvoid*)(sizeof(GLfloat) * (offset += structSizes[element - 1]))); element++;
|
||||
glVertexAttribPointer(element, structSizes[element], GL_FLOAT, GL_FALSE, stride, (GLvoid*)(sizeof(GLfloat) * (offset += structSizes[element - 1]))); element++;
|
||||
}
|
||||
@@ -91,7 +89,7 @@ Model::Model(std::string fileName)
|
||||
glEnableVertexAttribArray(2);
|
||||
glEnableVertexAttribArray(3);
|
||||
glEnableVertexAttribArray(4);
|
||||
if (m_RawModel->IsSkinned()) {
|
||||
if (rawModel->IsSkinned()) {
|
||||
glEnableVertexAttribArray(5);
|
||||
glEnableVertexAttribArray(6);
|
||||
}
|
||||
@@ -101,27 +99,29 @@ Model::Model(std::string fileName)
|
||||
|
||||
glm::vec3 mini(INFINITY);
|
||||
glm::vec3 maxi(-INFINITY);
|
||||
for (unsigned int i = 0; i < m_RawModel->NumVertices(); i++) {
|
||||
const auto& v = m_RawModel->Vertices()[i];
|
||||
for (unsigned int i = 0; i < rawModel->NumVertices(); i++) {
|
||||
const auto& v = rawModel->Vertices()[i];
|
||||
mini = glm::min(mini, v.Position);
|
||||
maxi = glm::max(maxi, v.Position);
|
||||
}
|
||||
m_Box = AABB(mini, maxi);
|
||||
|
||||
//m_Skeleton = m_RawModel->m_Skeleton;
|
||||
delete m_RawModel->m_Skeleton;
|
||||
m_Materials = m_RawModel->m_Materials;
|
||||
//m_Indices = m_RawModel->m_Indices;
|
||||
m_IsSkinned = m_RawModel->IsSkinned();
|
||||
m_Skeleton = rawModel->m_Skeleton;
|
||||
m_Materials = rawModel->m_Materials;
|
||||
m_Indices = rawModel->CollisionIndices();
|
||||
m_IsSkinned = rawModel->IsSkinned();
|
||||
// Copy vertex positions for collisions later
|
||||
for (auto& v : m_RawModel->m_Vertices) {
|
||||
//m_Vertices.push_back(v.Position);
|
||||
}
|
||||
m_Vertices = rawModel->CollisionVertices();
|
||||
|
||||
ResourceManager::Release("RawModel", fileName);
|
||||
}
|
||||
|
||||
Model::~Model()
|
||||
{
|
||||
|
||||
if (m_Skeleton != nullptr) {
|
||||
delete m_Skeleton;
|
||||
}
|
||||
for (auto material : m_Materials) {
|
||||
delete material.material;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user