Exemplo n.º 1
0
def ctrl_for_all(size='default', normal=(0, 1, 0)):
    selection = mc.ls(sl=True)

    for node in selection:
        node_name = node.split('|')[-1]

        pos = mc.xform(node, q=True, rp=True, ws=True)
        rot = mc.xform(node, q=True, ro=True, ws=True)
        sca = mc.xform(node, q=True, s=True)

        new_name = node_name + '_ctrl'

        bbox = mc.exactWorldBoundingBox(node, ignoreInvisible=True)

        # calculate ctrl size
        bbox_size = [0, 0]
        bbox_size[0] = bbox[3] - bbox[0]
        bbox_size[1] = bbox[5] - bbox[2]
        bbox_size.sort()
        ctrl_size = size
        if size == 'default':
            ctrl_size = bbox_size[1] * 0.6 / sca[0]

        # create circle and place it
        mc.circle(name=new_name, normal=normal, sections=8, radius=ctrl_size)
        mlutilities.color([new_name + 'Shape'], 'yellow')
        mc.addAttr(new_name, at='bool', k=True, h=False, ln='VISIBLE')
        mc.connectAttr(new_name + '.VISIBLE', node + '.visibility')
        mc.setAttr(new_name + '.VISIBLE', 1)
        mc.setAttr(new_name + '.visibility', k=False, cb=False)
        mc.makeIdentity(new_name, apply=True, s=True, r=True, t=True)
        mc.xform(new_name, t=pos)
        mc.xform(new_name, ro=rot)

        node_orig = orig.orig(node=[new_name])

        mc.parentConstraint('|' + node_orig + '|' + new_name, node)
        mc.scaleConstraint('|' + node_orig + '|' + new_name, node, mo=True)
        mc.delete(new_name, ch=True)

        # parent to existing hierarchy
        if mc.objExists('helper_ctrl'):
            mc.parent(node_orig, 'helper_ctrl')
        elif mc.objExists('walk_ctrl'):
            mc.parent(node_orig, 'walk_ctrl')
        else:
            pass

    # append ctrl to the existing rig set
    mlutilities.rigset()
