0 Volts -Maya gallery
Please Register to View Free Download Links
And Unwanted Ads

Join the forum, it's quick and easy

0 Volts -Maya gallery
Please Register to View Free Download Links
And Unwanted Ads
0 Volts -Maya gallery
Would you like to react to this message? Create an account in a few clicks or log in to continue.
Clicksor

OrientJoint.py

Go down

OrientJoint.py Empty OrientJoint.py

Post  Anoop K Fri Apr 27, 2012 3:10 pm

Code:
#                                                    #
#  Script :  0valts Orient Joints                                #
#                                                                                 #
#      Usage  : import OrientJoint                           #
#                                                            #
#                                                                        #
#                                                                                 #
#      Author : Anoop Augustine (anoop3d@yahoo.com)         #
#######################################################


import maya.cmds as mc
      
def OrientJoint():
   orientWin = 'orientWin'
   if mc.window (orientWin, exists =1): mc.deleteUI (orientWin)
   if mc.windowPref (orientWin, exists = 1): mc.windowPref (orientWin, remove = 1)
      
   mc.window (orientWin,wh =(340,256),t =' 0valts Joint Orient - 2.1',s=1)
   layout     =   mc.columnLayout( adjustableColumn=1 )
      
   sep0      = mc.separator( height=10, style='in')
   mainform0 = mc.rowColumnLayout( numberOfColumns=3,columnWidth=[(1, 110),(2,110),(3,110)])
   btnShow  = mc.button (l='Show Axis',h=25,al='center',c="OrientJoint.mc.toggle (state =1,localAxis=1)",ann ='Show Local Axis')
   btnHide  = mc.button (l='Hide Axis',h=25,al='center',c="OrientJoint.mc.toggle (state =0,localAxis=1)",ann ='Hide Local Axis')
   selHier  = mc.button (l='Select Hierarchy',h=25,al='center',c="OrientJoint.mc.select(hi = True)",ann ='Hide Local Axis')
   
   mc.separator (style = "none",h= 20)
   mc.setParent(layout)
   mainform1  = mc.rowColumnLayout( numberOfColumns=2,columnWidth=[(1, 210),(2,120)])
   mc.radioButtonGrp ('rbgAim',l='Aim Axis',nrb =3,la3=('X','Y','Z'),sl=1,cw4=(80,40,40,40))
   mc.checkBox ('cbRevAim', l='Reverse',v=0)
   mc.radioButtonGrp ('rbgup',l='Up Axis',nrb =3,la3=('X','Y','Z'),sl=3,cw4=(80,40,40,40))
   mc.checkBox ('cbRevup', l='Reverse',v=0)
   mc.radioButtonGrp ('rbgupDir', l='Up Direction',nrb =3,la3=('X','Y','Z'),sl=2,cw4=(80,40,40,40))
   mc.checkBox ('cbRevDir',l='Reverse',v=0)   
      
   mc.setParent(layout)
   mainform2 = mc.rowColumnLayout( numberOfColumns=1,columnWidth=[(1, 330)])
   sep1      = mc.separator(style='in',h=20)
   mc.setParent(mainform2)
   mainform3 = mc.rowColumnLayout( numberOfColumns=3,columnWidth=[(1, 80),(2, 170)])
   mc.separator (style = "none")
   btnOJ    = mc.button (l='Orient Joints',h=30,al='center',c=lambda event:OrientUI())
   mc.separator (style = "none")
   mc.setParent(mainform2)
   mainform4 = mc.rowColumnLayout( numberOfColumns=1,columnWidth=[(1, 330)])
   sepBig    = mc.separator (style ='double',h=20)
   text      = mc.iconTextButton (style ="textOnly", l =" 0valts  Rigging  Team")
   
   mc.showWindow (orientWin)   
   
   
def OrientUI():
   nAimAxis = mc.radioButtonGrp ('rbgAim',q= 1,sl= 1)
   nUpAxis  = mc.radioButtonGrp ('rbgup',q= 1,sl=1)
   nUpDir  = mc.radioButtonGrp ('rbgupDir',q= 1,sl =1)
   
   dic = ('x','y','z')
   aimAxis = dic[nAimAxis-1]
   upAxis  = dic[nUpAxis-1]
   upDir  = dic[nUpDir-1]
   
   if mc.checkBox ('cbRevAim',q=True,v=True):
      aimAxis = '-'+aimAxis
   if mc.checkBox ('cbRevup',q=True,v=True):
      upAxis  = '-'+upAxis
   if mc.checkBox ('cbRevDir',q=True,v=True):
      upDir = '-'+upDir
   
   joints = mc.ls(type='joint',sl=True)
   jnt_orient(joints, aimAxis, upAxis, upDir)
   mc.select (joints, r=True)
   
   
   
def jnt_orient(joints,aimAxisD,upAxisD,upDire):
   
   dic = {'x':(1,0,0),'y':(0,1,0),'z':(0,0,1),'-x':(-1,0,0),'-y':(0,-1,0),'-z':(0,0,-1)}
   aimAxis = dic[aimAxisD]
   upAxis  = dic[upAxisD]
   upDir  = dic[upDire]
   njnt    = len(joints)
   prevUp  = [0,0,0]
   childs  =[]
   parentlist = []
   
   ### Orient each joint ###
   for i in range(0,njnt,1):
      child  = mc.listRelatives (joints[i],children=True,type=('transform','joint'))
         
      if child != None:
         childs.append(child)
         if len(childs)>0:

            parents = mc.listRelatives (joints[i], parent = True)
            parentlist.append(parents)
            child = mc.parent (child, w=True)
            parent = parentlist[0]
         for childl in childs:
            if mc.nodeType(childl[0])=='joint':
               aimTgt = childl[0]
   
         if aimTgt != '':
            upVec = upDir
            aCons = mc.aimConstraint (aimTgt,joints[i],
                        aim =(aimAxis[0],aimAxis[1],aimAxis[2]),
                        upVector =(upAxis[0],upAxis[1],upAxis[2]),
                        worldUpVector =(upVec[0],upVec[1],upVec[2]),worldUpType='vector')
            mc.delete (aCons)   
            mag  = pow((upVec[0]*upVec[0]+upVec[1]*upVec[1]+upVec[2]*upVec[2]),0.5)
            curUpr = (upVec[0]/mag,upVec[1]/mag,upVec[2]/mag)
            dotlist = []
            for j in range(0,3,1):
               dot   =  curUpr[j]*prevUp[j]
               dotlist.append(dot)
               prevUp[j] = upVec[j]
            if i > 0 and dotlist[0]== 0 and dotlist[1]== 0 and dotlist[2]== 0 :
                  mc.xform (joints[i],r=True,os=True,ra= ((aimAxis[0]*180),(aimAxis[1]*180),(aimAxis[2]*180)))
                  for t in range(0,3,1): prevUp[t] *= -1.0
   
            mc.joint (joints[i],e =True,zso=True)
            mc.makeIdentity (joints[i],a=True)
   
         elif parent != '':

            oCons = mc.orientConstraint (parent,joints[i],weight=1.0)
            mc.delete(oCons)
            mc.joint (joints[i],e =True,zso=True)
            mc.makeIdentity (joints[i],a=True)
         if len(childs) >0:
            mc.parent (child,joints[i])

      else :
         mc.joint (joints[i],e =True,zso=True)
         mc.makeIdentity (joints[i],a=True)
         mc.setAttr(joints[i]+'.jointOrient',0,0,0)
         
OrientJoint()

Anoop K

Posts : 9
Points : 36
Reputation : -1
Join date : 2011-12-08

Back to top Go down

Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum