-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtri-checker.py
More file actions
73 lines (60 loc) · 2.39 KB
/
tri-checker.py
File metadata and controls
73 lines (60 loc) · 2.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import maya.cmds as cmds
import maya.api.OpenMaya as om
def get_mesh_dag_path(mesh_name):
"""
Retrieves the DAG path of the mesh and verifies it's a mesh.
"""
try:
selection_list = om.MSelectionList()
selection_list.add(mesh_name)
dag_path = selection_list.getDagPath(0)
# Extend to shape if it's a transform node
if dag_path.node().hasFn(om.MFn.kTransform):
dag_path.extendToShape()
# Ensure it's a mesh node
if not dag_path.node().hasFn(om.MFn.kMesh):
cmds.error(f"Node '{mesh_name}' is not a mesh.")
return None, None
mesh_fn = om.MFnMesh(dag_path)
return dag_path, mesh_fn
except Exception as e:
cmds.error(f"Mesh '{mesh_name}' not found or invalid. Error: {e}")
return None, None
def highlight_triangular_faces(mesh_name):
"""
Detects and highlights triangular faces (with 3 vertices) in the selected mesh.
"""
dag_path, mesh_fn = get_mesh_dag_path(mesh_name)
if dag_path is None or mesh_fn is None:
return False
face_iter = om.MItMeshPolygon(dag_path)
triangular_faces = []
while not face_iter.isDone():
if face_iter.polygonVertexCount() == 3: # Check if the face has 3 vertices
triangular_faces.append(face_iter.index())
face_iter.next()
if not triangular_faces:
cmds.confirmDialog(title='No Triangles', message="No triangular faces detected in the mesh.", button=['OK'], defaultButton='OK')
return True
# Highlight triangular faces
cmds.select(clear=True)
for face_id in triangular_faces:
cmds.select(f"{mesh_name}.f[{face_id}]", add=True)
cmds.confirmDialog(title='Triangles Detected', message=f"Highlighted {len(triangular_faces)} triangular faces.", button=['OK'], defaultButton='OK')
return True
def main():
selection = cmds.ls(selection=True, transforms=True)
if not selection:
cmds.error("Please select a mesh before running the script.")
return
mesh_name = selection[0]
cmds.undoInfo(openChunk=True)
try:
if highlight_triangular_faces(mesh_name):
print("Triangular face detection and highlighting completed successfully.")
except Exception as e:
cmds.error(f"Error processing mesh: {e}")
finally:
cmds.undoInfo(closeChunk=True)
if __name__ == "__main__":
main()