Exemplo n.º 1
0
def control(type="none", *args):
    """gets teh name from the button pushed and the axis from the radio button group"""
    axisRaw = cmds.radioButtonGrp(widgets["ctrlAxisRBG"], q=True, sl=True)
    if axisRaw == 1:
        axis = "x"
    if axisRaw == 2:
        axis = "y"
    if axisRaw == 3:
        axis = "z"				

    rig.createControl(name = "Ctrl", type = type, axis = axis, color = "yellow")
Exemplo n.º 2
0
def ribbonPremade(numJoints, dir=1, *args):
    
    name = cmds.ls(sl=True)[0]

    factor = 1.0/(numJoints)
    for x in range (numJoints + 1):
        val = x * factor
        print val
        folName = "%s_follicle%s"%(name, x)
        #create a follicle in the right direction
        if dir ==1:
            follicle = rig.follicle(name, folName, val, 0.5)[0]
        else:
            follicle = rig.follicle(name, folName, 0.5, val)[0]

        # follicleList.append(follicle)

        #create joint and parent to follicle
        jointName = "%s_fol%s_JNT"%(name, x)
#---------have to figure out how to orient this correctly (just translate and rotate the joints (or the controls they're under))
        #create joint control? then move the control and the joint under it to the correct rot and pos
        folPos = cmds.xform(follicle, q=True, ws=True, rp=True)
        folRot = cmds.xform(follicle, q=True, ws=True, ro=True)
        cmds.select(cl=True)
        folJoint = cmds.joint(n=jointName, p=(0,0,0))
        ctrl = rig.createControl(name = "{}Ctrl".format(jointName), type = "sphere", color = "red")
        cmds.parent(folJoint, ctrl)
        folGroup = cmds.group(ctrl, n="%s_GRP"%folJoint)	 #this could become control for the joint
        cmds.xform(folGroup, a=True, ws=True, t=folPos)
        cmds.xform(folGroup, a=True ,ws=True, ro=folRot)
        # follicleJntList.append(folJoint)
        # follicleGrpList.append(folGroup)
        cmds.parent(folGroup, follicle)
Exemplo n.º 3
0
def add_top_level_ctrl(origCtrl, type, geo, *args):
    """
    creates a new ctrl, orients it to the geo and parent constrains the orig ctrl rig under itself
    :param origCtrl: the control we're working from
    :param type: the ctrl type of shape see zbw_rig.createControl for options
    :param geo: the geo to orient to
    :param args:
    :return: topCtrl (the new ctrl), grp (the top ctrl grp freeze grp)
    """
    # THIS IS THE XTRA CTRL LAYER, THIS ORIENTS CTRL AND CONNECTS ORIG CTRL TO THE NEW CTRL
    origCtrlPos = cmds.xform(origCtrl, q=True, ws=True, rp=True)
    topCtrl = rig.createControl(name="{0}_moveCtrl".format(
        origCtrl.rpartition("_")[0]),
                                type=type,
                                axis="z",
                                color="yellow")
    grp = rig.groupFreeze(topCtrl)
    cmds.xform(grp, ws=True, t=origCtrlPos)
    nc = cmds.normalConstraint(geo,
                               grp,
                               worldUpType="vector",
                               upVector=(0, 1, 0))
    cmds.delete(nc)
    pc = cmds.parentConstraint(topCtrl, origCtrl, mo=True)
    sc = cmds.scaleConstraint(topCtrl, origCtrl, mo=True)
    return (topCtrl, grp)
Exemplo n.º 4
0
def ribbonPremade(numJoints, dir=1, *args):

    name = cmds.ls(sl=True)[0]

    factor = 1.0 / (numJoints)
    for x in range(numJoints + 1):
        val = x * factor
        print val
        folName = "%s_follicle%s" % (name, x)
        # create a follicle in the right direction
        if dir == 1:
            follicle = rig.follicle(name, folName, val, 0.5)[0]
        else:
            follicle = rig.follicle(name, folName, 0.5, val)[0]

            # follicleList.append(follicle)

            # create joint and parent to follicle
        jointName = "%s_fol%s_JNT" % (name, x)
        # ---------have to figure out how to orient this correctly (just translate and rotate the joints (or the controls they're under))
        # create joint control? then move the control and the joint under it to the correct rot and pos
        folPos = cmds.xform(follicle, q=True, ws=True, rp=True)
        folRot = cmds.xform(follicle, q=True, ws=True, ro=True)
        cmds.select(cl=True)
        folJoint = cmds.joint(n=jointName, p=(0, 0, 0))
        ctrl = rig.createControl(name="{}Ctrl".format(jointName), type="sphere", color="red")
        cmds.parent(folJoint, ctrl)
        folGroup = cmds.group(ctrl, n="%s_GRP" % folJoint)  # this could become control for the joint
        cmds.xform(folGroup, a=True, ws=True, t=folPos)
        cmds.xform(folGroup, a=True, ws=True, ro=folRot)
        # follicleJntList.append(folJoint)
        # follicleGrpList.append(folGroup)
        cmds.parent(folGroup, follicle)
