removing floating faces - Maxscript

Do anybody know way to do this, How to remove from object faces which are not connected with base mesh - floating faces.
I need it for tool I'm working on but I'm running out of ideas.
Can anybody advice something?
Would be great to hear from You.

Comments

Comment viewing options

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

.

The code below works with editable poly objects and edit poly modifier.

(   
    if selection.count != 0 do
    (
		max modify mode
        for curO in (selection as array) do
        (
			select curO
			curMod = modPanel.getCurrentObject()
			case classof curMod of
			(
				Editable_Poly:
				(
					curOfacesBA = #{1..curO.getnumfaces()}		 
					poSetFaceSelection = polyop.setFaceSelection
					poGetFaceSelection = polyop.getFaceSelection
					facesToDellBA = #{}
					while curOfacesBA.numberset != 0 do
					(
						--    select the last face by its index
						poSetFaceSelection curO (curOfacesBA as array)[1]
						curO.selectElement()
						if (selFacesBA = poGetFaceSelection curO).numberset <= 10 then
						(
							curOfacesBA = curOfacesBA - selFacesBA
							join facesToDellBA selFacesBA
						)
						else
						(
							curOfacesBA = curOfacesBA - selFacesBA
						)
					)
					polyop.deleteFaces curO facesToDellBA
				)
				Edit_Poly:
				(
					curOfacesBA = #{1..curMod.getNumFaces()}
					facesToDellBA = #{}
					subobjectlevel = 4
					while curOfacesBA.numberset != 0 do
					(
						curMod.SetSelection #Face #{}
						curMod.Select #Face #{(curOfacesBA as array)[1]}
						curMod.ConvertSelection #Face #Element
						if (selFacesBA = curMod.GetSelection #Face).numberset <= 10 then
						(
							curOfacesBA = curOfacesBA - selFacesBA
							join facesToDellBA selFacesBA
						)
						else
						(
							curOfacesBA = curOfacesBA - selFacesBA
						)
					)
					curMod.SetSelection #Face #{}
					curMod.Select #Face facesToDellBA
					curMod.ButtonOp #DeleteFace
					curMod.Commit()
				)
			)
        )
    )
)

But you have to explain what is "extra faces" in the attached scene.

kredka's picture

I forgot attachment.:)

I forgot attachment.:)

AttachmentSize
script1and2.zip 30.92 KB
kredka's picture

it work

I checked and it work. Thank You a lot. I have last one question about this.
Could you write this operation as 2 scripts:
1) for objects in selection with extra faces(number of extra faces

miauu's picture

.

What is "extra faces"?
In the attached scene the "extra faces" are the faces that are separate from the teqpots?

kredka's picture

almost work

Thanks, second script don't work( polyop.deleteFaces curO facesToDellBA) so I used $.modifiers[#Edit_Poly].ButtonOp #DeleteFace and work
command to delete mesh but my question is:
How can use it not only for one object but in object in selection(multiple objects)?

miauu's picture

.

My script works only with editable_poly objects. Edit_Poly modifier is not supported. So, if your object is with Edit_poly mod on top of the stack, then you have to change the code, as you did it.
Also, my second script works with selection of objects. I can show you a video with the scene that is attached above. Do you want to see it?

miauu's picture

.

The code below works with selection of objects:

(   
    if selection.count != 0 do
    (
        for curO in (selection as array) where classof curO == Editable_Poly do
        (
            curOfacesBA = #{1..curO.getnumfaces()}
 
            poSetFaceSelection = polyop.setFaceSelection
            poGetFaceSelection = polyop.getFaceSelection
            facesToDellBA = #{}
            while curOfacesBA.numberset != 0 do
            (
                --    select the last face by its index
                poSetFaceSelection curO (curOfacesBA as array)[1]
                curO.selectElement()
                if (selFacesBA = poGetFaceSelection curO).numberset <= 10 then
                (
                    curOfacesBA = curOfacesBA - selFacesBA
                    join facesToDellBA selFacesBA
                )
                else
                (
                    curOfacesBA = curOfacesBA - selFacesBA
                )
            )
            polyop.deleteFaces curO facesToDellBA
        )
    )
)
miauu's picture

.

The script deletes all floating faces that are made by only one polygon(face). Load the attached scene, select the Cylinder, uncomment the

 polyop.deleteFaces curO facesToDellBA

and execute the script. The top cap of the cylinder and the single face away from it will be deleted. The teapot and the torus have floating faces, which are separate elements. The script will not delete those elements, because they are made by 2 or more faces.

Now, the question is - how many faces have to have the floating element, that will be considered as "faces to delete", but not as "base mesh"?

You can have "base mesh" with 100 faces and floating element with 50 faces. How the script can know which one is "base mesh" and which one is "faces to delete"?

In the code above you can change how much faces must have the "floating faces" by changing the  if (selFacesBA = poGetFaceSelection curO).numberset == 1 then

to, for example:  if (selFacesBA = poGetFaceSelection curO).numberset &lt;= 10 then

which will delete all floating elemnts, that have 10 or less faces.

 

Exucly I would need one script which remove deatched faces - so there is hole in base mash and secund script for faces which are extra, outsdte base mesh.

Can you explain in more detalis how these two scripts have to works? Detached faces are detached as elements or...?? How the script must find them?

The code above deletes all elements, that have 10 or less faces, no matter if those elements are created by detaching faces from the base mesh or by deleting the faces, that connects the elements with the base mesh.

The faces, that are outside from the base mesh are also separate elements? Or they are not? If they are separate elements, then the script above will delete them. You need to set the proper value for the face count in those detached, floating, extra faces.

kredka's picture

Thank You, work nice and fast

Thank You, work nice and fast but it delete only one last face.
What I'm trying acheive is to remove multiple(one or many faces I don't know, I have to deal with many different geometry) So script should detect all faces which are not connected to base mesh. Script should work on object selection - multiple object so it should work like this:
1 Check meshes in selected geometrys(objects)for any floating faces and delete it if exist.

Exucly I would need one script which remove deatched faces - so there is hole in base mash and secund script for faces which are extra, outsdte base mesh.

I would be gratefull if You could help mi with this.
I can't come up with anything to menage this.

Max file in attachment and there is two kinds of this objects.

AttachmentSize
example_geometry_to_delete_poly.zip 69.29 KB
miauu's picture

.

If you wants to delete single faces(elements, formed by single polygons)

(	
	if selection.count == 1 and classof (curO = selection[1]) == Editable_Poly do
	(
		curOfacesBA = #{1..curO.getnumfaces()}
 
		poSetFaceSelection = polyop.setFaceSelection
		poGetFaceSelection = polyop.getFaceSelection
		facesToDellBA = #{}
		while curOfacesBA.numberset != 0 do
		(
			--	select the last face by its index
			poSetFaceSelection curO (curOfacesBA as array)[1]
			curO.selectElement()
			if (selFacesBA = poGetFaceSelection curO).numberset == 1 then
			(
				curOfacesBA = curOfacesBA - selFacesBA
				join facesToDellBA selFacesBA
			)
			else
			(
				curOfacesBA = curOfacesBA - selFacesBA
			)
		) 
		--	if you want to see which faces will be deleted. 
		--	Remove from your code, because this is not needed if you wants only to delete dhe faces
		poSetFaceSelection curO facesToDellBA
		--	uncomment to delete the faces
-- 		polyop.deleteFaces curO facesToDellBA
	)
)

Comment viewing options

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