// processes a node in a recursive fashion. Processes each individual mesh located at the node and repeats this process on its children nodes (if any).
voidprocessNode(aiNode*node,constaiScene*scene)
{
// process each mesh located at the current node
for(unsignedinti=0;i<node->mNumMeshes;i++)
{
// the node object only contains indices to index the actual objects in the scene.
// the scene contains all the data, node is just to keep stuff organized (like relations between nodes).
// after we've processed all of the meshes (if any) we then recursively process each of the children nodes
for(unsignedinti=0;i<node->mNumChildren;i++)
{
processNode(node->mChildren[i],scene);
}
}
MeshprocessMesh(aiMesh*mesh,constaiScene*scene)
{
// data to fill
vector<Vertex>vertices;
vector<unsignedint>indices;
vector<Texture>textures;
// walk through each of the mesh's vertices
for(unsignedinti=0;i<mesh->mNumVertices;i++)
{
Vertexvertex;
glm::vec3vector;// we declare a placeholder vector since assimp uses its own vector class that doesn't directly convert to glm's vec3 class so we transfer the data to this placeholder glm::vec3 first.
// positions
vector.x=mesh->mVertices[i].x;
vector.y=mesh->mVertices[i].y;
vector.z=mesh->mVertices[i].z;
vertex.Position=vector;
// normals
if(mesh->HasNormals())
{
vector.x=mesh->mNormals[i].x;
vector.y=mesh->mNormals[i].y;
vector.z=mesh->mNormals[i].z;
vertex.Normal=vector;
}
// texture coordinates
if(mesh->mTextureCoords[0])// does the mesh contain texture coordinates?
{
glm::vec2vec;
// a vertex can contain up to 8 different texture coordinates. We thus make the assumption that we won't
// use models where a vertex can have multiple texture coordinates so we always take the first set (0).
vec.x=mesh->mTextureCoords[0][i].x;
vec.y=mesh->mTextureCoords[0][i].y;
vertex.TexCoords=vec;
// tangent
vector.x=mesh->mTangents[i].x;
vector.y=mesh->mTangents[i].y;
vector.z=mesh->mTangents[i].z;
vertex.Tangent=vector;
// bitangent
vector.x=mesh->mBitangents[i].x;
vector.y=mesh->mBitangents[i].y;
vector.z=mesh->mBitangents[i].z;
vertex.Bitangent=vector;
}
else
vertex.TexCoords=glm::vec2(0.0f,0.0f);
vertices.push_back(vertex);
}
// now wak through each of the mesh's faces (a face is a mesh its triangle) and retrieve the corresponding vertex indices.
for(unsignedinti=0;i<mesh->mNumFaces;i++)
{
aiFaceface=mesh->mFaces[i];
// retrieve all indices of the face and store them in the indices vector