def Controllers():
    charName = cmds.textFieldGrp(NameInput, q=True, text=True)
    lengthY = locXYZ[1][1] - locXYZ[0][1]
    lengthZ = abs(locXYZ[0][2]) + abs(locXYZ[1][2])
    legY = locXYZ[0][1] - locXYZ[5][1]
    side = ['_L_', '_R_']
    nb = [1, -1]
    for i in range(len(side)):
        cmds.ikHandle(n=charName + '_Leg' + side[i] + 'ikHandle',
                      sj=charName + side[i] + 'thigh_Jnt_01',
                      ee=charName + side[i] + 'ankie_Jnt_01')
        cmds.spaceLocator(n=charName + '_poleVector' + side[i] + 'leg',
                          p=(nb[i] * locXYZ[4][0] - legY * 0.005,
                             locXYZ[4][1] + legY * 0.05, locXYZ[4][2]))
        cmds.xform(centerPivots=1)
        # aims the pole vector of 1 at 2.
        cmds.poleVectorConstraint(charName + '_poleVector' + side[i] + 'leg',
                                  charName + '_Leg' + side[i] + 'ikHandle')
        cmds.move(nb[i] * lengthY * 0.75,
                  -lengthY * 0.75,
                  charName + '_poleVector' + side[i] + 'leg',
                  moveXY=True)
        cmds.setAttr(charName + '_Leg' + side[i] + 'ikHandle.twist',
                     nb[i] * 90)
        cmds.ParentConstraint(charName + 'controllerfoot',
                              charName + '_poleVector' + side[i] + 'leg')
        cmds.parent(charName + '_poleVector' + side[i] + 'leg',
                    charName + '_Leg' + side[i] + 'ikHandle',
                    relative=True)
        cmds.ikHandle(n=charName + '_Foot' + side[i] + 'ball_ikHandle',
                      sj=charName + side[i] + 'ankie' + '_Jnt_01',
                      ee=charName + side[i] + 'ball' + '_Jnt_01')
        cmds.ikHandle(n=charName + '_Foot' + side[i] + 'toe_ikHandle',
                      sj=charName + side[i] + 'ball' + '_Jnt_01',
                      ee=charName + side[i] + 'toe' + '_Jnt_01')
        cmds.group(charName + '_Leg' + side[i] + 'ikHandle',
                   n=charName + '_Foot' + side[i] + 'heelPeel')
        #change pivot position
        Xpos = cmds.getAttr(charName + '_Foot' + side[i] +
                            'ball_ikHandle.translateX')
        Ypos = cmds.getAttr(charName + '_Foot' + side[i] +
                            'ball_ikHandle.translateY')
        Zpos = cmds.getAttr(charName + '_Foot' + side[i] +
                            'ball_ikHandle.translateZ')
        cmds.move(Xpos,
                  Ypos,
                  Zpos,
                  charName + '_Foot' + side[i] + 'heelPeel.scalePivot',
                  charName + '_Foot' + side[i] + 'heelPeel.rotatePivot',
                  absolute=True)
        cmds.group(charName + '_Foot' + side[i] + 'ball_ikHandle',
                   charName + '_Foot' + side[i] + 'toe_ikHandle',
                   n=charName + '_Foot' + side[i] + 'toeTap')
        cmds.move(Xpos,
                  Ypos,
                  Zpos,
                  charName + '_Foot' + side[i] + 'toeTap.scalePivot',
                  charName + '_Foot' + side[i] + 'toeTap.rotatePivot',
                  absolute=True)
        cmds.group(charName + '_Foot' + side[i] + 'ball_ikHandle',
                   charName + '_Foot' + side[i] + 'toeTap',
                   n=charName + '_Foot' + side[i] + 'TipToe')
        cmds.group(n=charName + '_Foot' + side[i] + '1', em=True)
        cmds.parent(charName + '_Foot' + side[i] + 'heelPeel',
                    charName + '_Foot' + side[i] + 'TipToe',
                    charName + '_Foot' + side[i] + '1',
                    relative=True)
        cmds.move(Xpos,
                  Ypos,
                  Zpos,
                  charName + '_Foot' + side[i] + '1.scalePivot',
                  charName + '_Foot' + side[i] + '1.rotatePivot',
                  absolute=True)
        Xpos = cmds.getAttr(charName + '_Foot' + side[i] +
                            'ball_ikHandle.translateX')
        Ypos = cmds.getAttr(charName + '_Foot' + side[i] +
                            'ball_ikHandle.translateY')
        Zpos = cmds.getAttr(charName + '_Foot' + side[i] +
                            'ball_ikHandle.translateZ')
        CreateCtr(charName + '_Foot' + side[i] + 'Crl',
                  charName + '_Foot' + side[i] + '1', (Xpos, Ypos, Zpos),
                  (lengthY / 60 * 10, lengthY / 60 * 10, lengthY / 60 * 16),
                  (0, 0, 0))
    #left Arm
    for i in range(len(side)):
        cmds.ikHandle(n=charName + '_Arm' + str(side[i]) + 'ikHandle',
                      sj=charName + str(side[i]) + 'shoulder' + '_Jnt_02',
                      ee=charName + str(side[i]) + 'wrist' + '_Jnt_01')
        cmds.CreateNURBSCircle()
        cmds.rename('nurbsCircle1', charName + '_Elbow' + str(side[i]) + 'Crl')
        cmds.move(nb[i] * locXYZ[2][0], locXYZ[2][1], locXYZ[2][2] * 30)
        cmds.scale(2, 2, 3)
        cmds.rotate(90, 0, 0)
        cmds.move(nb[i] * locXYZ[2][0],
                  locXYZ[2][1],
                  locXYZ[2][2],
                  charName + '_Elbow' + str(side[i]) + 'Crl.scalePivot',
                  charName + '_Elbow' + str(side[i]) + 'Crl.rotatePivot',
                  absolute=True)
        cmds.makeIdentity(apply=True)
        cmds.xform(centerPivots=1)
        cmds.poleVectorConstraint(
            charName + '_Elbow' + str(side[i]) + 'Crl',
            charName + '_Arm' + str(side[i]) + 'ikHandle')
        #left Arm controller
        CreateCtr(charName + '_Arm' + side[i] + 'Crl',
                  charName + '_Arm' + side[i] + 'ikHandle',
                  (nb[i] * locXYZ[3][0], locXYZ[3][1], locXYZ[3][2]),
                  (lengthY / 60 * 5, lengthY / 60 * 5, lengthY / 60 * 8),
                  (0, 0, nb[i] * 30))
    #spline
    cmds.parent(charName + '_R_shoulder_Jnt_01', w=True)
    cmds.parent(charName + '_L_shoulder_Jnt_01', w=True)
    cmds.select(d=True)
    cmds.select(charName + '_spline_Jnt_03')
    cmds.DisconnectJoint(charName + '_spline_Jnt_03')
    cmds.rename(charName + '_spline_Jnt_03', charName + '_neck_Jnt_00')
    cmds.rename('joint1', charName + '_spline_Jnt_03')
    cmds.rename(charName + '_root' + '_Jnt_01', charName + '_spline_Jnt_00')
    cmds.parent(charName + '_R_hip_Jnt_01', w=True)
    cmds.parent(charName + '_L_hip_Jnt_01', w=True)
    cmds.select(d=True)
    cmds.joint(p=(locXYZ[0][0], locXYZ[0][1], locXYZ[0][2]),
               n=charName + '_root' + '_Jnt_01')
    cmds.parent(charName + '_L_hip_Jnt_01')
    cmds.select(charName + '_root' + '_Jnt_01')
    cmds.parent(charName + '_R_hip_Jnt_01')
    cmds.curve(n=charName + '_SplineIK_Crv_01',
               p=[(locXYZ[0][0], locXYZ[0][1], locXYZ[0][2]),
                  (0.0, locXYZ[0][1] + lengthY * 0.43,
                   locXYZ[0][2] + lengthZ * 0.43),
                  (0.0, locXYZ[0][1] + lengthY * 0.8,
                   locXYZ[0][2] + lengthZ * 0.18),
                  (locXYZ[1][0], locXYZ[1][1], locXYZ[1][2])])
    cmds.ikHandle(n=charName + 'SplineIK_01',
                  sj=charName + '_spline_Jnt_00',
                  ee=charName + '_spline_Jnt_03',
                  curve=charName + '_SplineIK_Crv_01',
                  sol='ikSplineSolver',
                  createCurve=False,
                  parentCurve=False)
    for i in range(4):
        cmds.select(charName + '_SplineIK_Crv_01' + '.cv[' + str(i) + ']')
        cmds.cluster(n='cluster_' + str(i + 1))
    CreateCtr(charName + '_Spline_Ctrl_01', 'cluster_1Handle',
              (0, locXYZ[0][1] * 1.05, 0),
              (lengthY / 60 * 25, lengthY / 60 * 25, lengthY / 60 * 25),
              (0, 0, 0))
    cmds.parentConstraint(charName + '_Spline_Ctrl_01',
                          charName + '_root_Jnt_01',
                          maintainOffset=True)
    CreateCtr(charName + '_Chest_Ctrl_01', 'cluster_4Handle',
              (0, locXYZ[1][1], 0),
              (lengthY / 60 * 25, lengthY / 60 * 25, lengthY / 60 * 25),
              (0, 0, 0))
    for i in range(len(side)):
        cmds.parentConstraint(charName + '_Chest_Ctrl_01',
                              charName + side[i] + 'shoulder_Jnt_01',
                              maintainOffset=True)
        cmds.parent(charName + '_Arm' + side[i] + 'Crl_grp',
                    charName + '_Chest_Ctrl_01')
        cmds.parent(charName + '_Elbow' + side[i] + 'Crl',
                    charName + '_Chest_Ctrl_01')
    CreateCtr(charName + '_Chest_Ctrl_02', 'cluster_2Handle',
              (0, (locXYZ[0][1] + locXYZ[1][1]) / 2, 0),
              (lengthY / 60 * 20, lengthY / 60 * 20, lengthY / 60 * 20),
              (0, 0, 0))
    cmds.parentConstraint(charName + '_Chest_Ctrl_01',
                          charName + '_neck_Jnt_00',
                          maintainOffset=True,
                          w=1)
    cmds.parentConstraint(charName + '_Chest_Ctrl_01',
                          'cluster_3Handle',
                          maintainOffset=True,
                          weight=0.5)
    cmds.parentConstraint(charName + '_Chest_Ctrl_01',
                          charName + '_Chest_Ctrl_02_grp',
                          maintainOffset=True,
                          weight=0.5)
    cmds.parentConstraint(charName + '_Spline_Ctrl_01',
                          charName + '_Chest_Ctrl_02_grp',
                          maintainOffset=True,
                          weight=0.5)
    cmds.CreateNURBSCircle()
    cmds.rename('nurbsCircle1', charName + '_Hip_Ctrl_01')
    cmds.move(0, locXYZ[0][1], 0)
    cmds.scale(lengthY / 60 * 30, lengthY / 60 * 30, lengthY / 60 * 30)
    cmds.makeIdentity(apply=True)
    cmds.parentConstraint(charName + '_Hip_Ctrl_01',
                          charName + '_Spline_Ctrl_01',
                          maintainOffset=True,
                          weight=0.5)
    cmds.parentConstraint(charName + '_Hip_Ctrl_01',
                          charName + '_Chest_Ctrl_01',
                          maintainOffset=True,
                          weight=0.5)
    #clean
    for i in range(len(side)):
        cmds.parent(charName + side[i] + 'shoulder_Jnt_01',
                    charName + '_Joints_01')
        cmds.parent(charName + '_Chest_Ctrl_0' + str(i + 1) + '_grp',
                    charName + '_Controls_01')
        cmds.parent(charName + '_Foot' + side[i] + '1',
                    charName + '_Controls_01')
        cmds.parent(charName + '_Foot' + side[i] + 'Crl_grp',
                    charName + '_Controls_01')
        cmds.parent(charName + '_Arm' + side[i] + 'ikHandle',
                    charName + '_ikHandle_01')
        cmds.parent('cluster_' + str(i + 1) + 'Handle',
                    charName + '_ikHandle_01')
        cmds.parent('cluster_' + str(i + 3) + 'Handle',
                    charName + '_ikHandle_01')
    cmds.parent(charName + 'SplineIK_01', charName + '_ikHandle_01')
    cmds.parent(charName + '_SplineIK_Crv_01', charName + '_ikHandle_01')
    cmds.parent(charName + '_neck_Jnt_00', charName + '_Joints_01')
    cmds.parent(charName + '_root_Jnt_01', charName + '_Joints_01')
    cmds.parent(charName + '_spline_Jnt_00', charName + '_Joints_01')
    cmds.parent(charName + '_Spline_Ctrl_01_grp', charName + '_Controls_01')
    cmds.parent(charName + '_Hip_Ctrl_01', charName + '_Controls_01')
コード例 #2
0
def constraintParent(*args):
    parentCheckBoxInquiry=cmds.checkBox(parentCheckBox,q=True,v=True)
    cmds.ParentConstraint(w=1.0, mo=parentCheckBoxInquiry)
    print 'Constrain Parent'