Correctly consider aiProcess_FlipWindingOrder AND aiProcess_MakeLeftHanded when generating normals

pull/4892/head
lsnoel 2023-01-19 16:46:29 +00:00
parent 67eae8ee5a
commit eb5d3c51e8
4 changed files with 8 additions and 4 deletions

View File

@ -67,6 +67,7 @@ GenFaceNormalsProcess::~GenFaceNormalsProcess() = default;
bool GenFaceNormalsProcess::IsActive(unsigned int pFlags) const {
force_ = (pFlags & aiProcess_ForceGenNormals) != 0;
flippedWindingOrder_ = (pFlags & aiProcess_FlipWindingOrder) != 0;
leftHanded_ = (pFlags & aiProcess_MakeLeftHanded) != 0;
return (pFlags & aiProcess_GenNormals) != 0;
}
@ -131,7 +132,7 @@ 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]];
if (flippedWindingOrder_)
if (flippedWindingOrder_ != leftHanded_) // Boolean XOR
std::swap(pV2, pV3);
const aiVector3D vNor = ((*pV2 - *pV1) ^ (*pV3 - *pV1)).NormalizeSafe();

View File

@ -81,6 +81,7 @@ private:
bool GenMeshFaceNormals(aiMesh* pcMesh);
mutable bool force_ = false;
mutable bool flippedWindingOrder_ = false;
mutable bool leftHanded_ = false;
};
} // end of namespace Assimp

View File

@ -69,6 +69,7 @@ GenVertexNormalsProcess::~GenVertexNormalsProcess() = default;
bool GenVertexNormalsProcess::IsActive(unsigned int pFlags) const {
force_ = (pFlags & aiProcess_ForceGenNormals) != 0;
flippedWindingOrder_ = (pFlags & aiProcess_FlipWindingOrder) != 0;
leftHanded_ = (pFlags & aiProcess_MakeLeftHanded) != 0;
return (pFlags & aiProcess_GenSmoothNormals) != 0;
}
@ -141,7 +142,7 @@ bool GenVertexNormalsProcess::GenMeshVertexNormals(aiMesh *pMesh, unsigned int m
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]];
if (flippedWindingOrder_)
if (flippedWindingOrder_ != leftHanded_) // Boolean XOR
std::swap(pV2, pV3);
const aiVector3D vNor = ((*pV2 - *pV1) ^ (*pV3 - *pV1)).NormalizeSafe();

View File

@ -105,6 +105,7 @@ private:
ai_real configMaxAngle;
mutable bool force_ = false;
mutable bool flippedWindingOrder_ = false;
mutable bool leftHanded_ = false;
};
} // end of namespace Assimp