Hi, I have been trying to do some checks with python on some mesh in maya before I export them. I am using CMDS to do multiple checks that currently work, but there are two checks I want that I just can not seem to figure out.
First one is if there is any reversed normal in the uv for each mesh. I just need it to return a true or false on the normal has being inverted. I have been looking at the documentation for polyNormal as I felt like this is what I need I just don’t know what I need to get the outcome I want.
I am also looking to check if all the edges are soft again needing just a true or false return for each mesh if all the edges are soft or not. This one has fully stumped me I have no idea where to find this one so any help with these would be much appreciated.
Thanks
I hope that I correctly interpret your speech turns in the context of terms of polygonal geometry…
With cmds.polyNormal()
you can reverse nonmanifold polygons using the normalMode = 2
(conform
) flag.
But you CANNOT ask for normal values!
You will only be able to query/edit the value of the normalMode
flag for an already performed cmds.polyNormal()
operation contained in the object’s constructionHistory
stack…
I have given several options using cmds
or OpenMaya
.
If you described the final goals, then perhaps a completely different solution could be proposed that does not include checks…
import maya.api.OpenMaya as om2
import maya.cmds as cmds
maya_useNewAPI = True
# or:
def maya_useNewAPI():
pass
mesh_name = 'pCube1'
sel_list = om2.MSelectionList()
sel_list.add(mesh_name)
node, component = sel_list.getComponent(0)
# Search not soften edges with "maya.api.OpenMaya.MFnMesh().isEdgeSmooth()":
# Thish method is the fastest !
fn_mesh = om2.MFnMesh(node)
for i in range(fn_mesh.numEdges):
if not fn_mesh.isEdgeSmooth(i):
print(('Current mesh (\"{}\") contained not smooth edge(s)!').format(mesh_name))
break
# Or Search not soften edges with "MItMeshEdge().isSmooth".
# This method is one and a half times slower than "MFnMesh().isEdgeSmooth()" method:
it = om2.MItMeshEdge(node, component)
while not it.isDone():
if not it.isSmooth:
print(('Current mesh (\"{}\") contained not smooth edge(s)!').format(mesh_name))
break
it.next()
# Or Search not soften edges with "cmds.polySelectConstraint()":
# use "cmds.polySelectConstraint(type = 0x8000, mode = 3, smoothness = 1)"
# type = 0x8000 == "edge"; type = 0x0001 == "edge"
# mode = 3 == "all and next"; mode = 0 == "off"
# smoothness = 1 == "hard"; smoothness = 2 == "smooth"; smoothness = 0 == "off"
cmds.select(mesh_name)
cmds.polySelectConstraint(type = 0x8000, mode = 3, smoothness = 1)
harden_edges = cmds.ls(selection = True)
cmds.polySelectConstraint(mode = 0)
cmds.select(clear = True)
if harden_edges:
to_face = cmds.polyListComponentConversion(harden_edges, toFace = True, internal = True)
if to_face:
print(('Current mesh (\"{}\") contained not smooth edge(s):\n\t{}\nfrom face(s):\n\t{}'
).format(mesh_name, harden_edges, to_face))
# Search NonManifold with "cmds.polySelectConstraint()":
cmds.select(mesh_name)
cmds.polySelectConstraint(type = 0x0001, mode = 3, nonmanifold = 1)
nonmanifold_vertices = cmds.ls(selection = True)
cmds.polySelectConstraint(mode = 0)
cmds.select(clear = True)
if nonmanifold_vertices:
to_face = cmds.polyListComponentConversion(nonmanifold_vertices, toFace = True, internal = True)
if reverse_face:
print(('Current mesh (\"{}\") contained non manifild vertices:\n\t{}\nfrom face(s):\n\t{}.'
).format(mesh_name, nonmanifold_vertices, to_face))
# Search NonManifold with "cmds.polyInfo":
# use "cmds.polyInfo(mesh_name, nonManifoldUVs = True)"
# or use "cmds.polyInfo(mesh_name, nonManifoldVertices = True)"
# or use "cmds.polyInfo(mesh_name, nonManifoldUVEdges = True)"
non_manifold_uvs = cmds.polyInfo(mesh_name, nonManifoldUVs = True)
if non_manifold_uvs:
to_face = cmds.polyListComponentConversion(non_manifold_uvs, toFace = True, internal = True)
if to_face:
print(('Current mesh (\"{}\") contained non manifild UVs:\n\t{}\nfrom face(s):\n\t{}.'
).format(mesh_name, non_manifold_uvs, to_face))
command (Python): polySelectConstraint
command (Python): polyListComponentConversion
command (Python): ls
command (Python): polyInfo
Maya Python API 2.0 Reference: OpenMaya.MFnMesh Class Reference
Maya Python API 2.0 Reference: OpenMaya.MItMeshEdge Class Reference
Good luck! 