diff --git a/code/AssetLib/MMD/MMDImporter.cpp b/code/AssetLib/MMD/MMDImporter.cpp index 97b04f4eb..0905ce1e0 100644 --- a/code/AssetLib/MMD/MMDImporter.cpp +++ b/code/AssetLib/MMD/MMDImporter.cpp @@ -269,7 +269,7 @@ aiMesh *MMDImporter::CreateMesh(const pmx::PmxModel *pModel, dynamic_cast(v->skinning.get()); switch (v->skinning_type) { case pmx::PmxVertexSkinningType::BDEF1: - bone_vertex_map[vsBDEF1_ptr->bone_index].emplace_back(index, 1.0); + bone_vertex_map[vsBDEF1_ptr->bone_index].emplace_back(index, static_cast(1)); break; case pmx::PmxVertexSkinningType::BDEF2: bone_vertex_map[vsBDEF2_ptr->bone_index1].emplace_back(index, vsBDEF2_ptr->bone_weight); diff --git a/code/AssetLib/X3D/X3DGeoHelper.cpp b/code/AssetLib/X3D/X3DGeoHelper.cpp index e89aeb428..0a62ff9b0 100644 --- a/code/AssetLib/X3D/X3DGeoHelper.cpp +++ b/code/AssetLib/X3D/X3DGeoHelper.cpp @@ -193,7 +193,7 @@ void X3DGeoHelper::add_color(aiMesh &pMesh, const std::list &pColors, // create RGBA array from RGB. for (std::list::const_iterator it = pColors.begin(); it != pColors.end(); ++it) - tcol.emplace_back((*it).r, (*it).g, (*it).b, 1); + tcol.emplace_back((*it).r, (*it).g, (*it).b, static_cast(1)); // call existing function for adding RGBA colors add_color(pMesh, tcol, pColorPerVertex); @@ -238,7 +238,7 @@ void X3DGeoHelper::add_color(aiMesh &pMesh, const std::vector &pCoordId // create RGBA array from RGB. for (std::list::const_iterator it = pColors.begin(); it != pColors.end(); ++it) { - tcol.emplace_back((*it).r, (*it).g, (*it).b, 1); + tcol.emplace_back((*it).r, (*it).g, (*it).b, static_cast(1)); } // call existing function for adding RGBA colors @@ -440,7 +440,7 @@ void X3DGeoHelper::add_tex_coord(aiMesh &pMesh, const std::vector &pCoo // copy list to array because we are need indexed access to normals. texcoord_arr_copy.reserve(pTexCoords.size()); for (std::list::const_iterator it = pTexCoords.begin(); it != pTexCoords.end(); ++it) { - texcoord_arr_copy.emplace_back((*it).x, (*it).y, 0); + texcoord_arr_copy.emplace_back((*it).x, (*it).y, static_cast(0)); } if (pTexCoordIdx.size() > 0) { @@ -480,7 +480,7 @@ void X3DGeoHelper::add_tex_coord(aiMesh &pMesh, const std::list &pTe // copy list to array because we are need convert aiVector2D to aiVector3D and also get indexed access as a bonus. tc_arr_copy.reserve(pTexCoords.size()); for (std::list::const_iterator it = pTexCoords.begin(); it != pTexCoords.end(); ++it) { - tc_arr_copy.emplace_back((*it).x, (*it).y, 0); + tc_arr_copy.emplace_back((*it).x, (*it).y, static_cast(0)); } // copy texture coordinates to mesh diff --git a/code/AssetLib/X3D/X3DImporter_Geometry2D.cpp b/code/AssetLib/X3D/X3DImporter_Geometry2D.cpp index 2e97902d8..240ff14a8 100644 --- a/code/AssetLib/X3D/X3DImporter_Geometry2D.cpp +++ b/code/AssetLib/X3D/X3DImporter_Geometry2D.cpp @@ -151,7 +151,7 @@ void X3DImporter::readArcClose2D(XmlNode &node) { std::list &vlist = ((X3DNodeElementGeometry2D *)ne)->Vertices; // just short alias. if ((closureType == "PIE") || (closureType == "\"PIE\"")) - vlist.emplace_back(0, 0, 0); // center point - first radial line + vlist.emplace_back(static_cast(0), static_cast(0), static_cast(0)); // center point - first radial line else if ((closureType != "CHORD") && (closureType != "\"CHORD\"")) Throw_IncorrectAttrValue("ArcClose2D", "closureType"); @@ -323,7 +323,7 @@ void X3DImporter::readPolyline2D(XmlNode &node) { // convert vec2 to vec3 for (std::list::iterator it2 = lineSegments.begin(); it2 != lineSegments.end(); ++it2) - tlist.emplace_back(it2->x, it2->y, 0); + tlist.emplace_back(it2->x, it2->y, static_cast(0)); // convert point set to line set X3DGeoHelper::extend_point_to_line(tlist, ((X3DNodeElementGeometry2D *)ne)->Vertices); @@ -361,7 +361,7 @@ void X3DImporter::readPolypoint2D(XmlNode &node) { // convert vec2 to vec3 for (std::list::iterator it2 = point.begin(); it2 != point.end(); ++it2) { - ((X3DNodeElementGeometry2D *)ne)->Vertices.emplace_back(it2->x, it2->y, 0); + ((X3DNodeElementGeometry2D *)ne)->Vertices.emplace_back(it2->x, it2->y, static_cast(0)); } ((X3DNodeElementGeometry2D *)ne)->NumIndices = 1; @@ -405,10 +405,10 @@ void X3DImporter::readRectangle2D(XmlNode &node) { float y2 = size.y / 2.0f; std::list &vlist = ((X3DNodeElementGeometry2D *)ne)->Vertices; // just short alias. - vlist.emplace_back(x2, y1, 0); // 1st point - vlist.emplace_back(x2, y2, 0); // 2nd point - vlist.emplace_back(x1, y2, 0); // 3rd point - vlist.emplace_back(x1, y1, 0); // 4th point + vlist.emplace_back(x2, y1, static_cast(0)); // 1st point + vlist.emplace_back(x2, y2, static_cast(0)); // 2nd point + vlist.emplace_back(x1, y2, static_cast(0)); // 3rd point + vlist.emplace_back(x1, y1, static_cast(0)); // 4th point ((X3DNodeElementGeometry2D *)ne)->Solid = solid; ((X3DNodeElementGeometry2D *)ne)->NumIndices = 4; // check for X3DMetadataObject childs. @@ -449,7 +449,7 @@ void X3DImporter::readTriangleSet2D(XmlNode &node) { // convert vec2 to vec3 for (std::list::iterator it2 = vertices.begin(); it2 != vertices.end(); ++it2) { - ((X3DNodeElementGeometry2D *)ne)->Vertices.emplace_back(it2->x, it2->y, 0); + ((X3DNodeElementGeometry2D *)ne)->Vertices.emplace_back(it2->x, it2->y, static_cast(0)); } ((X3DNodeElementGeometry2D *)ne)->Solid = solid; diff --git a/code/PostProcessing/GenFaceNormalsProcess.cpp b/code/PostProcessing/GenFaceNormalsProcess.cpp index f104b98b6..d3520d4b2 100644 --- a/code/PostProcessing/GenFaceNormalsProcess.cpp +++ b/code/PostProcessing/GenFaceNormalsProcess.cpp @@ -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,8 +132,10 @@ 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_) - std::swap( pV2, pV3 ); + // 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(); for (unsigned int i = 0; i < face.mNumIndices; ++i) { diff --git a/code/PostProcessing/GenFaceNormalsProcess.h b/code/PostProcessing/GenFaceNormalsProcess.h index 586c4902e..c2f157e20 100644 --- a/code/PostProcessing/GenFaceNormalsProcess.h +++ b/code/PostProcessing/GenFaceNormalsProcess.h @@ -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 diff --git a/code/PostProcessing/GenVertexNormalsProcess.cpp b/code/PostProcessing/GenVertexNormalsProcess.cpp index 0cb2bddb1..5b9033383 100644 --- a/code/PostProcessing/GenVertexNormalsProcess.cpp +++ b/code/PostProcessing/GenVertexNormalsProcess.cpp @@ -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,8 +142,10 @@ 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_) - std::swap( pV2, pV3 ); + // 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(); for (unsigned int i = 0; i < face.mNumIndices; ++i) { diff --git a/code/PostProcessing/GenVertexNormalsProcess.h b/code/PostProcessing/GenVertexNormalsProcess.h index 0dcae793a..370bf42b1 100644 --- a/code/PostProcessing/GenVertexNormalsProcess.h +++ b/code/PostProcessing/GenVertexNormalsProcess.h @@ -105,6 +105,7 @@ private: ai_real configMaxAngle; mutable bool force_ = false; mutable bool flippedWindingOrder_ = false; + mutable bool leftHanded_ = false; }; } // end of namespace Assimp