Help needed for writing script that eliminates overlapping polygons

Hi,

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.

Thanks!

AttachmentSize
delcoplanarpolys.ms1.48 KB

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
br0t's picture

I tested it on a model

I tested it on a model consisting of one and a half teapot attached together, and it seemed to work the way I would expect it.....hm...
Just one thing that came to my mind: When you delete polygons by their index and start with the first one, I think the remaining polygon indices change, so polygon 2 now becomes polygon 1 and so on. Not sure if this might be a problem, but to avoid it you'd have to loop through your array starting at the back and going the reverse direction like:

// not: 
for z=1 to arrDeletePolys.count do (
)
 
// but: 
for z=arrDeletePolys.count to 1 by -1 do ( 
)

Might be worth a try,
cheers

Never get low & slow & out of ideas

Alen's picture

Thanks for the suggestion. I

Thanks for the suggestion. I tried it your way, but it seems that the result is the same. I am deleting always the first index in array because as an array item gets deleted, rest of the values get reindexed (so there will always be an index no. 1).

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.