Exemplo n.º 2
0
def create_bend_squash(bounds=False, center='low'):
    """that function creates a system composed of 2 bend (X and Z) and a squash"""

    # lists the current selected nodes
    selection = mc.ls(sl=True)
    i = 0

    # creates the system for every node in the current selection
    for node in selection:

        low_bound_ctrl = node + '_lowBound_ctrl'
        high_bound_ctrl = node + '_highBound_ctrl'

        # positions according to the bbox of the current node
        x1, y1, z1, x2, y2, z2 = mc.exactWorldBoundingBox(
            selection[i], calculateExactly=True, ignoreInvisible=True)
        bbox_size = [0, 0]
        bbox_size[0] = x2 - x1
        bbox_size[1] = y2 - y1
        bbox_size.sort()
        ctrl_size = bbox_size[1] * 0.5
        pointer_size = [ctrl_size / 4, ctrl_size / 4, ctrl_size / 4]

        low_pos = ((x2 + x1) / 2, y1, (z2 + z1) / 2)
        high_pos = ((x2 + x1) / 2, y2, (z2 + z1) / 2)
        mid_pos = ((x2 + x1) / 2, (y2 + y1) / 2, (z2 + z1) / 2)

        # defines bounds according to the specified parameter
        bound = [-2, 2]
        if center == 'mid':
            center_position = mid_pos
            bound = [-1, 1]
            low_bound_pos = low_pos
            high_bound_pos = high_pos
        elif center == 'high':
            center_position = high_pos
            low_bound_pos = low_pos
            high_bound_pos = [high_pos[0], high_pos[1] * 3, high_pos[2]]
        else:
            center_position = low_pos
            low_bound_pos = [low_pos[0], low_pos[1] * 3, low_pos[2]]
            high_bound_pos = high_pos

        # creates the first bend
        bend_x = create_deform('bend', 'X', node)
        mc.xform(bend_x[1], t=center_position, ro=[0, 0, 0])
        orig_bend_x = orig.orig([bend_x[1]])
        mc.setAttr(bend_x[0] + '.lowBound', bound[0])
        mc.setAttr(bend_x[0] + '.highBound', bound[1])

        # creates the second bend
        bend_z = create_deform('bend', 'Z', node)
        mc.xform(bend_z[1], t=center_position, ro=[0, 90, 0])
        orig_bend_z = orig.orig([bend_z[1]])
        mc.setAttr(bend_z[0] + '.lowBound', bound[0])
        mc.setAttr(bend_z[0] + '.highBound', bound[1])

        # creates the squash
        squash = create_deform('squash', 'Y', node)
        mc.xform(squash[1], t=center_position)
        orig_squash = orig.orig([squash[1]])
        mc.setAttr(squash[0] + '.lowBound', bound[0])
        mc.setAttr(squash[0] + '.highBound', bound[1])

        # creates the controller for the system
        # defines the ctrl name
        ctrl_name = node + '_ctrl'
        bendsquash_ctrl_name = node + '_bendSquash_ctrl'
        bendsquash_SR_name = node + '_bendSquash_SR'
        bendSquash_bounds_SR_name = node + '_bendSquash_bounds_SR'

        # creation and zeroOut
        orig_ctrl = mlutilities.create_ctrl(
            ctrl_type='quad_arrow',
            name=bendsquash_ctrl_name,
            sca=[ctrl_size, ctrl_size * 0.5, ctrl_size])[1]
        # place the zeroOut
        mc.xform(orig_ctrl,
                 t=[high_pos[0], high_pos[1] / 10 * 12, high_pos[2]])

        # creates and set setRange node
        mc.createNode('setRange', n=bendsquash_SR_name)
        mc.setAttr(bendsquash_SR_name + '.min', -180, -10, 180, type="double3")
        mc.setAttr(bendsquash_SR_name + '.max', 180, 10, -180, type="double3")
        mc.setAttr(bendsquash_SR_name + '.oldMin',
                   -10,
                   -bbox_size[1] * 4,
                   -10,
                   type="double3")
        mc.setAttr(bendsquash_SR_name + '.oldMax',
                   10,
                   bbox_size[1] * 4,
                   10,
                   type="double3")
        # connects ctrl to SR and SR to nonLinears
        mc.connectAttr(bendsquash_ctrl_name + '.translateX',
                       bendsquash_SR_name + '.valueX')
        mc.connectAttr(bendsquash_SR_name + '.outValueX',
                       bend_x[0] + '.curvature')
        mc.connectAttr(bendsquash_ctrl_name + '.translateY',
                       bendsquash_SR_name + '.valueY')
        mc.connectAttr(bendsquash_SR_name + '.outValueY',
                       squash[0] + '.factor')
        mc.connectAttr(bendsquash_ctrl_name + '.translateZ',
                       bendsquash_SR_name + '.valueZ')
        mc.connectAttr(bendsquash_SR_name + '.outValueZ',
                       bend_z[0] + '.curvature')

        mc.hide(orig_bend_x, orig_bend_z, orig_squash)

        # parent to existing hierarchy
        if mc.objExists(ctrl_name):
            mc.parent(orig_bend_x, orig_bend_z, orig_squash, orig_ctrl,
                      ctrl_name)
        elif mc.objExists('helper_ctrl'):
            mc.parent(orig_bend_x, orig_bend_z, orig_squash, orig_ctrl,
                      'helper_ctrl')
        else:
            mc.parent(orig_bend_x, orig_bend_z, orig_squash, orig_ctrl,
                      'walk_ctrl')

        if bounds:
            hb_limit_up = float(mid_pos[1] + 9 * fabs(high_bound_pos[1]))
            hb_limit_down = float(mid_pos[1] - 11 * fabs(high_bound_pos[1]))
            lb_limit_up = float(mid_pos[1] + 9 * fabs(low_bound_pos[1]))
            lb_limit_down = float(mid_pos[1] - 11 * fabs(low_bound_pos[1]))
            # creates bounds pointers
            mlutilities.create_ctrl(ctrl_type='pointer',
                                    size=pointer_size,
                                    name=high_bound_ctrl,
                                    rotation=[180, 0, 0])
            mc.xform(high_bound_ctrl, t=high_bound_pos)
            orig_highbound = orig.orig([high_bound_ctrl])
            mlutilities.create_ctrl(ctrl_type='pointer',
                                    size=pointer_size,
                                    name=low_bound_ctrl)
            mc.xform(low_bound_ctrl, t=low_bound_pos)
            orig_lowbound = orig.orig([low_bound_ctrl])

            # creates bounds SR and set it
            mc.createNode('setRange', n='bendSquash_bounds_SR')
            mc.setAttr(bendSquash_bounds_SR_name + '.min',
                       -10,
                       -10,
                       0,
                       type="double3")
            mc.setAttr(bendSquash_bounds_SR_name + '.max',
                       10,
                       10,
                       0,
                       type="double3")
            mc.setAttr(bendSquash_bounds_SR_name + '.oldMin',
                       hb_limit_down,
                       lb_limit_down,
                       0.0,
                       type="double3")
            mc.setAttr(bendSquash_bounds_SR_name + '.oldMax',
                       hb_limit_up,
                       lb_limit_up,
                       0.0,
                       type="double3")
            # connects controllers to SR and SR to nonLinears
            mc.connectAttr(node + '_highBound_ctrl.translateY',
                           bendSquash_bounds_SR_name + '.valueX')
            mc.connectAttr(bendSquash_bounds_SR_name + '.outValueX',
                           bend_x[0] + '.highBound')
            mc.connectAttr(bendSquash_bounds_SR_name + '.outValueX',
                           bend_z[0] + '.highBound')
            mc.connectAttr(node + '_lowBound_ctrl.translateY',
                           bendSquash_bounds_SR_name + '.valueY')
            mc.connectAttr(bendSquash_bounds_SR_name + '.outValueY',
                           bend_x[0] + '.lowBound')
            mc.connectAttr(bendSquash_bounds_SR_name + '.outValueY',
                           bend_z[0] + '.lowBound')

            # parent to existing hierarchy
            if mc.objExists(bendsquash_ctrl_name):
                mc.parent(orig_highbound, orig_lowbound, ctrl_name)
            elif mc.objExists('helper_ctrl'):
                mc.parent(orig_highbound, orig_lowbound, 'helper_ctrl')
            else:
                mc.parent(orig_highbound, orig_lowbound, 'walk_ctrl')

        i += 1
    mlutilities.rigset()
