def create_ctrl_ikfkSwitch(name='L_leg_fkIkSwitch', color='blue', parent=None, scale=1): """ Args: name: color: parent: Returns: """ fkikSwitch = curveLib.createShapeCtrl(type='crossPaddle', name=name, scale=scale, color=color) # addd 'rotOrder' lmin = -90 lmax = 90 # fkik stretchy attrs = ['fkIk', 'stretchy'] pm.addAttr(fkikSwitch, ln='fkIk', at='double', k=1, min=0, max=1) pm.addAttr(fkikSwitch, ln='stretchy', at='long', k=1, min=0, max=1) # group and limit zero = riggUtils.grpCtrl(fkikSwitch) riggUtils.cleanUpAttr( sel=fkikSwitch, listAttr=['sx', 'sy', 'sz', 'rx', 'ry', 'rz', 'tx', 'ty', 'tz'], l=0, k=0, cb=0) if parent is not None: riggUtils.snap(parent, zero) pm.parent(zero, parent) return fkikSwitch
def create_ctrl_spine(jnts, spine_count=4, scale=1): ''' Create COG, pelvis, spine and chest ctrls Args: jnts: spine_count: size: ctrl scale Returns: ''' ### TODO cest offset control, to rotate from chest if needed (human_luma:C_chest_offsetCtrl) log_info('Creating Spine Ctrls') side = 'C' scale = scale * 2 # scale multiplyier # - COG - # # create ctrl cog = curveLib.wireController(type='circle', name='C_COG_ctrl', size=scale*1.25, color='yellow', facingAxis='y+') riggUtils.cleanUpAttr(sel=[cog], listAttr=['sx', 'sy', 'sz'], l=0, k=0, cb=0) # grp - snap - parent - gimbal riggUtils.grpCtrl(cog) riggUtils.snap(jnts['pelvis01']['ctrlJnt'], cog.ZERO.get(), 'point') pm.parent(cog.ZERO.get(), 'DIRECTION') riggUtils.addGimbal(cog) # add to dictionary jnts['cog'] = {'ctrl': pm.PyNode('C_COG_ctrl')} spine_ctrl_grp = pm.createNode('transform', n='C_spineCtrl_grp', p=cog.gimbal.get()) riggUtils.snap(cog.gimbal.get(), spine_ctrl_grp) # - Pelvis - # log_debug('creating pelvis ctrls') jnts['pelvis01']['ctrl'] = curveLib.wireController(type='circle', name='C_pelvis_ctrl', size=scale, color='red', facingAxis='y+', aOffset=[0, -0.5, 0]) riggUtils.cleanUpAttr(sel=jnts['pelvis01']['ctrl'], listAttr=['sx', 'sy', 'sz'], l=0, k=0, cb=0) # rotation order jnts['pelvis01']['ctrlJnt'].rotateOrder.set(2) jnts['pelvis01']['ctrl'].rotateOrder.set(2) # grp - snap - parent - gimbal riggUtils.grpCtrl(jnts['pelvis01']['ctrl']) riggUtils.snap(jnts['pelvis01']['ctrlJnt'], jnts['pelvis01']['ctrl'].ZERO.get(), 'point') pm.parent(jnts['pelvis01']['ctrl'].ZERO.get(), spine_ctrl_grp) riggUtils.addGimbal(jnts['pelvis01']['ctrl']) # - Spine - # # ik spine log_debug('creating ik spine ctrls %s' % spine_count) spine_ik_jnts = pm.ls('C_spine*_ikJnt*') if len(spine_ik_jnts) < 3: log_info("No spine*_fkJnts found. Skipping") else: parent_to=spine_ctrl_grp # for ik ctrl, we skip 01 and 03, we will parent those to pelvis and chest, we only want a 'C_spine_midCtrl' ctrl = curveLib.wireController(type='cube', name='C_spineMid_ikCtrl', size=scale *0.25, color='blue', facingAxis='y+', aOffset=[0, 0, -3]) riggUtils.cleanUpAttr(ctrl, listAttr=['sx', 'sy', 'sz'], l=0, k=0, cb=0) riggUtils.grpCtrl(ctrl) riggUtils.snap(spine_ik_jnts[1], ctrl.ZERO.get(), 'point') pm.parent(ctrl.ZERO.get(), parent_to) # add to dic jnts['spine02']['ikCtrl'] = ctrl #parent jnt pm.parent(spine_ik_jnts[1], ctrl) # fk spine log_debug('creating fk spine ctrls %s' % spine_count) spine_fk_jnts = pm.ls('C_spine*_ctrlJnt') if len(spine_fk_jnts) == 0: log_info("No spine*_fkJnts found. Skipping") parent_to=spine_ctrl_grp for i in range(0, len(spine_fk_jnts)): jnt_nr = '%02d' % ( i + 1) ctrl = curveLib.wireController(type='circle', name='C_spine%s_fkCtrl'%jnt_nr, size=scale, color='blue', facingAxis='y+') riggUtils.cleanUpAttr(ctrl, listAttr=['sx', 'sy', 'sz'], l=0, k=0, cb=0) riggUtils.grpCtrl(ctrl) riggUtils.snap(spine_fk_jnts[i], ctrl.ZERO.get(), 'point') pm.parent(ctrl.ZERO.get(), parent_to) # parent next jnt to this ctrl parent_to = ctrl # add to dic jnts['spine%s'%jnt_nr]['fkCtrl'] = ctrl # - Chest - # log_debug('creating chest ctrls') jnts['chest01']['ctrl'] = curveLib.wireController(type='circle', name='C_spineChest_ctrl', size=scale, color='red', facingAxis='y+') riggUtils.cleanUpAttr(sel=jnts['chest01']['ctrl'], listAttr=['sx', 'sy', 'sz'], l=0, k=0, cb=0) # rotation order jnts['chest01']['ctrlJnt'].rotateOrder.set(2) jnts['chest01']['ctrl'].rotateOrder.set(2) # grp - snap - parent - gimbal riggUtils.grpCtrl(jnts['chest01']['ctrl']) riggUtils.snap(jnts['chest01']['ctrlJnt'], jnts['chest01']['ctrl'].ZERO.get(), 'point') pm.parent(jnts['chest01']['ctrl'].ZERO.get(), spine_ctrl_grp) riggUtils.addGimbal(jnts['chest01']['ctrl']) log_debug('spine_ik is %s'%spine_ik_jnts) # lets parent 01_ikJnt to pelvis ctrl and 03_ikJnt to chest (ik 2 has its own ctrl) if len(spine_ik_jnts) > 2: pm.parent(spine_ik_jnts[0], jnts['pelvis01']['ctrl']) pm.parent(spine_ik_jnts[2], jnts['chest01']['ctrl']) # align spineMid halfway between pelvis and chest pm.parentConstraint([jnts['pelvis01']['ctrl'], jnts['chest01']['ctrl']], jnts['spine02']['ikCtrl'].AUTO.get(), mo=1) log_debug('done create_ctrl_spine')
def setup_ik_leg(jnts, RL='L'): ikj_leg = jnts['%s_leg01' % RL]['ikJnt'] ikj_legend = pm.listRelatives(ikj_leg, children=1, ad=1, type='joint')[0] # last child ikj_ankle = jnts['%s_foot01' % RL]['ikJnt'] ikj_ball = jnts['%s_foot02' % RL]['ikJnt'] ikj_toe = jnts['%s_foot03' % RL]['ikJnt'] ikh_leg = pm.ikHandle(sj=ikj_leg, ee=ikj_legend, sol='ikRPsolver', n='%s_leg_ikh' % RL) ikh_ball = pm.ikHandle(sj=ikj_ankle, ee=ikj_ball, sol="ikSCsolver", n='%s_ball_ikh' % RL) ikh_toe = pm.ikHandle(sj=ikj_ball, ee=ikj_toe, sol="ikSCsolver", n='%s_toe_ikh' % RL) # pole vector pm.poleVectorConstraint(jnts['%s_foot01' % RL]['pvecCtrl'], ikh_leg[0]) # parent handle to ikCtrl or ikGimbalCtrl ik_ctrl = jnts['%s_foot01' % RL]['ikCtrl'] if not jnts['%s_foot01' % RL]['ikCtrl'].hasAttr('gimbal') \ else pm.PyNode(jnts['%s_foot01' % RL]['ikCtrl'].attr('gimbal').get()) pm.parent(ik[0], ik_ctrl) # this group is buffer that is aligned to foot01_ctrlJnt to orientConstrain without offset ik_grp = pm.createNode('transform', n='%s_foot01_ikGrp' % RL, p=ik_ctrl) riggUtils.snap(jnts['%s_foot01' % RL]['ctrlJnt'], ik_grp) con_node = pm.createNode('transform', n='%s_foot01_targetCon' % RL, p=ik_grp) # orient constraint will be shared by ik and fk ctrl, switch via reverse pm.orientConstraint(con_node, jnts['%s_foot01' % RL]['ctrlJnt'], mo=1, n='%s_foot01_ctrlJnt_orientCon' % RL) # for switch L_foot01_fkCtrlMatch con_node = pm.createNode('transform', n='%s_foot01_fkCtrlMatch' % RL, p=ik_grp) # foot attributes pm.addAttr(jnts['L_foot01']['ikCtrl'], ln='twist', at='double', k=1, min=-300, max=300.0) pm.addAttr(jnts['L_foot01']['ikCtrl'], ln='roll', at='double', k=1, min=-300, max=300.0) pm.addAttr(jnts['L_foot01']['ikCtrl'], ln='heelRoll', at='double', k=1, min=-300, max=300.0) pm.addAttr(jnts['L_foot01']['ikCtrl'], ln='bend', at='double', k=1, min=-300, max=300.0) pm.addAttr(jnts['L_foot01']['ikCtrl'], ln='side', at='double', k=1, min=-300, max=300.0) pm.addAttr(jnts['L_foot01']['ikCtrl'], ln='toeRoll', at='double', k=1, min=0, max=300.0) pm.addAttr(jnts['L_foot01']['ikCtrl'], ln='toeSpin', at='double', k=1, min=-300, max=300.0) pm.addAttr(jnts['L_foot01']['ikCtrl'], ln='toeWiggle', at='double', k=1, min=-300, max=300.0) footGroups = ("grp_footPivot", "grp_heel", "grp_toe", "grp_ball", "grp_flap") for item in footGroups: cmds.group(n=item, empty=True, world=True) log_info('Done: setup_ik_leg') return ik
def create_ctrl_ik_leg(jnts, side='L', parent='DIRECTION', scale=1): ''' Args: jnts: joint dictionary side: 'R' or 'L' Returns: joint dictionary ''' color = biped.define_color(side) id = '%s_foot01' % side # check if exists if pm.objExists('%s_ikCtrl' % id): pm.select('%s_ikCtrl' % id) return '%s_ikCtrl Exists' % id # -- ik ctrl -- # jnts[id]['ikCtrl'] = curveLib.createShapeCtrl(type='cube', name='%s_ikCtrl' % id, scale=scale, color=color) # group and align zero = riggUtils.grpCtrl(jnts[id]['ikCtrl']) riggUtils.snap(jnts[id]['ctrlJnt'], zero, typeCnx='point') riggUtils.grpIn('%s_leg_ctrlGrp' % side, zero) # parent leg_ctrlGrp # limit riggUtils.cleanUpAttr(sel=[jnts[id]['ikCtrl']], listAttr=['sx', 'sy', 'sz'], l=0, k=0, cb=0) log_debug('limit') # gimbal gimbalCtrl = pm.duplicate(jnts[id]['ikCtrl'], n='%s_ikGimbalCtrl' % id)[0] pm.parent(gimbalCtrl, jnts[id]['ikCtrl']) pm.xform('%s.cv[0:]' % gimbalCtrl.getShape(), s=(.8, .8, .8), r=1) pm.addAttr(jnts[id]['ikCtrl'], ln='gimbal_vis', at='bool', k=1) jnts[id]['ikCtrl'].gimbal_vis >> gimbalCtrl.visibility # store attr of gimbal on main ctrl pm.addAttr(jnts[id]['ikCtrl'], ln='gimbal', dt='string') jnts[id]['ikCtrl'].attr('gimbal').set('%s' % gimbalCtrl, k=0, l=0, type='string') log_debug('gimal done') # -- pole vector -- # jnts[id]['pvecCtrl'] = curveLib.createShapeCtrl(type='sphere', name='%s_pvecCtrl' % id, scale=scale, color=color) # group and align zero = riggUtils.grpCtrl(jnts[id]['pvecCtrl']) log_debug('finding pole position') polePos = riggUtils.poleVectorPosition( startJnt=jnts['%s_leg01' % side]['ikJnt'], midJnt=jnts['%s_leg02' % side]['ikJnt'], endJnt=jnts['%s_foot01' % side]['ctrlJnt'], length=12, createLoc=0, createViz=0) log_debug('polepos is %s' % polePos) pm.xform(zero, ws=1, t=(polePos.x, polePos.y, polePos.z)) riggUtils.grpIn('%s_leg_ctrlGrp' % side, zero) # parent leg_ctrlGrp riggUtils.grpIn(parent, '%s_leg_ctrlGrp' % side) # parent to DIRECTION # limit riggUtils.cleanUpAttr(sel=[jnts[id]['pvecCtrl']], listAttr=['sx', 'sy', 'sz', 'rx', 'ry', 'rz'], l=0, k=0, cb=0) log_info("Done create_ctrl_ik_leg()") return jnts
def create_ctrl_fk_leg(jnts, side='L', parent='DIRECTION', scale=1): ''' Args: jnts: joint dictionary side: 'R' or 'L' Returns: joint dictionary ''' if side == 'L': color = 'blue' else: color = 'red' zero = '' ids = ['%s_leg01' % side, '%s_leg02' % side, '%s_leg03' % side] for id in ids: jnts[id]['fkCtrl'] = curveLib.wireController(type='circle', name='%s_fkCtrl' % id, size=(scale), color=color, facingAxis='x+') # pm.xform('%sShape.cv[0:]' % jnts[id]['fkCtrl'], s=(1.75, 1, 1), t=(1.5, 0, 0), r=1) # group and align zero = riggUtils.grpCtrl(ctrl=jnts[id]['fkCtrl'], sdk=1) riggUtils.snap(jnts[id]['fkJnt'], zero) riggUtils.grpIn('%s_leg_ctrlGrp' % side, zero) # parent leg_ctrlGrp riggUtils.grpIn(parent, '%s_leg_ctrlGrp' % side) # limit riggUtils.cleanUpAttr(sel=[jnts[id]['fkCtrl']], listAttr=['sx', 'sy', 'sz', 'tx', 'ty', 'tz'], l=1, k=0, cb=0) # hide zero of leg03 zero.hide() id = '%s_foot01' % side jnts[id]['fkCtrl'] = curveLib.wireController(type='circle', name='%s_fkCtrl' % id, size=(scale), color=color, facingAxis='x+') # group and align zero = riggUtils.grpCtrl(ctrl=jnts[id]['fkCtrl'], sdk=1) riggUtils.snap(jnts[id]['ctrlJnt'], zero) riggUtils.grpIn( '%s_leg_ctrlGrp' % side, zero) # parent leg ctrlGrp, AUTO will be constraint to leg03_endJnt # limit riggUtils.cleanUpAttr(sel=[jnts[id]['fkCtrl']], listAttr=['sx', 'sy', 'sz', 'tx', 'ty', 'tz'], l=0, k=0, cb=0) id = '%s_foot02' % side jnts[id]['fkCtrl'] = curveLib.wireController(type='circle', name='%s_fkCtrl' % id, size=(scale), color=color, facingAxis='x+') # group and align zero = riggUtils.grpCtrl(ctrl=jnts[id]['fkCtrl'], sdk=1) riggUtils.snap(jnts[id]['ctrlJnt'], zero) riggUtils.grpIn( '%s_leg_ctrlGrp' % side, zero) # parent leg ctrlGrp, AUTO will be constraint to leg03_endJnt riggUtils.grpIn(parent, '%s_leg_ctrlGrp' % side) # parent to DIRECTION pm.parent(zero, jnts['%s_foot01' % side]['fkCtrl']) # parent foot2 # limit riggUtils.cleanUpAttr(sel=[jnts[id]['fkCtrl']], listAttr=['sx', 'sy', 'sz', 'tx', 'ty', 'tz'], l=0, k=0, cb=0) log_info("Done create_ctrl_fk_leg()")
def initializeRiggTab(self, tabHeight, tabWidth): columnWidth = 100 moduleSpecific_scrollHeight = 120 scrollHeight = tabHeight - moduleSpecific_scrollHeight - 20 #1. Get Info self.UIElements["mainColumn"] = pm.columnLayout("mainColumn") pm.rowColumnLayout("snapRowColumn", numberOfColumns=3, ro=[(1, "both", 2), (2, "both", 2), (3, "both", 2)], columnAttach=[(1, "both", 3), (2, "both", 3), (3, "both", 3)], columnWidth=[(1, columnWidth), (2, columnWidth), (3, columnWidth)]) pm.button( label="snapT", parent="snapRowColumn", bgc=(0.209, 0.209, 0.209), command=lambda a: mo_riggUtils.snap(pm.selected()[0], pm.selected()[-1], 'point')) pm.button( label="snapR", parent="snapRowColumn", bgc=(0.209, 0.209, 0.209), command=lambda a: mo_riggUtils.snap(pm.selected()[0], pm.selected()[-1], 'orient')) pm.button(label="snap", parent="snapRowColumn", bgc=(0.209, 0.209, 0.209), command=lambda a: mo_riggUtils.snap(pm.selected()[0], pm.selected()[-1])) pm.setParent(self.UIElements["mainColumn"]) pm.separator() self.UIElements["3"] = pm.rowColumnLayout(numberOfColumns=3, ro=[(1, "both", 2), (2, "both", 2), (3, "both", 2)], columnAttach=[(1, "both", 3), (2, "both", 3), (3, "both", 3) ], columnWidth=[ (1, columnWidth), (2, columnWidth), (3, columnWidth) ]) pm.button(label="hammerSkin", command=lambda a: pm.mel.eval('weightHammerVerts;')) pm.button(label="copySkin", command=lambda a: pm.mel.eval('artAttrSkinWeightCopy;')) pm.button(label="pasteSkin", command=lambda a: pm.mel.eval('artAttrSkinWeightPaste;')) pm.button(label="getSkinInfluenceJoints", command=lambda a: mo_riggUtils.getSkinInfluenceJoints()) pm.button(label="getJointChain", command=lambda a: mo_riggUtils.getJointChain()) pm.button(label="delChildConst", command=lambda a: libUtil.deleteChildrenConstraints()) pm.text(label="") #2. Rigg Editing pm.setParent(self.UIElements["mainColumn"]) pm.separator() self.UIElements["4"] = pm.rowColumnLayout(numberOfColumns=3, ro=[(1, "both", 2), (2, "both", 2), (3, "both", 2)], columnAttach=[(1, "both", 3), (2, "both", 3), (3, "both", 3) ], columnWidth=[ (1, columnWidth), (2, columnWidth), (3, columnWidth) ]) pm.button(label="transferSkin", command=lambda a: libUtil.TransferSkinWeightsPolyToPoly( pm.selected()[0], pm.selected()[0:])) pm.button(label="alignJ", command=lambda a: mo_riggUtils.alignJ()) pm.button(label="vecViz", command=lambda a: mo_riggUtils.vecVizObjects(pm.selected())) pm.button(label="createIKSpline", command=lambda a: mo_riggUtils.createIKSpline()) pm.button( label="createJointsAtPos", command=lambda a: mo_riggUtils.createJointsAtPos(pm.selected())) pm.button(label="splitJnt", command=lambda a: splitJointUI.splitSelJointUI()) pm.setParent(self.UIElements["mainColumn"]) pm.separator() self.UIElements["5"] = pm.rowColumnLayout(numberOfColumns=3, ro=[(1, "both", 2), (2, "both", 2), (3, "both", 2)], columnAttach=[(1, "both", 3), (2, "both", 3), (3, "both", 3) ], columnWidth=[ (1, columnWidth), (2, columnWidth), (3, columnWidth) ]) #3. Ctrl Editing pm.optionMenu("option_ctrlShape", width=columnWidth * 0.3) pm.menuItem(label='cube') pm.menuItem(label='circle') pm.menuItem(label='locator') self.swatchbtn = pm.button(w=32, h=32, l="", bgc=(1.0, 1.0, 0.0), c=self.set_color) #print('bg color is %s'%self.swatchbtn.getBackgroundColor()) pm.button(label="createCtrl", bgc=(0.439, 0.615, 0.184), command=lambda a: self.createCtrlWin(hi=0)) pm.button(label="addGibmal", command=lambda a: mo_riggUtils.addGimbal(pm.selected())) pm.button(label="addGibmal", command=lambda a: mo_riggUtils.addGimbal(pm.selected())) pm.button(label="createCtrlHi", bgc=(0.439, 0.615, 0.184), command=lambda a: self.createCtrlWin(hi=1, constrain=False)) #3. Ctrl Editing pm.optionMenu("option_scaleAxis", width=columnWidth * 0.3) pm.menuItem(label='XYZ') pm.menuItem(label='X') pm.menuItem(label='Y') pm.menuItem(label='Z') pm.menuItem(label='XY') pm.menuItem(label='XZ') pm.menuItem(label='YZ') pm.button( label="Scale +", command=lambda a: mo_riggUtils.scaleShape( 1.25, axis=pm.optionMenu("option_scaleAxis", q=1, value=1))) pm.button( label="Scale -", command=lambda a: mo_riggUtils.scaleShape( 0.75, axis=pm.optionMenu("option_scaleAxis", q=1, value=1))) #3. Ctrl Editing pm.optionMenu("option_rotateAxis", width=columnWidth * 0.3) pm.menuItem(label='X') pm.menuItem(label='Y') pm.menuItem(label='Z') pm.button( label="Rotate 90", command=lambda a: mo_riggUtils.rotateShape( 90, axis=pm.optionMenu("option_rotateAxis", q=1, value=1))) pm.button(label="Rotate 90") pm.button(label="connect", bgc=(0.439, 0.615, 0.184), command=lambda a: self.connectCtrlWin()) pm.button(label="disconnect", bgc=(0.901, 0.411, 0.298), command=lambda a: self.disconnectCtrlWin()) pm.button(label="grpZERO", command=lambda a: self.grpCtrlsWin()) pm.setParent(self.UIElements["mainColumn"]) return self.UIElements["mainColumn"]