Exemplo n.º 5
0
def bBox(*args):
    """creates a control based on the bounding box"""
    sel = cmds.ls(sl=True)

    box = cmds.exactWorldBoundingBox(
        sel)  #[xmin, ymin, zmin, xmax, ymax, zmax]
    X = om.MVector(box[0], box[3])
    Y = om.MVector(box[1], box[4])
    Z = om.MVector(box[2], box[5])

    #get bbox lengths along axes
    lenX = (X.y - X.x)
    lenY = (Y.y - Y.x)
    lenZ = (Z.y - Z.x)

    print lenX, lenY, lenZ

    ctrl = rig.createControl(name="ctrl", type="cube", color="pink")

    cvs = {
        "xyz": [5, 15],
        "-xyz": [0, 4],
        "xy-z": [10, 14],
        "x-yz": [6, 8],
        "-x-yz": [3, 7],
        "-x-y-z": [2, 12],
        "x-y-z": [9, 13],
        "-xy-z": [1, 11]
    }

    for a in cvs["xyz"]:
        cmds.xform("{0}.cv[{1}]".format(ctrl, a), ws=True, t=(X.y, Y.y, Z.y))
    for a in cvs["-xyz"]:
        cmds.xform("{0}.cv[{1}]".format(ctrl, a), ws=True, t=(X.x, Y.y, Z.y))
    for a in cvs["x-yz"]:
        cmds.xform("{0}.cv[{1}]".format(ctrl, a), ws=True, t=(X.y, Y.x, Z.y))
    for a in cvs["-x-yz"]:
        cmds.xform("{0}.cv[{1}]".format(ctrl, a), ws=True, t=(X.x, Y.x, Z.y))
    for a in cvs["xy-z"]:
        cmds.xform("{0}.cv[{1}]".format(ctrl, a), ws=True, t=(X.y, Y.y, Z.x))
    for a in cvs["-xy-z"]:
        cmds.xform("{0}.cv[{1}]".format(ctrl, a), ws=True, t=(X.x, Y.y, Z.x))
    for a in cvs["-x-y-z"]:
        cmds.xform("{0}.cv[{1}]".format(ctrl, a), ws=True, t=(X.x, Y.x, Z.x))
    for a in cvs["x-y-z"]:
        cmds.xform("{0}.cv[{1}]".format(ctrl, a), ws=True, t=(X.y, Y.x, Z.x))

    # center pivot on ctrl
    cmds.xform(ctrl, cp=True)
    cmds.select(ctrl)
Exemplo n.º 6
0
def create_joint(cvs, wts):
    tform = cvs[0].partition(".")[0]
    curve = cmds.listRelatives(tform, f=True, s=True)[0]
    
    ps = []
    center = []
    for cv in cvs:
        ps.append(cmds.pointPosition(cv))
        center = [sum(y)/len(y) for y in zip(*ps)]
    
    #create joint at location
    # ----------- should get closest point on surface   
    cmds.select(cl=True)    
    jnt = cmds.joint()
    cmds.xform(jnt, ws=True, t=center)
    
#---------------- orient the joint along the curve?
#---------------- here create the ctrl set up for the joint
    
    ctrl = rig.createControl(name="{0}Ctrl".format(jnt), type="sphere", color="red")
    grp = cmds.group(name="{0}Grp".format(ctrl), em=True)
    cmds.parent(ctrl, grp)
    cmds.xform(grp, ws=True, t=center)
    cmds.parent(jnt, ctrl)

    # scale the control
    comps = cmds.ls("{0}.cv[*]".format(ctrl))
    cmds.select(comps, r=True)
    cmds.scale(.2,.2,.2)

    #add influence to skin Cluster
    cmds.select(tform, r=True)
    cmds.skinCluster(e=True, ai=jnt, wt=0)
    
    cmds.setAttr("{0}.v".format(jnt), 0)

    #apply weights to that joint
    cls = mel.eval("findRelatedSkinCluster " + tform)
    for v in range(len(cvs)):
        cmds.skinPercent(cls, cvs[v], transformValue=[jnt, wts[v]])

    return(jnt, ctrl, grp)
