Example #1
0
def makeIK(*args):
    """This function creates IK handles on the joints that were created"""

    # Create the IK handle that controls the bucket of the arm and save it to variable
    # We use SingleChaing solveer as we are creating IK on two joints only
    bucketIK = cmds.ikHandle(startJoint=start.jointList[-2], endEffector=start.jointList[-1], solver="ikSCsolver", sticky="sticky")[0]

    # Check if there is a controller with the same name, 
    # if there is, this function with generate a new one
    bucketName = checkDuplicatedName("bucketCtrl")

    # Create controller
    bucketCtrl = cmds.circle(name=bucketName, radius=2)[0]

    # Select both controller and IK
    cmds.select(bucketCtrl, bucketIK)

    # Move controller to IK
    cmds.MatchTranslation()

    # Select them reversed
    cmds.select(bucketIK, bucketCtrl)

    # Parent IK to bucker
    cmds.parent()

    # Save the name of the controller on data object
    data.rootController = bucketCtrl

    # If there are more than two arm pieces, we can create a second IK just for the arm
    if  start.armsValue > 2:

        # Create arm IK handle on the joint three indices from the last [-4] and the previous to last [-2]
        # In python [-1] represents the last index on a list
        # We use Rotate plane solver as we have a chain of three joints
        armIK = cmds.ikHandle(startJoint=start.jointList[-4], endEffector=start.jointList[-2], solver="ikRPsolver")[0]

        # Check if there is a controller with the same name, 
        # if there is, this function with generate a new one
        armName = checkDuplicatedName("armCtrl")

        # Create controller for this IK
        armCtrl = cmds.circle(name=armName, radius=2)[0]

        # Move controller to IK and parent them correctly
        cmds.select(armCtrl, armIK)
        cmds.MatchTranslation()
        cmds.select(armIK, armCtrl)
        cmds.parent()

        # Parent previous IK to this one
        cmds.select(bucketCtrl, armCtrl)
        cmds.parent()

        # Add reference to data object
        data.rootController = armCtrl
Example #2
0
def main():
    selList = []
    selList = mc.ls(selection=True)

    for sel in selList:
        cone = createCone(sel)
        mc.select(cone, sel, replace=True)
        mc.MatchTranslation()
        mc.select(clear=True)
Example #3
0
def matchFreeze(tmp=True):
    if tmp:
        if cmds.checkBoxGrp(match_check, q=True, v1=True):
            cmds.MatchTranslation()
        if cmds.checkBoxGrp(match_check, q=True, v2=True):
            cmds.MatchRotation()
        if cmds.checkBoxGrp(match_check, q=True, v3=True):
            cmds.MatchScaling()
        if cmds.checkBoxGrp(match_check, q=True, v4=True):
            cmds.MatchPivots()
    else:
        if cmds.checkBoxGrp(match_check, q=True, v1=True):
            cmds.makeIdentity(a=True, t=1, r=0, s=0, n=0, pn=1)
        if cmds.checkBoxGrp(match_check, q=True, v2=True):
            cmds.makeIdentity(a=True, t=0, r=1, s=0, n=0, pn=1)
        if cmds.checkBoxGrp(match_check, q=True, v3=True):
            cmds.makeIdentity(a=True, t=0, r=0, s=1, n=0, pn=1)
Example #4
0
def controlOnLocator(controllerName="controller", *args):
    """This function adds controllers on the selected locators
    
    Parameters
    ----------
    controllerName : str
        The desired naming convention for the controllers and their group

    
    Returns
    -------
    list
        A list containing the driven group on index [0] and controller group on index [1]
    """

    controllerList = []

    for locator in args:
        # Create a curve with a cube shape
        cubeCtrl = cmds.curve(n=controllerName,
                   degree=1,
                   point=[(-0.5, 0.5, 0.5), (0.5, 0.5, 0.5), (0.5, 0.5, -0.5), (-0.5, 0.5, -0.5), (-0.5, 0.5, 0.5),
                          (-0.5, -0.5, 0.5), (-0.5, -0.5, -0.5), (0.5, -0.5, -0.5), (0.5, -0.5, 0.5), (-0.5, -0.5, 0.5),
                          (0.5, -0.5, 0.5), (0.5, 0.5, 0.5), (0.5, 0.5, -0.5), (0.5, -0.5, -0.5), (-0.5, -0.5, -0.5),
                          (-0.5, 0.5, -0.5)],
                   k=[0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0])

        controllerList.append(cubeCtrl)

        # Select both objects to match translation
        cmds.select(cubeCtrl, locator)
        cmds.MatchTranslation()
        cmds.select(cubeCtrl, r=True)
        cmds.FreezeTransformations()
        cmds.select(cubeCtrl, locator)
        cmds.parentConstraint(mo=True, w=1)

    cmds.select(args)
    locatorsGroup = cmds.group(name="PointLocatorsGroup")
    cmds.setAttr("{}.visibility".format(locatorsGroup), 0)

    cmds.select(controllerList)
    controllerGroup = cmds.group(name="{}Group".format(controllerName))

    return [locatorsGroup, controllerGroup]
Example #5
0
def makeMainController():
    """This function creates a MainController to drive the entire arm"""

    # Check if there is a controller with the same name, 
    # if there is, this function with generate a new one
    mainName = checkDuplicatedName("ArmMainController")

    # Create controller
    data.mainController = cmds.circle(name=mainName, radius=3, normal=(0,1,0))[0]

    # Create offset group
    data.mainControllerGroup = cmds.group(name="ArmMainControllerGroup")

    # Move group to root joint
    cmds.select(data.mainControllerGroup, data.rootJoint)
    cmds.MatchTranslation()

    # Parent joint and controller to this new MainController
    cmds.select(data.rootController, data.rootJoint, data.mainController)
    cmds.parent()