------------------------------------------------------------------------------------------------ Apply the step to the mesh
| 84 | // ------------------------------------------------------------------------------------------------ |
| 85 | // Apply the step to the mesh |
| 86 | bool FixInfacingNormalsProcess::ProcessMesh( aiMesh* pcMesh, unsigned int index) |
| 87 | { |
| 88 | ai_assert(nullptr != pcMesh); |
| 89 | |
| 90 | // Nothing to do if there are no model normals |
| 91 | if (!pcMesh->HasNormals()) { |
| 92 | return false; |
| 93 | } |
| 94 | |
| 95 | // Compute the bounding box of both the model vertices + normals and |
| 96 | // the unmodified model vertices. Then check whether the first BB |
| 97 | // is smaller than the second. In this case we can assume that the |
| 98 | // normals need to be flipped, although there are a few special cases .. |
| 99 | // convex, concave, planar models ... |
| 100 | |
| 101 | aiVector3D vMin0 (1e10f,1e10f,1e10f); |
| 102 | aiVector3D vMin1 (1e10f,1e10f,1e10f); |
| 103 | aiVector3D vMax0 (-1e10f,-1e10f,-1e10f); |
| 104 | aiVector3D vMax1 (-1e10f,-1e10f,-1e10f); |
| 105 | |
| 106 | for (unsigned int i = 0; i < pcMesh->mNumVertices;++i) |
| 107 | { |
| 108 | vMin1.x = std::min(vMin1.x,pcMesh->mVertices[i].x); |
| 109 | vMin1.y = std::min(vMin1.y,pcMesh->mVertices[i].y); |
| 110 | vMin1.z = std::min(vMin1.z,pcMesh->mVertices[i].z); |
| 111 | |
| 112 | vMax1.x = std::max(vMax1.x,pcMesh->mVertices[i].x); |
| 113 | vMax1.y = std::max(vMax1.y,pcMesh->mVertices[i].y); |
| 114 | vMax1.z = std::max(vMax1.z,pcMesh->mVertices[i].z); |
| 115 | |
| 116 | const aiVector3D vWithNormal = pcMesh->mVertices[i] + pcMesh->mNormals[i]; |
| 117 | |
| 118 | vMin0.x = std::min(vMin0.x,vWithNormal.x); |
| 119 | vMin0.y = std::min(vMin0.y,vWithNormal.y); |
| 120 | vMin0.z = std::min(vMin0.z,vWithNormal.z); |
| 121 | |
| 122 | vMax0.x = std::max(vMax0.x,vWithNormal.x); |
| 123 | vMax0.y = std::max(vMax0.y,vWithNormal.y); |
| 124 | vMax0.z = std::max(vMax0.z,vWithNormal.z); |
| 125 | } |
| 126 | |
| 127 | const float fDelta0_x = (vMax0.x - vMin0.x); |
| 128 | const float fDelta0_y = (vMax0.y - vMin0.y); |
| 129 | const float fDelta0_z = (vMax0.z - vMin0.z); |
| 130 | |
| 131 | const float fDelta1_x = (vMax1.x - vMin1.x); |
| 132 | const float fDelta1_y = (vMax1.y - vMin1.y); |
| 133 | const float fDelta1_z = (vMax1.z - vMin1.z); |
| 134 | |
| 135 | // Check whether the boxes are overlapping |
| 136 | if ((fDelta0_x > 0.0f) != (fDelta1_x > 0.0f))return false; |
| 137 | if ((fDelta0_y > 0.0f) != (fDelta1_y > 0.0f))return false; |
| 138 | if ((fDelta0_z > 0.0f) != (fDelta1_z > 0.0f))return false; |
| 139 | |
| 140 | // Check whether this is a planar surface |
| 141 | const float fDelta1_yz = fDelta1_y * fDelta1_z; |
| 142 | |
| 143 | if (fDelta1_x < 0.05f * std::sqrt( fDelta1_yz ))return false; |
nothing calls this directly
no test coverage detected