Exemplo n.º 7
0
def dupe_abc(*args):
    """
	creates a rig structure of the alembic objs with texture deformers added, etc and parents to camera
	"""
    cam = camera_check()
    if not cam:
        cmds.warning("no camera selected in window")

    sel = cmds.ls(sl=True)
    ctrlList = []

    rslight = cmds.checkBoxGrp(widgets["lightCBG"], q=True, v1=True)
    if rslight:
        rig.plugin_load("redshift4maya")

    tubes = [x for x in sel if not x.endswith("plane")]

    for geo in tubes:
        geoName = geo
        neon = cmds.duplicate(geo,
                              rr=True,
                              un=True,
                              name="{0}_neonInner".format(geo))[0]
        lightmesh = cmds.duplicate(geo,
                                   rr=True,
                                   un=True,
                                   name="{0}_lightOuter".format(geo))[0]
        geo = cmds.rename(geo, "{0}_glass".format(geo))

        ##### OUTER LIGHT
        cmds.select(lightmesh, r=True)
        lmTDef, lmTxform = cmds.textureDeformer(
            offset=0.0075,
            vectorSpace="Object",
            direction="Normal",
            pointSpace="UV",
            name="{0}_textureDef".format(lightmesh))
        lmTextTrans = cmds.rename(lmTxform,
                                  "{0}_lightmesh_TextureDef".format(geo))
        cmds.setAttr("{0}.texture".format(lmTDef), 1, 1, 1)
        outerShpOrig = cmds.listRelatives(lightmesh, s=True, f=True)[0]
        outerShp = cmds.rename(outerShpOrig, "{0}_shape".format(lightmesh))
        outerShpAttrs = [
            "rsAOCaster", "rsSelfShadows", "rsShadowReceiver",
            "rsShadowCaster", "rsSecondaryRayVisible", "rsPrimaryRayVisible",
            "rsGiVisible", "rsCausticVisible", "rsGiCaster"
        ]
        for attr in outerShpAttrs:
            cmds.setAttr("{0}.rsEnableVisibilityOverrides".format(outerShp), 1)
            cmds.setAttr("{0}.{1}".format(outerShp, attr), 0)

        ### GLASS
        cmds.select(geo)
        gTDef, gTxform = cmds.textureDeformer(
            offset=0.00,
            strength=0.00,
            vectorSpace="Object",
            direction="Normal",
            pointSpace="Local",
            name="{0}_textureDef".format(geo))
        gTextTrans = cmds.rename(gTxform, "{0}_glass_TextureDef".format(geo))
        cmds.setAttr("{0}.texture".format(gTDef), 1, 1, 1)

        #### NEON
        cmds.select(neon, r=True)
        nTDef, nTxform = cmds.textureDeformer(
            offset=-0.05,
            strength=0.02,
            vectorSpace="Object",
            direction="Normal",
            pointSpace="Local",
            name="{0}_textureDef".format(neon))
        nTextTrans = cmds.rename(nTxform, "{0}_neon_TextureDef".format(geo))
        innerShpOrig = cmds.listRelatives(neon, s=True, f=True)[0]
        innerShp = cmds.rename(innerShpOrig, "{0}_shape".format(neon))
        innerShpAttrs = ["rsShadowReceiver", "rsShadowCaster"]
        for attr in innerShpAttrs:
            cmds.setAttr("{0}.rsEnableVisibilityOverrides".format(innerShp), 1)
            cmds.setAttr("{0}.{1}".format(innerShp, attr))

        noiseText = cmds.shadingNode("fractal",
                                     asTexture=True,
                                     name="{0}_fractal".format(neon))
        noisePlace = cmds.shadingNode("place2dTexture",
                                      asUtility=True,
                                      name="{0}_factalPlace".format(neon))
        cmds.connectAttr("{0}.outUV".format(noisePlace),
                         "{0}.uv".format(noiseText))
        cmds.connectAttr("{0}.outUvFilterSize".format(noisePlace),
                         "{0}.uvFilterSize".format(noiseText))
        cmds.connectAttr("{0}.outColor".format(noiseText),
                         "{0}.texture".format(nTDef),
                         force=True)

        # light and finishing up
        if rslight:
            # make the red shift physical light and connect it to the outer geo. . . Set some init values on that
            lighttmp = mel.eval(
                "redshiftCreateLight(\"RedshiftPhysicalLight\")")
            physLight = "{0}_meshlight".format(geoName)
            physLight = cmds.rename(lighttmp, physLight)
            physLightShp = cmds.listRelatives(physLight, s=True)[0]
            # move light to camera
            rig.snapTo(lightmesh, physLight)
            cmds.setAttr("{0}.v".format(physLight), 0)
            # cmds.setAttr("{0}.areaShape".format(physLightShp), 4)
            # link the light with lightmesh (HOW THE HELL TO DO THIS?)

        # add controls to the main geo
        ctrl = rig.createControl(type="star",
                                 color="red",
                                 axis="y",
                                 name="{0}_CTRL".format(geoName))
        ctrlShp = cmds.listRelatives(ctrl, s=True)[0]
        rig.snapTo(cam, ctrl)
        objList = [lmTextTrans, nTextTrans, gTextTrans, neon, lightmesh, geo]
        if rslight:
            objList.append(physLight)
        cmds.parent(objList, ctrl)
        cmds.parent(ctrl, cam)
        cmds.setAttr("{0}.v".format(lightmesh), 0)

        cmds.addAttr(ctrl,
                     ln="thisCtrlVis",
                     at="short",
                     min=0,
                     max=1,
                     dv=0,
                     k=True)
        cmds.addAttr(ctrl,
                     ln="lightMeshTxStrength",
                     at="float",
                     min=0,
                     max=1.0,
                     dv=0.00,
                     k=True)
        cmds.addAttr(ctrl,
                     ln="neonTxStrength",
                     at="float",
                     min=0,
                     max=1.0,
                     dv=0.02,
                     k=True)
        cmds.addAttr(ctrl,
                     ln="glassTxStrength",
                     at="float",
                     min=0,
                     max=1.0,
                     dv=0.0,
                     k=True)
        cmds.addAttr(ctrl,
                     ln="lightMeshTxOffset",
                     at="float",
                     min=-1.0,
                     max=1.0,
                     dv=0.0075,
                     k=True)
        cmds.addAttr(ctrl,
                     ln="neonTxOffset",
                     at="float",
                     min=-1.0,
                     max=1.0,
                     dv=-0.03,
                     k=True)
        cmds.addAttr(ctrl,
                     ln="glassTxOffset",
                     at="float",
                     min=-1.0,
                     max=1.0,
                     dv=0.00,
                     k=True)

        cmds.connectAttr("{0}.thisCtrlVis".format(ctrl),
                         "{0}.visibility".format(ctrlShp))
        cmds.connectAttr("{0}.lightMeshTxStrength".format(ctrl),
                         "{0}.strength".format(lmTDef))
        cmds.connectAttr("{0}.neonTxStrength".format(ctrl),
                         "{0}.strength".format(nTDef))
        cmds.connectAttr("{0}.glassTxStrength".format(ctrl),
                         "{0}.strength".format(gTDef))
        cmds.connectAttr("{0}.lightMeshTxOffset".format(ctrl),
                         "{0}.offset".format(lmTDef))
        cmds.connectAttr("{0}.neonTxOffset".format(ctrl),
                         "{0}.offset".format(nTDef))
        cmds.connectAttr("{0}.glassTxOffset".format(ctrl),
                         "{0}.offset".format(gTDef))

        ctrlList.append(ctrl)

    cmds.select(ctrlList, r=True)
