* @brief Encode a quad (2 triangles) in ngon encoding, and make sure they are seen as a single ngon. * * @param tri1 First quad triangle * @param tri2 Second quad triangle * * @pre Triangles must be properly fanned from the most appropriate vertex. */
| 133 | * @pre Triangles must be properly fanned from the most appropriate vertex. |
| 134 | */ |
| 135 | void ngonEncodeQuad(aiFace *tri1, aiFace *tri2) { |
| 136 | ai_assert(tri1->mNumIndices == 3); |
| 137 | ai_assert(tri2->mNumIndices == 3); |
| 138 | ai_assert(tri1->mIndices[0] == tri2->mIndices[0]); |
| 139 | |
| 140 | // If the selected fanning vertex is the same as the previously |
| 141 | // emitted ngon, we use the opposite vertex which also happens to work |
| 142 | // for tri-fanning a concave quad. |
| 143 | // ref: https://github.com/assimp/assimp/pull/3695#issuecomment-805999760 |
| 144 | if (isConsideredSameAsLastNgon(tri1)) { |
| 145 | // Right-rotate indices for tri1 (index 2 becomes the new fanning vertex) |
| 146 | std::swap(tri1->mIndices[0], tri1->mIndices[2]); |
| 147 | std::swap(tri1->mIndices[1], tri1->mIndices[2]); |
| 148 | |
| 149 | // Left-rotate indices for tri2 (index 2 becomes the new fanning vertex) |
| 150 | std::swap(tri2->mIndices[1], tri2->mIndices[2]); |
| 151 | std::swap(tri2->mIndices[0], tri2->mIndices[2]); |
| 152 | |
| 153 | ai_assert(tri1->mIndices[0] == tri2->mIndices[0]); |
| 154 | } |
| 155 | |
| 156 | mLastNGONFirstIndex = tri1->mIndices[0]; |
| 157 | } |
| 158 | |
| 159 | /** |
| 160 | * @brief Check whether this triangle would be considered part of the lastly emitted ngon or not. |