When I was following the LearnOpenGL, a problem come up:
I can't figure out why the scene->mRootNode->mNumMeshes
is 0. However the scene has been imported rightly (I guess, 'cause scene->mNumMeshes
is 7).
void Model::loadModel(std::string path)
{
Assimp::Importer import;
const aiScene *scene = import.ReadFile(path, aiProcess_Triangulate | aiProcess_FlipUVs);
if (scene == nullptr || !scene->mRootNode || scene->mFlags & AI_SCENE_FLAGS_INCOMPLETE)
{
std::cout << "ERROR::ASSIMP::" << import.GetErrorString() << std::endl;
return;
}
directory = path.substr(0, path.find_last_of('/'));
processNode(scene->mRootNode, scene);
}
void Model::processNode(aiNode *node, const aiScene *scene)
{
for (unsigned int i = 0; i < node->mNumMeshes; i )
{
aiMesh *mesh = scene->mMeshes[node->mMeshes[i]];
meshes.push_back(processMesh(mesh, scene));
std::cout << "SUCCESS::ASSIMP::PROCESSED:" << i << std::endl;
}
for (unsigned int i = 0; i < node->mNumMeshes; i )
processNode(node->mChildren[i], scene);
}
CodePudding user response:
Meshes are not necessarily attached to the root node. They can also be attached to any of the child nodes (or children's child nodes). Having a scene which contains 7 meshes with scene->mRootNode->mNumMeshes
beeing 0 is perfectly valid.
But, the recursive loop in your code is wrong. You have to iterate over node->mNumChildren
instead of node->mNumMeshes
:
for (unsigned int i = 0; i < node->mNumChildren; i )
processNode(node->mChildren[i], scene);