Browse Source

Bug fixing in previous commit. The normals now look great

Panagiotis Christopoulos Charitos 13 years ago
parent
commit
44762fee44
2 changed files with 9 additions and 4 deletions
  1. 1 1
      include/anki/resource/MeshLoader.h
  2. 8 3
      src/resource/MeshLoader.cpp

+ 1 - 1
include/anki/resource/MeshLoader.h

@@ -44,7 +44,7 @@ class MeshLoader
 public:
 	/// If two vertices have the same position and normals under the angle 
 	/// specified by this constant then combine those normals
-	static constexpr F32 NORMALS_ANGLE_MERGE = getPi<F32>() / 6.0;
+	static constexpr F32 NORMALS_ANGLE_MERGE = getPi<F32>() / 6;
 
 	/// Vertex weight for skeletal animation
 	struct VertexWeight

+ 8 - 3
src/resource/MeshLoader.cpp

@@ -5,9 +5,13 @@
 
 namespace anki {
 
+std::string lala;
+
 //==============================================================================
 void MeshLoader::load(const char* filename)
 {
+	lala = filename;
+
 	// Try
 	try
 	{
@@ -271,7 +275,6 @@ void MeshLoader::createVertTangents()
 void MeshLoader::fixNormals()
 {
 	const F32 positionsDistanceThresh = getEpsilon<F32>() * getEpsilon<F32>();
-	const F32 normalsDotThresh = cos(NORMALS_ANGLE_MERGE);
 
 	for(U i = 1; i < vertCoords.size(); i++)
 	{
@@ -289,13 +292,15 @@ void MeshLoader::fixNormals()
 			if(distanceSq <= positionsDistanceThresh)
 			{
 				F32 dot = crntNormal.dot(otherNormal);
+				F32 ang = acos(dot);
 
-				if(dot <= normalsDotThresh)
+				if(ang <= NORMALS_ANGLE_MERGE)
 				{
 					Vec3 newNormal = (crntNormal + otherNormal) * 0.5;
 					newNormal.normalize();
 
-					newNormal = otherNormal = newNormal;
+					crntNormal = newNormal;
+					otherNormal = newNormal;
 				}
 			}
 		}