|
@@ -106,7 +106,8 @@ void GenFaceNormalsProcess::Execute( aiScene* pScene)
|
|
|
bool GenFaceNormalsProcess::GenMeshFaceNormals (aiMesh* pMesh)
|
|
|
{
|
|
|
if (NULL != pMesh->mNormals) {
|
|
|
- return false;
|
|
|
+ // return false;
|
|
|
+ delete[] pMesh->mNormals;
|
|
|
}
|
|
|
|
|
|
// If the mesh consists of lines and/or points but not of
|
|
@@ -135,8 +136,19 @@ bool GenFaceNormalsProcess::GenMeshFaceNormals (aiMesh* pMesh)
|
|
|
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]];
|
|
|
+
|
|
|
+ auto pV12 = *pV2 - *pV1;
|
|
|
+ auto pV31 = *pV3 - *pV1;
|
|
|
+
|
|
|
const aiVector3D vNor = ((*pV2 - *pV1) ^ (*pV3 - *pV1)).Normalize();
|
|
|
|
|
|
+ if (std::isnan(vNor.x) || std::isnan(vNor.y) || std::isnan(vNor.z)) {
|
|
|
+ for (unsigned int i = 0; i < face.mNumIndices; ++i) {
|
|
|
+ pMesh->mNormals[face.mIndices[i]] = aiVector3D(0.0f, 0.0f, 0.0f);
|
|
|
+ }
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
for (unsigned int i = 0;i < face.mNumIndices;++i) {
|
|
|
pMesh->mNormals[face.mIndices[i]] = vNor;
|
|
|
}
|