I am loading a model in my OpenGL application using Assimp library like this :
bool CGameObject::LoadModelFromFile(char* sZFilePath)
{
std::string fn = sZFilePath;
std::string td = "\\";
std::string mfn = _getcwd(NULL, 0) + td + fn;
Assimp::Importer importer;
const aiScene* scene = importer.ReadFile(mfn,
aiProcess_CalcTangentSpace |
aiProcess_Triangulate |
aiProcess_JoinIdenticalVertices |
aiProcess_SortByPType);
if (!scene) {
return false;
}
const int iVertexTotalSize = sizeof(aiVector3D) * 2 + sizeof(aiVector2D);
int iTotalVertices = 0;
for(UINT i = 0; i < scene->mNumMeshes; i++) {
aiMesh* mesh = scene->mMeshes[i];
int iMeshFaces = mesh->mNumFaces;
for (UINT f = 0; f <iMeshFaces; f++) {
const aiFace* face = &mesh->mFaces[f];
for (UINT k = 0; k < 3; k++) {
aiVector3D pos = mesh->mVertices[face->mIndices[k]];
Model.vertices.push_back(pos.x);
Model.vertices.push_back(pos.y);
Model.vertices.push_back(pos.z);
}
}
}
// VAO
glGenVertexArrays(1, &m_vao);
glBindVertexArray(m_vao);
// VBO
glGenBuffers(1, &m_vbo);
glBindBuffer(GL_ARRAY_BUFFER, m_vbo);
glBufferData(GL_ARRAY_BUFFER, this->Model.vertices.size() * sizeof(GLfloat), &this->Model.vertices[0], GL_STATIC_DRAW);
glVertexAttribPointer((GLuint)0, 3, GL_FLOAT, GL_FALSE, 0, 0);
glEnableVertexAttribArray(0);
// unbind buffers
glBindVertexArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
// return success when everything is loaded
return true;
}
and then render it like this :
for (GameObject::iterator i = GameObjects.begin(); i != GameObjects.end(); ++i)
{
CGameObject* pObj = *i;
glUniformMatrix4fv(MatrixID, 1, GL_FALSE, GetMVPMatrix(pObj->position));
glBindVertexArray(pObj->m_vao);
glVertexAttrib3f((GLuint)1, 1.0, 0.0, 0.0); // set constant color attribute
glDrawArrays(GL_TRIANGLES, 0, pObj->Model.vertices.size());
}
.
.
.
// function used to set MVP matrix
GLfloat* GetMVPMatrix(glm::vec3 position)
{
glm::mat4 Model = glm::translate(mat4(1.0), position);
glm::mat4 MVP3 = Projection * View * Model;
return &MVP3[0][0];
}
I created and exported my model using Blender. if I use OBJ format then it is rendered correctly :

but with DAE format it is like this :

My model has 5 meshes and debugging in Visual Studio shows that all 5 meshes are loaded.
Loading the DAE file in assimp_viewer shows the model file has been exported correctly :

Where am i doing it wrong ?