ASSIMP:mNumMeshes 为 0

ASSIMP : mNumMeshes is 0

我在学习LearnOpenGL的时候遇到了一个问题: 我不明白为什么 scene->mRootNode->mNumMeshes 是 0。但是场景已经正确导入(我猜,因为 scene->mNumMeshes 是 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);
}

网格不一定附加到根节点。它们也可以附加到任何子节点(或子节点的子节点)。拥有一个包含 7 个网格且 scene->mRootNode->mNumMeshes beeing 0 的场景是完全有效的。

但是,您代码中的递归循环是错误的。您必须遍历 node->mNumChildren 而不是 node->mNumMeshes:

for (unsigned int i = 0; i < node->mNumChildren; i++)
    processNode(node->mChildren[i], scene);