def CreateJointChainSquareRig(self, JointChain, UDaxis="Y"): if self.NameConv.is_name_in_format(JointChain[0]): if self.NameConv.get_from_name(JointChain[0], "side") == "LF": sideVariation = 1 else: sideVariation = -1 else: sideVariation = 1 if UDaxis in ["Y", "Z"]: BoxResetPoint, BoxControl = RMRigShapeControls.RMCreateBoxCtrl( JointChain[len(JointChain) - 1], ParentBaseSize=True, Xratio=.5, Yratio=.5, Zratio=.5) self.addChainParameters(BoxControl, len(JointChain) - 1) cmds.makeIdentity(BoxControl, apply=True, r=False, t=True, s=True, n=0) cmds.parentConstraint(JointChain[len(JointChain) - 1], BoxResetPoint) RMRigTools.RMLockAndHideAttributes(BoxControl, "0000000000") if UDaxis == "Y": LRaxis = "Z" elif UDaxis == "Z": LRaxis = "Y" for eachjoint in range(len(JointChain) - 1): RMRigTools.RMConnectWithLimits( BoxControl + ".UD" + str(eachjoint + 1), JointChain[eachjoint] + (".rotate%s" % UDaxis), [[-10, 100], [0, 0], [10, -100]]) RMRigTools.RMConnectWithLimits( BoxControl + ".LR" + str(eachjoint + 1), JointChain[eachjoint] + (".rotate%s" % LRaxis), [[-10, sideVariation * 100], [0, 0], [10, sideVariation * -100]]) RMRigTools.RMConnectWithLimits( BoxControl + ".Twist" + str(eachjoint + 1), JointChain[eachjoint] + ".rotateX", [[-10, sideVariation * 100], [0, 0], [10, sideVariation * -100]]) else: print "Not Valid UD Axis Provided"
def CreateFingerSquareRig(self, Finger): if self.NameConv.get_from_name(Finger[0], "side") == "L": sideVariation = 1 else: sideVariation = -1 BoxResetPoint, BoxControl = RMRigShapeControls.RMCreateBoxCtrl( Finger[len(Finger) - 1], ParentBaseSize=True, Xratio=.5, Yratio=.5, Zratio=.5) self.RMaddFinguerControls(BoxControl) pm.makeIdentity(BoxControl, apply=True, r=False, t=True, s=True, n=0) pm.parentConstraint(Finger[len(Finger) - 1], BoxResetPoint) RMRigTools.RMLockAndHideAttributes(BoxControl, "0000000000") RMRigTools.RMConnectWithLimits("%s.MidUD" % BoxControl, "%s.rotateY" % Finger[0], [[-10, 100], [0, 0], [10, -100]]) RMRigTools.RMConnectWithLimits( "%s.MidLR" % BoxControl, "%s.rotateZ" % Finger[0], [[-10, sideVariation * 120], [0, 0], [10, sideVariation * -127]]) RMRigTools.RMConnectWithLimits( "%s.MidTwist" % BoxControl, "%s.rotateX" % Finger[0], [[-10, sideVariation * 90], [0, 0], [10, sideVariation * -90]]) index = 1 for eachjoint in range(0, len(Finger) - 1): RMRigTools.RMConnectWithLimits("%s.UD%s" % (BoxControl, index), "%s.rotateY" % Finger[eachjoint], [[-10, 100], [0, 0], [10, -100]]) RMRigTools.RMConnectWithLimits("%s.LR%s" % (BoxControl, index), "%s.rotateZ" % Finger[eachjoint], [[-10, sideVariation * 120], [0, 0], [10, sideVariation * -127]]) RMRigTools.RMConnectWithLimits( "%s.Twist%s" % (BoxControl, index), "%s.rotateX" % Finger[eachjoint], [[-10, sideVariation * 90], [0, 0], [10, sideVariation * -90]]) index += 1 self.fingerControlsReset.append(BoxResetPoint) self.fingerContols.append(BoxControl)
def RMCreateClavicleSystem(self, rootClavicle, ClavicleJoints): resetClavicleControl, clavicleControl = RMRigShapeControls.RMCreateBoxCtrl( ClavicleJoints[0]) pm.parent(resetClavicleControl, self.ChestRotationControl) pm.parentConstraint(clavicleControl, ClavicleJoints[0]) return resetClavicleControl, clavicleControl
def RMCreateSpineIKSystem(self): self.spineIK, effector, self.spineCurve = pm.ikHandle( startJoint=self.spineJoints[0], endEffector=self.spineJoints[len(self.spineJoints) - 1], createCurve=True, numSpans=len(self.spineJoints), solver="ikSplineSolver", name="spineIK") self.NameConv.rename_based_on_base_name( self.spineJoints[len(self.spineJoints) - 1], self.spineIK) self.NameConv.rename_based_on_base_name( self.spineJoints[len(self.spineJoints) - 1], effector, name="spineIKEffector") self.NameConv.rename_based_on_base_name( self.spineJoints[len(self.spineJoints) - 1], self.spineCurve, name="spineIKCurve") Clusters = RMRigTools.RMCreateClustersOnCurve(self.spineCurve) ClustersGroup = RMRigTools.RMCreateGroupOnObj(Clusters[0]) RMRigTools.RMParentArray(ClustersGroup, Clusters[1:]) self.kinematics.append(ClustersGroup) self.kinematics.append(self.spineIK) #ResetCOG, COG = RMRigShapeControls.create_box_ctrl(self.spineJoints[0],Yratio=3,Zratio=3) ResetCOG, COG = RMRigShapeControls.RMImportMoveControl( self.spineJoints[0], scale=RMRigTools.RMLenghtOfBone(self.spineJoints[0]) * 7) self.NameConv.rename_set_from_name(COG, "COG", "name") ResetChest, Chest = RMRigShapeControls.RMCreateBoxCtrl( self.spineJoints[len(self.spineJoints) - 1], Yratio=3, Zratio=3) self.NameConv.rename_set_from_name(Chest, "Chest", "name") SpineLength = RMRigTools.RMPointDistance(COG, Chest) ResetChestRotation, ChestRotation = RMRigShapeControls.RMCircularControl( Chest, radius=SpineLength, name="ChestRotation") pm.parent(ResetChestRotation, Chest) pm.parentConstraint(ChestRotation, self.chestJoint, mo=True) self.ResetChestRotationControl = ResetChestRotation self.ChestRotationControl = ChestRotation #pm.parent(ResetChest,COG) pm.setAttr(self.spineIK + ".dTwistControlEnable", 1) pm.setAttr(self.spineIK + ".dWorldUpType", 4) #pm.setAttr(self.spineIK + ".dForwardAxis",0)#Valid Option only in Maya 2016 pm.setAttr(self.spineIK + ".dWorldUpAxis", 0) pm.connectAttr(COG + ".worldMatrix[0]", self.spineIK + ".dWorldUpMatrix") pm.connectAttr(Chest + ".worldMatrix[0]", self.spineIK + ".dWorldUpMatrixEnd") locators = RMRigTools.RMCreateNLocatorsBetweenObjects(COG, Chest, 3, align="FirstObj") ChestControls = [] ChestGroups = [] AllSpine = [COG] spineControlGroup = pm.group(empty=True, name="SpineControls") self.NameConv.rename_name_in_format(spineControlGroup, name=spineControlGroup) self.secondaryControls for eachPosition in locators: ControlGroup, NewControl = RMRigShapeControls.RMImportMoveControl( eachPosition, scale=SpineLength) self.secondaryControls.append(NewControl) ChestGroups.append(ControlGroup) ChestControls.append(NewControl) AllSpine.append(NewControl) ResetTransformGroup = RMRigTools.RMCreateGroupOnObj(ControlGroup) print ResetTransformGroup print spineControlGroup pm.parent(ResetTransformGroup, spineControlGroup) pm.delete(eachPosition) RMRigTools.RMLockAndHideAttributes(NewControl, "111000000h") AllSpine.append(Chest) pm.parent(spineControlGroup, COG) ChestChildGroup = RMRigTools.RMCreateGroupOnObj(Chest, Type="child", NameConv=self.NameConv) pm.xform(ChestChildGroup, t=[-SpineLength / 2, 0, 0], os=True, relative=True) spineEnds = [COG, ChestChildGroup] self.RMRedistributeConstraint(AllSpine, Clusters, 3, ConstraintType="parent") self.RMRedistributeConstraint(spineEnds, ChestGroups, 3, ConstraintType="parent") DeformedShape, OrigShape = pm.listRelatives(self.spineCurve, children=True, shapes=True) curveInfoOriginal = pm.shadingNode('curveInfo', asUtility=True, name="SpineCurveOriginalInfo") curveInfoDeformed = pm.shadingNode('curveInfo', asUtility=True, name="SpineCurveDeformedInfo") self.NameConv.rename_name_in_format(curveInfoOriginal, name=curveInfoOriginal) self.NameConv.rename_name_in_format(curveInfoDeformed, name=curveInfoDeformed) pm.connectAttr(OrigShape + ".worldSpace[0]", curveInfoOriginal + ".inputCurve") pm.connectAttr(DeformedShape + ".worldSpace[0]", curveInfoDeformed + ".inputCurve") curveScaleRatio = pm.shadingNode('multiplyDivide', asUtility=True, name="SpineScaleRatio") self.NameConv.rename_name_in_format(curveScaleRatio, name=curveScaleRatio) pm.connectAttr(curveInfoDeformed + ".arcLength", curveScaleRatio + ".input1X") pm.connectAttr(curveInfoOriginal + ".arcLength", curveScaleRatio + ".input2X") pm.setAttr(curveScaleRatio + ".operation", 2) #preparation for Scale multiplication function of each spine joint pm.addAttr(Chest, at="float", sn="ssf", ln="spineSquashFactor", hnv=1, hxv=1, h=0, k=1, smn=-10, smx=10) GaussLen = len(self.spineJoints) center = len(self.spineJoints) / 2 powMaxValue = 5 powRate = powMaxValue / center index = 1 for eachJoint in self.spineJoints[1:]: #translate stretch multiplication functions of each spine joint SpineStretchMult = pm.shadingNode( 'multiplyDivide', asUtility=True, name="SpineTranslateStretchMult" + self.NameConv.get_a_short_name(eachJoint)) self.NameConv.rename_name_in_format(SpineStretchMult, name=SpineStretchMult) CurrentXPosition = pm.getAttr(eachJoint + ".translateX") pm.setAttr(SpineStretchMult + ".input2X", CurrentXPosition) pm.connectAttr(curveScaleRatio + ".outputX", SpineStretchMult + ".input1X") pm.connectAttr(SpineStretchMult + ".outputX", eachJoint + ".translateX") #Scale multiplication function of each spine joint if index >= center: PowValue = (GaussLen - 1 - index) else: PowValue = index SpineStretchRatio = pm.shadingNode( 'multiplyDivide', asUtility=True, name="SpineStretchRatio" + self.NameConv.get_a_short_name(eachJoint)) self.NameConv.rename_name_in_format(SpineStretchRatio, name=SpineStretchRatio) pm.connectAttr(Chest + ".spineSquashFactor ", SpineStretchRatio + ".input1X") pm.setAttr(SpineStretchRatio + ".input2X", PowValue) pm.setAttr(SpineStretchRatio + ".operation", 1) SpineScaleStretchPow = pm.shadingNode( 'multiplyDivide', asUtility=True, name="SpineScaleStretchPow" + self.NameConv.get_a_short_name(eachJoint)) self.NameConv.rename_name_in_format(SpineScaleStretchPow, name=SpineScaleStretchPow) pm.connectAttr(curveScaleRatio + ".outputX ", SpineScaleStretchPow + ".input1X") pm.connectAttr(SpineStretchRatio + ".outputX ", SpineScaleStretchPow + ".input2X") pm.setAttr(SpineScaleStretchPow + ".operation", 3) SpineInversScaleRatio = pm.shadingNode( 'multiplyDivide', asUtility=True, name="SpineInverseScaleRatio") self.NameConv.rename_name_in_format(SpineInversScaleRatio, name=SpineInversScaleRatio) pm.connectAttr(SpineScaleStretchPow + ".outputX ", SpineInversScaleRatio + ".input1X") pm.setAttr(SpineInversScaleRatio + ".input2X", -1) pm.setAttr(SpineInversScaleRatio + ".operation", 3) pm.connectAttr(SpineInversScaleRatio + ".outputX", eachJoint + ".scaleY") pm.connectAttr(SpineInversScaleRatio + ".outputX", eachJoint + ".scaleZ") index += 1 resetWaist, waist = RMRigShapeControls.RMCircularControl( AllSpine[1], radius=SpineLength * .8, name="waist") pm.parent(ResetChest, waist) pm.parent(resetWaist, COG) self.chestControl = Chest self.resetChestControl = ResetChest self.waistControl = waist self.resetWaistControl = resetWaist self.COG = COG self.ResetCOG = ResetCOG self.SpineLength = SpineLength
def RMCreateTwist(self, TwistJoint, LookAtObject, NumberOfTB = 3, LookAtAxis = "Y"): #LookAtObject = pm.listRelatives( TwistJoint,type = "transform",children=True)[] positionA = pm.xform(TwistJoint, q=True,ws=True,rp=True) positionB = pm.xform(LookAtObject, q=True,ws=True,rp=True) vectorA = om.MVector(positionA) vectorB = om.MVector(positionB) self.RMCreateBonesBetweenPoints(vectorA,vectorB,NumberOfTB, AlignObject=TwistJoint) Distance = RMRigTools.RMPointDistance( TwistJoint, LookAtObject) pm.parentConstraint (TwistJoint, self.TwistResetJoints) resetPoint , control = RMRigShapeControls.RMCreateBoxCtrl(self.TwistJoints[0], Xratio=.1, Yratio=.1, Zratio=.1, customSize=Distance/5, name="TwistOrigin%s" % self.NameConv.get_a_short_name(TwistJoint).title()) #control = self.NameConv.RMRenameBasedOnBaseName(TwistJoint , control, NewName = self.NameConv.RMGetAShortName(control)) #resetPoint = self.NameConv.RMRenameBasedOnBaseName(TwistJoint , resetPoint, NewName = self.NameConv.RMGetAShortName(resetPoint)) sign = 1 MoveDistance = Distance/5 if "-" in LookAtAxis: sign = -1 if "Z" in LookAtAxis or "z" in LookAtAxis: MoveList = [0,0, MoveDistance * sign] WUV = [0,0,sign] elif "Y" in LookAtAxis or "y" in LookAtAxis: MoveList = [0,MoveDistance * sign, 0] WUV = [0,sign,0] pm.xform( resetPoint, os = True, relative=True, t = MoveList) pm.aimConstraint( LookAtObject,self.TwistJoints[0], aim = [1,0,0], worldUpVector = [0,0,1], worldUpType = "object", worldUpObject = control) TwistJointDivide = pm.shadingNode("multiplyDivide", asUtility=True, name="TwistJoint%s" % self.NameConv.get_a_short_name(TwistJoint).title()) self.NameConv.rename_based_on_base_name(TwistJoint, TwistJointDivide, name=self.NameConv.get_a_short_name(TwistJointDivide)) # TwistAddition = pm.shadingNode( "plusMinusAverage", asUtility = True, name = "TwistJointAdd" + # self.NameConv.get_a_short_name(TwistJoint).title()) # self.NameConv.rename_based_on_base_name(TwistJoint, TwistAddition, # name=self.NameConv.get_a_short_name(TwistAddition)) # NegativeLookAtRotation = pm.shadingNode("multiplyDivide", asUtility=True, # name="NegativeLookAtRotation%s" % self.NameConv.get_a_short_name(TwistJoint).title()) # self.NameConv.rename_based_on_base_name(TwistJoint, NegativeLookAtRotation, # name=self.NameConv.get_a_short_name(NegativeLookAtRotation)) # pm.connectAttr(LookAtObject + ".rotateX", NegativeLookAtRotation + ".input1X") # pm.setAttr("%s.input2X" % NegativeLookAtRotation, -1) # pm.setAttr("%s.operation" % NegativeLookAtRotation, 1) # pm.connectAttr("%s.rotateX" % self.TwistJoints[0], "%s.input1D[0]" % TwistAddition) # pm.connectAttr("%s.outputX" % NegativeLookAtRotation, "%s.input1D[1]" % TwistAddition) # pm.connectAttr("%s.output1D" % TwistAddition, "%s.input1X" % TwistJointDivide) pm.connectAttr("%s.rotateX" % self.TwistJoints[0], "%s.input1X" % TwistJointDivide) #pm.connectAttr(self.TwistJoints[0]+".rotateX", TwistJointDivide + ".input1X") in this case the rotation of the lookatNode was not affecting pm.setAttr("%s.input2X" % TwistJointDivide, -(len(self.TwistJoints) - 1)) pm.setAttr("%s.operation" % TwistJointDivide, 2) for eachJoint in self.TwistJoints[1:]: pm.connectAttr("%s.outputX" % TwistJointDivide, "%s.rotateX" % eachJoint) self.TwistControlResetPoint = resetPoint self.TwistControl = control
def StandardFeetIKRig(self, StandarFeetPointsDic, FeetControl=None): self.StandardFeetPointsDic = StandarFeetPointsDic Side = self.NameConv.get_from_name( self.StandardFeetPointsDic["feet"][0], "side") self.rootIKJoints, StandardFeetIKJoints = self.StandardReverseFeetJointStructure( StandarFeetPointsDic) self.NameConv.rename_set_from_name(StandardFeetIKJoints, "IK", "name", mode="add") FootIn = self.StandardFeetPointsDic["limitIn"] FootOut = self.StandardFeetPointsDic["limitOut"] FootBK = self.StandardFeetPointsDic["limitBack"] Length = RMRigTools.RMPointDistance( self.StandardFeetPointsDic["feet"][2], FootBK) Width = RMRigTools.RMPointDistance(FootIn, FootOut) BallGrp = pm.group(empty=True, name=self.NameConv.set_name_in_format(name="Ball", side=Side)) BallLift = pm.group(empty=True, name=self.NameConv.set_name_in_format( name="BallLift", side=Side)) TapGrp = pm.group(empty=True, name=self.NameConv.set_name_in_format(name="TapGrp", side=Side)) TipGrp = pm.group(empty=True, name=self.NameConv.set_name_in_format(name="TipGrp", side=Side)) SideInGrp = pm.group(empty=True, name=self.NameConv.set_name_in_format( name="SideInGrp", side=Side)) SideOutGrp = pm.group(empty=True, name=self.NameConv.set_name_in_format( name="SideOutGrp", side=Side)) FeetOrient = pm.group(empty=True, name=self.NameConv.set_name_in_format( name="FeetOrient", side=Side)) FeetPalmOrient = pm.group(empty=True, name=self.NameConv.set_name_in_format( name="FeetPalmOrient", side=Side)) RMRigTools.RMAlign(StandardFeetIKJoints[1], BallGrp, 3) RMRigTools.RMAlign(StandardFeetIKJoints[1], BallLift, 3) RMRigTools.RMAlign(StandardFeetIKJoints[1], TipGrp, 3) RMRigTools.RMAlign(StandardFeetIKJoints[2], TipGrp, 1) RMRigTools.RMAlign(StandardFeetIKJoints[1], TapGrp, 3) RMRigTools.RMAlign(FootIn, SideInGrp, 3) RMRigTools.RMAlign(FootOut, SideOutGrp, 3) RMRigTools.RMAlign(FootBK, TapGrp, 3) RMRigTools.RMAlign(BallGrp, FeetPalmOrient, 3) RMRigTools.RMAlign(StandardFeetIKJoints[0], FeetOrient, 3) pm.xform(FeetOrient, objectSpace=True, relative=True, t=[0, 0, Width]) pm.xform(FeetPalmOrient, objectSpace=True, relative=True, t=[0, 0, Width]) BallIK, BallIkEffector = pm.ikHandle( sj=StandardFeetIKJoints[0], ee=StandardFeetIKJoints[1], name="BallIK") # solver="ikRPsolver", TipIK, TipIkEffector = pm.ikHandle( sj=StandardFeetIKJoints[1], ee=StandardFeetIKJoints[2], name="TipIK") # solver="ikRPsolver", self.NameConv.rename_name_in_format(BallIK, side=Side) self.NameConv.rename_name_in_format(TipIK, side=Side) self.NameConv.rename_name_in_format(BallIkEffector, side=Side) self.NameConv.rename_name_in_format(TipIkEffector, side=Side) # pm.poleVectorConstraint (FeetOrient, BallIK) # pm.poleVectorConstraint (FeetPalmOrient, TipIK) pm.parent(BallIK, BallLift) pm.parent(TipIK, BallLift) pm.parent(BallLift, SideInGrp) pm.parent(BallGrp, SideInGrp) pm.parent(SideInGrp, SideOutGrp) pm.parent(SideOutGrp, TapGrp) pm.parent(TapGrp, TipGrp) pm.parent(FeetOrient, BallGrp) pm.parent(FeetPalmOrient, BallLift) TipData = self.rig_tools.RMCreateGroupOnObj(TipGrp) MainFeet = self.rig_tools.RMCreateGroupOnObj(TipData) self.NameConv.rename_set_from_name(MainFeet, "MainFeet", "name") if not FeetControl: fetControlReset, FeetControl = RMRigShapeControls.RMCreateBoxCtrl( StandarFeetPointsDic["feet"][0], customSize=Length, Yratio=.6, Zratio=.3, name="FeetControl") self.fetControlReset = fetControlReset # self.feetMainMoveIK = TipData pm.parentConstraint(FeetControl, TipData, mo=True) self.RMStandardRigAttributes(FeetControl) pm.makeIdentity(BallGrp, apply=True, t=1, r=1, s=1, n=0) pm.makeIdentity(BallLift, apply=True, t=1, r=1, s=1, n=0) pm.makeIdentity(TapGrp, apply=True, t=1, r=1, s=1, n=0) pm.makeIdentity(TipGrp, apply=True, t=1, r=1, s=1, n=0) pm.makeIdentity(SideInGrp, apply=True, t=1, r=1, s=1, n=0) pm.makeIdentity(SideOutGrp, apply=True, t=1, r=1, s=1, n=0) pm.makeIdentity(FeetOrient, apply=True, t=1, r=1, s=1, n=0) pm.makeIdentity(FeetPalmOrient, apply=True, t=1, r=1, s=1, n=0) # pm.parent (self.rootIKJoints, BallGrp) RMRigTools.RMConnectWithLimits("%s.ToeLift" % FeetControl, "%s.rotateZ" % BallLift, [[-10, -70], [0, 0], [10, 70]]) RMRigTools.RMConnectWithLimits("%s.BallPivot" % FeetControl, "%s.rotateZ" % BallGrp, [[-10, 70], [0, 0], [10, -70]]) RMRigTools.RMConnectWithLimits("%s.HeelPivot" % FeetControl, "%s.rotateZ" % TapGrp, [[-10, -70], [0, 0], [10, 70]]) RMRigTools.RMConnectWithLimits("%s.ToePivot" % FeetControl, "%s.rotateZ" % TipGrp, [[-10, 70], [0, 0], [10, -70]]) if (Side == "L"): RMRigTools.RMConnectWithLimits("%s.Tilt" % FeetControl, "%s.rotateX" % SideInGrp, [[-10, 70], [0, 0]]) RMRigTools.RMConnectWithLimits("%s.Tilt" % FeetControl, "%s.rotateX" % SideOutGrp, [[0, 0], [10, -70]]) RMRigTools.RMConnectWithLimits("%s.ToePivotSide" % FeetControl, "%s.rotateY" % TipGrp, [[-10, 70], [0, 0], [10, -70]]) # RMRigTools.RMConnectWithLimits( "%s.ToePivot" , TipGrp + ".rotateZ", [[-10,-70],[0,0],[10,70]]) else: RMRigTools.RMConnectWithLimits("%s.Tilt" % FeetControl, "%s.rotateX" % SideInGrp, [[-10, -70], [0, 0]]) RMRigTools.RMConnectWithLimits("%s.Tilt" % FeetControl, "%s.rotateX" % SideOutGrp, [[0, 0], [10, 70]]) RMRigTools.RMConnectWithLimits("%s.ToePivotSide" % FeetControl, "%s.rotateY" % TipGrp, [[-10, -70], [0, 0], [10, 70]]) # RMRigTools.RMCreateGroupOnObj( FeetControl) pm.scaleConstraint(FeetControl, MainFeet) self.MainFeetKinematics = MainFeet self.IKAttachPoint = BallGrp self.StandardFeetIKJoints = StandardFeetIKJoints
def RMCreateNeckRig(self): resetNeckControl, NeckControl = RMRigShapeControls.RMCreateBoxCtrl( self.NeckJoints[0], name="neck") pm.parentConstraint(NeckControl, self.NeckJoints[0]) return resetNeckControl, NeckControl