From 8699021f178f244cc0cd87d5fbfeef60f5c43ac3 Mon Sep 17 00:00:00 2001 From: tszirr Date: Mon, 21 Apr 2014 22:40:48 +0200 Subject: [PATCH 1/4] fix: OptimizeMeshes w/o SplitLargeMeshes was disabled due to obscure max_verts = 0 assignment --- code/OptimizeMeshes.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/OptimizeMeshes.cpp b/code/OptimizeMeshes.cpp index 3f5f84b99..937a678a6 100644 --- a/code/OptimizeMeshes.cpp +++ b/code/OptimizeMeshes.cpp @@ -74,7 +74,7 @@ bool OptimizeMeshesProcess::IsActive( unsigned int pFlags) const // That's a serious design flaw, consider redesign. if( 0 != (pFlags & aiProcess_OptimizeMeshes) ) { pts = (0 != (pFlags & aiProcess_SortByPType)); - max_verts = (0 != (pFlags & aiProcess_SplitLargeMeshes)) ? 0xdeadbeef : 0; + max_verts = (0 != (pFlags & aiProcess_SplitLargeMeshes)) ? 0xdeadbeef : max_verts; return true; } return false; From 0a01da72426732c3baf11d38f6613483d131e50b Mon Sep 17 00:00:00 2001 From: tszirr Date: Mon, 21 Apr 2014 22:52:50 +0200 Subject: [PATCH 2/4] fix: optimize meshes when vertex & primitive format final --- code/PostStepRegistry.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/code/PostStepRegistry.cpp b/code/PostStepRegistry.cpp index 3fdbeb257..b6ad6157d 100644 --- a/code/PostStepRegistry.cpp +++ b/code/PostStepRegistry.cpp @@ -145,9 +145,6 @@ void GetPostProcessingStepInstanceList(std::vector< BaseProcess* >& out) #if (!defined ASSIMP_BUILD_NO_OPTIMIZEGRAPH_PROCESS) out.push_back( new OptimizeGraphProcess()); #endif -#if (!defined ASSIMP_BUILD_NO_OPTIMIZEMESHES_PROCESS) - out.push_back( new OptimizeMeshesProcess()); -#endif #if (!defined ASSIMP_BUILD_NO_FINDDEGENERATES_PROCESS) out.push_back( new FindDegeneratesProcess()); #endif @@ -169,6 +166,9 @@ void GetPostProcessingStepInstanceList(std::vector< BaseProcess* >& out) #if (!defined ASSIMP_BUILD_NO_FINDINVALIDDATA_PROCESS) out.push_back( new FindInvalidDataProcess()); #endif +#if (!defined ASSIMP_BUILD_NO_OPTIMIZEMESHES_PROCESS) + out.push_back( new OptimizeMeshesProcess()); +#endif #if (!defined ASSIMP_BUILD_NO_FIXINFACINGNORMALS_PROCESS) out.push_back( new FixInfacingNormalsProcess()); #endif From 25c2dd58de975c968a31f1f3aa67534da961637d Mon Sep 17 00:00:00 2001 From: tszirr Date: Mon, 21 Apr 2014 23:12:51 +0200 Subject: [PATCH 3/4] fix: smoothed normal qnan handling & more stable smoothed normals for imprecise geometry w/ long thin faces --- code/GenVertexNormalsProcess.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/code/GenVertexNormalsProcess.cpp b/code/GenVertexNormalsProcess.cpp index 605ca7833..b278afb87 100644 --- a/code/GenVertexNormalsProcess.cpp +++ b/code/GenVertexNormalsProcess.cpp @@ -142,7 +142,7 @@ bool GenVertexNormalsProcess::GenMeshVertexNormals (aiMesh* pMesh, unsigned int const aiVector3D* pV1 = &pMesh->mVertices[face.mIndices[0]]; const aiVector3D* pV2 = &pMesh->mVertices[face.mIndices[1]]; const aiVector3D* pV3 = &pMesh->mVertices[face.mIndices[face.mNumIndices-1]]; - const aiVector3D vNor = ((*pV2 - *pV1) ^ (*pV3 - *pV1)).Normalize(); + const aiVector3D vNor = ((*pV2 - *pV1) ^ (*pV3 - *pV1)); for (unsigned int i = 0;i < face.mNumIndices;++i) { pMesh->mNormals[face.mIndices[i]] = vNor; @@ -209,18 +209,19 @@ bool GenVertexNormalsProcess::GenMeshVertexNormals (aiMesh* pMesh, unsigned int // Get all vertices that share this one ... vertexFinder->FindPositions( pMesh->mVertices[i] , posEpsilon, verticesFound); + aiVector3D vr = pMesh->mNormals[i]; + float vrlen = vr.Length(); + aiVector3D pcNor; for (unsigned int a = 0; a < verticesFound.size(); ++a) { - const aiVector3D& v = pMesh->mNormals[verticesFound[a]]; + aiVector3D v = pMesh->mNormals[verticesFound[a]]; // check whether the angle between the two normals is not too large // HACK: if v.x is qnan the dot product will become qnan, too // therefore the comparison against fLimit should be false // in every case. - if (v * pMesh->mNormals[i] < fLimit) - continue; - - pcNor += v; + if (v * vr >= fLimit * vrlen * v.Length()) + pcNor += v; } pcNew[i] = pcNor.Normalize(); } From 51cb2c042c571b5ed6070d49b75a42ebca92179a Mon Sep 17 00:00:00 2001 From: tszirr Date: Mon, 21 Apr 2014 23:20:34 +0200 Subject: [PATCH 4/4] fix: want to add if NOT qnan --- code/GenVertexNormalsProcess.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/code/GenVertexNormalsProcess.cpp b/code/GenVertexNormalsProcess.cpp index 605ca7833..a659350fc 100644 --- a/code/GenVertexNormalsProcess.cpp +++ b/code/GenVertexNormalsProcess.cpp @@ -217,10 +217,8 @@ bool GenVertexNormalsProcess::GenMeshVertexNormals (aiMesh* pMesh, unsigned int // HACK: if v.x is qnan the dot product will become qnan, too // therefore the comparison against fLimit should be false // in every case. - if (v * pMesh->mNormals[i] < fLimit) - continue; - - pcNor += v; + if (v * pMesh->mNormals[i] >= fLimit) + pcNor += v; } pcNew[i] = pcNor.Normalize(); }