Exemplo n.º 8
0
def extrude(name = "defaultName", *args):
    print "starting extrude"
    sel = cmds.ls(sl=True)
    guideCrv = sel[0]

    if len(sel)>1:
        profileCrv = cmds.duplicate(sel[1], name="{}_profile_CRV".format(name))[0]
    else:
        profileCrv = cmds.circle(r=1, normal = (0, 1, 0), name="{}_profile_CRV".format(name), ch=False)[0]

    if len(sel) == 3:
        capRig = sel[2]
    else:
        capRig = ""

    if len(sel) > 3:
        return

    capAxis = "y"
    capUp = "z"
    # upLoc = cmds.spaceLocator(name = "{}_upLoc".format(name))[0]

    ctrl = rig.createControl(type="sphere", name="{}_CTRL".format(name), color="blue")
    ctrlGrp = cmds.group(empty=True, name="{}_path_GRP".format(name))
    capGrp = cmds.group(empty=True, name="{}_cap_GRP".format(name))
    deadGrp = cmds.group(empty=True, name="{}_noInherit_GRP".format(name))
    if capRig:
        cmds.parent(capRig, capGrp)

    cmds.parent(deadGrp, ctrlGrp)	
    cmds.parent(ctrl, ctrlGrp)

    # add attrs to control
    cmds.addAttr(ctrl, ln="__xtraAttrs__", nn="__xtraAttrs__", at="bool", k=True)
    cmds.setAttr("{}.__xtraAttrs__".format(ctrl), l=True)
    cmds.addAttr(ctrl, ln="alongPath", at="float", min=0, max=100, k=True, dv=100.0)	
    cmds.setAttr("{}.alongPath".format(ctrl), 100)
    cmds.addAttr(ctrl, ln="reverseNormals", at="long", min=0, max=1, k=True)
    cmds.addAttr(ctrl, ln="capVisibility", at="long", min=0, max=1, k=True)
    cmds.setAttr("{}.capVisibility".format(ctrl), 1)
    cmds.addAttr(ctrl, ln="capWidth", at="float", k=True, min=.01, max=2.0, dv=1.0)	
    cmds.addAttr(ctrl, ln="capHeight", at="float", k=True, min=.01, max=2.0, dv=1.0)
    cmds.addAttr(ctrl, ln="profileWidth", at="float", k=True, min=.001, max=3, dv=1.0)	

    # driver attrs
    cmds.addAttr(ctrl, ln="textureRepeatMult", at="float", min = 0.01, dv= 1.0, k=True)
    cmds.addAttr(ctrl, ln="prmHolder", at="float", k=True)
    cmds.addAttr(ctrl, ln="rptHolder", at="float", k=True)

    # cmds.addAttr(ctrl, ln="repeatMult", at="message", k=True)
    # cmds.addAttr(ctrl, ln="parameterMult", at ="message", k=True)

    # connect mult to path
    mult = cmds.shadingNode("multiplyDivide", asUtility=True, name="{}_paraMult".format(name))
    cmds.connectAttr("{}.alongPath".format(ctrl), "{}.input1X".format(mult))
    cmds.setAttr("{}.input2X".format(mult), 0.01)
    cmds.connectAttr("{}.profileWidth".format(ctrl), "{}.scaleX".format(profileCrv))
    cmds.connectAttr("{}.profileWidth".format(ctrl), "{}.scaleZ".format(profileCrv))

    # reverse for normals
    reverse = cmds.shadingNode("reverse", asUtility=True, name="{}_reverse".format(name))
    cmds.connectAttr("{}.reverseNormals".format(ctrl), "{}.inputX".format(reverse))
    
    # cap and texture attrs and nodes
    cmds.connectAttr("{}.capVisibility".format(ctrl), "{}.v".format(capGrp))
    repeatMult = cmds.shadingNode("multiplyDivide", asUtility=True, name="{}_RptMult".format(name))
    cmds.connectAttr("{}.outputX".format(mult), "{}.input1X".format(repeatMult))
    cmds.connectAttr("{}.textureRepeatMult".format(ctrl), "{}.input2X".format(repeatMult))
    # cmds.connectAttr("{}.message".format(repeatMult), "{}.repeatMult".format(ctrl))
    # cmds.connectAttr("{}.message".format(mult), "{}.parameterMult".format(ctrl))
    cmds.connectAttr("{}.outputX".format(repeatMult), "{}.rptHolder".format(ctrl))
    cmds.connectAttr("{}.outputX".format(mult), "{}.prmHolder".format(ctrl))
    cmds.setAttr("{}.prmHolder".format(ctrl), l=True)
    cmds.setAttr("{}.rptHolder".format(ctrl), l=True)
    cmds.connectAttr("{}.capWidth".format(ctrl), "{}.scaleX".format(capGrp))
    cmds.connectAttr("{}.capWidth".format(ctrl), "{}.scaleZ".format(capGrp))
    cmds.connectAttr("{}.capHeight".format(ctrl), "{}.scaleY".format(capGrp))

    # position control at start of curve
    startPos = cmds.pointOnCurve(guideCrv, parameter = 0, position = True)
    cmds.xform(ctrlGrp, ws=True, t=startPos)
    # cmds.xform(upLoc, ws=True, t=(startPos[0], startPos[1]+3.0, startPos[2]))

    moPath = cmds.pathAnimation(capGrp, guideCrv, fractionMode=True, follow=True, followAxis=capAxis, upAxis=capUp,
                                worldUpType="scene", startTimeU=0.0, endTimeU=100.0)
    moPathAnimAttr = cmds.listConnections("{}.uValue".format(moPath), d=False, p=True)[0]

    start, end = getSliderRange()
    current = cmds.currentTime(q=True)
    cmds.currentTime(start)

    pPos = cmds.xform(capGrp, q=True, ws=True, rp=True)
    pRot = cmds.xform(capGrp, q=True, ws=True, ro=True)
    cmds.xform(profileCrv, ws=True, t=pPos)
    cmds.xform(profileCrv, ws=True, ro=pRot)

    cmds.currentTime(current)

    # extrude the curve
    extr = cmds.extrude(profileCrv, guideCrv, ch=True, range=True, polygon=True, extrudeType=2, useComponentPivot=True,
                        fixedPath=True, useProfileNormal=True, reverseSurfaceIfPathReversed=True)
    extrGeo, extrNode = extr[0], extr[1]
    
    normal = cmds.polyNormal(extrGeo, normalMode=4, userNormalMode=0, ch=1)[0]
    cmds.connectAttr("{}.outputX".format(reverse), "{}.normalMode".format(normal))
    
    # get extrude connections
    connects = cmds.listConnections(extrNode)
    profNode, pathNode, tessNode = connects[0], connects[1], connects[2]

    # connect up stuff to extrusion
    cmds.connectAttr("{}.outputX".format(mult), "{}.maxValue".format(pathNode))
    cmds.parent(guideCrv, ctrl)
    cmds.setAttr("{}.inheritsTransform".format(deadGrp), 0)
    cmds.parent(extrGeo, deadGrp)
    cmds.parent(profileCrv, deadGrp)	
    cmds.setAttr("{}.v".format(profileCrv), 0)
    cmds.parent(capGrp, deadGrp)	

    # motion path stuff
    cmds.delete(moPathAnimAttr.partition(".")[0])
    cmds.connectAttr("{}.outputX".format(mult), "{}.uValue".format(moPath))

    # reference
    # extrude -ch true -rn true -po 1 -et 2 -ucp 1 -fpt 1 -upn 1 -rotation 0 -scale 1 -rsp 1 "nurbsCircle1" "curve4" ;

    print "ending extrude"