Exemplo n.º 3
0
def softmod_for_each(size=1):
    """Create a softMod deformer and controlers for every selected element"""

    # what's selected
    selection = mc.ls(sl=True)

    # for each selected node
    for node in selection:

        # get the name and the transforms
        node_name = node.split('|')[-1]
        pos = mc.xform(node, q=True, rp=True, ws=True)

        # def name of the new nodes
        ctrl_name = node_name + '_ctrl'
        # softmod names
        soft_name = node_name + '_softMod'
        soft_control = node_name + '_softMod_ctrl'
        mover_name = node_name + '_mover_ctrl'

        if mc.objExists(soft_name):
            softmod_list = [
                softmod for softmod in mc.ls(et='softMod')
                if soft_name in softmod
            ]

            number = str(len(softmod_list))
            soft_name = node_name + '_softMod_' + number
            soft_control = soft_name + '_ctrl'
            mover_name = node_name + '_mover' + number + '_ctrl'

        # calculate ctrl size
        #bbox
        bbox = mc.exactWorldBoundingBox(node, ignoreInvisible=True)
        bbox_size = [0, 0]
        bbox_size[0] = bbox[3] - bbox[0]
        bbox_size[1] = bbox[5] - bbox[2]
        bbox_size.sort()
        bbox_height = bbox[4] - bbox[1]

        ctrl_size = bbox_size[1] * 0.6

        if ctrl_size > 5.0:
            mover_size = 2.0
        else:
            mover_size = ctrl_size / 2.0

        # create ctrl and place it
        mc.circle(name=soft_control,
                  normal=(0, 1, 0),
                  sections=8,
                  radius=ctrl_size)
        #delete history
        mc.delete(soft_control, ch=True)
        orig_soft_ctrl = orig.orig([soft_control])

        mover = mlutilities.create_ctrl(ctrl_type='simple_orb',
                                        name=mover_name,
                                        size=mover_size)

        mc.spaceLocator(name=mover_name + 'loc', a=True, p=[0, 0, 0])
        mc.parent(mover_name + 'loc', soft_control)

        # create softMod
        mc.softMod(node, n=soft_name, wn=(mover_name, mover_name))

        # creates softMod hierarchy
        mc.parent(mover[1], soft_control)

        # create/set/connect Attributes
        #visibility
        mc.connectAttr(mover_name + 'locShape.worldPosition',
                       soft_name + '.falloffCenter')
        #size
        mc.addAttr(mover_name,
                   at='float',
                   k=True,
                   h=False,
                   ln='size',
                   dv=5,
                   min=0.001,
                   max=50)
        mc.connectAttr(mover_name + '.size', soft_name + '.falloffRadius')
        #set display in channel box
        #mover
        mc.setAttr(mover_name + '.visibility', k=False, cb=False)
        #softMod ctrl
        mc.setAttr(soft_control + '.scaleX', k=False, cb=False)
        mc.setAttr(soft_control + '.scaleY', k=False, cb=False)
        mc.setAttr(soft_control + '.scaleZ', k=False, cb=False)
        mc.setAttr(soft_control + '.visibility', k=False, cb=False)
        #locator
        mc.setAttr(mover_name + 'loc.visibility', 0)

        #color
        mlutilities.color([soft_control + 'Shape'], 'cyan')
        mlutilities.color([mover_name + 'Shape'], 'dark_pink')

        # bindPreMatrix
        mc.connectAttr(soft_control + '.worldInverseMatrix',
                       soft_name + '.bindPreMatrix')
        mc.connectAttr(node + '.worldMatrix[0]',
                       soft_name + '.geomMatrix[0]',
                       f=True)

        # ctrl placement
        mc.xform(orig_soft_ctrl,
                 t=[pos[0], pos[1] + (bbox_height / 2), pos[2]])
        #mc.xform(orig_soft_ctrl, ro=rot)

        # parent to existing hierarchy
        if mc.objExists(ctrl_name):
            mc.parent(orig_soft_ctrl, ctrl_name)
        elif mc.objExists('helper_ctrl'):
            mc.parent(orig_soft_ctrl, 'helper_ctrl')
        elif mc.objExists('walk_ctrl'):
            mc.parent(orig_soft_ctrl, 'walk_ctrl')
        else:
            pass

    mlutilities.rigset()
