I’ve been trying to load a 3ds model with Assimp, but once I get to the point of rendering nothing appears,
below is the rendering code I’m trying to use due to the original not rendering for me and below that is the mesh and texture loading code. So I my question in the end would be why is it not rendering?
void Core::RenderMesh(const ModelInstance& inst)
{
ModelAsset* asset = inst.asset;
Rendering::Program* shaders = asset->shaders;
shaders->use();
shaders->setUniform("camera", gCamera.matrix());
shaders->setUniform("model", inst.transform);
shaders->setUniform("tex", 0);
glEnable(GL_VERTEX_ARRAY);
glEnable(GL_NORMAL_ARRAY);
glEnable(GL_TEXTURE_COORD_ARRAY);
glVertexPointer(3, GL_FLOAT, 0,asset->mesh.vertexArray);
glNormalPointer(GL_FLOAT, 0, asset->mesh.normalArray);
glActiveTexture(GL_TEXTURE0_ARB);
glTexCoordPointer(2, GL_FLOAT, 0, asset->mesh.uvArray);
glBindVertexArray(asset->vao);
glDrawArrays(GL_TRIANGLES,0,asset->mesh.numTriangles);
glDisable(GL_VERTEX_ARRAY);
glDisable(GL_NORMAL_ARRAY);
glDisable(GL_TEXTURE_COORD_ARRAY);
shaders->stopUsing();
}
void Mesh::LoadMesh(std::string filename)
{
Assimp::Importer importer;
const aiScene *scene = importer.ReadFile(filename, aiProcessPreset_TargetRealtime_Fast);
aiMesh *mesh = scene->mMeshes[0];
numTriangles = mesh->mNumFaces * 3;
int index = 0;
numUvCoords = mesh->GetNumUVChannels();
vertexArray = new float[mesh->mNumFaces * 3 * 3];
normalArray = new float[mesh->mNumFaces * 3 * 3];
uvArray = new float[mesh->mNumFaces * 3 * 2];
for (unsigned int i = 0; i < mesh->mNumFaces; i++)
{
const aiFace& face = mesh->mFaces[i];
//foreach index
for (int j = 0; j < 3; j++)//assume all faces are triangulated
{
aiVector3D uv = mesh->mTextureCoords[0][face.mIndices[j]];
memcpy(uvArray, &uv, sizeof(float)* 2);
uvArray += 2;
aiVector3D normal = mesh->mNormals[face.mIndices[j]];
memcpy(normalArray, &normal, sizeof(float)* 3);
normalArray += 3;
aiVector3D pos = mesh->mVertices[face.mIndices[j]];
memcpy(vertexArray, &pos, sizeof(float)* 3);
vertexArray += 3;
}
}
uvArray -= mesh->mNumFaces * 3 * 2;
normalArray -= mesh->mNumFaces * 3 * 3;
vertexArray -= mesh->mNumFaces * 3 * 3;
}