Exemplo n.º 9
0
def larger_ctrls(grps, sel):
    # create controls for every 10? ctrls, get center then get nearest point on curve?
    ctrlNodes = []
    bigCtrls = []
    l_ctrl_grp = cmds.group(em=True, name="{0}_ctrlRigGrp".format(sel))

    ctrlNodes.append(grps[-1]) # add last grp
    for i in range(0, len(grps)-1, 10):
        local = []
        pos = (0,0,0)
        # print "-------- I'm on i: {0}".format(i)
        if grps[i] not in ctrlNodes: # if not (last), add grp to ctrlNodes
            ctrlNodes.insert(-1, grps[i])
        if i == 0:
            # set pc from 0-10
            pcwgts = [1, .9, .8, .7, .6, .5, .4, .3, .2 ,.1]
            local = grps[0:10]
            list(set(local))
            pos = get_center_point(local)
            box = rig.createControl(name="{0}_largeCtrl_{1}".format(sel, i), type="cube", color="green")
            grp = cmds.group(em=True, name="{0}_GRP".format(box))
            cmds.parent(box, grp)
            cmds.xform(grp, ws=True, t=pos)
            for k in range(len(local)):
                pc = cmds.parentConstraint(box, local[k], mo=True, w=pcwgts[k])
            bigCtrls.append(grp)
            # print "zero: ({0}): ".format(len(local))+ str(local)
        elif i == 10:
            # only set front from 5-9, back from 10-19
            pcwgts = [.1, .2, .4, .6, .8, 1, .9, .8, .7, .6, .5, .4, .3, .2, .1]              
            for j in grps[5:10]:
                local.append(j)
            for j in grps[10:20]:
                local.append(j)
            list(set(local))
            pos = get_center_point(local)
            box = rig.createControl(name="{0}_largeCtrl_{1}".format(sel, i), type="cube", color="green")
            grp = cmds.group(em=True, name="{0}_GRP".format(box))
            cmds.parent(box, grp)
            cmds.xform(grp, ws=True, t=pos)           
            for k in range(len(local)):
                pc = cmds.parentConstraint(box, local[k], mo=True, w=pcwgts[k])
            bigCtrls.append(grp)                
            # print "one ({0}): ".format(len(local)) + str(local)
        elif i == len(ctrlNodes)-1: # last
            pcwgts = [.2, .4, .6, .8, 1]              
            local = grps[-5:]
            list(set(local))
            pos = get_center_point(local)
            box = rig.createControl(name="{0}_largeCtrl_{1}".format(sel, i), type="cube", color="green")
            grp = cmds.group(em=True, name="{0}_GRP".format(box))
            cmds.parent(box, grp)
            cmds.xform(grp, ws=True, t=pos)
            for k in range(len(local)):
                pc = cmds.parentConstraint(box, local[k], mo=True, w=pcwgts[k])
            bigCtrls.append(grp)                
            # print "second ({0}): ".format(len(local)) + str(local)
        elif i == len(ctrlNodes)-2: # second to last
            pcwgts = [.1, .2, .3, .4, .5, .6, .7, .8, .9, 1, .9, .8, .7, .6, .5, .4, .3, .2, .1]        
            for j in grps[i-1:i-10]:
                local.append(j)
            for j in grps[i:len(grps)-4]:
                local.append(j)
            list(set(local))
            pos = get_center_point(local)
            box = rig.createControl(name="{0}_largeCtrl_{1}".format(sel, i), type="cube", color="green")
            grp = cmds.group(em=True, name="{0}_GRP".format(box))
            cmds.parent(box, grp)
            cmds.xform(grp, ws=True, t=pos)           
            for obj in local:
                pc = cmds.parentConstraint(box, local[k], mo=True, w=pcwgts[k])
            bigCtrls.append(grp)                
            # print "second ({0}): ".format(len(local)) + str(local)
        else:
            pcwgts = [.1, .2, .3, .4, .5, .6, .7, .8, .9, 1, .9, .8, .7, .6, .5, .4, .3, .2, .1]
            for j in grps[i-10:i]: # all of these go from grps-9, ctrlNode, grps+9
                local.append(j)
            for j in grps[i:i+9]:
                local.append(j)
            list(set(local))
            pos = get_center_point(local)
            box = rig.createControl(name="{0}_largeCtrl_{1}".format(sel, i), type="cube", color="green")
            grp = cmds.group(em=True, name="{0}_GRP".format(box))
            cmds.parent(box, grp)
            cmds.xform(grp, ws=True, t=pos)           
            for k in range(len(local)):
                pc = cmds.parentConstraint(box, local[k], mo=True, w=pcwgts[k])
            bigCtrls.append(grp)
            # print "{0} ({1}): ".format(len(local), i) + str(local) 

    for c in bigCtrls:
        cmds.parent(c, l_ctrl_grp)

    return(l_ctrl_grp, bigCtrls)