Exemplo n.º 4
0
def bend_chain(crv, controller, bones_nbr):
    jnt_nbr = bones_nbr + 1
    # get shape
    crv_shape = mc.listRelatives(crv, c=True, s=True)[0]

    # calculation of the number of cv
    crv_degree = mc.getAttr(crv_shape + '.degree')
    crv_span = mc.getAttr(crv_shape + '.spans')

    cv_nbr = crv_degree + crv_span

    # place curve pivot on first cv
    crv_info = mc.createNode('curveInfo', n=crv + '_curveInfo')
    mc.connectAttr(crv_shape + '.worldSpace', crv_info + '.inputCurve')

    cv_tx = mc.getAttr(crv_info + '.controlPoints[0].xValue')
    cv_ty = mc.getAttr(crv_info + '.controlPoints[0].yValue')
    cv_tz = mc.getAttr(crv_info + '.controlPoints[0].zValue')
    mc.xform(crv, piv=(cv_tx, cv_ty, cv_tz), ws=True)

    # Stretch creation
    mult = mc.shadingNode('multiplyDivide',
                          asUtility=True,
                          name='multiplyDivide_STRETCH_' + crv)
    mc.connectAttr('%s.arcLength' % crv_info, '%s.input1X' % mult)
    crv_length = mc.getAttr(crv_info + '.arcLength')
    mc.setAttr(mult + '.input2X', crv_length)
    mc.setAttr(mult + '.operation', 2)

    # Joint chain creation
    jnt_length = crv_length / bones_nbr
    first_jnt = mc.joint(p=(cv_tx, cv_ty, cv_tz), name='SK_' + crv + '_0')

    for i in range(1, jnt_nbr):
        i = str(i)
        current_jnt = mc.joint(p=(jnt_length, 0, 0),
                               r=True,
                               name='SK_' + crv + '_' + i)
        mc.connectAttr(mult + '.outputX', current_jnt + '.scaleX')

    # ikSpline creation
    ik = 'IKSPLINE_' + crv
    mc.ikHandle(curve=crv,
                ee='SK_' + crv + '_' + str(bones_nbr),
                sol='ikSplineSolver',
                sj=first_jnt,
                name=ik,
                ccv=0)
    jnt_rotation = mc.xform(first_jnt, q=True, ro=True)

    # Orig joint
    orig.orig([first_jnt], 'orig')

    # offset de l'ik
    orig.orig([ik], 'orig')

    for j in range(0, cv_nbr):
        # Creation des clusters :)

        cls_nbr = str(j)
        cv = (crv + '.cv[' + cls_nbr + ']')

        mc.select(cv)
        cluster = mc.cluster()
        mc.select(deselect=True)

        # Recuperation de la position des clusters
        cls_pos_x = mc.getAttr('%s.controlPoints[%s].xValue' %
                               (crv_info, cls_nbr))
        cls_pos_y = mc.getAttr('%s.controlPoints[%s].yValue' %
                               (crv_info, cls_nbr))
        cls_pos_z = mc.getAttr('%s.controlPoints[%s].zValue' %
                               (crv_info, cls_nbr))

        # Controllers creation
        ctrl = mc.duplicate(controller, name='%s_%s_ctrl' % (crv, cls_nbr))
        ctrl = mc.rename(ctrl, '%s_%s_ctrl' % (crv, cls_nbr))
        mc.xform(ctrl, t=(cls_pos_x, cls_pos_y, cls_pos_z), ws=True)
        mc.xform(ctrl, ro=jnt_rotation)

        # Controllers orig
        orig.orig([ctrl], 'orig')

        # Cluster hierarchy

        mc.parent(cluster, ctrl)

    mc.select('%s_*_ctrl_orig' % crv)
    mc.group(name='%s_ctrl_grp' % crv)
    mc.select(deselect=True)
