------------------------------------------------------------------------------------------------ Try to remove UV seams
| 77 | // ------------------------------------------------------------------------------------------------ |
| 78 | // Try to remove UV seams |
| 79 | void RemoveUVSeams(aiMesh *mesh, aiVector3D *out) { |
| 80 | // TODO: just a very rough algorithm. I think it could be done |
| 81 | // much easier, but I don't know how and am currently too tired to |
| 82 | // to think about a better solution. |
| 83 | |
| 84 | const static ai_real LOWER_LIMIT = ai_real(0.1); |
| 85 | const static ai_real UPPER_LIMIT = ai_real(0.9); |
| 86 | |
| 87 | const static ai_real LOWER_EPSILON = ai_real(10e-3); |
| 88 | const static ai_real UPPER_EPSILON = ai_real(1.0 - 10e-3); |
| 89 | |
| 90 | for (unsigned int fidx = 0; fidx < mesh->mNumFaces; ++fidx) { |
| 91 | const aiFace &face = mesh->mFaces[fidx]; |
| 92 | if (face.mNumIndices < 3) { |
| 93 | continue; // triangles and polygons only, please |
| 94 | } |
| 95 | |
| 96 | unsigned int smallV = face.mNumIndices, large = smallV; |
| 97 | bool zero = false, one = false, round_to_zero = false; |
| 98 | |
| 99 | // Check whether this face lies on a UV seam. We can just guess, |
| 100 | // but the assumption that a face with at least one very small |
| 101 | // on the one side and one very large U coord on the other side |
| 102 | // lies on a UV seam should work for most cases. |
| 103 | for (unsigned int n = 0; n < face.mNumIndices; ++n) { |
| 104 | if (out[face.mIndices[n]].x < LOWER_LIMIT) { |
| 105 | smallV = n; |
| 106 | |
| 107 | // If we have a U value very close to 0 we can't |
| 108 | // round the others to 0, too. |
| 109 | if (out[face.mIndices[n]].x <= LOWER_EPSILON) |
| 110 | zero = true; |
| 111 | else |
| 112 | round_to_zero = true; |
| 113 | } |
| 114 | if (out[face.mIndices[n]].x > UPPER_LIMIT) { |
| 115 | large = n; |
| 116 | |
| 117 | // If we have a U value very close to 1 we can't |
| 118 | // round the others to 1, too. |
| 119 | if (out[face.mIndices[n]].x >= UPPER_EPSILON) |
| 120 | one = true; |
| 121 | } |
| 122 | } |
| 123 | if (smallV != face.mNumIndices && large != face.mNumIndices) { |
| 124 | for (unsigned int n = 0; n < face.mNumIndices; ++n) { |
| 125 | // If the u value is over the upper limit and no other u |
| 126 | // value of that face is 0, round it to 0 |
| 127 | if (out[face.mIndices[n]].x > UPPER_LIMIT && !zero) |
| 128 | out[face.mIndices[n]].x = 0.0; |
| 129 | |
| 130 | // If the u value is below the lower limit and no other u |
| 131 | // value of that face is 1, round it to 1 |
| 132 | else if (out[face.mIndices[n]].x < LOWER_LIMIT && !one) |
| 133 | out[face.mIndices[n]].x = 1.0; |
| 134 | |
| 135 | // The face contains both 0 and 1 as UV coords. This can occur |
| 136 | // for faces which have an edge that lies directly on the seam. |
no outgoing calls
no test coverage detected