From 4be720a677a776bf9848130d76ff6122ff536891 Mon Sep 17 00:00:00 2001 From: wuyize Date: Sat, 8 Apr 2023 17:13:14 +0800 Subject: [PATCH] =?UTF-8?q?Fix:=20=E6=89=93=E5=BC=80=E6=B2=A1=E6=9C=89?= =?UTF-8?q?=E7=BA=B9=E7=90=86=E5=9D=90=E6=A0=87=E7=9A=84=E6=A8=A1=E5=9E=8B?= =?UTF-8?q?=E5=AF=BC=E8=87=B4=E5=B4=A9=E6=BA=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ArchitectureColoredPainting/src/Renderer/Model.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/ArchitectureColoredPainting/src/Renderer/Model.cpp b/ArchitectureColoredPainting/src/Renderer/Model.cpp index 6b0663a..ef56a08 100644 --- a/ArchitectureColoredPainting/src/Renderer/Model.cpp +++ b/ArchitectureColoredPainting/src/Renderer/Model.cpp @@ -135,10 +135,12 @@ std::unique_ptr Model::processMesh(aiMesh* mesh, const aiScene* scene, std::vector 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 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([&] {