From fa626aa8557021b18ed321577f2abc265df08f2a Mon Sep 17 00:00:00 2001 From: David Jordan Date: Thu, 16 Apr 2015 18:01:24 -0400 Subject: [PATCH 1/5] Added NaN check when outputting normals in PLY exporter, to avoid outputting '-1.#IND' --- code/PlyExporter.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/PlyExporter.cpp b/code/PlyExporter.cpp index 692b02668..a1479ee32 100644 --- a/code/PlyExporter.cpp +++ b/code/PlyExporter.cpp @@ -216,7 +216,7 @@ void PlyExporter::WriteMeshVerts(const aiMesh* m, unsigned int components) m->mVertices[i].z ; if(components & PLY_EXPORT_HAS_NORMALS) { - if (m->HasNormals()) { + if (m->HasNormals() && is_not_qnan(m->mNormals[i].x)) { mOutput << " " << m->mNormals[i].x << " " << m->mNormals[i].y << From f00101f496939d1726935c76e9da55f220df7d99 Mon Sep 17 00:00:00 2001 From: David Jordan Date: Thu, 16 Apr 2015 21:30:50 -0400 Subject: [PATCH 2/5] Added include of qnan.h (now that AssimpPCH.h include was taken out) --- code/PlyExporter.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/code/PlyExporter.cpp b/code/PlyExporter.cpp index 72c95e884..32cb61058 100644 --- a/code/PlyExporter.cpp +++ b/code/PlyExporter.cpp @@ -48,7 +48,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "../include/assimp/scene.h" #include "../include/assimp/version.h" #include "../include/assimp/IOSystem.hpp" -#include "../include/assimp/Exporter.hpp" +#include "../include/assimp/Exporter.hpp" +#include "qnan.h" using namespace Assimp; From e86d40e4e2fb91dbdb898938830783f76e8ee00f Mon Sep 17 00:00:00 2001 From: David Jordan Date: Fri, 17 Apr 2015 23:29:26 -0400 Subject: [PATCH 3/5] Added infinity check for outputting PLY normals --- code/PlyExporter.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/code/PlyExporter.cpp b/code/PlyExporter.cpp index 32cb61058..6f86c6b8e 100644 --- a/code/PlyExporter.cpp +++ b/code/PlyExporter.cpp @@ -214,6 +214,8 @@ PlyExporter::PlyExporter(const char* _filename, const aiScene* pScene, bool bina // ------------------------------------------------------------------------------------------------ void PlyExporter::WriteMeshVerts(const aiMesh* m, unsigned int components) { + static const float inf = std::numeric_limits::infinity(); + // If a component (for instance normal vectors) is present in at least one mesh in the scene, // then default values are written for meshes that do not contain this component. for (unsigned int i = 0; i < m->mNumVertices; ++i) { @@ -223,11 +225,11 @@ void PlyExporter::WriteMeshVerts(const aiMesh* m, unsigned int components) m->mVertices[i].z ; if(components & PLY_EXPORT_HAS_NORMALS) { - if (m->HasNormals() && is_not_qnan(m->mNormals[i].x)) { + if (m->HasNormals() && is_not_qnan(m->mNormals[i].x) && std::absf(m->mNormals[i].x) != inf) { mOutput << - " " << m->mNormals[i].x << - " " << m->mNormals[i].y << - " " << m->mNormals[i].z; + " " << m->mNormals[i].x << + " " << m->mNormals[i].y << + " " << m->mNormals[i].z; } else { mOutput << " 0.0 0.0 0.0"; From b575acf2b6d5ad654ab2c3478eb20d87cc1d4a2f Mon Sep 17 00:00:00 2001 From: David Jordan Date: Fri, 17 Apr 2015 23:38:54 -0400 Subject: [PATCH 4/5] std::absf to std::fabsf --- code/PlyExporter.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/PlyExporter.cpp b/code/PlyExporter.cpp index 6f86c6b8e..38bf5e9fc 100644 --- a/code/PlyExporter.cpp +++ b/code/PlyExporter.cpp @@ -225,7 +225,7 @@ void PlyExporter::WriteMeshVerts(const aiMesh* m, unsigned int components) m->mVertices[i].z ; if(components & PLY_EXPORT_HAS_NORMALS) { - if (m->HasNormals() && is_not_qnan(m->mNormals[i].x) && std::absf(m->mNormals[i].x) != inf) { + if (m->HasNormals() && is_not_qnan(m->mNormals[i].x) && std::fabsf(m->mNormals[i].x) != inf) { mOutput << " " << m->mNormals[i].x << " " << m->mNormals[i].y << From b38572d1bc4a5aa6b3fda80935a1af133d804ade Mon Sep 17 00:00:00 2001 From: David Jordan Date: Fri, 17 Apr 2015 23:50:14 -0400 Subject: [PATCH 5/5] std::fabs from cmath should be right --- code/PlyExporter.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/code/PlyExporter.cpp b/code/PlyExporter.cpp index 38bf5e9fc..0a4c94a48 100644 --- a/code/PlyExporter.cpp +++ b/code/PlyExporter.cpp @@ -44,6 +44,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "PlyExporter.h" #include +#include #include "Exceptional.h" #include "../include/assimp/scene.h" #include "../include/assimp/version.h" @@ -225,7 +226,7 @@ void PlyExporter::WriteMeshVerts(const aiMesh* m, unsigned int components) m->mVertices[i].z ; if(components & PLY_EXPORT_HAS_NORMALS) { - if (m->HasNormals() && is_not_qnan(m->mNormals[i].x) && std::fabsf(m->mNormals[i].x) != inf) { + if (m->HasNormals() && is_not_qnan(m->mNormals[i].x) && std::fabs(m->mNormals[i].x) != inf) { mOutput << " " << m->mNormals[i].x << " " << m->mNormals[i].y <<