Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit aa90b54

Browse files
authored
Merge pull request tinyobjloader#192 from basicNew/ChangeLoopTerminationConstraint
Change triangulation loop termination constraint
2 parents a957ebe + b404f3a commit aa90b54

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

tiny_obj_loader.h

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,20 +1171,34 @@ static bool exportGroupsToShape(shape_t *shape,
11711171
area += (v0x * v1y - v0y * v1x) * static_cast<real_t>(0.5);
11721172
}
11731173

1174-
int maxRounds = 10; // arbitrary max loop count to protect against
1175-
// unexpected errors
11761174

11771175
face_t remainingFace = face; // copy
11781176
size_t guess_vert = 0;
11791177
vertex_index_t ind[3];
11801178
real_t vx[3];
11811179
real_t vy[3];
1182-
while (remainingFace.vertex_indices.size() > 3 && maxRounds > 0) {
1180+
1181+
// How many iterations can we do without decreasing the remaining
1182+
// vertices.
1183+
size_t remainingIterations = face.vertex_indices.size();
1184+
size_t previousRemainingVertices = remainingFace.vertex_indices.size();
1185+
1186+
while (remainingFace.vertex_indices.size() > 3 && remainingIterations > 0){
11831187
npolys = remainingFace.vertex_indices.size();
11841188
if (guess_vert >= npolys) {
1185-
maxRounds -= 1;
11861189
guess_vert -= npolys;
11871190
}
1191+
1192+
if (previousRemainingVertices != npolys) {
1193+
// The number of remaining vertices decreased. Reset counters.
1194+
previousRemainingVertices = npolys;
1195+
remainingIterations = npolys;
1196+
} else {
1197+
// We didn't consume a vertex on previous iteration, reduce the
1198+
// available iterations.
1199+
remainingIterations--;
1200+
}
1201+
11881202
for (size_t k = 0; k < 3; k++) {
11891203
ind[k] = remainingFace.vertex_indices[(guess_vert + k) % npolys];
11901204
size_t vi = size_t(ind[k].v_idx);

0 commit comments

Comments
 (0)