PDA

View Full Version : Removing Floating Faces


dellis
12-09-2008, 02:38 PM
I was wondering if there is a way to select single faces through Maxscript. Like, say for instance you have a single object consisting of a cylinder and then a whole bunch of faces (triangles) floating around it which are attached. Basically i would like to just select those faces which are just floating there...the single triangles...not the cylinder. Thanks for the help!

instinct-vfx
12-09-2008, 03:23 PM
Didnt test that, but my first idea would be to select each element of the object one by one and checking the amount of selected faces. An isolated face is an element of it's own....so basically delete (all elements that only have a single face) should do the trick

Regards,
Thorsten

Bobo
12-09-2008, 03:37 PM
I was wondering if there is a way to select single faces through Maxscript. Like, say for instance you have a single object consisting of a cylinder and then a whole bunch of faces (triangles) floating around it which are attached. Basically i would like to just select those faces which are just floating there...the single triangles...not the cylinder. Thanks for the help!


Well, there are some ways to figure this out. A floating face that is attached but not welded to the rest (in other words, does not share vertices with the main object) is an ELEMENT. You can loop through the faces and get the element of the face using meshop.getElementsUsingFace(). If the returned element consists of the current face alone, then you have an isolated face unconnected to anything else. Even if the floating faces are sometimes connected in quads, you could introduce a threshold to delete for example up to 2 or 3 or 4 faces in an element if not connected to the main body.

Here is a possible implementation as a function:



fn IsolatedFaces theMesh mode:#return theThreshold:1 =
(
local toDeleteBitArray = #{} --a bitarray to collect the faces to be deleted
--loop through all faces, skipping those that are NOT on the list already (speeds it up)
for f = 1 to theMesh.numfaces where not toDeleteBitArray[f] do
(
local theElement = meshop.getElementsUsingFace theMesh f --grab all faces connected to f
--if the number of faces is less or equal to the threshold, collect them
if theElement.numberset <= theThreshold do toDeleteBitArray += theElement
)--end f loop
case mode of --depending on the mode, either delete or select the collected faces
(
#delete: (meshop.deleteFaces theMesh toDeleteBitArray; redrawviews())
#select: (setFaceSelection theMesh toDeleteBitArray)
)
toDeleteBitArray --return the collected bitarray
)
IsolatedFaces $Cylinder01 mode:#delete theThreshold:12

The function has 3 modes:

If mode: is set to #select, the floating faces will only be selected
If mode: is set to #delete, the floating faces will be deleted
If mode: is not set or set to anything else than the two options above, the bitarray of the floating faces will be returned without selecting or deleting anything.

I created a Cylinder, collapsed to EMesh and created some floating faces around it. I also attached a box to it (a box has 12 faces). Running the above code, both the box and the floating faces were deleted. If you set theThreshold to 1, only single triangles will be deleted.

dellis
12-09-2008, 07:52 PM
Bobo,

I'd say you're a genius...but you probably already know it. Worked like a charm...I'm going to give a way a few of these models once i get them cleaned up. One good turn deserves another. Thanks again for the help!

CGTalk Moderation
12-09-2008, 07:52 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.