From 8d1256f472702cc22292abcb8bbd6f15b1edda64 Mon Sep 17 00:00:00 2001 From: lsnoel <52174215+lsnoel@users.noreply.github.com> Date: Fri, 20 Jan 2023 14:55:06 +0000 Subject: [PATCH] Comments about winding order fix for gen normals --- code/PostProcessing/GenFaceNormalsProcess.cpp | 4 +++- code/PostProcessing/GenVertexNormalsProcess.cpp | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/code/PostProcessing/GenFaceNormalsProcess.cpp b/code/PostProcessing/GenFaceNormalsProcess.cpp index 0edbd9c6f..d3520d4b2 100644 --- a/code/PostProcessing/GenFaceNormalsProcess.cpp +++ b/code/PostProcessing/GenFaceNormalsProcess.cpp @@ -132,7 +132,9 @@ 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_ != leftHanded_) // Boolean XOR + // Boolean XOR - if either but not both of these flags is set, then the winding order has + // changed and the cross product to calculate the normal needs to be reversed + if (flippedWindingOrder_ != leftHanded_) std::swap(pV2, pV3); const aiVector3D vNor = ((*pV2 - *pV1) ^ (*pV3 - *pV1)).NormalizeSafe(); diff --git a/code/PostProcessing/GenVertexNormalsProcess.cpp b/code/PostProcessing/GenVertexNormalsProcess.cpp index e9541c7d9..5b9033383 100644 --- a/code/PostProcessing/GenVertexNormalsProcess.cpp +++ b/code/PostProcessing/GenVertexNormalsProcess.cpp @@ -142,7 +142,9 @@ 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_ != leftHanded_) // Boolean XOR + // Boolean XOR - if either but not both of these flags is set, then the winding order has + // changed and the cross product to calculate the normal needs to be reversed + if (flippedWindingOrder_ != leftHanded_) std::swap(pV2, pV3); const aiVector3D vNor = ((*pV2 - *pV1) ^ (*pV3 - *pV1)).NormalizeSafe();