Wednesday, September 26, 2012

Align Selected Polygon Vertices To Origin

I wrote this short script using Maya and Python to help with mirroring mesh. It snaps selected vertices to origin so the mesh half is ready to mirror. There may be some bugs.
Hope you find it helpful.

(A couple short modeling tips: saving camera layout as a shelf, reusing modeled character parts (ex: arms,torso,legs,fingers,toes,heads), using lattices for modeling ...)
(I'm still fairly a beginner at Python but a couple of short tips I used on this tool: using map and lambda to do something on each element of a list, is none to verify list is not empty ... )




import maya.cmds as cmds

#move selected polygon vertices to origin in chosen axis
#@note default x
def alignSelectedPolyVertexToOrigin(x=True,y=False, z=False):
    selected = = True)
    component = cmds.filterExpand( sm=(28,31) )
    if component is not None:
        isX = x
        isY = y
        isZ = z
        for obj in component:
  , replace = True)
            worldPosition = cmds.xform(obj,translation = True, query=True, worldSpace = True)
            offSet = map( lambda x: -1*x, worldPosition )
  , replace = True)
        print '\nRequires Polygon Vertices Selected\n'

def alignSelectedPolyVertexToOrigin_unitTest():
    cube = cmds.polyCube()
    vtx=map( lambda x: cube[0]+x, [ '.vtx[0]', '.vtx[2]', '.vtx[4]', '.vtx[6]' ] ),replace=True)
    alignSelectedPolyVertexToOrigin(x=True,y=False, z=False)