Area :: Header
Interested in making Indie games?

Register for a Meet the Experts webinar with Digital-Tutors today!
Discussion Groups

Modeling

Reply
Distinguished Contributor
andrewmcadam1402
Posts: 141
Registered: ‎07-09-2009

How do I deleting duplicate faces?

2253 Views, 9 Replies
07-12-2011 02:05 AM
Yo. I have a very old model from one of our previous projects. It was previously rendered with max scan line and had standard materials on it. Now we are updating it for a HD render and updated with mental ray and arch&design material. When doing test renders there have been some very strange results, on closer inspection I have realised the models have been duplicated. They have been duplicated in exactally the same spot and are part of the same element. I’m currently trying to go through each polygon(element) and delete the duplicate but its taking an age. It was a model imported from iges format so the model is very broken up.

Does anyone have a good method for deleting duplicate surfaces?
I have tried xview but selecting the results just seems to select the whole model which ever method I choose.
Mac
Please use plain text.
Distinguished Mentor
blakestone
Posts: 929
Registered: ‎04-01-2010

Re: How do I deleting duplicate faces?

07-12-2011 02:34 AM in reply to: andrewmcadam1402
ouch, not a fun task...
here is a method i have used in the past which may assist you. in a nutshell its simply splitting up the mesh via the uvw unwrap modifier and using this to easily select the duplicate faces.

as per the attachment:


as you can see i have 2 teapots here sitting ontop of each other


i have attached both objects to be a single object.


i add the uvw unwrap modifier and using the spherical preset use this break up the model. you may find a differe preset may work better with the object your working with.


using the tools > pack uvws in the uvw unwrap window it aligns all the objects so that none are overlapping.


now i can easily identify the duplicate faces and select the ones i wish to delete, note i have ticked select element so i can quickly select the objects as a whole rather than trying to get all the faces separately. also note... you can not delete the selected faces yet


with the faces still selected i collapse the uvw unwrap modifer so its just an editable poly. i switch to element and my selection has been retained, now i can press 'delete' to delete the duplicate faces.


i re-appply the uvw unwrap modifer to confirm that the duplicate faces have now been deleted, successfully.

--------------------------------------------------------------------------------------------------
Position: Technical 3D Graphic Artist
Software: Autodesk 3ds Max 2014 - Service Pack 5 (64-Bit)

www.facebook.com/all3dmax
--------------------------------------------------------------------------------------------------
Please use plain text.
Distinguished Contributor
andrewmcadam1402
Posts: 141
Registered: ‎07-09-2009

Re: How do I deleting duplicate faces?

07-12-2011 02:58 AM in reply to: andrewmcadam1402
Thanks for this blakestone, thats a neat trick, thinking out of the box. I had a go but the model is so badly imported that i have a few hundred polygons splattered around making it difficult to identify what i need to delete :smileysad: and i have around 20 of these all different. I have attached an image.

Any other ideas?

Please use plain text.
Distinguished Mentor
blakestone
Posts: 929
Registered: ‎04-01-2010

Re: How do I deleting duplicate faces?

07-12-2011 03:48 AM in reply to: andrewmcadam1402
The only other suggestion which comes to mind is writing a maxscript which checks the xyz co-ordinates of each face and then checks to see if there are any other faces with the same xyz co-ordinates and presto delete one of them.

This is an easy script to write if you know the max language however i don't. It would be something like this:

== this is not a working script ================================================================

global $array = selection

$array = array.sort()

for $a = 0 to array.count($array)
if $array = $array then face.delete($array)
next

================================================================================================

someone with some maxscript experience may be able to write something for you!?
--------------------------------------------------------------------------------------------------
Position: Technical 3D Graphic Artist
Software: Autodesk 3ds Max 2014 - Service Pack 5 (64-Bit)

www.facebook.com/all3dmax
--------------------------------------------------------------------------------------------------
Please use plain text.
Distinguished Contributor
amarhys
Posts: 103
Registered: ‎08-13-2004

Re: How do I deleting duplicate faces?

07-12-2011 04:30 AM in reply to: andrewmcadam1402
I would suggest :

a) If not already the case, convert your object in Editable Mesh
b) Select all vertices and weld them using a very low threshold value (to weld together only vertices which have the exact same coordinates)
c) Apply an STL checker modifier and configure it to find and select double faces
d) Apply an Edit Mesh modifier, set sub-object selection to faces (it will retrieve face selection from STL modifier) and delete the selected faces
e) Collapse the stack

- amarhys
Please use plain text.
Valued Contributor
hathMirx
Posts: 57
Registered: ‎05-24-2009

Re: How do I deleting duplicate faces?

07-12-2011 10:45 AM in reply to: andrewmcadam1402
CONFORM(2x). WELD.

(start over using the original clueless model as a template; maybe after a manditory ATTACH in subobj epoly)
Please use plain text.
Distinguished Contributor
amarhys
Posts: 103
Registered: ‎08-13-2004

Re: How do I deleting duplicate faces?

07-13-2011 01:32 AM in reply to: andrewmcadam1402
My mistake, STL ckecker does not select only duplicated faces .. it returns them by pair .. so not really useful

I wrote a script to do the job for you.

This script assumes the following :
1) Your object is a Editable Mesh (collasped, not an object with an Edit Mesh modifier on the top)
2) Your object is selected
3) You have performed a vertices weld before. The script identifies a duplicate face when it has the same 3 vertices as another existing face.

