Merge pull request #3838 from Garux/fixGenNormals
consider aiProcess_FlipWindingOrder in aiProcess_GenNormals & aiProcess_GenSmoothNormalspull/3839/head^2
commit
b1b937ea79
|
@ -70,6 +70,7 @@ GenFaceNormalsProcess::~GenFaceNormalsProcess() {
|
||||||
// Returns whether the processing step is present in the given flag field.
|
// Returns whether the processing step is present in the given flag field.
|
||||||
bool GenFaceNormalsProcess::IsActive(unsigned int pFlags) const {
|
bool GenFaceNormalsProcess::IsActive(unsigned int pFlags) const {
|
||||||
force_ = (pFlags & aiProcess_ForceGenNormals) != 0;
|
force_ = (pFlags & aiProcess_ForceGenNormals) != 0;
|
||||||
|
flippedWindingOrder_ = (pFlags & aiProcess_FlipWindingOrder) != 0;
|
||||||
return (pFlags & aiProcess_GenNormals) != 0;
|
return (pFlags & aiProcess_GenNormals) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,6 +135,8 @@ bool GenFaceNormalsProcess::GenMeshFaceNormals(aiMesh *pMesh) {
|
||||||
const aiVector3D *pV1 = &pMesh->mVertices[face.mIndices[0]];
|
const aiVector3D *pV1 = &pMesh->mVertices[face.mIndices[0]];
|
||||||
const aiVector3D *pV2 = &pMesh->mVertices[face.mIndices[1]];
|
const aiVector3D *pV2 = &pMesh->mVertices[face.mIndices[1]];
|
||||||
const aiVector3D *pV3 = &pMesh->mVertices[face.mIndices[face.mNumIndices - 1]];
|
const aiVector3D *pV3 = &pMesh->mVertices[face.mIndices[face.mNumIndices - 1]];
|
||||||
|
if (flippedWindingOrder_)
|
||||||
|
std::swap( pV2, pV3 );
|
||||||
const aiVector3D vNor = ((*pV2 - *pV1) ^ (*pV3 - *pV1)).NormalizeSafe();
|
const aiVector3D vNor = ((*pV2 - *pV1) ^ (*pV3 - *pV1)).NormalizeSafe();
|
||||||
|
|
||||||
for (unsigned int i = 0; i < face.mNumIndices; ++i) {
|
for (unsigned int i = 0; i < face.mNumIndices; ++i) {
|
||||||
|
|
|
@ -80,6 +80,7 @@ public:
|
||||||
private:
|
private:
|
||||||
bool GenMeshFaceNormals(aiMesh* pcMesh);
|
bool GenMeshFaceNormals(aiMesh* pcMesh);
|
||||||
mutable bool force_ = false;
|
mutable bool force_ = false;
|
||||||
|
mutable bool flippedWindingOrder_ = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // end of namespace Assimp
|
} // end of namespace Assimp
|
||||||
|
|
|
@ -70,6 +70,7 @@ GenVertexNormalsProcess::~GenVertexNormalsProcess() {
|
||||||
// Returns whether the processing step is present in the given flag field.
|
// Returns whether the processing step is present in the given flag field.
|
||||||
bool GenVertexNormalsProcess::IsActive(unsigned int pFlags) const {
|
bool GenVertexNormalsProcess::IsActive(unsigned int pFlags) const {
|
||||||
force_ = (pFlags & aiProcess_ForceGenNormals) != 0;
|
force_ = (pFlags & aiProcess_ForceGenNormals) != 0;
|
||||||
|
flippedWindingOrder_ = (pFlags & aiProcess_FlipWindingOrder) != 0;
|
||||||
return (pFlags & aiProcess_GenSmoothNormals) != 0;
|
return (pFlags & aiProcess_GenSmoothNormals) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,6 +143,8 @@ bool GenVertexNormalsProcess::GenMeshVertexNormals(aiMesh *pMesh, unsigned int m
|
||||||
const aiVector3D *pV1 = &pMesh->mVertices[face.mIndices[0]];
|
const aiVector3D *pV1 = &pMesh->mVertices[face.mIndices[0]];
|
||||||
const aiVector3D *pV2 = &pMesh->mVertices[face.mIndices[1]];
|
const aiVector3D *pV2 = &pMesh->mVertices[face.mIndices[1]];
|
||||||
const aiVector3D *pV3 = &pMesh->mVertices[face.mIndices[face.mNumIndices - 1]];
|
const aiVector3D *pV3 = &pMesh->mVertices[face.mIndices[face.mNumIndices - 1]];
|
||||||
|
if (flippedWindingOrder_)
|
||||||
|
std::swap( pV2, pV3 );
|
||||||
const aiVector3D vNor = ((*pV2 - *pV1) ^ (*pV3 - *pV1)).NormalizeSafe();
|
const aiVector3D vNor = ((*pV2 - *pV1) ^ (*pV3 - *pV1)).NormalizeSafe();
|
||||||
|
|
||||||
for (unsigned int i = 0; i < face.mNumIndices; ++i) {
|
for (unsigned int i = 0; i < face.mNumIndices; ++i) {
|
||||||
|
|
|
@ -104,6 +104,7 @@ private:
|
||||||
/** Configuration option: maximum smoothing angle, in radians*/
|
/** Configuration option: maximum smoothing angle, in radians*/
|
||||||
ai_real configMaxAngle;
|
ai_real configMaxAngle;
|
||||||
mutable bool force_ = false;
|
mutable bool force_ = false;
|
||||||
|
mutable bool flippedWindingOrder_ = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // end of namespace Assimp
|
} // end of namespace Assimp
|
||||||
|
|
Loading…
Reference in New Issue