------------------------------------------------------------------------------------------------ Executes the post processing step on the given imported mesh
| 132 | // ------------------------------------------------------------------------------------------------ |
| 133 | // Executes the post processing step on the given imported mesh |
| 134 | bool FindDegeneratesProcess::ExecuteOnMesh(aiMesh *mesh) { |
| 135 | mesh->mPrimitiveTypes = 0; |
| 136 | |
| 137 | std::vector<bool> remove_me; |
| 138 | if (mConfigRemoveDegenerates) { |
| 139 | remove_me.resize(mesh->mNumFaces, false); |
| 140 | } |
| 141 | |
| 142 | unsigned int deg = 0, limit; |
| 143 | for (unsigned int a = 0; a < mesh->mNumFaces; ++a) { |
| 144 | aiFace &face = mesh->mFaces[a]; |
| 145 | bool first = true; |
| 146 | auto vertex_in_range = [numVertices = mesh->mNumVertices](unsigned int vertex_idx) { return vertex_idx < numVertices; }; |
| 147 | |
| 148 | // check whether the face contains degenerated entries |
| 149 | for (unsigned int i = 0; i < face.mNumIndices; ++i) { |
| 150 | if (!std::all_of(face.mIndices, face.mIndices + face.mNumIndices, vertex_in_range)) |
| 151 | continue; |
| 152 | |
| 153 | // Polygons with more than 4 points are allowed to have double points, that is |
| 154 | // simulating polygons with holes just with concave polygons. However, |
| 155 | // double points may not come directly after another. |
| 156 | limit = face.mNumIndices; |
| 157 | if (face.mNumIndices > 4) { |
| 158 | limit = std::min(limit, i + 2); |
| 159 | } |
| 160 | |
| 161 | for (unsigned int t = i + 1; t < limit; ++t) { |
| 162 | if (mesh->mVertices[face.mIndices[i]] == mesh->mVertices[face.mIndices[t]]) { |
| 163 | // we have found a matching vertex position |
| 164 | // remove the corresponding index from the array |
| 165 | --face.mNumIndices; |
| 166 | --limit; |
| 167 | for (unsigned int m = t; m < face.mNumIndices; ++m) { |
| 168 | face.mIndices[m] = face.mIndices[m + 1]; |
| 169 | } |
| 170 | --t; |
| 171 | |
| 172 | // NOTE: we set the removed vertex index to an unique value |
| 173 | // to make sure the developer gets notified when his |
| 174 | // application attempts to access this data. |
| 175 | face.mIndices[face.mNumIndices] = 0xdeadbeef; |
| 176 | |
| 177 | if (first) { |
| 178 | ++deg; |
| 179 | first = false; |
| 180 | } |
| 181 | |
| 182 | if (mConfigRemoveDegenerates) { |
| 183 | remove_me[a] = true; |
| 184 | goto evil_jump_outside; // hrhrhrh ... yeah, this rocks baby! |
| 185 | } |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | if (mConfigCheckAreaOfTriangle) { |
| 190 | if (face.mNumIndices == 3) { |
| 191 | ai_real area = GeometryUtils::calculateAreaOfTriangle(face, mesh); |