+
You can often "simulate" recursion with partially-recursive code.
One trick is to "checkpoint" the results, so that you recurse in "chunks" and your stack never gets too big.
If you have pseudo-code you could post, we could possibly suggest some other tricks (there's others too)?
The checkpoint sounds well. Still I'm unsure how I could use it with my problem, but I'll think about it... :-)
The task is to find for a 3d modell all adjacent polygons with a soft angle (between their normal vectors) and setting them to the same smooth-group. The pseudo code looks like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| main { List polygonlist; int current_smoothgroup_number; for (each polygon in polygonlist) { if (polygon's smoothgroup_number isn't set) { set polygon's smoothgroup_number to current_smoothgroup_number; call find_neighbours(polygon); current_smoothgroup_number++; } } }
find_neighbours(polygon) { get all neighbour polygons; for (each neighbour_polygon) { if ( neighbour_polygon's smoothgroup_number isn't set && angle of normal vectors between polygon and neighbour_polygon < crease_angle) { set neighbour_polygon's smoothgroup_number to current_smoothgroup_number; call find_neighbours(neighbour_polygon); } } } |
Now imagine a sphere with several thousands polygons which all have soft edges...