Changed assimp to force regeneration of normals.

pull/1996/head
Sebastian Maisch 2018-05-29 13:01:11 +02:00
parent bdbad4c64f
commit c6eda67296
2 changed files with 17 additions and 3 deletions

View File

@ -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;
}

View File

@ -112,8 +112,10 @@ void GenVertexNormalsProcess::Execute( aiScene* pScene)
// Executes the post processing step on the given imported data.
bool GenVertexNormalsProcess::GenMeshVertexNormals (aiMesh* pMesh, unsigned int meshIndex)
{
if (NULL != pMesh->mNormals)
return false;
if (NULL != pMesh->mNormals) {
delete[] pMesh->mNormals;
}
// return false;
// If the mesh consists of lines and/or points but not of
// triangles or higher-order polygons the normal vectors