GenVertexNormal bugfix. Angle limit wasn't correct.

git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@119 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
pull/1/head
aramis_acg 2008-08-28 23:49:20 +00:00
parent cae8563764
commit ad4cc033d8
7 changed files with 36 additions and 17 deletions

View File

@ -64,7 +64,7 @@ using namespace Assimp;
// Constructor to be privately used by Importer // Constructor to be privately used by Importer
CalcTangentsProcess::CalcTangentsProcess() 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 // get the current value of the property
this->configMaxAngle = pImp->GetPropertyFloat(AI_CONFIG_PP_CT_MAX_SMOOTHING_ANGLE,45.f); 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); this->configMaxAngle = AI_DEG_TO_RAD(this->configMaxAngle);
} }
@ -205,6 +205,8 @@ bool CalcTangentsProcess::ProcessMesh( aiMesh* pMesh)
SpatialSort vertexFinder( meshPos, pMesh->mNumVertices, sizeof( aiVector3D)); SpatialSort vertexFinder( meshPos, pMesh->mNumVertices, sizeof( aiVector3D));
std::vector<unsigned int> verticesFound; std::vector<unsigned int> verticesFound;
const float fLimit = cosf(this->configMaxAngle);
// in the second pass we now smooth out all tangents and bitangents at the same local position // in the second pass we now smooth out all tangents and bitangents at the same local position
// if they are not too far off. // if they are not too far off.
std::vector<bool> vertexDone( pMesh->mNumVertices, false); std::vector<bool> vertexDone( pMesh->mNumVertices, false);
@ -231,9 +233,9 @@ bool CalcTangentsProcess::ProcessMesh( aiMesh* pMesh)
continue; continue;
if( meshNorm[idx] * origNorm < angleEpsilon) if( meshNorm[idx] * origNorm < angleEpsilon)
continue; continue;
if( acosf( meshTang[idx] * origTang) > this->configMaxAngle) if( meshTang[idx] * origTang < fLimit)
continue; continue;
if( acosf( meshBitang[idx] * origBitang) > this->configMaxAngle) if( meshBitang[idx] * origBitang < fLimit)
continue; continue;
// it's similar enough -> add it to the smoothing group // it's similar enough -> add it to the smoothing group

View File

@ -85,6 +85,13 @@ public:
*/ */
void SetupProperties(const Importer* pImp); void SetupProperties(const Importer* pImp);
// setter for configMaxAngle
inline void SetMaxSmoothAngle(float f)
{
configMaxAngle =f;
}
protected: protected:
// ------------------------------------------------------------------- // -------------------------------------------------------------------

View File

@ -53,15 +53,16 @@ using namespace Assimp;
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Constructor to be privately used by Importer // Constructor to be privately used by Importer
GenFaceNormalsProcess::GenFaceNormalsProcess() GenFaceNormalsProcess::GenFaceNormalsProcess()
{ {
} // nothing to do here
}
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Destructor, private as well // Destructor, private as well
GenFaceNormalsProcess::~GenFaceNormalsProcess() GenFaceNormalsProcess::~GenFaceNormalsProcess()
{ {
// nothing to do here // nothing to do here
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Returns whether the processing step is present in the given flag field. // 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 pDelta1 = *pV2 - *pV1;
aiVector3D pDelta2 = *pV3 - *pV1; aiVector3D pDelta2 = *pV3 - *pV1;
aiVector3D vNor = pDelta1 ^ pDelta2; aiVector3D vNor = pDelta1 ^ pDelta2;
vNor.Normalize();
//if (face.mIndices[1] > face.mIndices[2]) //if (face.mIndices[1] > face.mIndices[2])
// vNor *= -1.0f; // vNor *= -1.0f;

View File

@ -56,6 +56,7 @@ using namespace Assimp;
// Constructor to be privately used by Importer // Constructor to be privately used by Importer
GenVertexNormalsProcess::GenVertexNormalsProcess() 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) void GenVertexNormalsProcess::SetupProperties(const Importer* pImp)
{ {
// get the current value of the property // get the current value of the property
this->configMaxAngle = pImp->GetPropertyFloat(AI_CONFIG_PP_GSN_MAX_SMOOTHING_ANGLE,180.f); this->configMaxAngle = pImp->GetPropertyFloat(AI_CONFIG_PP_GSN_MAX_SMOOTHING_ANGLE,175.f);
this->configMaxAngle = std::max(std::min(this->configMaxAngle,180.0f),0.0f); this->configMaxAngle = std::max(std::min(this->configMaxAngle,175.0f),0.0f);
this->configMaxAngle = AI_DEG_TO_RAD(this->configMaxAngle); 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)); SpatialSort vertexFinder( pMesh->mVertices, pMesh->mNumVertices, sizeof( aiVector3D));
std::vector<unsigned int> verticesFound; std::vector<unsigned int> verticesFound;
const float fLimit = this->configMaxAngle; const float fLimit = cosf(this->configMaxAngle);
aiVector3D* pcNew = new aiVector3D[pMesh->mNumVertices]; aiVector3D* pcNew = new aiVector3D[pMesh->mNumVertices];
for (unsigned int i = 0; i < pMesh->mNumVertices;++i) for (unsigned int i = 0; i < pMesh->mNumVertices;++i)
@ -162,7 +163,7 @@ bool GenVertexNormalsProcess::GenMeshVertexNormals (aiMesh* pMesh)
unsigned int vidx = verticesFound[a]; unsigned int vidx = verticesFound[a];
// check whether the angle between the two normals is not too large // 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; continue;
pcNor += pMesh->mNormals[vidx]; pcNor += pMesh->mNormals[vidx];

View File

@ -89,6 +89,13 @@ public:
*/ */
void Execute( aiScene* pScene); void Execute( aiScene* pScene);
// setter for configMaxAngle
inline void SetMaxSmoothAngle(float f)
{
configMaxAngle =f;
}
protected: protected:
// ------------------------------------------------------------------- // -------------------------------------------------------------------

View File

@ -123,10 +123,10 @@ void ComputeNormalsWithSmoothingsGroups(MeshWithSmoothingGroups<T>& sMesh)
a != poResult.end();++a) a != poResult.end();++a)
{ {
vNormals += sMesh.mNormals[(*a)]; vNormals += sMesh.mNormals[(*a)];
fDiv += 1.0f; //fDiv += 1.0f;
} }
vNormals.x /= fDiv;vNormals.y /= fDiv;vNormals.z /= fDiv; //vNormals.x /= fDiv;vNormals.y /= fDiv;vNormals.z /= fDiv;
//vNormals.Normalize(); vNormals.Normalize();
avNormals[(*i).mIndices[c]] = vNormals; avNormals[(*i).mIndices[c]] = vNormals;
//poResult.clear(); //poResult.clear();
} }

View File

@ -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 * This applies to the CalcTangentSpace-Step. The angle is specified
* in degrees , so 180 is PI. The default value is * 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. * Property type: float.
*/ */
#define AI_CONFIG_PP_CT_MAX_SMOOTHING_ANGLE "pp.ct.max_smoothing" #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 * This applies to the GenSmoothNormals-Step. The angle is specified
* in degrees, so 180 is PI. The default value is * 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. * Property type: float.
*/ */
#define AI_CONFIG_PP_GSN_MAX_SMOOTHING_ANGLE "pp.gsn.max_smoothing" #define AI_CONFIG_PP_GSN_MAX_SMOOTHING_ANGLE "pp.gsn.max_smoothing"