Added forced generation of normals with extra flag.
parent
c6eda67296
commit
f15dcf7663
|
@ -74,6 +74,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;
|
||||||
return (pFlags & aiProcess_GenNormals) != 0;
|
return (pFlags & aiProcess_GenNormals) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,8 +107,8 @@ void GenFaceNormalsProcess::Execute( aiScene* pScene)
|
||||||
bool GenFaceNormalsProcess::GenMeshFaceNormals (aiMesh* pMesh)
|
bool GenFaceNormalsProcess::GenMeshFaceNormals (aiMesh* pMesh)
|
||||||
{
|
{
|
||||||
if (NULL != pMesh->mNormals) {
|
if (NULL != pMesh->mNormals) {
|
||||||
// return false;
|
if (force_) delete[] pMesh->mNormals;
|
||||||
delete[] pMesh->mNormals;
|
else return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the mesh consists of lines and/or points but not of
|
// If the mesh consists of lines and/or points but not of
|
||||||
|
|
|
@ -78,7 +78,8 @@ public:
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool GenMeshFaceNormals (aiMesh* pcMesh);
|
bool GenMeshFaceNormals(aiMesh* pcMesh);
|
||||||
|
mutable bool force_ = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // end of namespace Assimp
|
} // end of namespace Assimp
|
||||||
|
|
|
@ -72,6 +72,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;
|
||||||
return (pFlags & aiProcess_GenSmoothNormals) != 0;
|
return (pFlags & aiProcess_GenSmoothNormals) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,9 +114,9 @@ void GenVertexNormalsProcess::Execute( aiScene* pScene)
|
||||||
bool GenVertexNormalsProcess::GenMeshVertexNormals (aiMesh* pMesh, unsigned int meshIndex)
|
bool GenVertexNormalsProcess::GenMeshVertexNormals (aiMesh* pMesh, unsigned int meshIndex)
|
||||||
{
|
{
|
||||||
if (NULL != pMesh->mNormals) {
|
if (NULL != pMesh->mNormals) {
|
||||||
delete[] pMesh->mNormals;
|
if (force_) delete[] pMesh->mNormals;
|
||||||
|
else return false;
|
||||||
}
|
}
|
||||||
// return false;
|
|
||||||
|
|
||||||
// If the mesh consists of lines and/or points but not of
|
// If the mesh consists of lines and/or points but not of
|
||||||
// triangles or higher-order polygons the normal vectors
|
// triangles or higher-order polygons the normal vectors
|
||||||
|
@ -147,7 +148,18 @@ bool GenVertexNormalsProcess::GenMeshVertexNormals (aiMesh* pMesh, unsigned int
|
||||||
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]];
|
||||||
const aiVector3D vNor = ((*pV2 - *pV1) ^ (*pV3 - *pV1));
|
|
||||||
|
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) {
|
for (unsigned int i = 0;i < face.mNumIndices;++i) {
|
||||||
pMesh->mNormals[face.mIndices[i]] = vNor;
|
pMesh->mNormals[face.mIndices[i]] = vNor;
|
||||||
|
|
|
@ -107,6 +107,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;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // end of namespace Assimp
|
} // end of namespace Assimp
|
||||||
|
|
|
@ -555,10 +555,13 @@ enum aiPostProcessSteps
|
||||||
* of the imported model. And if so, it uses that.
|
* of the imported model. And if so, it uses that.
|
||||||
*/
|
*/
|
||||||
aiProcess_EmbedTextures = 0x10000000,
|
aiProcess_EmbedTextures = 0x10000000,
|
||||||
|
|
||||||
// aiProcess_GenEntityMeshes = 0x100000,
|
// aiProcess_GenEntityMeshes = 0x100000,
|
||||||
// aiProcess_OptimizeAnimations = 0x200000
|
// aiProcess_OptimizeAnimations = 0x200000
|
||||||
// aiProcess_FixTexturePaths = 0x200000
|
// aiProcess_FixTexturePaths = 0x200000
|
||||||
|
|
||||||
|
|
||||||
|
aiProcess_ForceGenNormals = 0x20000000,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue