Fix: 打开没有纹理坐标的模型导致崩溃

main v0.1.0
wuyize 2023-04-08 17:13:14 +08:00
parent f0ac3bf4f7
commit 4be720a677
1 changed files with 7 additions and 2 deletions

View File

@ -135,10 +135,12 @@ std::unique_ptr<Drawable> Model::processMesh(aiMesh* mesh, const aiScene* scene,
std::vector<Vertex> vertices;
for (unsigned int i = 0; i < mesh->mNumVertices; i++)
{
if (mesh->mNormals && mesh->mTextureCoords[0])
if (mesh->mNormals)
{
auto pos = mesh->mVertices[i];
vertices.push_back(Vertex(pos, mesh->mNormals[i], mesh->mTextureCoords[0][i]));
aiVector3D textureCoords;
if (mesh->mTextureCoords[0]) textureCoords = mesh->mTextureCoords[0][i];
vertices.push_back(Vertex(pos, mesh->mNormals[i], textureCoords));
auto worldPos = model * pos;
minPos = glm::min(minPos, glm::vec3(worldPos.x, worldPos.y, worldPos.z));
maxPos = glm::max(maxPos, glm::vec3(worldPos.x, worldPos.y, worldPos.z));
@ -149,6 +151,9 @@ std::unique_ptr<Drawable> Model::processMesh(aiMesh* mesh, const aiScene* scene,
for (auto face = mesh->mFaces; face < mesh->mFaces + mesh->mNumFaces; face++)
indices.insert(indices.end(), face->mIndices, face->mIndices + face->mNumIndices);
if (vertices.empty() || indices.empty())
return nullptr;
aiMaterial* material = scene->mMaterials[mesh->mMaterialIndex];
if (auto iter = paintingMap.find([&] {