Exemplo n.º 10
0
def create_ctrls():
    sel = cmds.ls(sl=True)[0]

    cvs = cmds.ls("{0}.cv[*]".format(sel), fl=True)
    jnts = []
    ctrls = []
    grps = []

    masterGrp = cmds.group(em=True, name="{0}_fineCtrls_GRP".format(sel))

    cmds.select(cl=True)
    initialJnt = cmds.joint(name="{0}_initJnt".format(sel), p=(0, 0, 0))
    cmds.setAttr("{0}.v".format(initialJnt), 0)
    cls = cmds.skinCluster(initialJnt, sel, normalizeWeights=2)[0]
    print "++++++++++++++++++ ", cls

    for i in range(0, len(cvs), 3):
        nextCvs = []
        weights = []        
        if i == 0:
            # create a joint with those 3
            nextCvs = [cvs[0], cvs[1], cvs[2]]
            weights = [1.0, .67, .33]
            # create_joints(nextCvs, weights)
        else:
            nextCvs = [cvs[i]]
            weights = [1, .33, .33, .67, .67]
            for j in range(2, 0, -1):
                nextCvs.append(cvs[i-j])
                try:
                    nextCvs.append(cvs[i+j])
                except:
                    pass
        jnt, ctrl, grp = create_joint(nextCvs, weights)
        jnts.append(jnt)
        ctrls.append(ctrl)
        grps.append(grp)

        cmds.parent(grp, masterGrp)

    # cls = mel.eval("findRelatedSkinCluster " + sel)
    for cv in cvs:
        cmds.skinPercent(cls, cv, transformValue=[initialJnt, 0])

    cmds.skinCluster(cls, e=True, forceNormalizeWeights=True)
    cmds.parent(initialJnt, masterGrp)

    geoGrp = cmds.group(em=True, name="{0}_geo_grp".format(sel))
    cmds.setAttr("{0}.inheritsTransform".format(geoGrp), 0)
    cmds.parent(sel, geoGrp)

    l_ctrls = larger_ctrls(grps, sel)

    # create master ctrl
    master = rig.createControl(type="star", color="blue", name="{0}_master_CTRL".format(sel))
    rig.groupFreeze(master)

    cmds.addAttr(master, ln="showFineCtrls", at="long", min=0, max=1, dv=0, k=True)
    cmds.addAttr(master, ln="showLargeCtrls", at="long", min=0, max=1, dv=0, k=True)

    for g in grps:
        cmds.connectAttr("{0}.showFineCtrls".format(master), "{0}.v".format(g))
    for l in l_ctrls[1]:
        cmds.connectAttr("{0}.showLargeCtrls".format(master), "{0}.v".format(l))

    cmds.parent(l_ctrls[0], master)
    cmds.parent(geoGrp, master)
    cmds.parent(masterGrp, master)
