Created
June 20, 2022 13:54
-
-
Save BigRoy/0762f283d91c689307f198cb781466c1 to your computer and use it in GitHub Desktop.
Maya get faces of mesh per island or poly shell
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
from maya import cmds | |
def get_shells(mesh, as_selection_string=True): | |
"""Return faces per shell of mesh""" | |
num_shells = cmds.polyEvaluate(mesh, shell=True) | |
num_faces = cmds.polyEvaluate(mesh, face=True) | |
unprocessed = set(range(num_faces)) | |
shells = [] | |
while unprocessed: | |
face_index = next(iter(unprocessed)) | |
shell_faces = cmds.polySelect(mesh, extendToShell=face_index, noSelection=True) | |
if as_selection_string: | |
yield ["{}.f[{}]".format(mesh, face_index) for face_index in shell_faces] | |
else: | |
yield shell_faces | |
unprocessed.difference_update(shell_faces) | |
for node in cmds.ls(sl=1, objectsOnly=True): | |
for faces in get_shells(node): | |
print(faces) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment