Created
August 24, 2023 20:09
-
-
Save BigRoy/0c00ae92bdabdcc00ea17649660fd81d to your computer and use it in GitHub Desktop.
Maya find meshes with holes in them (that are not watertight) by checking if any edge is a boundary edge (not connected to two faces)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import maya.api.OpenMaya as om | |
from maya import cmds | |
def has_boundaries(mesh): | |
sel = om.MSelectionList() | |
sel.add(mesh) | |
dag = sel.getDagPath(0) | |
it = om.MItMeshEdge(dag) | |
while not it.isDone(): | |
if it.onBoundary(): | |
return True | |
it.next() | |
return False | |
for mesh in cmds.ls(type="mesh"): | |
print(mesh, has_boundaries(mesh)) |
I noticed MFnMesh.getHoles
exists but in Maya 2024.1 it always seems to return an empty tuple for me.
Doesn't work.
import maya.api.OpenMaya as om
from maya import cmds
def get_holes(mesh):
sel = om.MSelectionList()
sel.add(mesh)
dag = sel.getDagPath(0)
fn = om.MFnMesh(dag)
return fn.getHoles()
for mesh in cmds.ls(type="mesh"):
print(mesh, get_holes(mesh))
If you allow multiple mesh shells (separate geometry in a single mesh node) to exist but each be watertight the boundary check would still hold. But if you don't allow that you should also check the amount of shells, e.g. maya.cmds.polyEvaluate(mesh, shell=True) != 1
. You'd do that before the boundaries check (because it's faster) and that way optimize the query for heavy geometry.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Or by doing the edge count check manually: