Sfoglia il codice sorgente

Merge pull request #257 from tszirr/dev

Better smoothed normals & deferred OptimizeMeshes step
Alexander Gessler 11 anni fa
parent
commit
b5eb13dd58
3 ha cambiato i file con 11 aggiunte e 10 eliminazioni
  1. 7 6
      code/GenVertexNormalsProcess.cpp
  2. 1 1
      code/OptimizeMeshes.cpp
  3. 3 3
      code/PostStepRegistry.cpp

+ 7 - 6
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();
 		}

+ 1 - 1
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;

+ 3 - 3
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