Exemplo n.º 5
0
def wave_for_each():
    """Create a wave deformer and controlers for every selected element"""

    # what's selected
    selection = mc.ls(sl=True)

    # for each selected node
    for node in selection:
        datas['count_w']+=1
        # get the name and the transforms
        node_name = node.split('|')[-1]
        pos = mc.xform(node, q=True, rp=True, ws=True)

        # def name of the new nodes
        ctrl_name = node_name + '_ctrl'
        wave_name = node_name + '_wave'
        wave_control = node_name + '_wave_ctrl'
        orb_name = node_name + '_orb'
        mover_name = node_name + '_mover'

        # calculate ctrl size
        #bbox
        bbox = mc.exactWorldBoundingBox(node, ignoreInvisible=True)
        bbox_size = [0, 0]
        bbox_size[0] = bbox[3] - bbox[0]
        bbox_size[1] = bbox[5] - bbox[2]
        bbox_size.sort()
        bbox_height = bbox[4] - bbox[1]

        ctrl_size = bbox_size[1] * 0.5

        # orb and mover
        orb_size = 5

        # create ctrl and place it
        mc.circle(name=wave_control, normal=(0, 1, 0), sections=8, radius=ctrl_size)
        orig_wave_ctrl = orig.orig([wave_control])

        mlutilities.create_orb(sca=orb_size/2, name=orb_name)
        mc.spaceLocator(name=mover_name + 'loc', a=True, p=[0, 0, 0])
        mc.parent(mover_name + 'loc', orb_name)

        # create wave
        wavenode = create_deform('wave', '', node)
        print wavenode

        # creates wave hierarchy
        mc.parent(orb_name, wave_control)

        #color
        mlutilities.color([wave_control + 'Shape'], 'light_blue')
        mlutilities.color([orb_name], 'green')

        # bindPreMatrix
        #mc.connectAttr(wave_control + '.worldInverseMatrix', wave_name + '.bindPreMatrix')

        # ctrl placement
        mc.xform(orig_wave_ctrl, t=[pos[0], pos[1] + (bbox_height / 2), pos[2]])
        #mc.xform(orig_wave_ctrl, ro=rot)

        # parent to existing hierarchy        
        if mc.objExists(ctrl_name):
            mc.parent(orig_wave_ctrl, ctrl_name)
        elif mc.objExists('helper_ctrl'):
            mc.parent(orig_wave_ctrl, 'helper_ctrl')
        else:
            mc.parent(orig_wave_ctrl, 'walk_ctrl')