Normalize() is replaced with NormalizeSafe() to prevent invalid vectors generation
parent
078dd0c08b
commit
b6f14eb917
|
@ -192,7 +192,7 @@ bool GenVertexNormalsProcess::GenMeshVertexNormals (aiMesh* pMesh, unsigned int
|
||||||
const aiVector3D& v = pMesh->mNormals[verticesFound[a]];
|
const aiVector3D& v = pMesh->mNormals[verticesFound[a]];
|
||||||
if (is_not_qnan(v.x))pcNor += v;
|
if (is_not_qnan(v.x))pcNor += v;
|
||||||
}
|
}
|
||||||
pcNor.Normalize();
|
pcNor.NormalizeSafe();
|
||||||
|
|
||||||
// Write the smoothed normal back to all affected normals
|
// Write the smoothed normal back to all affected normals
|
||||||
for (unsigned int a = 0; a < verticesFound.size(); ++a)
|
for (unsigned int a = 0; a < verticesFound.size(); ++a)
|
||||||
|
@ -225,7 +225,7 @@ bool GenVertexNormalsProcess::GenMeshVertexNormals (aiMesh* pMesh, unsigned int
|
||||||
if (v * vr >= fLimit * vrlen * v.Length())
|
if (v * vr >= fLimit * vrlen * v.Length())
|
||||||
pcNor += v;
|
pcNor += v;
|
||||||
}
|
}
|
||||||
pcNew[i] = pcNor.Normalize();
|
pcNew[i] = pcNor.NormalizeSafe();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -116,6 +116,8 @@ public:
|
||||||
/** @brief Normalize the vector */
|
/** @brief Normalize the vector */
|
||||||
aiVector3t& Normalize();
|
aiVector3t& Normalize();
|
||||||
|
|
||||||
|
/** @brief Normalize the vector with extra check for zero vectors */
|
||||||
|
aiVector3t& NormalizeSafe();
|
||||||
|
|
||||||
/** @brief Componentwise multiplication of two vectors
|
/** @brief Componentwise multiplication of two vectors
|
||||||
*
|
*
|
||||||
|
|
|
@ -101,6 +101,14 @@ AI_FORCE_INLINE aiVector3t<TReal>& aiVector3t<TReal>::Normalize() {
|
||||||
}
|
}
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
template <typename TReal>
|
template <typename TReal>
|
||||||
|
AI_FORCE_INLINE aiVector3t<TReal>& aiVector3t<TReal>::NormalizeSafe() {
|
||||||
|
TReal len = Length();
|
||||||
|
if (len > static_cast<TReal>(0))
|
||||||
|
*this /= Length();
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
// ------------------------------------------------------------------------------------------------
|
||||||
|
template <typename TReal>
|
||||||
AI_FORCE_INLINE const aiVector3t<TReal>& aiVector3t<TReal>::operator += (const aiVector3t<TReal>& o) {
|
AI_FORCE_INLINE const aiVector3t<TReal>& aiVector3t<TReal>::operator += (const aiVector3t<TReal>& o) {
|
||||||
x += o.x; y += o.y; z += o.z; return *this;
|
x += o.x; y += o.y; z += o.z; return *this;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue