From 11754c5c99b82bf757c7260c97e7425237a93b6c Mon Sep 17 00:00:00 2001 From: TheNumbat Date: Mon, 12 Oct 2020 15:43:10 -0400 Subject: [PATCH] fix nan(ind) bug in assimp --- deps/assimp/include/assimp/fast_atof.h | 6 ++++++ src/scene/scene.cpp | 7 +++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/deps/assimp/include/assimp/fast_atof.h b/deps/assimp/include/assimp/fast_atof.h index 6e9a1bb..ffa2f89 100644 --- a/deps/assimp/include/assimp/fast_atof.h +++ b/deps/assimp/include/assimp/fast_atof.h @@ -269,6 +269,12 @@ const char* fast_atoreal_move(const char* c, Real& out, bool check_comma = true) ++c; } + if ((c[0] == 'N' || c[0] == 'n') && ASSIMP_strincmp(c, "nan(ind)", 8) == 0) { + out = std::numeric_limits::quiet_NaN(); + c += 8; + return c; + } + if ((c[0] == 'N' || c[0] == 'n') && ASSIMP_strincmp(c, "nan", 3) == 0) { out = std::numeric_limits::quiet_NaN(); c += 3; diff --git a/src/scene/scene.cpp b/src/scene/scene.cpp index a0e6158..a9aeda8 100644 --- a/src/scene/scene.cpp +++ b/src/scene/scene.cpp @@ -324,7 +324,6 @@ static void load_node(Scene &scobj, std::vector &errors, std::vector> polys; for (unsigned int j = 0; j < mesh->mNumFaces; j++) { const aiFace &face = mesh->mFaces[j]; - std::vector poly; for (unsigned int k = 0; k < face.mNumIndices; k++) { poly.push_back(face.mIndices[k]); @@ -404,12 +403,16 @@ static void load_node(Scene &scobj, std::vector &errors, for (unsigned int j = 0; j < mesh->mNumVertices; j++) { const aiVector3D &vpos = mesh->mVertices[j]; - const aiVector3D &vnorm = mesh->mNormals[j]; + aiVector3D vnorm; + if(mesh->HasNormals()) { + vnorm = mesh->mNormals[j]; + } mesh_verts.push_back({aiVec(vpos), aiVec(vnorm), 0}); } for (unsigned int j = 0; j < mesh->mNumFaces; j++) { const aiFace &face = mesh->mFaces[j]; + if(face.mNumIndices < 3) continue; unsigned int start = face.mIndices[0]; for (size_t k = 1; k <= face.mNumIndices - 2; k++) { mesh_inds.push_back(start); -- GitLab