diff --git a/code/CalcTangentsProcess.cpp b/code/CalcTangentsProcess.cpp index 6e07a65b4..7e3b622af 100644 --- a/code/CalcTangentsProcess.cpp +++ b/code/CalcTangentsProcess.cpp @@ -64,7 +64,7 @@ using namespace Assimp; // Constructor to be privately used by Importer CalcTangentsProcess::CalcTangentsProcess() { - // nothing to do here + this->configMaxAngle = AI_DEG_TO_RAD(45.f); } // ------------------------------------------------------------------------------------------------ @@ -87,7 +87,7 @@ void CalcTangentsProcess::SetupProperties(const Importer* pImp) { // get the current value of the property this->configMaxAngle = pImp->GetPropertyFloat(AI_CONFIG_PP_CT_MAX_SMOOTHING_ANGLE,45.f); - this->configMaxAngle = std::max(std::min(this->configMaxAngle,180.0f),0.0f); + this->configMaxAngle = std::max(std::min(this->configMaxAngle,45.0f),0.0f); this->configMaxAngle = AI_DEG_TO_RAD(this->configMaxAngle); } @@ -205,6 +205,8 @@ bool CalcTangentsProcess::ProcessMesh( aiMesh* pMesh) SpatialSort vertexFinder( meshPos, pMesh->mNumVertices, sizeof( aiVector3D)); std::vector verticesFound; + const float fLimit = cosf(this->configMaxAngle); + // in the second pass we now smooth out all tangents and bitangents at the same local position // if they are not too far off. std::vector vertexDone( pMesh->mNumVertices, false); @@ -231,9 +233,9 @@ bool CalcTangentsProcess::ProcessMesh( aiMesh* pMesh) continue; if( meshNorm[idx] * origNorm < angleEpsilon) continue; - if( acosf( meshTang[idx] * origTang) > this->configMaxAngle) + if( meshTang[idx] * origTang < fLimit) continue; - if( acosf( meshBitang[idx] * origBitang) > this->configMaxAngle) + if( meshBitang[idx] * origBitang < fLimit) continue; // it's similar enough -> add it to the smoothing group diff --git a/code/CalcTangentsProcess.h b/code/CalcTangentsProcess.h index 60bc35cb2..4f0dc8c9d 100644 --- a/code/CalcTangentsProcess.h +++ b/code/CalcTangentsProcess.h @@ -85,6 +85,13 @@ public: */ void SetupProperties(const Importer* pImp); + + // setter for configMaxAngle + inline void SetMaxSmoothAngle(float f) + { + configMaxAngle =f; + } + protected: // ------------------------------------------------------------------- diff --git a/code/GenFaceNormalsProcess.cpp b/code/GenFaceNormalsProcess.cpp index 4c8666a41..f7a7a7c84 100644 --- a/code/GenFaceNormalsProcess.cpp +++ b/code/GenFaceNormalsProcess.cpp @@ -53,15 +53,16 @@ using namespace Assimp; // ------------------------------------------------------------------------------------------------ // Constructor to be privately used by Importer GenFaceNormalsProcess::GenFaceNormalsProcess() - { - } +{ + // nothing to do here +} // ------------------------------------------------------------------------------------------------ // Destructor, private as well GenFaceNormalsProcess::~GenFaceNormalsProcess() - { +{ // nothing to do here - } +} // ------------------------------------------------------------------------------------------------ // Returns whether the processing step is present in the given flag field. @@ -110,6 +111,7 @@ bool GenFaceNormalsProcess::GenMeshFaceNormals (aiMesh* pMesh) aiVector3D pDelta1 = *pV2 - *pV1; aiVector3D pDelta2 = *pV3 - *pV1; aiVector3D vNor = pDelta1 ^ pDelta2; + vNor.Normalize(); //if (face.mIndices[1] > face.mIndices[2]) // vNor *= -1.0f; diff --git a/code/GenVertexNormalsProcess.cpp b/code/GenVertexNormalsProcess.cpp index df854b026..ee0d78b13 100644 --- a/code/GenVertexNormalsProcess.cpp +++ b/code/GenVertexNormalsProcess.cpp @@ -56,6 +56,7 @@ using namespace Assimp; // Constructor to be privately used by Importer GenVertexNormalsProcess::GenVertexNormalsProcess() { + this->configMaxAngle = AI_DEG_TO_RAD(175.f); } // ------------------------------------------------------------------------------------------------ @@ -76,8 +77,8 @@ bool GenVertexNormalsProcess::IsActive( unsigned int pFlags) const void GenVertexNormalsProcess::SetupProperties(const Importer* pImp) { // get the current value of the property - this->configMaxAngle = pImp->GetPropertyFloat(AI_CONFIG_PP_GSN_MAX_SMOOTHING_ANGLE,180.f); - this->configMaxAngle = std::max(std::min(this->configMaxAngle,180.0f),0.0f); + this->configMaxAngle = pImp->GetPropertyFloat(AI_CONFIG_PP_GSN_MAX_SMOOTHING_ANGLE,175.f); + this->configMaxAngle = std::max(std::min(this->configMaxAngle,175.0f),0.0f); this->configMaxAngle = AI_DEG_TO_RAD(this->configMaxAngle); } // ------------------------------------------------------------------------------------------------ @@ -145,7 +146,7 @@ bool GenVertexNormalsProcess::GenMeshVertexNormals (aiMesh* pMesh) SpatialSort vertexFinder( pMesh->mVertices, pMesh->mNumVertices, sizeof( aiVector3D)); std::vector verticesFound; - const float fLimit = this->configMaxAngle; + const float fLimit = cosf(this->configMaxAngle); aiVector3D* pcNew = new aiVector3D[pMesh->mNumVertices]; for (unsigned int i = 0; i < pMesh->mNumVertices;++i) @@ -162,7 +163,7 @@ bool GenVertexNormalsProcess::GenMeshVertexNormals (aiMesh* pMesh) unsigned int vidx = verticesFound[a]; // check whether the angle between the two normals is not too large - if (acosf(pMesh->mNormals[vidx] * pMesh->mNormals[i]) > fLimit) + if (pMesh->mNormals[vidx] * pMesh->mNormals[i] < fLimit) continue; pcNor += pMesh->mNormals[vidx]; diff --git a/code/GenVertexNormalsProcess.h b/code/GenVertexNormalsProcess.h index 18d71e5dc..a627cf157 100644 --- a/code/GenVertexNormalsProcess.h +++ b/code/GenVertexNormalsProcess.h @@ -89,6 +89,13 @@ public: */ void Execute( aiScene* pScene); + + // setter for configMaxAngle + inline void SetMaxSmoothAngle(float f) + { + configMaxAngle =f; + } + protected: // ------------------------------------------------------------------- diff --git a/code/SmoothingGroups.inl b/code/SmoothingGroups.inl index 42468afac..1cb089c65 100644 --- a/code/SmoothingGroups.inl +++ b/code/SmoothingGroups.inl @@ -123,10 +123,10 @@ void ComputeNormalsWithSmoothingsGroups(MeshWithSmoothingGroups& sMesh) a != poResult.end();++a) { vNormals += sMesh.mNormals[(*a)]; - fDiv += 1.0f; + //fDiv += 1.0f; } - vNormals.x /= fDiv;vNormals.y /= fDiv;vNormals.z /= fDiv; - //vNormals.Normalize(); + //vNormals.x /= fDiv;vNormals.y /= fDiv;vNormals.z /= fDiv; + vNormals.Normalize(); avNormals[(*i).mIndices[c]] = vNormals; //poResult.clear(); } diff --git a/include/aiConfig.h b/include/aiConfig.h index aa65b1abf..005290395 100644 --- a/include/aiConfig.h +++ b/include/aiConfig.h @@ -128,7 +128,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * This applies to the CalcTangentSpace-Step. The angle is specified * in degrees , so 180 is PI. The default value is - * 45 degrees. The maximum value is 180. + * 45 degrees. The maximum value is 175. * Property type: float. */ #define AI_CONFIG_PP_CT_MAX_SMOOTHING_ANGLE "pp.ct.max_smoothing" @@ -139,7 +139,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * This applies to the GenSmoothNormals-Step. The angle is specified * in degrees, so 180 is PI. The default value is - * 180 degrees (all vertex normals are smoothed). The maximum value is 180 + * 180 degrees (all vertex normals are smoothed). The maximum value is 175 * Property type: float. */ #define AI_CONFIG_PP_GSN_MAX_SMOOTHING_ANGLE "pp.gsn.max_smoothing"