assimp模型加载不会加载所有网格

时间:2018-09-15 15:41:08

标签: c++ opengl assimp

我正在努力通过具有多个网格的assimp加载模型,这是加载模型的代码:

A class: C'tor called...!
B class: C'tor called...!

我要加载的模型有两个网格,头部和躯干

如果我这样开始循环:bool loadAssImp( const char * path, std::vector<unsigned short> & indices, std::vector<glm::vec3> & vertices, std::vector<glm::vec2> & uvs, std::vector<glm::vec3> & normals ) { Assimp::Importer importer; const aiScene* scene = importer.ReadFile(path, aiProcess_Triangulate); if (!scene) { cout << importer.GetErrorString() << endl; return false; } aiMesh* mesh; for (unsigned int l = 0; l < scene->mNumMeshes; l++) { mesh = scene->mMeshes[l]; cout << l << endl; // Fill vertices positions vertices.reserve(mesh->mNumVertices); for (unsigned int i = 0; i < mesh->mNumVertices; i++) { aiVector3D pos = mesh->mVertices[i]; vertices.push_back(glm::vec3(pos.x, pos.y, pos.z)); } // Fill vertices texture coordinates uvs.reserve(mesh->mNumVertices); for (unsigned int i = 0; i < mesh->mNumVertices; i++) { aiVector3D UVW = mesh->mTextureCoords[0][i]; // Assume only 1 set of UV coords; AssImp supports 8 UV sets. uvs.push_back(glm::vec2(UVW.x, UVW.y)); } // Fill vertices normals normals.reserve(mesh->mNumVertices); for (unsigned int i = 0; i < mesh->mNumVertices; i++) { aiVector3D n = mesh->mNormals[i]; normals.push_back(glm::vec3(n.x, n.y, n.z)); } // Fill face indices indices.reserve(3 * mesh->mNumFaces); for (unsigned int i = 0; i < mesh->mNumFaces; i++) { // Assume the model has only triangles. indices.push_back(mesh->mFaces[i].mIndices[0]); indices.push_back(mesh->mFaces[i].mIndices[1]); indices.push_back(mesh->mFaces[i].mIndices[2]); } } // The "scene" pointer will be deleted automatically by "importer" return true; } ,则它几乎正确地加载了模型,某些模型的顶点无法正确绘制,但是头部和几乎所有躯干都被绘制了。

如果我这样开始循环:for (int l = scene->mNumMeshes - 1; l >= 0 ; l--)仅画出躯干(但完全画出而没有任何缺失的部分)

奇怪的是,顶点和索引数都相同。

1 个答案:

答案 0 :(得分:0)

您还需要设置aiNode-instances描述的转换。因此,当在节点上加载场景循环时,请设置本地节点转换,然后将分配的网格绘制到当前节点。 Whithout应用这些转换信息将破坏模型的呈现。