def autoRig(self,meshName): height = self.getSizeY(meshName) minPosY = height[1] height = height[0] width = self.getSizeX(meshName) minPosX = width[1] width = width[0] bassinPoint = (minPosX + width * 0.0,minPosY + height * 0.48,self.getZ(minPosX + width * 0.0,minPosY + height * 0.48,meshName)) couPoint = (minPosX + width * 0.0,minPosY + height * 0.870,self.getZ(minPosX + width * 0.0,minPosY + height * 0.870,meshName)) epaulePoint = (minPosX + width * 0.129,minPosY + height * 0.825,self.getZ(minPosX + width * 0.129,minPosY + height * 0.825,meshName)) coudePoint = (minPosX + width * 0.315,minPosY + height * 0.825,self.getZ(minPosX + width * 0.315,minPosY + height * 0.825,meshName)) poignetPoint = (minPosX + width * 0.461,minPosY + height * 0.825,self.getZ(minPosX + width * 0.461,minPosY + height * 0.825,meshName)) jambePoint = (minPosX + width * 0.0955,minPosY + height * 0.4,self.getZ(minPosX + width * 0.0955,minPosY + height * 0.4,meshName)) genouPoint = (minPosX + width * 0.1,minPosY + height * 0.285,self.getZ(minPosX + width * 0.1,minPosY + height * 0.285,meshName)) piedPoint = (minPosX + width * 0.12,minPosY + height * 0.039 ,self.getZ(minPosX + width * 0.12,minPosY + height * 0.039,meshName)) cmds.select(clear=True) cmds.joint(p=bassinPoint,name="bassinBase") cmds.select("bassinBase") rigList = [couPoint,epaulePoint,coudePoint,poignetPoint] self.createListRig(rigList,"rigTop","bassinBase") cmds.select("bassinBase") rigList2 = [jambePoint,genouPoint,piedPoint] self.createListRig(rigList2,"rigBot","bassinBase") cmds.select("rigTop1") cmds.mirrorJoint(mirrorYZ=True) cmds.select("rigBot0") cmds.mirrorJoint(mirrorYZ=True) cmds.select("bassinBase") cmds.select(meshName,tgl=True) cmds.bindSkin()
def movePetalsAroundBulb(self, offset=1): # counter to mark the range of petals in layers. Every next layer will have "curr_count" more petals curr_count = 0 # distance and rotate the petals around the bulb for each row of petals for j in range(self.rows): next_count = curr_count + self.rows + j for i in range(curr_count, next_count): # make sure petal found is within max number of petals in flower. Else, end search if i < len(self.all_petals): mc.rotate(0, (360 / (self.rows+j)) * i, 0, self.all_petals[i], r=True, fo=True, os=True) mc.move(self.pos[0][0] - (j * offset), self.pos[0][1], self.pos[0][2], self.all_petals[i], r=True, wd=True, os=True) mc.bindSkin(self.all_petals[i], self.all_joints[i]) # create the spine rigs for each petal grp, names = (AdvancedRigging.createLinearSpineControllers(self.all_joints[i], ctrl_scale=1, createXtra_grp=False)) self.all_grps.append(grp) self.all_ctrls.append(names) else: break curr_count = next_count
def bindToSurface(self, selection, *args): #bind each object by closest point on selection sel = mc.ls(sl=True) if sel == []: mc.headsUpMessage("Select desired joints then geometry") return sel else: mc.bindSkin(bcp=True)
def applyShaders(treeHeight, planeCnt, myBranch, myLetter, season): barkMat = cmds.shadingNode('lambert', asShader=True, n='barkMat') cmds.setAttr('barkMat'+'.color', 0.45, 0.30, 0.2) #green - spring leafMat1 = cmds.shadingNode('lambert', asShader=True, n='leafMat1') cmds.setAttr('leafMat1'+'.color', 0.0, 0.90, 0.2) #green - summer leafMat2 = cmds.shadingNode('lambert', asShader=True, n='leafMat2') cmds.setAttr('leafMat2'+'.color', 0.2, 1.5, 0.0) #orange/red - fall leafMat2 = cmds.shadingNode('lambert', asShader=True, n='leafMat3') cmds.setAttr('leafMat3'+'.color', 1.5, 0.30, 0.05) #apply bark cmds.select(all=True) for i in range (1, treeHeight): cmds.select('base'+str(i), d=True) for i in range (1, planeCnt): cmds.select('leaf'+str(i), d=True) cmds.polyUnite(o=True, n='barkUnite') cmds.hyperShade(assign=barkMat) cmds.delete(ch=True) cmds.select(d = True) #apply leaf if not winter if season != 4: for i in range (1, planeCnt): cmds.select('leaf'+str(i), add=True) cmds.hyperShade(assign='leafMat'+str(season)) cmds.select('barkUnite', add=True) cmds.polyUnite(o=True, n='treeMesh') cmds.select(d=True) cmds.select('treeMesh') cmds.delete(ch=True) for i in range (1, treeHeight): cmds.select('base'+str(i), add=True) if season == 4: cmds.select('barkUnite', add=True) #select joints one by one (select all doesn't work) for h in range (1,3): maxJnts = 6 jointNum = 6 for i in range(1, myBranch[h]): maxJnts-=1 for j in range(1, maxJnts+2): cmds.select('branch'+myLetter[h]+str(i)+'_'+str(j), add=True) cmds.makeIdentity(apply=True, t=1, r=1, s=1, n=0) cmds.bindSkin(tsb=True) cmds.delete(ch=True)
def addDeformers(sel): sel='headGeo' mc.select('R_Brow_GEO',sel) mm.eval('CreateWrap') mc.select('L_Brow_GEO',sel) mm.eval('CreateWrap') mc.select('CharacterHead') mc.select('lowerNeck_JNT',add=True) mc.bindSkin()
def create_joints_and_bind(obj, joints): x1, y1, z1 = percet2loc(obj, joints[0]) x2, y2, z2 = percet2loc(obj, joints[1]) cmds.select(cl=1) j1 = cmds.joint(p=(x1, y1, z1), rad =0.5) j2 = cmds.joint(p=(x2, y2, z2), rad =0.5) cmds.joint(j1, e=True, zso=True, oj='xyz', sao='yup') cmds.select(obj, j1, r=1) cmds.bindSkin() return j1, j2
def SplineIK(self, selectHierarchy): if selectHierarchy: cmds.select(hierarchy = 1) sels = cmds.ls(selection = 1) lastJoint = "" for sel in sels: if cmds.listRelatives(sel, children = 1) == None: lastJoint = sel curvePoints = list() for sel in sels: curvePoints.append(cmds.xform(sel, query = 1, translation = 1, worldSpace = 1)) tokenizedSel = sels[0].split("_") spline = cmds.curve(editPoint = curvePoints, name = tokenizedSel[0] + "_spline_IK_CV") ikHndl = cmds.ikHandle(startJoint = sels[0], endEffector = lastJoint, createCurve = 0, curve = spline, solver = "ikSplineSolver", name = tokenizedSel[0] + "_spline_IK_HNDL") ctrlJointPositions = list() for var in range(0, len(sels), 2): ctrlJointPositions.append(cmds.xform(sels[var], query = 1, translation = 1, worldSpace = 1)) if ctrlJointPositions[(len(sels)/2) - 1] != cmds.xform(lastJoint, query = 1, translation = 1, worldSpace = 1): ctrlJointPositions.append(cmds.xform(lastJoint, query = 1, translation = 1, worldSpace = 1)) firstCtrlJoint = None lastCtrlJoint = None cmds.select(clear = 1) for var in range(0, len(ctrlJointPositions)): currentJoint = cmds.joint(position = ctrlJointPositions[var], name = tokenizedSel[0] + "_spline_Ctrl_0" + str((var + 1)) + "_JNT") if firstCtrlJoint == None: firstCtrlJoint = currentJoint lastCtrlJoint = currentJoint cmds.joint(firstCtrlJoint, edit = 1, orientJoint = "xzy", secondaryAxisOrient = "xup", children = 1) cmds.setAttr(lastCtrlJoint + ".jointOrientX", 0) cmds.setAttr(lastCtrlJoint + ".jointOrientY", 0) cmds.setAttr(lastCtrlJoint + ".jointOrientZ", 0) cmds.bindSkin(spline, firstCtrlJoint)
def generate(self, params): print("OK !! " + str(params)) cmds.select(clear=True) cmds.joint(p=params["hip"]["point"],name="bassinBase") cmds.select("bassinBase") rigList = [params["neck"]["point"],params["shoulder_left"]["point"],params["elbow_left"]["point"],params["wrist_left"]["point"]] self.createListRig(rigList,"rigTop","bassinBase") cmds.select("bassinBase") rigList2 = [params["leg_left"]["point"],params["knee_left"]["point"],params["foot_left"]["point"]] self.createListRig(rigList2,"rigBot","bassinBase") cmds.select("rigTop1") cmds.mirrorJoint(mirrorYZ=True) cmds.select("rigBot0") cmds.mirrorJoint(mirrorYZ=True) cmds.select("bassinBase") cmds.select(params["mesh_name"],tgl=True) cmds.bindSkin()
def selectMesh(): global characterMesh characterMesh = mc.ls(sl=True) meshChildren = mc.ls(mc.listRelatives(characterMesh, ad=True, type="transform"), dag=True, lf=True, ni=True) print meshChildren #influences = [] #for i in SJ: #influences.append(i) #c = [] #c = mc.ls(mc.listRelatives(characterMesh, ad = True, type = "transform"), dag = True, lf = True, ni = True) #print c #for i in c: #print i #mc.skinCluster(influences,i, toSelectedBones=True, bindMethod=0, skinMethod=0, normalizeWeights=1) #WILL SMOOTH BIND INDIVIDUALLY. MAKE OPTION FOR UNNBIND #OR TELL THEM TO BIND SKIN THEN ENHANCE IT ###mc.skinCluster(characterMesh,mc.ls(sl=True), toSelectedBones=True, bindMethod=0, skinMethod=0, normalizeWeights=1, useGeometry = True) #mc.skinCluster(characterMesh,mc.ls(sl=True),smoothWeights = .1, bindMethod=0, skinMethod=0, normalizeWeights=1, weightDistribution = 0, dropoffRate = 1.0) tempSJ = [] tempSJ = LJR[:] + LJL[:] + AJR[:] + AJL[:] + SJ[1:] + RFL[:] + RFR[:] print "tempSJ: " + str(tempSJ) mc.bindSkin(characterMesh, tempSJ, tsb=True, cj=True) #cmds.select( ['pPlane1.vtx[5]', 'pPlane1.vtx[11]', 'pPlane1.vtx[17]', 'pPlane1.vtx[23]']) #cmds.percent( 'testCluster', v=0.5 ) #t = SJ[2:] #mc.flexor(t, type = "jointLattice", aj = True) mc.flexor(LJL[0], type="jointCluster", aj=True) mc.flexor(LJR[0], type="jointCluster", aj=True) mc.disable(bindMeshBtn, v=True)
def rigRope(arg=None): #input num_joints = int(mc.textField(num_joints_input, q=True, tx=True)) num_ctrls = int(mc.textField(num_ctrls_input, q=True, tx=True)) is_stretchy = mc.checkBox(is_stretchy_input, q=1, v=1) #save selection cyl = mc.ls(sl=1)[0] #deselect mc.select(d=1) #get start end values for joint bbox = mc.exactWorldBoundingBox(cyl) cyl_pivot = mc.xform(cyl, q=1, t=1) cyl_start = cyl_pivot[0], bbox[1], cyl_pivot[2] cyl_end = cyl_pivot[0], bbox[4], cyl_pivot[2] #create and orient joint joint_start = mc.joint(p=cyl_start) joint_end = mc.joint(p=cyl_end) mc.joint(joint_start, e=True, zso=True, oj='xyz') mc.joint(joint_end, e=True, zso=True, oj='xyz') #mc.setAttr(joint_start + ".visibility", 0)#hide joint #split joint space = (cyl_end[1] - cyl_start[1]) / num_joints prev_joint = joint_start for i in range(num_joints - 1): new_joint = mc.insertJoint(prev_joint) mc.move(space, new_joint, y=1, r=1) prev_joint = new_joint mc.move(cyl_end[0], cyl_end[1], cyl_end[2], joint_end, a=1, ws=1) #set spline ik ik_handle = mc.ikHandle(sj=joint_start, ee=joint_end, sol='ikSplineSolver', ccv=1, roc=1, scv=1)[0] #get curve ik_curve_shape = mc.ikHandle(q=1, c=1) ik_curve = mc.listRelatives(ik_curve_shape, p=1)[0] mc.setAttr(ik_handle + ".visibility", 0) #hide ik handle mc.setAttr(ik_curve + ".visibility", 0) #hide ik curve #stretchy joints if (is_stretchy): #create curve info node and add attr curve_info_node = mc.arclen(ik_curve, ch=1) mc.addAttr(curve_info_node, longName='normalizedScale', attributeType='float') print(curve_info_node) curve_length = mc.getAttr(curve_info_node + '.arcLength') #create multiply/divide node divide_node = mc.createNode('multiplyDivide', n=ik_curve + '_normalizedScale') mc.setAttr(divide_node + ".operation", 2) #make connections mc.connectAttr(curve_info_node + ".arcLength", divide_node + ".input1X") mc.setAttr(divide_node + ".input2X", curve_length) mc.connectAttr(divide_node + ".outputX", curve_info_node + ".normalizedScale") #connect to joints scaleY chain_joints = mc.ikHandle(ik_handle, q=1, jl=1) for jnt in chain_joints: mc.connectAttr(curve_info_node + ".normalizedScale", jnt + ".scaleY") #bind cylinder to joints mc.bindSkin(cyl, joint_start) #create floating joints and ctrls circle_ctrl = mc.circle(nr=(0, 1, 0), c=cyl_start, r=0.5) mc.xform(circle_ctrl, cp=1) #base base_ctrl = mc.duplicate(circle_ctrl, n='base_jnt_Ctrl') mc.select(d=1) base_joint = mc.joint(p=cyl_start, n='base_joint') mc.parent(base_joint, base_ctrl) mc.setAttr(base_joint + ".visibility", 0) #hide joint #tip tip_ctrl = mc.duplicate(circle_ctrl, n='tip_jnt_Ctrl') mc.move(cyl_end[1] - cyl_start[1], tip_ctrl, y=1, r=1) mc.select(d=1) tip_joint = mc.joint(p=cyl_end, n='tip_joint') mc.parent(tip_joint, tip_ctrl) mc.setAttr(tip_joint + ".visibility", 0) #hide joint #mid space = (cyl_end[1] - cyl_start[1]) / (num_ctrls - 1) mid_joints = [] parent_ctrl = base_ctrl for i in range(num_ctrls - 2): mid_ctrl = mc.duplicate(circle_ctrl, n='mid_joint' + str(i + 1) + '_Ctrl') mc.select(d=1) mid_joint = mc.joint(p=cyl_start, n='mid_joint' + str(i + 1)) mc.move(space * (i + 1), mid_joint, y=1, r=1) mc.move(space * (i + 1), mid_ctrl, y=1, r=1) mc.parent(mid_joint, mid_ctrl) mc.parent(mid_ctrl, parent_ctrl) mc.setAttr(mid_joint + ".visibility", 0) #hide joint mid_joints.append(mid_joint) parent_ctrl = mid_ctrl mc.parent(tip_ctrl, parent_ctrl) mc.delete(circle_ctrl) #bind curve to floating joints curve_skin_cluster = mc.skinCluster(ik_curve, base_joint, tip_joint) for jnt in mid_joints: mc.skinCluster(curve_skin_cluster, e=1, ai=jnt) #create master ctrl #double circle large_circle = mc.circle(nr=(0, 1, 0), c=cyl_start, n='Rope_MASTER_Ctrl') small_circle = mc.circle(nr=(0, 1, 0), c=cyl_start, r=0.85, n='smallCircle') circle_shape = mc.listRelatives(small_circle, s=1) mc.parent(circle_shape, large_circle, add=1, s=1) mc.xform(large_circle, cp=1) mc.makeIdentity(apply=True, t=1, r=1, s=1, n=0) mc.delete(small_circle) mc.parent(base_ctrl, large_circle) #group joint chain and parent constrain jnt_chain_grp = mc.group(joint_start, n='jointChain_grp', w=1) mc.parentConstraint(large_circle, jnt_chain_grp) #group everything mc.group(cyl, ik_curve, ik_handle, large_circle, jnt_chain_grp, n='rope_##', r=1)
def generate(self, nombre, headVal, bodyVal, leftArmVal, rightArmVal, leftLegVal, rightLegVal): #model head: headName = 'head' + randomNaming cmds.polyCube(name=headName,d = headVal, h = headVal, w = headVal) cmds.move(10, y=True) cmds.polySmooth( headName + '.f[0:5]', dv=headVal ) #model body: bodyName = 'body' + randomNaming bodyJ1 = 'bodyJ1' + randomNaming bodyJ2 = 'bodyJ2' + randomNaming bodyJ3 = 'bodyJ3' + randomNaming cmds.polyCube(name=bodyName, w = bodyVal, h = bodyVal*3, d= bodyVal) cmds.move(8, y=True) cmds.polySmooth( bodyName+'.f[0:5]', dv=bodyVal ) cmds.select( d=True ) cmds.joint(n=bodyJ1, p=(0, 9, 0) ) cmds.joint(n=bodyJ2, p=(0, 8, 0) ) cmds.joint(n=bodyJ3, p=(0, 7, 0) ) cmds.ikHandle( sj=bodyJ1, ee=bodyJ3) cmds.bindSkin( bodyName, bodyJ1) #model leftArm: leftArm = 'leftArm' + randomNaming leftArmJ = 'leftArmJ' + randomNaming leftElbowJ = 'leftElbowJ'+randomNaming leftWristJ = 'leftWristJ'+randomNaming cmds.polyCube(name=leftArm, w = leftArmVal*2, h = leftArmVal*0.25, d = leftArmVal) cmds.scale(0.3, z = True) cmds.move(1,8.5,0) cmds.xform(r= True, ro=(0, 0, -45) ) cmds.polySmooth( leftArm+'.f[0:5]', dv=leftArmVal ) cmds.select( d=True ) cmds.joint(n=leftArmJ, p=(0.5, 9, 0) ) cmds.joint(n=leftElbowJ, p=(1, 8.5, 0) ) cmds.joint(n=leftWristJ, p=(1.5, 8, 0) ) cmds.ikHandle( sj=leftArmJ, ee=leftWristJ) cmds.bindSkin( leftArm, leftArmJ) #model rightArm: rightArm = 'rightArm' + randomNaming rightArmJ = 'rightArmJ'+ randomNaming rightElbowJ = 'rightElbowJ'+randomNaming rightWristJ = 'rightWristJ'+randomNaming cmds.polyCube(name=rightArm, w =rightArmVal*2, h = rightArmVal*0.25, d = rightArmVal) cmds.scale(0.3, z = True) cmds.move(-1,8.5,0) cmds.xform(r= True, ro=(0, 0, 45) ) cmds.polySmooth( rightArm + '.f[0:5]', dv=rightArmVal ) cmds.select( d=True ) cmds.joint(n=rightArmJ, p=(-0.5, 9, 0) ) cmds.joint(n=rightElbowJ, p=(-1, 8.5, 0) ) cmds.joint(n=rightWristJ, p=(-1.5, 8, 0) ) cmds.ikHandle( sj=rightArmJ, ee=rightWristJ) cmds.bindSkin( rightArm, rightArmJ) #model leftLeg: leftLeg = 'leftLeg' + randomNaming leftLegJ = 'leftLegJ' + randomNaming leftLegKneeJ = 'leftLegKneeJ'+randomNaming leftLegCalvesJ = 'leftLegCalvesJ' +randomNaming cmds.polyCube(name=leftLeg, w =leftLegVal*0.3, h = leftLegVal*3.5, d = leftLegVal) cmds.scale(0.3, z = True) cmds.move(-0.3,6,0) cmds.polySmooth( leftLeg + '.f[0:5]', dv=leftLegVal ) cmds.select( d=True ) cmds.joint(n=leftLegJ, p=(-0.3, 7, 0) ) cmds.joint(n=leftLegKneeJ, p=(-0.3, 6, 0) ) cmds.joint(n=leftLegCalvesJ, p=(-0.3, 5, 0) ) cmds.ikHandle( sj=leftLegJ, ee=leftLegCalvesJ) cmds.bindSkin( leftLeg, leftLegJ) #model rightLeg: rightLeg = 'rightLeg' + randomNaming rightLegJ = 'rightLegJ'+ randomNaming rightLegKneeJ = 'rightLegKneeJ'+randomNaming rightLegCalvesJ = 'rightLegCalvesJ'+randomNaming cmds.polyCube(name=rightLeg, w = rightLegVal*0.3, h = rightLegVal*3.5, d = rightLegVal) cmds.scale(0.3, z = True) cmds.move(0.3,6,0) cmds.polySmooth( rightLeg +'.f[0:5]', dv=rightLegVal ) cmds.select( d=True ) cmds.joint(n=rightLegJ, p=(0.3, 7, 0) ) cmds.joint(n=rightLegKneeJ, p=(0.3, 6, 0) ) cmds.joint(n=rightLegCalvesJ, p=(0.3, 5, 0) ) cmds.ikHandle( sj=rightLegJ, ee=rightLegCalvesJ) cmds.bindSkin( rightLeg, rightLegJ) #group everything: cmds.group(headName, bodyName, leftArm, rightArm, leftLeg, rightLeg, n=nombre)
def BindCallback(*Args): #cmds.select('root') cmds.bindSkin('root')
def createLimb(self, controlSize): getGuide=cmds.ls("*_guide") spine=(cmds.ls("spine*_guide")) spineTwist=(cmds.ls("spine*_guide")) spineSection=len(spine)/3 sudoSpine=spine[:1]+[spine[spineSection]]+spine[-spineSection-1::spineSection+1]+spine[-1:] cmds.select(cl=1) lastSpineJoint=spine[-1:] for each in spine: jointSuffix='_jnt' getClass.rigJoints(each, jointSuffix) cmds.select(cl=1) for each in spine: jointSuffix='FK_jnt' getClass.rigJoints(each, jointSuffix) cmds.select(cl=1) for each in spine: jointSuffix='IK_jnt' getClass.rigJoints(each, jointSuffix) cmds.select(cl=1) #for each in spine[::2]: for each in spine: jointSuffix='_Clst_jnt' getClass.rigJoints(each, jointSuffix) resetOrient=[ "spine01_jnt", "spine01FK_jnt", "spine01IK_jnt", ] for each in resetOrient: cmds.joint( each, e=1, children=1, zso=1, oj='xyz', sao='yup', spa=1) cmds.select(cl=1) ################################## ################################## ################################## ################################## ######################CONTROLLERS translations=[".tx", ".ty", ".tz"] rotation=[".rx", ".ry", ".rz"] FKSpineJoints=[(each) for each in cmds.listRelatives("spine01FK_jnt", ad=1, typ="joint")] FKSpineJoints.append("spine01FK_jnt") fkSpine=sorted(FKSpineJoints) bindSpine=[(each) for each in cmds.listRelatives("spine01_jnt", ad=1, typ="joint") if "spine" in each] bindSpine.append("spine01_jnt") lastSpineJoint=bindSpine[-1:] lastSpine=lastSpineJoint[0].split("_") colour1=18 colour2=colour1 colour3=colour1 transformWorldMatrix = cmds.xform(spine[-1:], q=True, wd=1, t=True) rotateWorldMatrix = cmds.xform(spine[-1:], q=True, wd=1, ro=True) getClass.guideBuild(each, transformWorldMatrix, rotateWorldMatrix, colour1, colour2, colour3 ) getsel=cmds.ls(sl=1) cmds.setAttr(getsel[0]+".overrideColor", colour1) cmds.rename(getsel[0], "spineArmParent_nod") getsel=cmds.ls(sl=1) getClass.buildGrp(getsel[0]) clusterSpline=cmds.ls("spine*Clst_jnt") CLSspine=cmds.listRelatives(clusterSpline[0], ad=1, typ="joint") spineFK_Ctrls=[] spineIK_CLSTR=[] spine=cmds.ls("spine*_guide") if spine[ len(spine) / 2 - 1] < spine[ len(spine) / 2 ]: clstrSplineCtrl=spine[ len(spine) / 2 - 1] else: clstrSplineCtrl=spine[ len(spine) / 2 ] # clstrSplineCnt= spine[::2] # #clstrSplineCnt= spine # clstrSplineCtrl=clstrSplineCnt[1:-1] clstrCtrl=[] #create the hips transformWorldMatrix = cmds.xform(spine[:1], q=True, wd=1, t=True) rotateWorldMatrix = cmds.xform(spine[:1], q=True, wd=1, ro=True) name="Hips_Ctrl" grpname="Hips_grp" size=controlSize[0] colour=13 nrx=0 nry=1 nrz=0 getClass.buildCtrl(spine[:1], name, grpname,transformWorldMatrix, rotateWorldMatrix, size, colour, nrx, nry, nrz) spineFK_Ctrls.append("Hips_Ctrl") #spineFK_Ctrls.append(clstrCtrl)4 #create clusters for IK chain lognm=clstrSplineCtrl.replace("guide", "clst") name="Torso_IK_Ctrl" grpname="Torso_IK_grp" size=controlSize[1] colour=13 nrx=0 nry=1 nrz=0 transformWorldMatrix = cmds.xform(clstrSplineCtrl, q=True, wd=1, t=True) rotateWorldMatrix = cmds.xform(clstrSplineCtrl, q=True, wd=1, ro=True) getClass.buildCtrl(clstrSplineCtrl, name, grpname,transformWorldMatrix, rotateWorldMatrix, size, colour, nrx, nry, nrz) getClass.buildGrp(name) clstrCtrl.append(name) cmds.setAttr(name+".sx" , keyable=0, lock=1) cmds.setAttr(name+".sy" , keyable=0, lock=1) cmds.setAttr(name+".sz", keyable=0, lock=1) FKCtrl=[] spineguides=cmds.ls("spine*_guide") for each in spineguides[::2]: FKTorsoJoint=each.split("_guide")[0]+"FK_jnt" name=each.split("_guide")[0]+"_FK_ctrl" grpname=each.split("_guide")[0]+"_FK_grp" size=controlSize[1] colour=6 nrx=0 nry=1 nrz=0 transformWorldMatrix = cmds.xform(each, q=True, wd=1, t=True) rotateWorldMatrix = cmds.xform(each, q=True, wd=1, ro=True) getClass.buildCtrl(each, name, grpname,transformWorldMatrix, rotateWorldMatrix, size, colour, nrx, nry, nrz) spineFK_Ctrls.append(name) FKCtrl.append(name) cmds.parentConstraint(name, FKTorsoJoint , mo=1) name="LowerBody_Ctrl" grpname="LowerBody_grp" size=controlSize[0] colour=22 nrx=0 nry=1 nrz=0 transformWorldMatrix = cmds.xform(spine[1:2], q=True, wd=1, t=True) rotateWorldMatrix = cmds.xform(spine[1:2], q=True, wd=1, ro=True) getClass.buildCtrl(spine[:1], name, grpname,transformWorldMatrix, rotateWorldMatrix, size, colour, nrx, nry, nrz) name="WaistFollow_Ctrl" grpname="WaistFollow_grp" size=35 colour=22 nrx=0 nry=1 nrz=0 transformWorldMatrix = cmds.xform(spine[:1], q=True, wd=1, t=True) rotateWorldMatrix = cmds.xform(spine[:1], q=True, wd=1, ro=True) getClass.buildCtrl(spine[:1], name, grpname,transformWorldMatrix, rotateWorldMatrix, size, colour, nrx, nry, nrz) name="WaistFollow_offset_Ctrl" grpname="WaistFollow_offset_grp" size=controlSize[0] colour=23 nrx=0 nry=1 nrz=0 getClass.buildCtrl(spine[:1], name, grpname,transformWorldMatrix, rotateWorldMatrix, size, colour, nrx, nry, nrz) cmds.group( em=True, name='IK_grp' ) #create the main controller cmds.circle(n="Master_Ctrl", r=30, nrx=0, nry=1, nrz=0) cmds.setAttr("Master_CtrlShape.overrideEnabled", 1) cmds.setAttr("Master_CtrlShape.overrideColor", 13) getClass.buildGrp("Master_Ctrl") cmds.circle(n="Main_Ctrl", r=25, nrx=0, nry=1, nrz=0) cmds.setAttr("Main_CtrlShape.overrideEnabled", 1) cmds.setAttr("Main_CtrlShape.overrideColor", 17) getClass.buildGrp("Main_Ctrl") cmds.circle(n="Main_offset_Ctrl", r=27, nrx=0, nry=1, nrz=0) cmds.setAttr("Main_offset_CtrlShape.overrideEnabled", 1) cmds.setAttr("Main_offset_CtrlShape.overrideColor", 23) getClass.buildGrp("Main_offset_Ctrl") #create the IK controller name="Chest_IK_Ctrl" grpname="ChestIK_grp" num=controlSize[1] colour=13 nrx=0 nry=1 nrz=0 transformWorldMatrix = cmds.xform(spine[-2:-1], q=True, wd=1, t=True) rotateWorldMatrix = cmds.xform(spine[-2:-1], q=True, wd=1, ro=True) # transformWorldMatrix = cmds.xform(spine[-1:], q=True, wd=1, t=True) # rotateWorldMatrix = cmds.xform(spine[-1:], q=True, wd=1, ro=True) getClass.buildCtrl(each, name, grpname,transformWorldMatrix, rotateWorldMatrix, size, colour, nrx, nry, nrz) #getClass.squareI(name, grpname, num, transformWorldMatrix, rotateWorldMatrix, colour) cmds.makeIdentity("Chest_IK_Ctrl", a=True, t=1, s=1, r=1, n=0) OrigName="Chest_FK" num=controlSize[1] colour=6 nrx=0 nry=1 nrz=0 eachPiece=OrigName+"_jnt" name=OrigName+"_Ctrl" grpname=OrigName+"_grp" transformWorldMatrix = cmds.xform(spine[-1:], q=True, wd=1, t=True) rotateWorldMatrix = cmds.xform(spine[-1:], q=True, wd=1, ro=True) getClass.buildCtrl(each, name, grpname,transformWorldMatrix, rotateWorldMatrix, size, colour, nrx, nry, nrz) cmds.makeIdentity("Chest_FK_Ctrl", a=True, t=1, s=1, r=1, n=0) spineFK_Ctrls.append("Chest_FK_Ctrl") #IK #'''-------------------------------------- # SPINE #--------------------------------------''' spineJoints=(cmds.ls("spine*_jnt")) lastJoint=spineJoints[-1:] spineTwistJnt=(cmds.ls("spine*IK_jnt")) spineLow=(cmds.ls("spine*FK_jnt")) spineCtrl=(cmds.ls("spine*_Ctrl")) #spineCtrlGrp=cmds.pickWalk(spineCtrl, d="up") '''-------------------------------------- # set axis for scale --------------------------------------''' scaleAxis='X' lastSpineJoint=spineTwistJnt[-1:] allButLastspineJoints=spineJoints[:-1] '''-------------------------------------- # create spline IK --------------------------------------''' cmds.ikHandle(n="spineIK", sj="spine01IK_jnt", ee=str(lastSpineJoint[0]), sol="ikSplineSolver", scv=0, ns=4, rtm=1) '''-------------------------------------- # find the spline of the IK --------------------------------------''' list=cmds.listConnections('spineIK', t="shape") cmds.rename(list, "spineIK_crv") '''-------------------------------------- # get length of spline --------------------------------------''' curvInf=cmds.arclen("spineIK_crv", ch=1) '''-------------------------------------- # connect the length to a multiplyDivide --------------------------------------''' MDshader=cmds.shadingNode( "multiplyDivide", au=1) '''-------------------------------------- # set multiplyDivide to Divide --------------------------------------''' cmds.setAttr(str(MDshader)+".operation", 2) '''-------------------------------------- # connect length of spline to MD node --------------------------------------''' cmds.connectAttr(curvInf+".arcLength", MDshader+".input1"+scaleAxis, f=1) '''-------------------------------------- # input the length into the second input --------------------------------------''' spineCrvLength=cmds.getAttr(MDshader+".input1"+scaleAxis) cmds.setAttr(MDshader+".input2"+scaleAxis,spineCrvLength) '''-------------------------------------- # skinbind lowres spine to the spline --------------------------------------''' for each in CLSspine: cmds.bindSkin(each,"spineIK_crv") #cmds.bindSkin(clusterSpline[0],"spineIK_crv") cmds.addAttr("Hips_Ctrl", ln="spineFK_IK", min=0, max=1, at="double",en="FK:IK:", k=1, nn="spineFK_IK") cmds.setAttr("Hips_Ctrl.spineFK_IK", 1) Controller="Hips_Ctrl.spineFK_IK" baseSpine=[(each.split("_")[0])for each in bindSpine] #IK setup for each in baseSpine: getClass.blendColors(each, Controller) getSortedclusterSpline=cmds.ls("spine*_Clst_jnt") if getSortedclusterSpline[ len(getSortedclusterSpline) / 2 - 1] < getSortedclusterSpline[ len(getSortedclusterSpline) / 2 ]: clstrSplineCtrl=getSortedclusterSpline[ len(getSortedclusterSpline) / 2 - 1] else: clstrSplineCtrl=getSortedclusterSpline[ len(getSortedclusterSpline) / 2 ] cmds.pointConstraint(clstrCtrl, clstrSplineCtrl, mo=1) num0, num1, num2, num3 = 1, .5, .7, .9 colour=13 for each in getSortedclusterSpline[1:-1]: name=each+"_Ctrl" grpname=each+"_grp" cmds.parent(each, w=1) getTranslation, getRotation=getClass.locationXForm(each) getClass.CCCircle(name, grpname, num0, num1, num2, num3,getTranslation, getRotation, colour) cmds.parentConstraint(name, each) fkSpine=sorted(FKSpineJoints) ChildActivatedValue=1 ChildDeactivatedValue=0 ControllerSecondValue=1 ControllerFirstValue=0 Controller="Hips_Ctrl.spineFK_IK" defaultSet=1 for each in clstrCtrl: Child=each+".visibility" getClass.controlSecondValueChildOn(Controller, Child, defaultSet, ChildActivatedValue, ChildDeactivatedValue, ControllerSecondValue, ControllerFirstValue) #constrain FK spin to controls #cmds.parent(spineFK_Ctrls[0], "Hips_Ctrl") cmds.pointConstraint("Hips_Ctrl", "spine01_jnt", mo=1) cmds.orientConstraint("Chest_FK_Ctrl", fkSpine[-1], mo=1) ChildActivatedValue=1 ChildDeactivatedValue=0 ControllerSecondValue=1 ControllerFirstValue=0 Child="Chest_IK_Ctrl.visibility" Controller="Hips_Ctrl.spineFK_IK" defaultSet=1 getClass.controlSecondValueChildOn(Controller, Child, defaultSet, ChildActivatedValue, ChildDeactivatedValue, ControllerSecondValue, ControllerFirstValue) ChildActivatedValue=1 ChildDeactivatedValue=0 ControllerSecondValue=1 ControllerFirstValue=0 Child="Chest_FK_Ctrl.visibility" Controller="Hips_Ctrl.spineFK_IK" defaultSet=1 getClass.controlFirstValueChildOn(Controller, Child, defaultSet, ChildActivatedValue, ChildDeactivatedValue, ControllerSecondValue, ControllerFirstValue) #stretch getIKClass.stretchSpline("spine01IK_jnt") cmds.addAttr("Hips_Ctrl", ln="StretchSpine", at="enum",en="on:off:", k=1, nn="StretchSpine") ChildActivatedValue=2 ChildDeactivatedValue=0 ControllerSecondValue=1 ControllerFirstValue=0 Child="spine01IK_jnt_cond.operation" Controller="Hips_Ctrl.StretchSpine" defaultSet=0 getClass.controlFirstValueChildOn(Controller, Child, defaultSet, ChildActivatedValue, ChildDeactivatedValue, ControllerSecondValue, ControllerFirstValue) ChildActivatedValue=1 ChildDeactivatedValue=0 ControllerSecondValue=1 ControllerFirstValue=0 Controller="Hips_Ctrl.spineFK_IK" defaultSet=1 for each in FKCtrl: Child=each+".visibility" getClass.controlFirstValueChildOn(Controller, Child, defaultSet, ChildActivatedValue, ChildDeactivatedValue, ControllerSecondValue, ControllerFirstValue) cmds.setAttr("Hips_Ctrl.spineFK_IK", 1) cmds.parent("Main_Ctrl_grp", "Main_offset_Ctrl") cmds.parent("Main_offset_Ctrl_grp", "Master_Ctrl") lastClstr=cmds.listRelatives(clstrCtrl, ap=1) firstClstr=cmds.listRelatives(clstrCtrl, ap=1) # else: lastFK=cmds.listRelatives(FKCtrl, ap=1) firstFK=cmds.listRelatives(FKCtrl, ap=1) lastFKCtrl=FKCtrl firstFKCtrl=FKCtrl bindSpine=[(each) for each in cmds.listRelatives("spine01_jnt", ad=1, typ="joint") if "spine" in each] cmds.parent(firstFK, "Hips_Ctrl") cmds.parent("Hips_grp","LowerBody_Ctrl") cmds.parent("ChestIK_grp","LowerBody_Ctrl") cmds.parent("LowerBody_grp","Main_Ctrl") cmds.parent("spine01_jnt","Hips_Ctrl") cmds.parent("spine01FK_jnt","Hips_Ctrl") cmds.parent("spine01IK_jnt","Hips_Ctrl") cmds.connectAttr("Chest_IK_Ctrl.rotate.rotateY", "spineIK.twist") cmds.parent("Main_offset_Ctrl_grp", "WaistFollow_Ctrl") cmds.parent("WaistFollow_grp", "WaistFollow_offset_Ctrl") cmds.parent("WaistFollow_offset_grp", "Master_Ctrl") cmds.setAttr("WaistFollow_CtrlShape.visibility" , 0) cmds.setAttr("WaistFollow_offset_CtrlShape.visibility" , 0) spineChildBones=[(each) for each in cmds.listRelatives('spine01_jnt', ad=1, typ="joint") if "spine" in each] cmds.parent("spineIK","Chest_IK_Ctrl") cmds.parent("spineArmParent_nod_grp", spineChildBones[0]) seq=cmds.ls("spine*Clst_jnt") size=3 getClusterChunk=[] getMiddleClusters=[] splitsize = 1.0/size*len(seq) for i in range(size): getClusterChunk.append(seq[int(round(i*splitsize)):int(round((i+1)*splitsize))]) # getClusterChunk=[seq[i:i+size] for i in range(0, len(seq), size)] for each in getClusterChunk[0]: cmds.parent(each, "Hips_Ctrl") if len(getClusterChunk[0])>1: cmds.parent(getClusterChunk[0][-1:],"Torso_IK_Ctrl") else: pass for each in getClusterChunk[1]: cmds.parent(each,"Torso_IK_Ctrl") for each in getClusterChunk[2]: cmds.parent(each, "Chest_IK_Ctrl") if len(getClusterChunk[2])>1: cmds.parent(getClusterChunk[2][0],"Torso_IK_Ctrl") else: pass poleAxis=("X", "Y", "Z") for each in poleAxis: cmds.connectAttr("Chest_IK_Ctrl.rotate.rotate"+each, "spineIK.poleVector.poleVector"+each) getMidClstr=cmds.ls("spine*_Clst_jnt_grp") num = float(len(getMidClstr))/size getMiddleClusters = [ getMidClstr [i:i + int(num)] for i in range(0, (size-1)*int(num), int(num))] getMiddleClusters.append(getMidClstr[(size-1)*int(num):]) if len(getMiddleClusters[0])>1: cmds.parentConstraint("Hips_Ctrl", getMiddleClusters[0][0], mo=1, w=.8) cmds.parentConstraint("Torso_IK_Ctrl", getMiddleClusters[0][0], mo=1, w=.2) cmds.parentConstraint("Hips_Ctrl", getMiddleClusters[0][1], mo=1, w=.4) cmds.parentConstraint("Torso_IK_Ctrl", getMiddleClusters[0][1], mo=1, w=.6) else: cmds.parentConstraint("Hips_Ctrl", getMiddleClusters[0], mo=1, w=1.0) if len(getMiddleClusters[1])>1: cmds.parentConstraint("Hips_Ctrl", getMiddleClusters[1][0], mo=1, w=.3) cmds.parentConstraint("Torso_IK_Ctrl", getMiddleClusters[1][0], mo=1, w=.7) cmds.parentConstraint("Chest_IK_Ctrl", getMiddleClusters[1][1], mo=1, w=.3) cmds.parentConstraint("Torso_IK_Ctrl", getMiddleClusters[1][1], mo=1, w=.7) else: cmds.parentConstraint("Torso_IK_Ctrl", getMiddleClusters[1], mo=1, w=1.0) if len(getMiddleClusters[2])>1: cmds.parentConstraint("Chest_IK_Ctrl", getMiddleClusters[2][0], mo=1, w=.4) cmds.parentConstraint("Torso_IK_Ctrl", getMiddleClusters[2][0], mo=1, w=.6) cmds.parentConstraint("Chest_IK_Ctrl", getMiddleClusters[2][1], mo=1, w=.8) cmds.parentConstraint("Torso_IK_Ctrl", getMiddleClusters[2][1], mo=1, w=.2) else: cmds.parentConstraint("Chest_IK_Ctrl", getMiddleClusters[2], mo=1, w=1.0) cmds.parentConstraint( "Hips_Ctrl", "Torso_IK_grp",mo=1, w=.50) cmds.parentConstraint( "Chest_IK_Ctrl", "Torso_IK_grp",mo=1, w=.50) #lock off head cmds.parentConstraint("spineIK","spineArmParent_nod_grp", mo=1) ChildActivatedValue=1 ChildDeactivatedValue=0 ControllerSecondValue=1 ControllerFirstValue=0 Child="spineArmParent_nod_grp_parentConstraint1.spineIKW0" Controller="Hips_Ctrl.spineFK_IK" defaultSet=1 getClass.controlSecondValueChildOn(Controller, Child, defaultSet, ChildActivatedValue, ChildDeactivatedValue, ControllerSecondValue, ControllerFirstValue) #create control on the ends of the IK spline #cmds.disconnectAttr("spine01IK_jnt_cond.outColorR", "spine06IK_jnt.scale.scaleX") cmds.disconnectAttr("spine01IK_jnt_cond.outColorR", "spine07IK_jnt.scale.scaleX") cmds.disconnectAttr("spine01IK_jnt_cond.outColorR", "spine01IK_jnt.scale.scaleX") #lock off IK spline Vector="X" YUpswitch=0 cmds.setAttr("spineIK.dTwistControlEnable", 0) cmds.setAttr("spineIK.dWorldUpType", 4) cmds.setAttr("spineIK.dWorldUpAxis", 1) cmds.connectAttr("Hips_Ctrl.xformMatrix", "spineIK.dWorldUpMatrix", f=1) cmds.connectAttr("Chest_IK_Ctrl.xformMatrix", "spineIK.dWorldUpMatrixEnd", f=1) cmds.setAttr("spineIK.dWorldUpVector"+Vector, 1) cmds.setAttr("spineIK.dWorldUpVectorEnd"+Vector, 1) if YUpswitch==0: cmds.setAttr("spineIK.dWorldUpVectorY", YUpswitch) cmds.setAttr("spineIK.dWorldUpVectorEndY", YUpswitch) else: pass cmds.setAttr("spineIK.ikFkManipulation", 1) if len(FKCtrl)>1: lastFK=cmds.listRelatives(FKCtrl[-1:], ap=1) firstFK=cmds.listRelatives(FKCtrl[:1], ap=1) lastFKCtrl=FKCtrl[-1:] firstFKCtrl=FKCtrl[:1] for eachctrl in xrange(len(FKCtrl) - 1): current_item, next_item = FKCtrl[eachctrl], FKCtrl[eachctrl + 1] getParentgrp=cmds.listRelatives(next_item, ap=1) cmds.parent(getParentgrp[0], current_item) cmds.parent("Chest_FK_grp", FKCtrl[-1:]) else: cmds.parent("Chest_FK_grp", FKCtrl[0])
def __init__(self): getGuide=cmds.ls("*_guide") neck=(cmds.ls("neck*_guide")) head=(cmds.ls("head*_guide")) spine=(cmds.ls("spine*_guide")) spineTwist=(cmds.ls("spine*_guide")) spineSection=len(spine)/3 neckTwist=[neck[0]]+["head01_guide"] sudoSpine=spine[:1]+[spine[spineSection]]+spine[-spineSection-1::spineSection+1]+spine[-1:] getLimbs=(neck, head, spine) cmds.select(cl=1) lastSpineJoint=spine[-1:] for each in spine: jointSuffix='_jnt' getClass.rigJoints(each, jointSuffix) cmds.select(cl=1) for each in spine: jointSuffix='FK_jnt' getClass.rigJoints(each, jointSuffix) cmds.select(cl=1) for each in spine: jointSuffix='IK_jnt' getClass.rigJoints(each, jointSuffix) cmds.select(cl=1) for each in spine[::2]: jointSuffix='_Clst_jnt' getClass.rigJoints(each, jointSuffix) getTranslation=cmds.xform("neck01_guide", q=1, t=1) cmds.joint(p=getTranslation) cmds.select(cl=1) for each in neck: jointSuffix='_jnt' getClass.rigJoints(each, jointSuffix) cmds.select(cl=1) cmds.select(cl=1) for each in head: jointSuffix='_jnt' getClass.rigJoints(each, jointSuffix) cmds.select(cl=1) try: neckChildBones=cmds.listRelatives('neck01_jnt', ad=1, typ="joint") lastNeckJoint=neckChildBones[:1] except: lastNeckJoint='neck01_jnt' spineChildBones=cmds.listRelatives('spine01_jnt', ad=1, typ="joint") cmds.parent("neck01_jnt", spineChildBones[:1]) cmds.parent("head01_jnt", lastNeckJoint) resetOrient=[ "spine01_jnt", "spine01FK_jnt", "spine01IK_jnt", "head01_jnt" ] for each in resetOrient: cmds.joint( each, e=1, children=1, zso=1, oj='xyz', sao='yup', spa=1) cmds.select(cl=1) ################################## ################################## ################################## ################################## ######################CONTROLLERS translations=[".tx", ".ty", ".tz"] rotation=[".rx", ".ry", ".rz"] loResSpine=[(each) for each in cmds.listRelatives("spine01FK_jnt", ad=1, typ="joint")] loResSpine.append("spine01FK_jnt") bindSpine=[(each) for each in cmds.listRelatives("spine01_jnt", ad=1, typ="joint") if "spine" in each] bindSpine.append("spine01_jnt") lastSpineJoint=bindSpine[-1:] lastSpine=lastSpineJoint[0].split("_") colour1=18 colour2=colour1 colour3=colour1 transformWorldMatrix = cmds.xform(spine[-1:], q=True, wd=1, t=True) rotateWorldMatrix = cmds.xform(spine[-1:], q=True, wd=1, ro=True) getClass.guideBuild(each, transformWorldMatrix, rotateWorldMatrix, colour1, colour2, colour3 ) getsel=cmds.ls(sl=1) cmds.setAttr(getsel[0]+".overrideColor", colour1) cmds.rename(getsel[0], "spineArmParent_nod") getsel=cmds.ls(sl=1) getClass.buildGrp(getsel[0]) CLSspine=cmds.listRelatives("spine01_Clst_jnt", ad=1, typ="joint") getCLSspine=[(each) for each in CLSspine if "spine" in each] getSpineClstParts=spine[1:-1] spineFK_Ctrls=[] spineIK_CLSTR=[] spine=cmds.ls("spine*_guide") clstrSplineCnt= spine[::2] clstrSplineCtrl=clstrSplineCnt[1:-1] clstrCtrl=[] FKCtrl=[] #create clusters for IK chain for each in clstrSplineCtrl: name=each+"_ctrl" grpname=each+"_grp" size=12 colour=13 nrx=0 nry=1 nrz=0 transformWorldMatrix = cmds.xform(each, q=True, wd=1, t=True) rotateWorldMatrix = cmds.xform(each, q=True, wd=1, ro=True) getClass.buildCtrl(each, name, grpname,transformWorldMatrix, rotateWorldMatrix, size, colour, nrx, nry, nrz) getClass.buildGrp(name) clstrCtrl.append(name) name=each+"FK_ctrl" grpname=each+"FK_grp" size=10 colour=6 nrx=0 nry=1 nrz=0 transformWorldMatrix = cmds.xform(each, q=True, wd=1, t=True) rotateWorldMatrix = cmds.xform(each, q=True, wd=1, ro=True) getClass.buildCtrl(each, name, grpname,transformWorldMatrix, rotateWorldMatrix, size, colour, nrx, nry, nrz) #getClass.buildGrp(name) # cmds.setAttr(each+"FK_ctrl.tx", l=1, cb=0) # cmds.setAttr(each+"FK_ctrl.ty", l=1, cb=0) # cmds.setAttr(each+"FK_ctrl.tz", l=1, cb=0) FKCtrl.append(name) #create the hips transformWorldMatrix = cmds.xform(spine[:1], q=True, wd=1, t=True) rotateWorldMatrix = cmds.xform(spine[:1], q=True, wd=1, ro=True) name="Hips_ctrl" grpname="Hips_grp" size=12 colour=22 nrx=0 nry=1 nrz=0 getClass.buildCtrl(spine[:1], name, grpname,transformWorldMatrix, rotateWorldMatrix, size, colour, nrx, nry, nrz) spineFK_Ctrls.append("Hips_ctrl") spineFK_Ctrls.append(FKCtrl) #spineFK_Ctrls.append(clstrCtrl) name="UpperBody_ctrl" grpname="UpperBody_grp" size=16 colour=13 nrx=0 nry=1 nrz=0 getClass.buildCtrl(spine[:1], name, grpname,transformWorldMatrix, rotateWorldMatrix, size, colour, nrx, nry, nrz) cmds.group( em=True, name='IK_grp' ) #create the main controller cmds.circle(n="Master_ctrl", r=30, nrx=0, nry=1, nrz=0) cmds.setAttr("Master_ctrlShape.overrideEnabled", 1) cmds.setAttr("Master_ctrlShape.overrideColor", 13) getClass.buildGrp("Master_ctrl") cmds.circle(n="Main_ctrl", r=25, nrx=0, nry=1, nrz=0) cmds.setAttr("Main_ctrlShape.overrideEnabled", 1) cmds.setAttr("Main_ctrlShape.overrideColor", 17) getClass.buildGrp("Main_ctrl") cmds.circle(n="Main_offset_ctrl", r=27, nrx=0, nry=1, nrz=0) cmds.setAttr("Main_offset_ctrlShape.overrideEnabled", 1) cmds.setAttr("Main_offset_ctrlShape.overrideColor", 23) getClass.buildGrp("Main_offset_ctrl") #create the IK controller name="Chest_ctrl" num=12 colour=13 transformWorldMatrix = cmds.xform(spine[-1:], q=True, wd=1, t=True) rotateWorldMatrix = cmds.xform(spine[-1:], q=True, wd=1, ro=True) getClass.squareI(name, num, transformWorldMatrix, rotateWorldMatrix, colour) cmds.move(0, -num/3, 0, "Chest_ctrl" ,r=1, rpr=1, ) cmds.move(0, num/3, 0, "Chest_ctrl.rotatePivot" ,r=1, rpr=1 ) cmds.makeIdentity("Chest_ctrl", a=True, t=1, s=1, r=1, n=0) name="Body_ctrl" num=9 colour=6 transformWorldMatrix = cmds.xform(spine[-1:], q=True, wd=1, t=True) rotateWorldMatrix = cmds.xform(spine[-1:], q=True, wd=1, ro=True) getClass.cubeI(name, num, transformWorldMatrix, rotateWorldMatrix, colour) cmds.move(0, -num, 0, "Body_ctrl" ,r=1, rpr=1, ) cmds.move(0, num, 0, "Body_ctrl.rotatePivot" ,r=1, rpr=1 ) cmds.makeIdentity("Body_ctrl", a=True, t=1, s=1, r=1, n=0) spineFK_Ctrls.append("Body_ctrl") #makehead OrigName= "head01" colour1=6 colour2=colour1 colour3=colour1 size=15 colour=13 nrx=0 nry=1 nrz=0 eachPiece=OrigName+"_jnt" name=OrigName+"_ctrl" grpname=OrigName+"_grp" getTranslation, getRotation=getClass.locationXForm(eachPiece) getClass.buildCtrl(each, name, grpname,getTranslation, getRotation, size, colour, nrx, nry, nrz) cmds.move(0, size, 0, "head01_ctrl" ,r=1, rpr=1, ) cmds.move(0, -size, 0, "head01_ctrl.rotatePivot" ,r=1, rpr=1 ) cmds.makeIdentity("head01_ctrl", a=True, t=1, s=1, r=1, n=0) ################################## ################################## ################################## ################################## ################################## ################################## ################################## ################################## ################################## #IK #'''-------------------------------------- # SPINE #--------------------------------------''' spineJoints=(cmds.ls("spine*_jnt")) lastJoint=spineJoints[-1:] spineTwistJnt=(cmds.ls("spine*IK_jnt")) spineLow=(cmds.ls("spine*FK_jnt")) spineCtrl=(cmds.ls("spine*_ctrl")) #spineCtrlGrp=cmds.pickWalk(spineCtrl, d="up") '''-------------------------------------- # set axis for scale --------------------------------------''' scaleAxis='X' lastSpineJoint=spineTwistJnt[-1:] allButLastspineJoints=spineJoints[:-1] '''-------------------------------------- # create spline IK --------------------------------------''' cmds.ikHandle(n="spineIK", sj="spine01IK_jnt", ee=str(lastSpineJoint[0]), sol="ikSplineSolver", scv=0, ns=3, rtm=1) '''-------------------------------------- # find the spline of the IK --------------------------------------''' list=cmds.listConnections('spineIK', t="shape") cmds.rename(list, "spineIK_crv") '''-------------------------------------- # get length of spline --------------------------------------''' curvInf=cmds.arclen("spineIK_crv", ch=1) '''-------------------------------------- # connect the length to a multiplyDivide --------------------------------------''' MDshader=cmds.shadingNode( "multiplyDivide", au=1) '''-------------------------------------- # set multiplyDivide to Divide --------------------------------------''' cmds.setAttr(str(MDshader)+".operation", 2) '''-------------------------------------- # connect length of spline to MD node --------------------------------------''' cmds.connectAttr(curvInf+".arcLength", MDshader+".input1"+scaleAxis, f=1) '''-------------------------------------- # input the length into the second input --------------------------------------''' spineCrvLength=cmds.getAttr(MDshader+".input1"+scaleAxis) cmds.setAttr(MDshader+".input2"+scaleAxis,spineCrvLength) '''-------------------------------------- # skinbind lowres spine to the spline --------------------------------------''' cmds.bindSkin("spine01_Clst_jnt","spineIK_crv") cmds.addAttr("Hips_ctrl", ln="spineFK_IK", at="enum",en="FK:IK:", k=1, nn="spineFK_IK") cmds.setAttr("Hips_ctrl.spineFK_IK", 1) baseSpine=[(each.split("_")[0])for each in bindSpine] #IK setup for each in baseSpine: getClass.blendColors(each) for each in baseSpine: cmds.connectAttr("Hips_ctrl.spineFK_IK", each+"_blnd.blender", f=1) cmds.connectAttr("Hips_ctrl.spineFK_IK", each+"_sblnd.blender", f=1) for each in CLSspine: cmds.parent(each, w=1) #cmds.parentConstraint("Chest_ctrl", getCLSspine[0], mo=1) getSortedclusterSpline=cmds.ls("spine*_Clst_jnt") #spineIK_CLSTR=cmds.ls("spine*_clstr_ctrl") #connect IK to cluster spline cmds.parentConstraint("Hips_ctrl", "spine01_Clst_jnt ", mo=1) #cmds.parentConstraint("Chest_ctrl", getSortedclusterSpline[-1:], mo=1) cmds.parentConstraint("Chest_ctrl", getSortedclusterSpline[-1:], mo=1) for each, item in map(None, getSortedclusterSpline[1:-1], clstrCtrl): cmds.pointConstraint(item, each, mo=1) fkSpline=sorted(loResSpine) sortedSpline=fkSpline[::2] for each, item in map(None, fkSpline[::2], spineFK_Ctrls): cmds.parentConstraint(item, each, mo=1) #constrain FK spin to controls #for each, item in map(None, sortedSpline[1:], spineFK_Ctrls): # for nextControl, eachControl in enumerate(spineFK_Ctrls[:-1]): # currentItem = eachControl # nextItem = spineFK_Ctrls[(nextControl+1)%len(spineFK_Ctrls)] # getParentgrp=cmds.listRelatives(nextItem, ap=1) # cmds.parent(getParentgrp, currentItem) #cmds.parent(spineFK_Ctrls[0], "Hips_ctrl") cmds.pointConstraint("Hips_ctrl", "spine01_jnt", mo=1) cmds.orientConstraint("head01_ctrl", "head01_jnt", mo=1) bindneck=[(each) for each in cmds.listRelatives("neck01_jnt", ad=1, typ="joint") if "neck" in each] if len(bindneck)>1: cmds.parentConstraint(bindneck[:1], "head01_grp", mo=1) else: cmds.parentConstraint("neck01_jnt", "head01_grp", mo=1) #cmds.pointConstraint("Chest_ctrl", "head01_grp", mo=1) cmds.setAttr("Hips_ctrl.spineFK_IK", 1) cmds.setAttr("Chest_ctrl.visibility", 1) cmds.setDrivenKeyframe("Chest_ctrl.visibility", cd="Hips_ctrl.spineFK_IK") cmds.setAttr("Hips_ctrl.spineFK_IK", 0) cmds.setAttr("Chest_ctrl.visibility", 0) cmds.setDrivenKeyframe("Chest_ctrl.visibility", cd="Hips_ctrl.spineFK_IK") cmds.setAttr("Hips_ctrl.spineFK_IK", 1) #stretch getIKClass.stretchSpline("spine01IK_jnt") cmds.addAttr("Hips_ctrl", ln="StretchSpine", at="enum",en="on:off:", k=1, nn="StretchSpine") cmds.setAttr("spine01IK_jnt_cond.operation", 2) cmds.setDrivenKeyframe("spine01IK_jnt_cond.operation", cd="Hips_ctrl.StretchSpine") cmds.setAttr("Hips_ctrl.StretchSpine", 1) cmds.setAttr("spine01IK_jnt_cond.operation", 0) cmds.setDrivenKeyframe("spine01IK_jnt_cond.operation", cd="Hips_ctrl.StretchSpine") cmds.setAttr("Hips_ctrl.StretchSpine", 1) cmds.parent("Main_ctrl_grp", "Main_offset_ctrl") cmds.parent("Main_offset_ctrl_grp", "Master_ctrl") if len(clstrCtrl)>1: lastClstr=cmds.listRelatives(clstrCtrl[-1:], ap=1) firstClstr=cmds.listRelatives(clstrCtrl[:1], ap=1) # lastClstr=clstrCtrl[-1:] # firstClstr=clstrCtrl[:1] else: lastClstr=cmds.listRelatives(clstrCtrl, ap=1) firstClstr=cmds.listRelatives(clstrCtrl, ap=1) #lastClstr=clstrCtrl #firstClstr=clstrCtrl if len(FKCtrl)>1: lastFK=FKCtrl[-1:] firstFK=FKCtrl[:1] #lastFK=FKCtrl[-1:] #firstFK=FKCtrl[:1] else: lastFK=FKCtrl firstFK=FKCtrl #lastFK=FKCtrl #firstFK=FKCtrl cmds.parent("Body_ctrl_grp", lastFK) cmds.parent(firstFK, "Hips_ctrl") cmds.parent("Hips_grp","UpperBody_ctrl") #cmds.orientConstraint("Body_ctrl", "Chest_ctrl", mo=1) #cmds.pointConstraint( "Chest_ctrl", "Body_ctrl") #cmds.parent("Body_ctrl_grp",lastFK) #cmds.parent(firstClstr, "Hips_ctrl") #cmds.parent("Chest_ctrl_grp", "Body_ctrl") #cmds.parent("Chest_ctrl_grp", "Body_ctrl") #cmds.parent("UpperBody_grp","Body_ctrl") getMaster_IKCtrls=["Chest_ctrl", "Hips_ctrl"] getClstr_ctrls=clstrCtrl for item in getMaster_IKCtrls: for each in getClstr_ctrls: cmds.parentConstraint(item, each, mo=1, w=.5)
23 Jul 20 Jacob Lilly """ # variables for potential future use guide = 'guide' geo = 'rain_fullBody_GEO' rig = 'rig' rootJnt = 'spine_C0_0_jnt' # shouldn't need to change this # A checkbox for opening the bind skin options or using the settings from last time bindOption = 0 # Unbind Skin and delete rig cmds.select(geo) cmds.bindSkin(unbind=True) cmds.delete(rig) # Build new rig from mgear cmds.select(guide) mg.Rig.buildFromSelection(Rig=rig) """ #BUG: needs a Rig object. For now, just manually use Build from Selection in Shifter Guide Manager.""" # Resize joints cmds.select(rootJnt, hi=True) for jnt in cmds.ls(sl=1): cmds.setAttr("{}.radius".format(jnt), .07) # Bind Skin
def chain_create(self, objs = None, fwd = None, up=None, name = None, upSetup = "guess", extendStart = None, extendEnd = True, mNucleus=None, upControl = None, aimUpMode = None, **kws): _str_func = 'chain_create' if not objs: _sel = mc.ls(sl=1) if _sel:objs = _sel ml = cgmMeta.asMeta( objs, noneValid = True ) ml_baseTargets = copy.copy(ml) if not ml: return log.warning("No objects passed. Unable to chain_create") if not name: name = ml[-1].p_nameBase _idx = self.get_nextIdx() #Make our sub group... mGrp = self.doCreateAt(setClass=1) mGrp.p_parent = self mGrp.rename("chain_{0}_grp".format(name)) mGrp.dagLock() self.connectChildNode(mGrp.mNode,'chain_{0}'.format(_idx),'owner') #holders and dat... ml_targets = [] ml_posLocs = [] ml_aim_locs = [] fwd = fwd or self.fwd up = up or self.up upSetup = upSetup or self.upSetup extendStart = extendStart or self.extendStart extendEnd = extendEnd or self.extendEnd upControl = upControl or self.upControl aimUpMode = aimUpMode or self.aimUpMode #fwdAxis = simpleAxis(fwd) #upAxis = simpleAxis(up) fwdAxis = TRANS.closestAxisTowardObj_get(ml[0], ml[1]) upAxis = TRANS.crossAxis_get(fwdAxis) mGrp.doStore('fwd', fwdAxis.p_string) mGrp.doStore('up', upAxis.p_string) #Curve positions... l_pos = [] if upSetup == 'manual': if len(ml) < 2: log.debug(cgmGEN.logString_msg(_str_func, 'Single count. Adding extra handle.')) mLoc = ml[0].doLoc() mLoc.rename("chain_{0}_end_loc".format(name)) _size = DIST.get_bb_size(ml[0],True,'max') mLoc.p_position = ml[0].getPositionByAxisDistance(fwdAxis.p_string,_size) ml.append(mLoc) mLoc.p_parent = mGrp for obj in ml: l_pos.append(obj.p_position) _v_baseDist = DIST.get_distance_between_points(l_pos[-1],l_pos[-2]) _v_baseDist = MATHUTILS.Clamp(_v_baseDist, .5,None) _p_baseExtend = DIST.get_pos_by_axis_dist(ml[-1], fwdAxis.p_string, _v_baseDist) if extendEnd: log.debug(cgmGEN.logString_msg(_str_func, 'extendEnd...')) extendEnd = VALID.valueArg(extendEnd) if issubclass(type(extendEnd),bool):#VALID.boolArg(extendEnd): log.debug(cgmGEN.logString_msg(_str_func, 'extendEnd | guess')) l_pos.append(_p_baseExtend) elif extendEnd: log.debug(cgmGEN.logString_msg(_str_func, 'extendEnd | {0}'.format(extendEnd))) l_pos.append( DIST.get_pos_by_axis_dist(ml[-1], fwdAxis.p_string, extendEnd )) else: l_pos.append( _p_baseExtend) if extendStart: f_extendStart = VALID.valueArg(extendStart) if f_extendStart: l_pos.insert(0, DIST.get_pos_by_axis_dist(ml[0], fwdAxis.inverse.p_string, f_extendStart )) else: log.debug(cgmGEN.logString_msg(_str_func, 'Resolving aim')) if len(ml) < 2: return log.error(cgmGEN.logString_msg(_str_func, 'Single count. Must use manual upSetup and aim/up args')) for obj in ml: l_pos.append(obj.p_position) _vecEnd = MATHUTILS.get_vector_of_two_points(l_pos[-2],l_pos[-1]) if extendEnd: log.debug(cgmGEN.logString_msg(_str_func, 'extendEnd...')) extendEnd = VALID.valueArg(extendEnd) if issubclass(type(extendEnd),bool):#VALID.boolArg(extendEnd): log.debug(cgmGEN.logString_msg(_str_func, 'extendEnd | guess')) l_pos.append( DIST.get_pos_by_vec_dist(l_pos[-1], _vecEnd, (DIST.get_distance_between_points(l_pos[-2],l_pos[-1])/2))) elif extendEnd: log.debug(cgmGEN.logString_msg(_str_func, 'extendStart | {0}'.format(extendEnd))) l_pos.append( DIST.get_pos_by_vec_dist(l_pos[-1], _vecEnd, extendEnd)) if extendStart: f_extendStart = VALID.valueArg(extendStart) if f_extendStart: log.debug(cgmGEN.logString_msg(_str_func, 'extendStart...')) _vecStart = MATHUTILS.get_vector_of_two_points(l_pos[1],l_pos[0]) l_pos.insert(0, DIST.get_pos_by_vec_dist(l_pos[0], _vecStart, f_extendStart)) #pprint.pprint(l_pos) #for i,p in enumerate(l_pos): # LOC.create(position=p,name='p_{0}'.format(i)) crv = CORERIG.create_at(create='curve',l_pos= l_pos, baseName = name) mInCrv = cgmMeta.asMeta(crv) mInCrv.rename("{0}_inCrv".format(name)) mGrp.connectChildNode(mInCrv.mNode,'mInCrv') mc.select(cl=1) # make the dynamic setup log.debug(cgmGEN.logString_sub(_str_func,'dyn setup')) b_existing = False b_existing_nucleus = False mHairSys = self.getMessageAsMeta('mHairSysShape') if mHairSys: mHairSysDag = mHairSys.getTransform(asMeta=1) log.info(cgmGEN.logString_msg(_str_func,'Using existing system: {0}'.format(mHairSys.mNode))) mc.select(mHairSysDag.mNode, add=True) b_existing = True if self.useExistingNucleus or mNucleus: mNucleus = self.get_nucleus(mNucleus) if mNucleus: #mc.select(mNucleus.mNode,add=1) b_existing_nucleus = True log.info(cgmGEN.logString_msg(_str_func,'Using existing nucleus: {0}'.format(mNucleus.mNode))) self.connectChildNode(mNucleus.mNode,'mNucleus') mc.select(mInCrv.mNode,add=True) mel.eval('makeCurvesDynamic 2 { "0", "0", "1", "1", "0" }') # get relevant nodes follicle = mc.listRelatives(mInCrv.mNode,parent=True)[0] mFollicle = cgmMeta.asMeta(follicle) mFollicle.rename("{0}_foll".format(name)) parent = mFollicle.getParent(asMeta=1) mFollicle.p_parent = mGrp mFollicleShape = mFollicle.getShapes(1)[0] mc.delete(parent.mNode) _follicle = mFollicle.mNode mGrp.connectChildNode(mFollicle.mNode,'mFollicle','group') follicleShape = mFollicleShape.mNode#mc.listRelatives(mFollicle.mNode, shapes=True)[0] _hairSystem = mc.listRelatives( mc.listConnections('%s.currentPosition' % follicleShape)[0], shapes=True)[0] if not b_existing: mHairSys = cgmMeta.asMeta(_hairSystem) mHairSysDag = mHairSys.getTransform(asMeta=1) mHairSysDag.rename("{0}_hairSys".format(self.baseName)) self.connectChildNode(mHairSysDag.mNode,'mHairSysDag','owner') self.connectChildNode(mHairSys.mNode,'mHairSysShape','owner') mHairSysDag.p_parent = self _hairSystem = mHairSys.mNode outCurve = mc.listConnections('%s.outCurve' % _follicle)[0] mCrv = cgmMeta.asMeta(outCurve) parent = mCrv.getParent(asMeta=1) outCurveShape = mc.listRelatives(mCrv.mNode, shapes=True)[0] mCrv.p_parent = mGrp.mNode mc.delete(parent.mNode) _nucleus = mc.listConnections( '%s.currentState' % mHairSys.mNode )[0] if not b_existing_nucleus: mNucleus = cgmMeta.asMeta(_nucleus) mNucleus.rename("cgmDynFK_nucleus") #self.connectChildNode(mNucleus.mNode,'mNucleus','owner') self.connectChildNode(mNucleus.mNode,'mNucleus') if self.startFrame is not None: mNucleus.startFrame = self.startFrame else: #Because maya is crappy we gotta manually wire the existing nucleus ##startFrame out to startFrame in ##outputObjects[x] - nextState ##shape.currentState>inputActive[x] ##shape.startState>inputActiveStart[x] if cgmMeta.asMeta(_nucleus).mNode != mNucleus.mNode: mc.delete(_nucleus) _useNucleus = mNucleus.mNode """ _useIdx = ATTR.get_nextCompoundIndex(mNucleus.mNode,'outputObjects') log.info("useIdx: {0}".format(_useIdx)) ATTR.connect('{0}.outputObjects[{1}]'.format(_useNucleus,_useIdx),'{0}.nextState'.format(_hairSystem)) ATTR.connect('{0}.currentState'.format(_hairSystem),'{0}.inputActive[{1}]'.format(_useNucleus,_useIdx)) ATTR.connect('{0}.startState'.format(_hairSystem),'{0}.inputActiveStart[{1}]'.format(_useNucleus,_useIdx))""" mParent = ml[0].getParent(asMeta=1) if not mParent: mParent = ml[0].doGroup(1,1, asMeta=True, typeModifier = 'dynFKParent', setClass='cgmObject') #else: #mParent.getParent(asMeta=1) mGrp.connectChildNode(mCrv.mNode,'mOutCrv','group') #self.follicles.append(follicle) #self.outCurves.append(outCurve) # set default properties mFollicleShape.pointLock = 1 #mc.setAttr( '%s.pointLock' % follicleShape, 1 ) mc.parentConstraint(ml[0].getParent(), _follicle, mo=True) # create locators on objects locators = [] prs = [] ml_locs = [] ml_aims = [] ml_prts = [] _upVector = None if upSetup == 'guess': log.debug(cgmGEN.logString_msg(_str_func, 'Resolving up/aim')) poci_base = CURVES.create_pointOnInfoNode(mInCrv.mNode,1) mPoci_base = cgmMeta.asMeta(poci_base) _upVector = mPoci_base.normalizedNormal log.debug(cgmGEN.logString_msg(_str_func, "upVector: {0}".format(_upVector))) #Let's make an up object as the parent of the root isn't good enough mUp = ml[0].doCreateAt(setClass=1) mUp.rename("chain_{0}_up".format(name)) mUp.p_parent = mGrp if _upVector: SNAP.aim_atPoint(mUp.mNode, DIST.get_pos_by_vec_dist(mUp.p_position, _upVector, 10),aimAxis='y+',upAxis='z+') if upControl: log.debug(cgmGEN.logString_msg(_str_func,'upControl')) if len(ml_baseTargets)>1: sizeControl = DIST.get_distance_between_targets([mObj.mNode for mObj in ml_baseTargets],True) else: sizeControl = DIST.get_bb_size(ml[0],True,'max') crv = CURVES.create_controlCurve(mUp.mNode,'arrowSingle', size= sizeControl, direction = 'y+') CORERIG.shapeParent_in_place(mUp.mNode, crv, False) mUpGroup = mUp.doGroup(True,True, asMeta=True, typeModifier = 'master', setClass='cgmObject') mc.parentConstraint(ml[0].getParent(), mUpGroup.mNode, mo=True) else: mc.parentConstraint(ml[0].getParent(), mUp.mNode, mo=True) # create control joint chain mc.select(cl=True) chain = [] for obj in ml: if len(chain) > 0: mc.select(chain[-1]) jnt = mc.joint(name='%s_%s_jnt' % (name, obj.p_nameBase)) SNAP.matchTarget_set(jnt, obj.mNode) mObj = cgmMeta.asMeta(jnt) mObj.doSnapTo(mObj.getMessageAsMeta('cgmMatchTarget')) chain.append(jnt) mc.parent(chain[0], _follicle) mInCrv.p_parent = mGrp mc.bindSkin(mInCrv.mNode, chain[0], ts=True) log.debug(cgmGEN.logString_msg(_str_func,'aimUpMode: {0}'.format(aimUpMode))) for i, mObj in enumerate(ml): if not i: mUpUse = mUp else: mUpUse = ml_locs[-1] mLoc = cgmMeta.asMeta( LOC.create(mObj.getNameLong()) ) loc = mLoc.mNode ml_locs.append(mLoc) #loc = LOC.create(mObj.getNameLong()) mAim = mLoc.doGroup(False,False, asMeta=True, typeModifier = 'aim', setClass='cgmObject') ml_aims.append(mAim) #aimNull = mc.group(em=True) #aimNull = mc.rename('%s_aim' % mObj.getShortName()) poc = CURVES.create_pointOnInfoNode(outCurveShape) #mc.createNode('pointOnCurveInfo', name='%s_pos' % loc) mPoci_obj = cgmMeta.asMeta(poc) mPoci_obj.rename('%s_pos' % loc) pocAim = CURVES.create_pointOnInfoNode(outCurveShape) #mc.createNode('pointOnCurveInfo', name='%s_aim' % loc) pr = CURVES.getUParamOnCurve(loc, outCurve) mPoci_obj.parameter = pr #mc.connectAttr( '%s.worldSpace[0]' % outCurveShape, '%s.inputCurve' % poc, f=True ) #mc.connectAttr( '%s.worldSpace[0]' % outCurveShape, '%s.inputCurve' % pocAim, f=True ) #mc.setAttr( '%s.parameter' % poc, pr ) if i < len(ml)-1: nextpr = CURVES.getUParamOnCurve(ml[i+1], outCurve) mc.setAttr('%s.parameter' % pocAim, (nextpr))# + pr))# * .5) else: if extendStart: mc.setAttr( '%s.parameter' % pocAim, len(ml)+1 ) else: mc.setAttr( '%s.parameter' % pocAim, len(ml) ) mLocParent = mLoc.doGroup(False,False, asMeta=True, typeModifier = 'pos', setClass='cgmObject') ml_prts.append(mLocParent) #locParent = mc.group(em=True) #locParent = mc.rename( '%s_pos' % mObj.getShortName() ) mc.connectAttr( '%s.position' % mPoci_obj.mNode, '%s.translate' % mLocParent.mNode) mc.connectAttr( '%s.position' % pocAim, '%s.translate' % mAim.mNode) if aimUpMode == 'master': aimConstraint = mc.aimConstraint( mAim.mNode, mLocParent.mNode, aimVector=fwdAxis.p_vector, upVector = upAxis.p_vector, worldUpType = "objectrotation", worldUpVector = upAxis.p_vector, worldUpObject = mUp.mNode ) elif aimUpMode == 'orientToMaster': mc.orientConstraint( mUp.mNode, mLocParent.mNode, maintainOffset = 1) elif aimUpMode == 'sequential': aimConstraint = mc.aimConstraint( mAim.mNode, mLocParent.mNode, aimVector=fwdAxis.p_vector, upVector = upAxis.p_vector, worldUpType = "objectrotation", worldUpVector = upAxis.p_vector, worldUpObject = mUpUse.mNode ) elif aimUpMode == 'joint': aimConstraint = mc.aimConstraint( mAim.mNode, mLocParent.mNode, aimVector=fwdAxis.p_vector, upVector = upAxis.p_vector, worldUpType = "objectrotation", worldUpVector = upAxis.p_vector, worldUpObject = chain[i] ) elif aimUpMode == 'curveNormal': mUpLoc = mLoc.doGroup(False,False, asMeta=True, typeModifier = 'up', setClass='cgmObject') mUpLoc.p_parent = mLocParent aimConstraint = mc.aimConstraint( mAim.mNode, mLocParent.mNode, aimVector=fwdAxis.p_vector, upVector = upAxis.p_vector, worldUpType = "object") mPlusMinusAverage = cgmMeta.cgmNode(name="{0}_pma".format(mObj.p_nameBase), nodeType = 'plusMinusAverage') mPlusMinusAverage.operation = 3 mPoci_obj.doConnectOut('position','{0}.input3D[0]'.format(mPlusMinusAverage.mNode)) mPoci_obj.doConnectOut('normalizedNormal','{0}.input3D[1]'.format(mPlusMinusAverage.mNode)) mUpLoc.doConnectIn('translate','{0}.output3D'.format(mPlusMinusAverage.mNode)) mLoc.p_parent = mLocParent mAim.p_parent = mGrp mLocParent.p_parent = mGrp #mc.parent(loc, locParent) mCrv.rename("{0}_outCrv".format(name)) mCrvParent = mCrv.getParent(asMeta=1) mCrvParent.p_parent = mGrp mGrp.msgList_connect('mLocs',ml_locs) mGrp.msgList_connect('mAims',ml_aims) mGrp.msgList_connect('mParents',ml_prts) mGrp.msgList_connect('mTargets',ml) mGrp.msgList_connect('mBaseTargets',ml_baseTargets) mGrp.msgList_connect('mObjJointChain',chain) mGrp.doStore('cgmName', name) mNucleus.doConnectOut('startFrame',"{0}.startFrame".format(mHairSys.mNode))
def create_my_toolbox(standalone=False): '''Create my toolbox dockable window''' # Reload scripts reload(rename_functions) reload(joint_functions) reload(auto_rigs) reload(simple_functions) reload(custom_outliner) reload(create_joints) reload(create_controls) reload(create_locator) reload(custom_outliner) reload(random_placement) reload(custom_animation_window) reload(color_override) w_width = 160 w_width = 160 sep_height = 12 my_window = 'CSAToolboxWindow' my_dock_control='CSAToolbox' two_button_row = (1, 'both', 0) # Create window if cmds.window(my_window, q=True, exists=True): cmds.deleteUI(my_window) my_window = cmds.window(my_window, width=w_width) # Create main column main_column = cmds.columnLayout('ColumnLayout', p=my_window, adjustableColumn=True, columnAlign='center') # Create header image_row = cmds.rowLayout(p=main_column, nc=2, adj=2, columnAlign=(2,'center'), bgc=(1,1,1)) my_image = cmds.picture(p=image_row, image='logo-32.png') my_name = cmds.text(p=image_row, label='Cody Anderson') # Create tab layout my_tabs = cmds.tabLayout('TabLayout', p=main_column) # Tab 1 t1_column = cmds.columnLayout('TabColumn1',p=my_tabs, adj=1, columnAlign='center') # MODELING TOOLS cmds.separator(p=t1_column, height=sep_height) other_label = cmds.text(p=t1_column, l='Modeling') cmds.separator(p=t1_column, height=sep_height) # Poly Count poly_count_button = cmds.button(p=t1_column, l='Poly Count', ann='Toggle poly count', command=lambda *args: simple_functions.toggle_poly_count()) cmds.separator(p=t1_column, height=sep_height) # Simple modeling tools delete_history_button = cmds.button(p=t1_column, l='Delete History', ann='Delete history', command=lambda *args: simple_functions.delete_history()) freeze_transform_button = cmds.button(p=t1_column, l='Freeze Transformations', ann='Freeze all transformations', command=lambda *args: simple_functions.freeze_transformations()) center_pivot_button = cmds.button(p=t1_column, l='Center Pivot', ann='Center pivot', command=lambda *args: simple_functions.center_pivot()) cmds.separator(p=t1_column, height=sep_height) # Rename Functions rename_button = cmds.button(p=t1_column, l='Rename', ann='Sequential renamer', command=lambda *args: rename_functions.rename_prompt()) search_and_replace_button = cmds.button(p=t1_column, l='Search And Replace', ann='Search and replace', command=lambda *args: rename_functions.search_and_replace()) # RIGGING TOOLS cmds.separator(p=t1_column, height=sep_height) other_label = cmds.text(p=t1_column, l='Rigging') cmds.separator(p=t1_column, height=sep_height) # Locator locator_row = cmds.rowLayout(p=t1_column, nc=3, adj=3, columnWidth=(1, 60)) create_locator_button = cmds.button(p=locator_row, l='Locators', ann='Create locator(s)', command=lambda *args: create_locator.center_locator(locator_buttons)) locator_buttons = cmds.radioCollection(p=locator_row) locator_button_1 = cmds.radioButton(l='Each', ann='Create locator at each selection') locator_button_2 = cmds.radioButton(l='All', ann='Create locator at center of entire selection') cmds.radioCollection(locator_buttons, edit=True, select=locator_button_1) # Covert to Joints create_joints_row = cmds.rowLayout(p=t1_column, nc=2, adj=2, columnWidth=(1, 110), columnAttach=(1, 'left', 0)) create_joints_button = cmds.button(p=create_joints_row, l='Selection to Joints', ann='Places joint at selection', command=lambda *args: create_joints.convert_to_joints(create_joints_checkbox)) create_joints_checkbox = cmds.checkBox(p=create_joints_row, l='Del', ann='Delete selection?', align='right') # Place Controls place_controls_button = cmds.button(p=t1_column, l='Place Controls', ann='Place controls at selection', command=lambda *args: create_controls.place_controls()) cmds.separator(p=t1_column, height=sep_height) # Change color color_slider = cmds.colorIndexSliderGrp(p=t1_column, w=w_width/2, cw=(1, 60), adj=2, min=1, max=32, v=1) color_buttons_row = cmds.rowLayout(p=t1_column, nc=2, adj=2, columnWidth=(1, 75), columnAttach=two_button_row) color_set_button = cmds.button(p=color_buttons_row, l='Set Color', ann='Changes color to slider color', command=lambda *args: color_override.change_color_slider(color_slider)) color_default_button = cmds.button(p=color_buttons_row, l='Default Color', ann='Changes color back to default', command=lambda *args: color_override.default_color()) cmds.separator(p=t1_column, height=sep_height) # Contstraints parent_constrain_button = cmds.button(p=t1_column, l='Parent Constrain', ann='Parent constrain', command=lambda *args: cmds.parentConstraint()) scale_constrain_button = cmds.button(p=t1_column, l='Scale Constrain', ann='Scale constrain', command=lambda *args: cmds.scaleConstraint()) point_constrain_button = cmds.button(p=t1_column, l='Point Constrain', ann='Point constrain', command=lambda *args: cmds.pointConstraint()) orient_constrain_button = cmds.button(p=t1_column, l='Orient Constrain', ann='Orient constrain', command=lambda *args: cmds.orientConstraint()) pole_vector_constrain_button = cmds.button(p=t1_column, l='Pole Vector Constrain', ann='Pole vector constrain', command=lambda *args: cmds.poleVectorConstraint()) cmds.separator(p=t1_column, height=sep_height) #Orient Joint orient_joint_row = cmds.rowLayout(p=t1_column, nc=2, adj=2, columnWidth=(1, 125), columnAttach=two_button_row) orient_joint_button = cmds.button(p=orient_joint_row, l='Orient Joint Options', ann='Display orient joint options', command=lambda *args: joint_functions.display_orient_joint_options()) display_axis_toggle = cmds.iconTextButton(p=orient_joint_row, ann='Toggle display axis for all joints', style='iconOnly', image1='channelBoxUseManips.png', command=lambda *args: joint_functions.display_local_axis()) orient_channelbox_button = cmds.button(p=t1_column, l='Toggle Joint Attributes', ann='Toggles joint attributes', command=lambda *args: joint_functions.show_joint_attr()) cmds.separator(p=t1_column, height=sep_height) #Scale Compensation scale_comp_label = cmds.text(p=t1_column, l='Scale Compensation') scale_comp_row = cmds.rowLayout(p=t1_column, nc=2, adj=2, columnWidth=(1, 75), columnAttach=two_button_row) scale_comp_on_button = cmds.button(parent=scale_comp_row, label='On', annotation='Turn scale compensation on', command=lambda *args: joint_functions.scale_compensate(1)) scale_comp_off_button = cmds.button(parent=scale_comp_row, label='Off', annotation='Turn scale compensation off', command=lambda *args: joint_functions.scale_compensate(0)) cmds.separator(p=t1_column, height=sep_height) #Auto rigs auto_rigs_row = cmds.rowLayout(p=t1_column, nc=4, columnAlign=(2, 'left')) fk_button = cmds.iconTextButton(p=auto_rigs_row, l='FK', ann='Creates a FK rig. Select first joint', style='iconAndTextVertical', image1='kinJoint.png', command=lambda *args: auto_rigs.simple_fk()) broken_fk_button = cmds.iconTextButton(p=auto_rigs_row, l='Broken', ann='Creates a broken FK rig. Select first joint', style='iconAndTextVertical', image1='kinJoint.png', command=lambda *args: auto_rigs.broken_fk()) ik_button = cmds.iconTextButton(p=auto_rigs_row, l='IK', ann='Creates an IK rig. Select first joint', style='iconAndTextVertical', image1='kinHandle.png', command=lambda *args: auto_rigs.simple_ik()) rk_button = cmds.iconTextButton(p=auto_rigs_row, l='RK', ann='Creates a RK rig. Select first joint', style='iconAndTextVertical', image1='kinJoint.png', command=lambda *args: auto_rigs.simple_rk()) cmds.separator(p=t1_column, height=sep_height) # Skinning bind_skin_button = cmds.button(p=t1_column, l='Bind Skin', ann='Binds skin to joint(s)', command=lambda *args: cmds.bindSkin()) influence_row = cmds.rowLayout(p=t1_column, nc=2, adj=2, columnWidth=(1, 75), columnAttach=two_button_row) cmds.button(p=influence_row, l='Add', ann='Removes unused influences', command=lambda *args: mel.eval('AddInfluence')) cmds.button(p=influence_row, l='Remove', ann='Removes unused influences', command=lambda *args: mel.eval('RemoveInfluence')) remove_inf_button = cmds.button(p=t1_column, l='Remove Unused', ann='Removes unused influences', command=lambda *args: mel.eval('removeUnusedInfluences')) cmds.separator(p=t1_column, height=sep_height) # Paint Weights paint_weights_button = cmds.button(p=t1_column, l='Paint Weights', ann='Opens paint weight options', command=lambda *args: mel.eval('ArtPaintSkinWeightsToolOptions')) pw_options_row = cmds.rowLayout(p=t1_column, nc=2, adj=2, columnWidth=(1, 75), columnAttach=two_button_row) mirror_weights_button = cmds.button(p=pw_options_row, l='Mirror', ann='Opens mirror weight options', command=lambda *args: mel.eval('MirrorSkinWeightsOptions')) copy_weights_button = cmds.button(p=pw_options_row, l='Copy', ann='Opens copy weight options', command=lambda *args: mel.eval('CopySkinWeightsOptions')) # ANIMATION TOOLS cmds.separator(p=t1_column, height=sep_height) other_label = cmds.text(p=t1_column, l='Animation') cmds.separator(p=t1_column, height=sep_height) anim_row = cmds.rowLayout(p=t1_column, nc=2, adj=2, columnWidth=(1, 75), columnAttach=two_button_row) cmds.button(p=anim_row, l='Graph Editor', ann='Opens graph editor', command=lambda *args: mel.eval('GraphEditor')) cmds.button(p=anim_row, l='Exporter', ann='Opens fbx game exporter window', command=lambda *args: mel.eval('gameFbxExporter')) # tab 2 t2_column = cmds.columnLayout(p=my_tabs, adj=True, columnAlign='center') cmds.separator(p=t2_column, height=sep_height) other_label = cmds.text(p=t2_column, l='BETA Functions Below!') cmds.separator(p=t2_column, height=sep_height) # Random Placement random_placement_button = cmds.button(p=t2_column, l='Random Placement', ann='Random placement options', command=lambda *args: random_placement.random_placement_prompt()) # Custom Outliner custom_outliner_button = cmds.button(p=t2_column, l='Custom Outliner', ann='Open custom outliner', command=lambda *args: custom_outliner.custom_outliner()) # Custom Animation window custom_outliner_button = cmds.button(p=t2_column, l='Animator', ann='Open animation master', command=lambda *args: custom_animation_window.custom_animation()) # Add tabs cmds.tabLayout(my_tabs, edit=True, tabLabel=[(t1_column, 'Main'), (t2_column, 'BETA')]) # Show window # cmds.showWindow(my_window) # Check if dockable window exists if cmds.dockControl(my_dock_control, q=True, exists=True): cmds.deleteUI(my_dock_control, control=True) # Create dockable window my_dock_control = cmds.dockControl(my_dock_control, area='right', width=w_width, fixedWidth=True, aa=['right', 'left'], content=my_window)
def rig(self) : cmds.group(em=True, n='Rig' ) cmds.joint( p= (0.171124,-43.991319,0)) cmds.joint( p= (0.171124,-21.637474,0)) cmds.joint('joint1',e=True,zso=True,oj='xyz',sao='yup') cmds.joint( p= (0.171124,8.977573 ,0)) cmds.joint('joint2',e=True,zso=True,oj='xyz',sao='yup') cmds.joint( p= (0.171124,34.733089,0)) cmds.joint('joint3',e=True,zso=True,oj='xyz',sao='yup') cmds.joint( p= (0.171124,57.086934,0)) cmds.joint('joint4',e=True,zso=True,oj='xyz',sao='yup') cmds.joint( p= (0.171124,77.011012,0)) cmds.joint('joint5',e=True,zso=True,oj='xyz',sao='yup') cmds.joint( p= (8.168084,46.565763,0)) cmds.joint('joint7',e=True,zso=True,oj='xyz',sao='yup') cmds.parent('joint7','joint4') cmds.joint( p= (-8.168084,46.040793,0)) cmds.parent('joint8','joint4') cmds.joint( p= (-20.167369,43.581907,0)) cmds.joint( p= (-19.793546,43.581907,0)) cmds.joint( p= (-60.166378,43.581907,0)) cmds.joint('joint9',e=True,zso=True,oj='xyz',sao='yup') cmds.joint( p= (-100.165388,43.581907,0)) cmds.joint('joint10',e=True,zso=True,oj='xyz',sao='yup') cmds.joint( p= (-115.118288,43.581907,0)) cmds.joint('joint11',e=True,zso=True,oj='xyz',sao='yup') cmds.select(clear=True) cmds.joint( p= (20.097474,44.088276,0)) cmds.joint( p= (59.887389,44.474585,0)) cmds.joint('joint14',e=True,zso=True,oj='xyz',sao='yup') cmds.joint( p= (100.449924,44.474585,0)) cmds.joint('joint15',e=True,zso=True,oj='xyz',sao='yup') cmds.joint( p= (114.743389,44.474585,0)) cmds.joint('joint16',e=True,zso=True,oj='xyz',sao='yup') cmds.parent('joint14','joint7') cmds.select(clear=True) cmds.joint( p= (-17.206283,-61.004095,0)) cmds.joint( p= (-20.334698,-115.229957,0)) cmds.joint('joint18',e=True,zso=True,oj='xyz',sao='yup') cmds.joint( p= (-19.813296,-171.020027,0)) cmds.joint('joint19',e=True,zso=True,oj='xyz',sao='yup') cmds.joint( p= (-19.813296,-225.997318,0)) cmds.joint('joint20',e=True,zso=True,oj='xyz',sao='yup') cmds.parent('joint18','joint1') cmds.select(clear=True) cmds.joint( p= (15.815459,-60.351589,0)) cmds.joint( p= (20.855821,-116.154906,0)) cmds.joint('joint22',e=True,zso=True,oj='xyz',sao='yup') cmds.joint( p= (20.272872,-170.369114,0)) cmds.joint('joint23',e=True,zso=True,oj='xyz',sao='yup') cmds.joint( p= (20.272872,-225.166271,0)) cmds.joint('joint24',e=True,zso=True,oj='xyz',sao='yup') cmds.parent('joint22','joint1') cmds.ikHandle(sj='joint10', ee='joint12',name='Bras_G_IK') cmds.ikHandle(sj='joint14', ee='joint16',name='Bras_D_IK') cmds.ikHandle(sj='joint22', ee='joint24',name='Jambe_G_IK') cmds.ikHandle(sj='joint18', ee='joint20',name='Jambe_D_IK') cmds.ikHandle(sj='joint1', ee='joint14',name='Colonne_IK') cmds.bindSkin(self.name, 'joint1') cmds.circle( nr=(0, 1, 0), c=(0, 0, 0), sw=360, r=1,name='Poignet_G_CTRL') cmds.move(-100.16539,43.581905,1.17984e-07) cmds.rotate(0,0,90) cmds.scale(15,15,15) cmds.makeIdentity(apply=True) cmds.parentConstraint('Poignet_G_CTRL','Bras_G_IK') cmds.circle( nr=(0, 1, 0), c=(0, 0, 0), sw=360, r=1,name='Poignet_D_CTRL') cmds.move(100.449921,44.474586,0) cmds.rotate(0,0,90) cmds.scale(15,15,15) cmds.makeIdentity(apply=True) cmds.parentConstraint('Poignet_D_CTRL','Bras_D_IK') cmds.circle( nr=(0, 1, 0), c=(0, 0, 0), sw=360, r=1,name='Jambe_D_CTRL') cmds.move(-19.813295,-171.02002,0) cmds.scale(20,20,20) cmds.makeIdentity(apply=True) cmds.parentConstraint('Jambe_D_CTRL','Jambe_D_IK') cmds.circle( nr=(0, 1, 0), c=(0, 0, 0), sw=360, r=1, name='Jambe_G_CTRL') cmds.move(20.272873,-170.36911,0) cmds.scale(20,20,20) cmds.makeIdentity(apply=True) cmds.parentConstraint('Jambe_G_CTRL','Jambe_G_IK')
def Bind(): charName = cmds.textFieldGrp(NameInput, q=True, text=True) cmds.select(charName + '_Joints_01', hi=True) # if charName+'_Geo_01' null print 'put your model in Main>Geo group' cmds.select(charName + '_Geo_01', hi=True, add=True) cmds.bindSkin()
def makeTwistJoints( topJnt, numJnts, bone = 'shoulder' ): if mc.objExists( 'cMuscleSurfAttach1' ): mc.error( 'please rename your cMuscleSurfAttach stuff' ) prefix = topJnt[0:-4] kidJnt = mc.listRelatives(topJnt, c = 1, type = 'joint')[0] jntLen = mc.getAttr( kidJnt + '.tx' ) twistX = stepsBetweenFloats( 0, jntLen, numJnts - 1 ) twistJnts = [] for i, x in enumerate( twistX ): name = topJnt[:-3] + '_jnt' jnt = mc.joint( topJnt, p = [ x, 0, 0 ], r = 1, n = prefix + str(i +1) + 'Twist_jnt', rad = 0.25 ) twistJnts.append(jnt) rivetCrv = curveBetweenPoints( [0,0,0], [jntLen,0,0], prefix = prefix + 'Deform' ) mc.rebuildCurve( rivetCrv, s = 5, d = 3, ch = 0 ) rivetSrf = makeRibbonSrf( inCurve = rivetCrv, vect = [0, 0, 0.5] ) driveSrf = mc.duplicate( rivetSrf, n = prefix + 'DriveTwist_srf' ) mc.delete( mc.parentConstraint( topJnt, rivetSrf ), rivetCrv ) if bone == 'shoulder': mc.parentConstraint( topJnt, rivetSrf, sr = [ 'x' ] ) else: mc.bindSkin( rivetSrf, topJnt ) twist = mc.nonLinear( driveSrf, type = 'twist') # name flag bugged twistNode = mc.listConnections( twist[1], d = 1, type = 'nonLinear' )[0] mc.rotate( 0, 0, 90, twist ) bls = mc.blendShape( driveSrf, rivetSrf, foc = True, w = [0, 1], n = prefix + '_bls' )[0] vs = stepsBetweenFloats( 0, 1, numJnts - 1 ) for i, v in enumerate( vs ): # This command is black boxed and really wonky to use but beats making follicles mc.select( mc.ls( '%sShape.uv[.5][%s]' %( rivetSrf[0], v )) ) r = mm.eval( 'cMuscleSurfAttachSetup();' ) mc.select( clear = 1 ) newName = prefix + str( i + 1 ) + '_riv' mc.rename( 'cMuscleSurfAttach1', newName ) mc.orientConstraint( newName, twistJnts[i], mo = 1 ) # clean and organize parts partsGrp = mc.group( n = prefix + 'Twist_grp', em = 1 ) mc.setAttr( partsGrp + '.it', 0 ) mc.rename( 'grpSurfAttachRIG', prefix + 'Rivet_grp' ) mc.rename(twistNode, prefix + 'Twist_nld' ) mc.rename( twist[1], prefix + 'Twist_hdl' ) attachGrp = prefix + 'Rivet_grp' twistHdl = prefix + 'Twist_hdl' twistNode = prefix + 'Twist_nld' mc.parent( attachGrp, twistHdl, rivetSrf, driveSrf, partsGrp ) # make additive nodes for start and end ( for connecting ribbons ) addNodes = [] for plug in [ 'end', 'start']: addNode = mc.createNode( 'addDoubleLinear', n = prefix + plug.title() + '_add' ) mc.connectAttr( addNode + '.output', twistNode + '.' + plug + 'Angle' ) addNodes.append( addNode ) if bone == 'shoulder': mc.connectAttr( topJnt + '.rx', addNodes[1] + '.input1' ) else: mc.connectAttr( kidJnt + '.rx', addNodes[1] + '.input1' ) return { 'nonLinear': twistNode, 'addStart': addNodes[1] + '.input2', 'addEnd': addNodes[0] + '.input2', 'topJnt': topJnt, 'kidJnt': kidJnt }