ソースを参照

Added infinity check for outputting PLY normals

David Jordan 10 年 前
コミット
e86d40e4e2
1 ファイル変更6 行追加4 行削除
  1. 6 4
      code/PlyExporter.cpp

+ 6 - 4
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)
 void PlyExporter::WriteMeshVerts(const aiMesh* m, unsigned int components)
 {
 {
+	static const float inf = std::numeric_limits<float>::infinity();
+	
 	// If a component (for instance normal vectors) is present in at least one mesh in the scene,
 	// 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.
 	// then default values are written for meshes that do not contain this component.
 	for (unsigned int i = 0; i < m->mNumVertices; ++i) {
 	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
 			m->mVertices[i].z
 		;
 		;
 		if(components & PLY_EXPORT_HAS_NORMALS) {
 		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 << 
 				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 {
 			else {
 				mOutput << " 0.0 0.0 0.0"; 
 				mOutput << " 0.0 0.0 0.0";