Exemplo n.º 11
0
def curve_CV_controls_execute(crv, *args):
    """
    takes given curve and makes a ctrl for each cv. Then connects the matrix of the control directly to the point
    position of the cv. Basically hijacking the shape node, more or less. If there's a parent to the curve,
    will put whole rig under that and turn off inherit transforms for the crv itself.
    puts an attr called 'controlScale' on the group controls are under to scale size of controls
    Args:
        crv: string - name of given curve
        *args:

    Returns:
        Void
    """

    par = cmds.listRelatives(crv, p=True)

    ctrlGrps = []
    cvs = cmds.ls("{0}.cv[*]".format(crv), fl=True)
    xformGrp = cmds.group(empty=True, name="{0}_ctrl_GRP".format(crv))
    cmds.addAttr(xformGrp,
                 ln="controlScale",
                 at="float",
                 min=0.01,
                 max=100,
                 dv=1.0,
                 k=True)
    for x in range(0, len(cvs)):
        pos = cmds.pointPosition(cvs[x])
        shp = cmds.listRelatives(crv, s=True)[0]
        ctrl = rig.createControl(type="sphere",
                                 name="{0}_{1}_CTRL".format(crv, x),
                                 color="red")
        grp = rig.groupFreeze(ctrl)
        cmds.connectAttr("{0}.controlScale".format(xformGrp),
                         "{0}.sx".format(ctrl))
        cmds.connectAttr("{0}.controlScale".format(xformGrp),
                         "{0}.sy".format(ctrl))
        cmds.connectAttr("{0}.controlScale".format(xformGrp),
                         "{0}.sz".format(ctrl))
        cmds.setAttr("{0}.scale".format(ctrl), l=True, k=False)
        cmds.xform(grp, ws=True, t=pos)

        dm = cmds.shadingNode("decomposeMatrix",
                              asUtility=True,
                              name="{0}_{1}_DM".format(crv, x))
        cmds.connectAttr("{0}.worldMatrix[0]".format(ctrl),
                         "{0}.inputMatrix".format(dm))
        cmds.connectAttr("{0}.outputTranslate".format(dm),
                         "{0}.controlPoints[{1}]".format(shp, x))
        ctrlGrps.append(grp)

    cmds.xform(xformGrp,
               ws=True,
               t=(cmds.xform(crv, ws=True, q=True, rp=True)))
    cmds.xform(xformGrp,
               ws=True,
               ro=(cmds.xform(crv, ws=True, q=True, ro=True)))
    cmds.xform(xformGrp, s=(cmds.xform(crv, q=True, r=True, s=True)))

    if par:
        inhGrp = cmds.group(empty=True, name="noInherit_{0}_GRP".format(crv))
        cmds.parent(xformGrp, par[0])
        cmds.parent(inhGrp, par[0])
        cmds.parent(crv, inhGrp)
        cmds.setAttr("{0}.inheritsTransform".format(inhGrp), 0)

    cmds.parent(ctrlGrps, xformGrp)
    cmds.xform(crv, ws=True, t=(0, 0, 0))
    cmds.xform(crv, ws=True, ro=(0, 0, 0))
    cmds.xform(crv, a=True, s=(1, 1, 1))
Exemplo n.º 12
0
sel = cmds.ls(sl=True)

box = cmds.exactWorldBoundingBox(sel)  #[xmin, ymin, zmin, xmax, ymax, zmax]
X = om.MVector(box[0], box[3])
Y = om.MVector(box[1], box[4])
Z = om.MVector(box[2], box[5])

#get bbox lengths along axes
lenX = (X.y - X.x)
lenY = (Y.y - Y.x)
lenZ = (Z.y - Z.x)

print lenX, lenY, lenZ

ctrl = rig.createControl(name="ctrl", type="cube", color="pink")

cvs = {
    "xyz": [5, 15],
    "-xyz": [0, 4],
    "xy-z": [10, 14],
    "x-yz": [6, 8],
    "-x-yz": [3, 7],
    "-x-y-z": [2, 12],
    "x-y-z": [9, 13],
    "-xy-z": [1, 11]
}

for a in cvs["xyz"]:
    cmds.xform("{0}.cv[{1}]".format(ctrl, a), ws=True, t=(X.y, Y.y, Z.y))