At the end of the execution, the duplicated faces (only) are selected on your mesh.

I checked it on two teapots merged together (total of 12640 faces) under Max 2012.

Note :
The script also assumes that the function getFace returns a point3 where vertex indexes are sorted. I am not sure it is always the case, but I guess. If it does not work with your mesh, try to uncomment the line -- if ((DuplicateFace ... and to comment if (facesCertices == .... However, the processing time will be longer ..

Hope it will help.

- amarhys


global nbFaces = (getNumFaces $)

global facesVertices = #()
global duplicateFaceArray = #()

----------------------------------------------------------
-- Progress Bar
----------------------------------------------------------
rollout pgbar "Get Duplicate Faces"
(
progressBar pgb value:0 orient:#horizontal color:(color 0 128 128) pos: width:220
)

----------------------------------------------------------
-- Return 1 if faces are duplicated
----------------------------------------------------------
function DuplicateFace fv1 fv2 =
(
local f1a = # (fv1.x, fv1.y, fv1.z)
local f2a = # (fv2.x, fv2.y, fv2.z)
sort f1a
sort f2a

-- compare array
if (f1a == f2a and f1a == f2a and f1a == f2a) then return 1 else return 0
)


-- Store faces vertex indexes
for i = 1 to nbFaces do
facesVertices = getFace $ i

createDialog pgbar width:250 height:50

-- Loop all faces one by one and check if they are duplicated or not
for f1 = 1 to nbFaces do
(
-- If face not already flagged as duplicated
if ((findItem duplicateFaceArray f1) == 0) then
(
for f2 = (f1+1) to nbFaces do
(
--if ((DuplicateFace facesVertices facesVertices)==1) then
if (facesVertices == facesVertices) then
(
append duplicateFaceArray f2
exit
)
)
)

current_percent = 100*f1/nbFaces
pgbar.pgb.value = current_percent

)

setFaceSelection $ duplicateFaceArray

Please use plain text.
Moderator
Steve_Curley
Posts: 18,549
Registered: ‎08-07-2007

Re: How do I deleting duplicate faces?

07-13-2011 03:19 AM in reply to: andrewmcadam1402
A couple of things there...

Chances are that the objects are Editable Polys rather than Editable Meshes, so forcing the issue (convertToMesh) might be an idea. Same complaint could be levelled at my code below which assumes an Editable Poly :smileywink:

For the vertex position tests to work, the locations must be absolutely identical. You can't rely on the displayed values (spinners at the bottom of the Max window) as they tend to be rounded, so you may think they are coincident when they actually aren't. Even the slightest difference like 0.999997 instead of 1.0 will cause the tests to fail.

With Editable Polys there no guarantee that the vertices (from getFaceVerts) will be returned in the same order (it returns an array of point3 values) - depends entirely on how the model (or its duplicate) was constructed, so I used getFaceCenter, but even that has potential problems as outlined in the help. Welding of remaining vertices could easily be added, if required.

Note. IF we're going to discuss this further (script-wise) it might be better for us to cretae a thread in the Maxscript forum and link to that thread from here (saves cluttering up this thread with code).

(
--change this value if the script is deleting too few or too many faces
local limit = 0.01
local obj = selection

fn p3Equal p3a p3b = --"close enough" for point3 values
(
local pm = limit / 2.0
if (p3b > (p3a - pm)) and (p3b < (p3a + pm)) and
(p3b > (p3a - pm)) and (p3b < (p3a + pm)) and
(p3b > (p3a - pm)) and (p3b < (p3a + pm))
then
true
else
false
)

(
local polyList = #{}
polyCount = polyOp.getNumFaces obj
polyList.count = polyCount
for p = 1 to polyCount - 1 do
(
if not polyList

then
(
polyLoc = polyOp.getFaceCenter obj p
for np = p + 1 to polyCount do
(
npolyLoc = polyOp.getFaceCenter obj np
if p3Equal polyLoc npolyLoc then
polyList = true
)
)
)
--could be replaced with a setFaceSelection if required
polyOp.deleteFaces obj polyList
)
)


Max 4.2 through 2015 (SP1), Composite 2014.
Win7Pro x64 (SP1). i5-3570K @ 4.4GHz, 8Gb Ram, DX11.
nVidia GTX760 (2GB) (Driver 335.23).

Please use plain text.
Distinguished Contributor
amarhys
Posts: 103
Registered: ‎08-13-2004

Re: How do I deleting duplicate faces?

07-13-2011 04:01 AM in reply to: Steve_Curley
Like you Steve, I should have used a bit array instead of a standard array in my script to store the duplicated faces .. faster to be accessed and to be tested (not polyList

test should be really faster than findItem .. test, especially for big amount of faces), then a better runtime at the end.
Please use plain text.
Moderator
Steve_Curley
Posts: 18,549
Registered: ‎08-07-2007

Re: How do I deleting duplicate faces?

07-13-2011 05:55 AM in reply to: Steve_Curley
I actually started out with an integer array, then realised that I was effectively only storing a binary (yes/no) value despite actually storing a face number, so I switched to a bitArray. It wasn't done purely on a "need for speed" basis - that's just a useful side effect :smileywink:

Max 4.2 through 2015 (SP1), Composite 2014.
Win7Pro x64 (SP1). i5-3570K @ 4.4GHz, 8Gb Ram, DX11.
nVidia GTX760 (2GB) (Driver 335.23).

Please use plain text.