Help needed for writing script that eliminates overlapping polygons
I've recently started learning max script (I've had some previous scripting experience, most notably in LUA). And as a first script I tried to make one that eliminates polygons that perfectly overlap each other. I've encountered this problem before and its very difficult to get rid of (AFAIK max has no tools for solving this).
I've constructed a script that takes each polygon in selection and compares it to each other polygon (yes, it's very slow on complex object and I plan to introduce some optimization).
On simple objects I used for testing works perfectly, but when I tried using it on a "real" model (a building with 4000 polys), it deleted a lot of polygons that were not supposed to be, while it left some overlapping ones...
If someone can take a look at my script and give me some input as what I'm missing, I'd be very grateful!
I'm uploading the script as an attachement.