コード例 #1
0
ファイル: softTweaks.py プロジェクト: rusn07/mgear
def _createSoftModTweak(baseCtl, tweakCtl, name, targets):

    sm = pm.softMod(targets, wn=[tweakCtl, tweakCtl])
    pm.rename(sm[0], "{}_softMod".format(name))

    # disconnect default connection
    plugs = sm[0].softModXforms.listConnections(p=True)
    for p in plugs:
        pm.disconnectAttr(p, sm[0].softModXforms)
        pm.delete(p.node())

    dm_node = node.createDecomposeMatrixNode(baseCtl.worldMatrix[0])
    pm.connectAttr(dm_node.outputTranslate, sm[0].falloffCenter)
    mul_node = node.createMulNode(dm_node.outputScaleX,
                                  tweakCtl.attr("falloff"))
    pm.connectAttr(mul_node.outputX, sm[0].falloffRadius)
    mulMatrix_node = applyop.gear_mulmatrix_op(tweakCtl.worldMatrix[0],
                                               tweakCtl.parentInverseMatrix[0])
    pm.connectAttr(mulMatrix_node.output, sm[0].weightedMatrix)
    pm.connectAttr(baseCtl.worldInverseMatrix[0], sm[0].postMatrix)
    pm.connectAttr(baseCtl.worldMatrix[0], sm[0].preMatrix)
    attribute.addAttribute(sm[0], "_isSoftTweak", "bool", False, keyable=False)

    sm[0].addAttr("ctlRoot", at='message', m=False)
    sm[0].addAttr("ctlBase", at='message', m=False)
    sm[0].addAttr("ctlTweak", at='message', m=False)
    pm.connectAttr(baseCtl.getParent().attr("message"), sm[0].attr("ctlRoot"))
    pm.connectAttr(baseCtl.attr("message"), sm[0].attr("ctlBase"))
    pm.connectAttr(tweakCtl.attr("message"), sm[0].attr("ctlTweak"))

    return sm[0]
コード例 #2
0
    def setUp(self):
        self.config = {
            "movePolicy":
            "merge",
            "proxyPolicy":
            "index",
            "map": [["shoulder_ik", "armUI_R0_ctl", "armUI_L0_ctl", 0],
                    ["shoulder_rotRef", "armUI_R0_ctl", "armUI_L0_ctl", 0],
                    ["shoulder_rotRef", "armUI_R1_ctl", "armUI_L0_ctl", 0]]
        }

        self.pcs = pm.polyCube(n="armUI_R0_ctl")
        self.pcs2 = pm.polyCube(n="armUI_R1_ctl")
        self.pct = pm.polyCube(n="armUI_L0_ctl")
        att.addAttribute(self.pcs[0],
                         "shoulder_ik",
                         "double",
                         0,
                         minValue=0,
                         maxValue=1)
        ch2 = att.addAttribute(self.pcs[0],
                               "shoulder_rotRef",
                               "double",
                               0,
                               minValue=0,
                               maxValue=1)
        ch3 = att.addAttribute(self.pcs2[0],
                               "shoulder_rotRef",
                               "double",
                               0,
                               minValue=0,
                               maxValue=1)
        pm.connectAttr(ch2, self.pcs[0].ty)
        pm.connectAttr(ch3, self.pcs2[0].ty)
コード例 #3
0
def source_nodes():
    cmds.file(new=True, force=True)

    pcs = pm.polyCube(name="armUI_R0_ctl")
    pcs2 = pm.polyCube(name="armUI_R1_ctl")
    attribute.addAttribute(pcs[0],
                           "shoulder_ik",
                           "double",
                           0,
                           minValue=0,
                           maxValue=1)
    ch2 = attribute.addAttribute(pcs[0],
                                 "shoulder_rotRef",
                                 "double",
                                 0,
                                 minValue=0,
                                 maxValue=1)
    ch3 = attribute.addAttribute(pcs2[0],
                                 "shoulder_rotRef",
                                 "double",
                                 0,
                                 minValue=0,
                                 maxValue=1)
    pm.connectAttr(ch2, pcs[0].ty)
    pm.connectAttr(ch3, pcs2[0].ty)
コード例 #4
0
 def setUp(self):
     self.testName = self.shortDescription()
     if (self.testName in ["proxy_channel", "proxy_channel_index", "proxy_channel_fullName"]):
         pm.displayInfo("Running: {}".format(self.testName))
         self.pcs = pm.polyCube(n="pCube_source")
         self.pcs2 = pm.polyCube(n="pCube_source2")
         self.pct = pm.polyCube(n="pCube_target")
         self.chanName = "bla_{}".format(self.testName)
         ch1 = att.addAttribute(self.pcs[0], self.chanName, "double", 0, minValue=0, maxValue=1 )
         ch2 = att.addAttribute(self.pcs2[0], self.chanName, "double", 0, minValue=0, maxValue=1 )
         pm.connectAttr(ch1, self.pcs[0].ty)
         pm.connectAttr(ch2, self.pcs2[0].ty)
     else:
         pm.displayWarning("UNKNOWN TEST ROUTINE: {}".format(self.testName))
コード例 #5
0
    def addSetupParam(self, longName, niceName, attType, value, minValue=None,
                      maxValue=None, keyable=True, readable=True,
                      storable=True, writable=True):
        """Add a parameter to the setup property.
        Note that animatable and keyable are False per default.

        Args:
            longName (str): The attribute name.
            niceName (str): The attribute nice name. (optional)
            attType (str): The Attribute Type. Exp: 'string', 'bool', etc..
            value (float or int): The default value.
            minValue (float or int): minimum value. (optional)
            maxValue (float or int): maximum value. (optional)
            keyable (bool): Set if the attribute is keyable or not.(optional)
            readable (bool): Set if the attribute is readable or not.(optional)
            storable (bool): Set if the attribute is storable or not.(optional)
            writable (bool): Set if the attribute is writable or not.(optional)

        Returns:
            str: The long name of the new attribute

        """
        attr = attribute.addAttribute(self.root, longName, attType, value,
                                      niceName, None, minValue=minValue,
                                      maxValue=maxValue, keyable=keyable,
                                      readable=readable, storable=storable,
                                      writable=writable)

        return attr
コード例 #6
0
def createRoot(*args):
    """Create new root to organise the rig

    Args:
        *args: Maya Dummy

    Returns:
        dagNode: The group
    """
    group = False
    dialog = NameUIDialog(getMayaWindow())
    dialog.exec_()
    oName = dialog.rootName
    if oName:
        group = pm.group(n=oName + "_" + ROOT_EXTENSION)
        attribute.addAttribute(group, "animSets", "bool", False)
    return group
コード例 #7
0
    def addAnimParam(self, longName, niceName, attType, value, minValue=None,
                     maxValue=None, keyable=True, readable=True, storable=True,
                     writable=True):
        """Add a parameter to the animation property.

        Note that animatable and keyable are True per default.

        Args:
            longName (str): The attribute name.
            niceName (str): The attribute nice name. (optional)
            attType (str): The Attribute Type.Exp:'string', 'bool', 'long', etc
            value (float or int): The default value.
            minValue (float or int): minimum value. (optional)
            maxValue (float or int): maximum value. (optional)
            keyable (bool): Set if the attribute is keyable or not. (optional)
            readable (bool): Set if the attribute is readable or not.(optional)
            storable (bool): Set if the attribute is storable or not.(optional)
            writable (bool): Set if the attribute is writable or not.(optional)

        Returns:
            str: The long name of the new attribute

        """
        if self.options["classicChannelNames"]:
            attr = attribute.addAttribute(self.uihost, self.getName(longName),
                                          attType, value, niceName, None,
                                          minValue=minValue, maxValue=maxValue,
                                          keyable=keyable, readable=readable,
                                          storable=storable, writable=writable)
        else:
            if self.uihost.hasAttr(self.getCompName(longName)):
                attr = self.uihost.attr(self.getCompName(longName))
            else:
                attr = attribute.addAttribute(self.uihost,
                                              self.getCompName(longName),
                                              attType, value, niceName, None,
                                              minValue=minValue,
                                              maxValue=maxValue,
                                              keyable=keyable,
                                              readable=readable,
                                              storable=storable,
                                              writable=writable)

        return attr
コード例 #8
0
def source_nodes():
    cmds.file(new=True, force=True)

    source1, _ = pm.polyCube(name="source1")
    source2, _ = pm.polyCube(name="source2")
    target, _ = pm.polyCube(name="target")

    ch1 = att.addAttribute(source1,
                           "chanName",
                           "double",
                           0,
                           minValue=0,
                           maxValue=1)
    ch2 = att.addAttribute(source2,
                           "chanName",
                           "double",
                           0,
                           minValue=0,
                           maxValue=1)

    pm.connectAttr(ch1, source1.ty)
    pm.connectAttr(ch2, source2.ty)
コード例 #9
0
ファイル: guide.py プロジェクト: moChen0607/mgear
    def addBlade(self, name, parentPos, parentDir):
        """
        Add a blade object to the guide.
        This mehod can initialize the object or draw it.
        Blade object is a 3points curve to define a plan in the guide.

        Args:
            name (str): Local name of the element.
            parentPos (dagNode): The parent of the element.
            parentDir (dagNode): The direction constraint of the element.

        Returns:
            dagNode:  The created blade curve.

        """
        if name not in self.blades.keys():
            self.blades[name] = vec.Blade(
                tra.getTransformFromPos(dt.Vector(0, 0, 0)))
            offset = False
        else:
            offset = True

        dist = .6 * self.root.attr("scaleX").get()
        blade = ico.guideBladeIcon(parent=parentPos,
                                   name=self.getName(name),
                                   lenX=dist,
                                   color=13,
                                   m=self.blades[name].transform)
        aim_cns = aop.aimCns(blade,
                             parentDir,
                             axis="xy",
                             wupType=2,
                             wupVector=[0, 1, 0],
                             wupObject=self.root,
                             maintainOffset=offset)
        pm.pointConstraint(parentPos, blade)

        offsetAttr = att.addAttribute(blade, "bladeRollOffset", "float",
                                      aim_cns.attr("offsetX").get())
        pm.connectAttr(offsetAttr, aim_cns.attr("offsetX"))
        att.lockAttribute(blade)

        return blade
コード例 #10
0
def setUserRigPivot(*args):
    """Set user pivot for a part of the rig.


    Args:
        *args: Maya dummy

    Returns:
        dagNode, dagNode: the axis and the group
    """
    listSelection = [oSel for oSel in pm.selected()]
    if listSelection:
        parent = listSelection[0].listRelatives(p=True)
        if parent:
            parent = parent[0]
        else:
            pm.displayWarning("In order to set user pivot, the selected "
                              "object must have one parent or Root")
            return False, False
        dialog = NameUIDialog(getMayaWindow())
        dialog.exec_()
        oName = dialog.rootName

        bbCenter, bbRadio, bb = bBoxData(listSelection, yZero=False)
        t = transform.getTransformFromPos(bbCenter)

        axis = ico.axis(parent=parent,
                        name=oName + "_" + PIVOT_EXTENSION,
                        width=bbRadio * 2,
                        color=[0, 0, 0],
                        m=t)

        attribute.addAttribute(axis, "animTranslation", "bool", True)
        attribute.addAttribute(axis, "animRotation", "bool", True)
        attribute.addAttribute(axis, "animScale", "bool", True)
        attribute.addEnumAttribute(axis, "ctlIcon", 0, iconList)

        pgrp = pm.group(listSelection,
                        p=parent,
                        n=oName + "_" + PGROUP_EXTENSION)
        return axis, pgrp
    else:
        pm.displayWarning("Please select the objects to set and "
                          "the parent root/userPivot")
        return False, False
コード例 #11
0
ファイル: eye_rigger.py プロジェクト: milesckt/mgear
def eyeRig(eyeMesh,
           edgeLoop,
           blinkH,
           namePrefix,
           offset,
           rigidLoops,
           falloffLoops,
           headJnt,
           doSkin,
           parent=None,
           ctlName="ctl",
           sideRange=False,
           customCorner=False,
           intCorner=None,
           extCorner=None,
           ctlGrp=None,
           defGrp=None):

    """Create eyelid and eye rig

    Args:
        eyeMesh (TYPE): Description
        edgeLoop (TYPE): Description
        blinkH (TYPE): Description
        namePrefix (TYPE): Description
        offset (TYPE): Description
        rigidLoops (TYPE): Description
        falloffLoops (TYPE): Description
        headJnt (TYPE): Description
        doSkin (TYPE): Description
        parent (None, optional): Description
        ctlName (str, optional): Description
        sideRange (bool, optional): Description
        customCorner (bool, optional): Description
        intCorner (None, optional): Description
        extCorner (None, optional): Description
        ctlGrp (None, optional): Description
        defGrp (None, optional): Description

    Returns:
        TYPE: Description
    """
    # Checkers
    if edgeLoop:
        edgeLoopList = [pm.PyNode(e) for e in edgeLoop.split(",")]
    else:
        pm.displayWarning("Please set the edge loop first")
        return

    if eyeMesh:
        try:
            eyeMesh = pm.PyNode(eyeMesh)
        except pm.MayaNodeError:
            pm.displayWarning("The object %s can not be found in the "
                              "scene" % (eyeMesh))
            return
    else:
        pm.displayWarning("Please set the eye mesh first")

    if doSkin:
        if not headJnt:
            pm.displayWarning("Please set the Head Jnt or unCheck "
                              "Compute Topological Autoskin")
            return

    # Initial Data
    bboxCenter = meshNavigation.bboxCenter(eyeMesh)

    extr_v = meshNavigation.getExtremeVertexFromLoop(edgeLoopList, sideRange)
    upPos = extr_v[0]
    lowPos = extr_v[1]
    inPos = extr_v[2]
    outPos = extr_v[3]
    edgeList = extr_v[4]
    vertexList = extr_v[5]

    # Detect the side L or R from the x value
    if inPos.getPosition(space='world')[0] < 0.0:
        side = "R"
        inPos = extr_v[3]
        outPos = extr_v[2]
        normalPos = outPos
        npw = normalPos.getPosition(space='world')
        normalVec = npw - bboxCenter
    else:
        side = "L"
        normalPos = outPos
        npw = normalPos.getPosition(space='world')
        normalVec = bboxCenter - npw
    # Manual Vertex corners
    if customCorner:
        if intCorner:
            try:
                if side == "R":
                    inPos = pm.PyNode(extCorner)
                else:
                    inPos = pm.PyNode(intCorner)
            except pm.MayaNodeError:
                pm.displayWarning("%s can not be found" % intCorner)
                return
        else:
            pm.displayWarning("Please set the internal eyelid corner")
            return

        if extCorner:
            try:
                normalPos = pm.PyNode(extCorner)
                npw = normalPos.getPosition(space='world')
                if side == "R":
                    outPos = pm.PyNode(intCorner)
                    normalVec = npw - bboxCenter
                else:
                    outPos = pm.PyNode(extCorner)
                    normalVec = bboxCenter - npw
            except pm.MayaNodeError:
                pm.displayWarning("%s can not be found" % extCorner)
                return
        else:
            pm.displayWarning("Please set the external eyelid corner")
            return

    # Check if we have prefix:
    if namePrefix:
        namePrefix = string.removeInvalidCharacter(namePrefix)
    else:
        pm.displayWarning("Prefix is needed")
        return

    def setName(name, ind=None):
        namesList = [namePrefix, side, name]
        if ind is not None:
            namesList[1] = side + str(ind)
        name = "_".join(namesList)
        return name

    if pm.ls(setName("root")):
        pm.displayWarning("The object %s already exist in the scene. Please "
                          "choose another name prefix" % setName("root"))
        return

    # Eye root
    eye_root = primitive.addTransform(None, setName("root"))
    eyeCrv_root = primitive.addTransform(eye_root, setName("crvs"))

    # Eyelid Main crvs
    try:
        upEyelid = meshNavigation.edgeRangeInLoopFromMid(
            edgeList, upPos, inPos, outPos)
        upCrv = curve.createCurveFromOrderedEdges(
            upEyelid, inPos, setName("upperEyelid"), parent=eyeCrv_root)
        upCrv_ctl = curve.createCurveFromOrderedEdges(
            upEyelid, inPos, setName("upCrv_%s" % ctlName), parent=eyeCrv_root)
        pm.rebuildCurve(upCrv_ctl, s=2, rt=0, rpo=True, ch=False)

        lowEyelid = meshNavigation.edgeRangeInLoopFromMid(
            edgeList, lowPos, inPos, outPos)
        lowCrv = curve.createCurveFromOrderedEdges(
            lowEyelid, inPos, setName("lowerEyelid"), parent=eyeCrv_root)
        lowCrv_ctl = curve.createCurveFromOrderedEdges(
            lowEyelid,
            inPos,
            setName("lowCrv_%s" % ctlName),
            parent=eyeCrv_root)

        pm.rebuildCurve(lowCrv_ctl, s=2, rt=0, rpo=True, ch=False)

    except UnboundLocalError:
        if customCorner:
            pm.displayWarning("This error is maybe caused because the custom "
                              "Corner vertex is not part of the edge loop")
        pm.displayError(traceback.format_exc())
        return

    upBlink = curve.createCurveFromCurve(
        upCrv, setName("upblink_crv"), nbPoints=30, parent=eyeCrv_root)
    lowBlink = curve.createCurveFromCurve(
        lowCrv, setName("lowBlink_crv"), nbPoints=30, parent=eyeCrv_root)

    upTarget = curve.createCurveFromCurve(
        upCrv, setName("upblink_target"), nbPoints=30, parent=eyeCrv_root)
    lowTarget = curve.createCurveFromCurve(
        lowCrv, setName("lowBlink_target"), nbPoints=30, parent=eyeCrv_root)
    midTarget = curve.createCurveFromCurve(
        lowCrv, setName("midBlink_target"), nbPoints=30, parent=eyeCrv_root)

    rigCrvs = [upCrv,
               lowCrv,
               upCrv_ctl,
               lowCrv_ctl,
               upBlink,
               lowBlink,
               upTarget,
               lowTarget,
               midTarget]

    for crv in rigCrvs:
        crv.attr("visibility").set(False)

    # localBBOX
    localBBox = eyeMesh.getBoundingBox(invisible=True, space='world')
    wRadius = abs((localBBox[0][0] - localBBox[1][0]))
    dRadius = abs((localBBox[0][1] - localBBox[1][1]) / 1.7)

    # Groups
    if not ctlGrp:
        ctlGrp = "rig_controllers_grp"
    try:
        ctlSet = pm.PyNode(ctlGrp)
    except pm.MayaNodeError:
        pm.sets(n=ctlGrp, em=True)
        ctlSet = pm.PyNode(ctlGrp)
    if not defGrp:
        defGrp = "rig_deformers_grp"
    try:
        defset = pm.PyNode(defGrp)
    except pm.MayaNodeError:
        pm.sets(n=defGrp, em=True)
        defset = pm.PyNode(defGrp)

    # Calculate center looking at
    averagePosition = ((upPos.getPosition(space='world')
                        + lowPos.getPosition(space='world')
                        + inPos.getPosition(space='world')
                        + outPos.getPosition(space='world'))
                       / 4)
    if side == "R":
        negate = False
        offset = offset
        over_offset = dRadius
    else:
        negate = False
        over_offset = dRadius

    if side == "R" and sideRange or side == "R" and customCorner:
        axis = "z-x"
        # axis = "zx"
    else:
        axis = "z-x"

    t = transform.getTransformLookingAt(
        bboxCenter,
        averagePosition,
        normalVec,
        axis=axis,
        negate=negate)

    over_npo = primitive.addTransform(
        eye_root, setName("center_lookatRoot"), t)

    over_ctl = icon.create(over_npo,
                           setName("over_%s" % ctlName),
                           t,
                           icon="square",
                           w=wRadius,
                           d=dRadius,
                           ro=datatypes.Vector(1.57079633, 0, 0),
                           po=datatypes.Vector(0, 0, over_offset),
                           color=4)
    node.add_controller_tag(over_ctl)
    attribute.add_mirror_config_channels(over_ctl)
    attribute.setKeyableAttributes(
        over_ctl,
        params=["tx", "ty", "tz", "ro", "rx", "ry", "rz", "sx", "sy", "sz"])

    if side == "R":
        over_npo.attr("rx").set(over_npo.attr("rx").get() * -1)
        over_npo.attr("ry").set(over_npo.attr("ry").get() + 180)
        over_npo.attr("sz").set(-1)

    if len(ctlName.split("_")) == 2 and ctlName.split("_")[-1] == "ghost":
        pass
    else:
        pm.sets(ctlSet, add=over_ctl)

    center_lookat = primitive.addTransform(
        over_ctl, setName("center_lookat"), t)

    # Tracking
    # Eye aim control
    t_arrow = transform.getTransformLookingAt(bboxCenter,
                                              averagePosition,
                                              upPos.getPosition(space='world'),
                                              axis="zy", negate=False)

    radius = abs((localBBox[0][0] - localBBox[1][0]) / 1.7)
    arrow_npo = primitive.addTransform(eye_root, setName("aim_npo"), t_arrow)
    arrow_ctl = icon.create(arrow_npo,
                            setName("aim_%s" % ctlName),
                            t_arrow,
                            icon="arrow",
                            w=1,
                            po=datatypes.Vector(0, 0, radius),
                            color=4)
    if len(ctlName.split("_")) == 2 and ctlName.split("_")[-1] == "ghost":
        pass
    else:
        pm.sets(ctlSet, add=arrow_ctl)
    attribute.setKeyableAttributes(arrow_ctl, params=["rx", "ry", "rz"])

    # tracking custom trigger
    if side == "R":
        tt = t_arrow
    else:
        tt = t
    aimTrigger_root = primitive.addTransform(
        center_lookat, setName("aimTrigger_root"), tt)
    aimTrigger_lvl = primitive.addTransform(
        aimTrigger_root, setName("aimTrigger_lvl"), tt)
    aimTrigger_lvl.attr("tz").set(1.0)
    aimTrigger_ref = primitive.addTransform(
        aimTrigger_lvl, setName("aimTrigger_ref"), tt)
    aimTrigger_ref.attr("tz").set(0.0)
    # connect  trigger with arrow_ctl
    pm.parentConstraint(arrow_ctl, aimTrigger_ref, mo=True)

    # Controls lists
    upControls = []
    trackLvl = []

    # upper eyelid controls
    upperCtlNames = ["inCorner", "upInMid", "upMid", "upOutMid", "outCorner"]
    cvs = upCrv_ctl.getCVs(space="world")
    if side == "R" and not sideRange:
        # if side == "R":
        cvs = [cv for cv in reversed(cvs)]
    for i, cv in enumerate(cvs):
        if utils.is_odd(i):
            color = 14
            wd = .5
            icon_shape = "circle"
            params = ["tx", "ty", "tz"]
        else:
            color = 4
            wd = .7
            icon_shape = "square"
            params = ["tx",
                      "ty",
                      "tz",
                      "ro",
                      "rx",
                      "ry",
                      "rz",
                      "sx",
                      "sy",
                      "sz"]

        t = transform.setMatrixPosition(t, cvs[i])
        npo = primitive.addTransform(center_lookat,
                                     setName("%s_npo" % upperCtlNames[i]),
                                     t)
        npoBase = npo
        if i == 2:
            # we add an extra level to input the tracking ofset values
            npo = primitive.addTransform(npo,
                                         setName("%s_trk" % upperCtlNames[i]),
                                         t)
            trackLvl.append(npo)

        ctl = icon.create(npo,
                          setName("%s_%s" % (upperCtlNames[i], ctlName)),
                          t,
                          icon=icon_shape,
                          w=wd,
                          d=wd,
                          ro=datatypes.Vector(1.57079633, 0, 0),
                          po=datatypes.Vector(0, 0, offset),
                          color=color)
        attribute.add_mirror_config_channels(ctl)
        node.add_controller_tag(ctl, over_ctl)
        upControls.append(ctl)
        if len(ctlName.split("_")) == 2 and ctlName.split("_")[-1] == "ghost":
            pass
        else:
            pm.sets(ctlSet, add=ctl)
        attribute.setKeyableAttributes(ctl, params)
        if side == "R":
            npoBase.attr("ry").set(180)
            npoBase.attr("sz").set(-1)

    # adding parent average contrains to odd controls
    for i, ctl in enumerate(upControls):
        if utils.is_odd(i):
            pm.parentConstraint(upControls[i - 1],
                                upControls[i + 1],
                                ctl.getParent(),
                                mo=True)

    # lower eyelid controls
    lowControls = [upControls[0]]
    lowerCtlNames = ["inCorner",
                     "lowInMid",
                     "lowMid",
                     "lowOutMid",
                     "outCorner"]

    cvs = lowCrv_ctl.getCVs(space="world")
    if side == "R" and not sideRange:
        cvs = [cv for cv in reversed(cvs)]
    for i, cv in enumerate(cvs):
        # we skip the first and last point since is already in the uper eyelid
        if i in [0, 4]:
            continue
        if utils.is_odd(i):
            color = 14
            wd = .5
            icon_shape = "circle"
            params = ["tx", "ty", "tz"]
        else:
            color = 4
            wd = .7
            icon_shape = "square"
            params = ["tx",
                      "ty",
                      "tz",
                      "ro",
                      "rx",
                      "ry",
                      "rz",
                      "sx",
                      "sy",
                      "sz"]

        t = transform.setMatrixPosition(t, cvs[i])
        npo = primitive.addTransform(center_lookat,
                                     setName("%s_npo" % lowerCtlNames[i]),
                                     t)
        npoBase = npo
        if i == 2:
            # we add an extra level to input the tracking ofset values
            npo = primitive.addTransform(npo,
                                         setName("%s_trk" % lowerCtlNames[i]),
                                         t)
            trackLvl.append(npo)
        ctl = icon.create(npo,
                          setName("%s_%s" % (lowerCtlNames[i], ctlName)),
                          t,
                          icon=icon_shape,
                          w=wd,
                          d=wd,
                          ro=datatypes.Vector(1.57079633, 0, 0),
                          po=datatypes.Vector(0, 0, offset),
                          color=color)
        attribute.add_mirror_config_channels(ctl)

        lowControls.append(ctl)
        if len(ctlName.split("_")) == 2 and ctlName.split("_")[-1] == "ghost":
            pass
        else:
            pm.sets(ctlSet, add=ctl)
        attribute.setKeyableAttributes(ctl, params)
        # mirror behaviout on R side controls
        if side == "R":
            npoBase.attr("ry").set(180)
            npoBase.attr("sz").set(-1)
    for lctl in reversed(lowControls[1:]):
        node.add_controller_tag(lctl, over_ctl)
    lowControls.append(upControls[-1])

    # adding parent average contrains to odd controls
    for i, ctl in enumerate(lowControls):
        if utils.is_odd(i):
            pm.parentConstraint(lowControls[i - 1],
                                lowControls[i + 1],
                                ctl.getParent(),
                                mo=True)

    # Connecting control crvs with controls
    applyop.gear_curvecns_op(upCrv_ctl, upControls)
    applyop.gear_curvecns_op(lowCrv_ctl, lowControls)

    # adding wires
    w1 = pm.wire(upCrv, w=upBlink)[0]
    w2 = pm.wire(lowCrv, w=lowBlink)[0]

    w3 = pm.wire(upTarget, w=upCrv_ctl)[0]
    w4 = pm.wire(lowTarget, w=lowCrv_ctl)[0]

    # adding blendshapes
    bs_upBlink = pm.blendShape(upTarget,
                               midTarget,
                               upBlink,
                               n="blendShapeUpBlink")
    bs_lowBlink = pm.blendShape(lowTarget,
                                midTarget,
                                lowBlink,
                                n="blendShapeLowBlink")
    bs_mid = pm.blendShape(lowTarget,
                           upTarget,
                           midTarget,
                           n="blendShapeLowBlink")

    # setting blendshape reverse connections
    rev_node = pm.createNode("reverse")
    pm.connectAttr(bs_upBlink[0].attr(midTarget.name()), rev_node + ".inputX")
    pm.connectAttr(rev_node + ".outputX", bs_upBlink[0].attr(upTarget.name()))
    rev_node = pm.createNode("reverse")
    pm.connectAttr(bs_lowBlink[0].attr(midTarget.name()), rev_node + ".inputX")
    pm.connectAttr(rev_node + ".outputX",
                   bs_lowBlink[0].attr(lowTarget.name()))
    rev_node = pm.createNode("reverse")
    pm.connectAttr(bs_mid[0].attr(upTarget.name()), rev_node + ".inputX")
    pm.connectAttr(rev_node + ".outputX", bs_mid[0].attr(lowTarget.name()))

    # setting default values
    bs_mid[0].attr(upTarget.name()).set(blinkH)

    # joints root
    jnt_root = primitive.addTransformFromPos(
        eye_root, setName("joints"), pos=bboxCenter)

    # head joint
    if headJnt:
        try:
            headJnt = pm.PyNode(headJnt)
            jnt_base = headJnt
        except pm.MayaNodeError:
            pm.displayWarning(
                "Aborted can not find %s " % headJnt)
            return
    else:
        # Eye root
        jnt_base = jnt_root

    eyeTargets_root = primitive.addTransform(eye_root,
                                             setName("targets"))

    eyeCenter_jnt = rigbits.addJnt(arrow_ctl,
                                   jnt_base,
                                   grp=defset,
                                   jntName=setName("center_jnt"))

    # Upper Eyelid joints ##################################################

    cvs = upCrv.getCVs(space="world")
    upCrv_info = node.createCurveInfoNode(upCrv)

    # aim constrain targets and joints
    upperEyelid_aimTargets = []
    upperEyelid_jnt = []
    upperEyelid_jntRoot = []

    for i, cv in enumerate(cvs):

        # aim targets
        trn = primitive.addTransformFromPos(eyeTargets_root,
                                            setName("upEyelid_aimTarget", i),
                                            pos=cv)
        upperEyelid_aimTargets.append(trn)
        # connecting positions with crv
        pm.connectAttr(upCrv_info + ".controlPoints[%s]" % str(i),
                       trn.attr("translate"))

        # joints
        jntRoot = primitive.addJointFromPos(jnt_root,
                                            setName("upEyelid_jnt_base", i),
                                            pos=bboxCenter)
        jntRoot.attr("radius").set(.08)
        jntRoot.attr("visibility").set(False)
        upperEyelid_jntRoot.append(jntRoot)
        applyop.aimCns(jntRoot, trn, axis="zy", wupObject=jnt_root)

        jnt_ref = primitive.addJointFromPos(jntRoot,
                                            setName("upEyelid_jnt_ref", i),
                                            pos=cv)
        jnt_ref.attr("radius").set(.08)
        jnt_ref.attr("visibility").set(False)

        jnt = rigbits.addJnt(jnt_ref,
                             jnt_base,
                             grp=defset,
                             jntName=setName("upEyelid_jnt", i))
        upperEyelid_jnt.append(jnt)

    # Lower Eyelid joints ##################################################

    cvs = lowCrv.getCVs(space="world")
    lowCrv_info = node.createCurveInfoNode(lowCrv)

    # aim constrain targets and joints
    lowerEyelid_aimTargets = []
    lowerEyelid_jnt = []
    lowerEyelid_jntRoot = []

    for i, cv in enumerate(cvs):
        if i in [0, len(cvs) - 1]:
            continue

        # aim targets
        trn = primitive.addTransformFromPos(eyeTargets_root,
                                            setName("lowEyelid_aimTarget", i),
                                            pos=cv)
        lowerEyelid_aimTargets.append(trn)
        # connecting positions with crv
        pm.connectAttr(lowCrv_info + ".controlPoints[%s]" % str(i),
                       trn.attr("translate"))

        # joints
        jntRoot = primitive.addJointFromPos(jnt_root,
                                            setName("lowEyelid_base", i),
                                            pos=bboxCenter)
        jntRoot.attr("radius").set(.08)
        jntRoot.attr("visibility").set(False)
        lowerEyelid_jntRoot.append(jntRoot)
        applyop.aimCns(jntRoot, trn, axis="zy", wupObject=jnt_root)

        jnt_ref = primitive.addJointFromPos(jntRoot,
                                            setName("lowEyelid_jnt_ref", i),
                                            pos=cv)
        jnt_ref.attr("radius").set(.08)
        jnt_ref.attr("visibility").set(False)

        jnt = rigbits.addJnt(jnt_ref,
                             jnt_base,
                             grp=defset,
                             jntName=setName("lowEyelid_jnt", i))
        lowerEyelid_jnt.append(jnt)

    # Channels
    # Adding and connecting attributes for the blink
    up_ctl = upControls[2]
    blink_att = attribute.addAttribute(
        over_ctl, "blink", "float", 0, minValue=0, maxValue=1)
    blinkMult_att = attribute.addAttribute(
        over_ctl, "blinkMult", "float", 1, minValue=1, maxValue=2)
    midBlinkH_att = attribute.addAttribute(
        over_ctl, "blinkHeight", "float", blinkH, minValue=0, maxValue=1)
    mult_node = node.createMulNode(blink_att, blinkMult_att)
    pm.connectAttr(mult_node + ".outputX",
                   bs_upBlink[0].attr(midTarget.name()))
    pm.connectAttr(mult_node + ".outputX",
                   bs_lowBlink[0].attr(midTarget.name()))
    pm.connectAttr(midBlinkH_att, bs_mid[0].attr(upTarget.name()))

    low_ctl = lowControls[2]

    # Adding channels for eye tracking
    upVTracking_att = attribute.addAttribute(up_ctl,
                                             "vTracking",
                                             "float",
                                             .02,
                                             minValue=0,
                                             maxValue=1,
                                             keyable=False,
                                             channelBox=True)
    upHTracking_att = attribute.addAttribute(up_ctl,
                                             "hTracking",
                                             "float",
                                             .01,
                                             minValue=0,
                                             maxValue=1,
                                             keyable=False,
                                             channelBox=True)

    lowVTracking_att = attribute.addAttribute(low_ctl,
                                              "vTracking",
                                              "float",
                                              .01,
                                              minValue=0,
                                              maxValue=1,
                                              keyable=False,
                                              channelBox=True)
    lowHTracking_att = attribute.addAttribute(low_ctl,
                                              "hTracking",
                                              "float",
                                              .01,
                                              minValue=0,
                                              maxValue=1,
                                              keyable=False,
                                              channelBox=True)

    mult_node = node.createMulNode(upVTracking_att, aimTrigger_ref.attr("ty"))
    pm.connectAttr(mult_node + ".outputX", trackLvl[0].attr("ty"))
    mult_node = node.createMulNode(upHTracking_att, aimTrigger_ref.attr("tx"))
    pm.connectAttr(mult_node + ".outputX", trackLvl[0].attr("tx"))

    mult_node = node.createMulNode(lowVTracking_att, aimTrigger_ref.attr("ty"))
    pm.connectAttr(mult_node + ".outputX", trackLvl[1].attr("ty"))
    mult_node = node.createMulNode(lowHTracking_att, aimTrigger_ref.attr("tx"))
    pm.connectAttr(mult_node + ".outputX", trackLvl[1].attr("tx"))

    # Tension on blink
    node.createReverseNode(blink_att, w1.scale[0])
    node.createReverseNode(blink_att, w3.scale[0])
    node.createReverseNode(blink_att, w2.scale[0])
    node.createReverseNode(blink_att, w4.scale[0])

    ###########################################
    # Reparenting
    ###########################################
    if parent:
        try:
            if isinstance(parent, basestring):
                parent = pm.PyNode(parent)
            parent.addChild(eye_root)
        except pm.MayaNodeError:
            pm.displayWarning("The eye rig can not be parent to: %s. Maybe "
                              "this object doesn't exist." % parent)

    ###########################################
    # Auto Skinning
    ###########################################
    if doSkin:
        # eyelid vertex rows
        totalLoops = rigidLoops + falloffLoops
        vertexLoopList = meshNavigation.getConcentricVertexLoop(vertexList,
                                                                totalLoops)
        vertexRowList = meshNavigation.getVertexRowsFromLoops(vertexLoopList)

        # we set the first value 100% for the first initial loop
        skinPercList = [1.0]
        # we expect to have a regular grid topology
        for r in range(rigidLoops):
            for rr in range(2):
                skinPercList.append(1.0)
        increment = 1.0 / float(falloffLoops)
        # we invert to smooth out from 100 to 0
        inv = 1.0 - increment
        for r in range(falloffLoops):
            for rr in range(2):
                if inv < 0.0:
                    inv = 0.0
                skinPercList.append(inv)
            inv -= increment

        # this loop add an extra 0.0 indices to avoid errors
        for r in range(10):
            for rr in range(2):
                skinPercList.append(0.0)

        # base skin
        geo = pm.listRelatives(edgeLoopList[0], parent=True)[0]
        # Check if the object has a skinCluster
        objName = pm.listRelatives(geo, parent=True)[0]

        skinCluster = skin.getSkinCluster(objName)
        if not skinCluster:
            skinCluster = pm.skinCluster(headJnt,
                                         geo,
                                         tsb=True,
                                         nw=2,
                                         n='skinClsEyelid')

        eyelidJoints = upperEyelid_jnt + lowerEyelid_jnt
        pm.progressWindow(title='Auto skinning process',
                          progress=0,
                          max=len(eyelidJoints))
        firstBoundary = False
        for jnt in eyelidJoints:
            pm.progressWindow(e=True, step=1, status='\nSkinning %s' % jnt)
            skinCluster.addInfluence(jnt, weight=0)
            v = meshNavigation.getClosestVertexFromTransform(geo, jnt)

            for row in vertexRowList:

                if v in row:
                    it = 0  # iterator
                    inc = 1  # increment
                    for i, rv in enumerate(row):
                        try:
                            perc = skinPercList[it]
                            t_val = [(jnt, perc), (headJnt, 1.0 - perc)]
                            pm.skinPercent(skinCluster,
                                           rv,
                                           transformValue=t_val)
                            if rv.isOnBoundary():
                                # we need to compare with the first boundary
                                # to check if the row have inverted direction
                                # and offset the value
                                if not firstBoundary:
                                    firstBoundary = True
                                    firstBoundaryValue = it

                                else:
                                    if it < firstBoundaryValue:
                                        it -= 1
                                    elif it > firstBoundaryValue:
                                        it += 1
                                inc = 2
                        except IndexError:
                            continue

                        it = it + inc
        pm.progressWindow(e=True, endProgress=True)

        # Eye Mesh skinning
        skinCluster = skin.getSkinCluster(eyeMesh)
        if not skinCluster:
            skinCluster = pm.skinCluster(eyeCenter_jnt,
                                         eyeMesh,
                                         tsb=True,
                                         nw=1,
                                         n='skinClsEye')
コード例 #12
0
    def addSetupParam(self, longName, niceName, attType, value, minValue=None, maxValue=None, keyable=True, readable=True, storable=True, writable=True):

        attr = att.addAttribute(self.root, self.getName(longName), attType, value, niceName, None, minValue=minValue, maxValue=maxValue, keyable=keyable, readable=readable, storable=storable, writable=writable)

        return attr
コード例 #13
0
def simpleRig(rigName="rig", wCntCtl=False, *args):
    """Create a simple 1Click rig.

    Args:
        rigName (str, optional): Name of the rig.
        wCntCtl (bool, optional): Place the Golbal control in the wolrd
            center or use the general BBox of the selection.
        *args: Description

    Returns:
        dagNode: Rig top node
    """
    meshList = []
    ctlList = []
    lvlList = []
    absBB = []
    absRadio = 0.5

    listSelection = [oSel for oSel in pm.selected()]

    # Create base structure
    rig = pm.createNode('transform', n=rigName)
    geo = pm.createNode('transform', n="geo", p=rig)
    geo.attr("overrideEnabled").set(1)
    geo.attr("overrideDisplayType").set(2)

    attribute.addAttribute(rig, "is_rig", "bool", True)
    attribute.addAttribute(rig, "rig_name", "string", "rig")
    attribute.addAttribute(rig, "user", "string", getpass.getuser())
    attribute.addAttribute(rig, "date", "string", str(datetime.datetime.now()))

    attribute.addAttribute(rig, "maya_version", "string",
                           str(pm.mel.eval("getApplicationVersionAsFloat")))

    attribute.addAttribute(rig, "gear_version", "string", mgear.getVersion())
    attribute.addAttribute(rig, "ctl_vis", "bool", True)
    attribute.addAttribute(rig, "jnt_vis", "bool", False)

    attribute.addAttribute(rig, "quickselA", "string", "")
    attribute.addAttribute(rig, "quickselB", "string", "")
    attribute.addAttribute(rig, "quickselC", "string", "")
    attribute.addAttribute(rig, "quickselD", "string", "")
    attribute.addAttribute(rig, "quickselE", "string", "")
    attribute.addAttribute(rig, "quickselF", "string", "")

    rig.addAttr("rigGroups", at='message', m=1)
    rig.addAttr("rigPoses", at='message', m=1)

    for oSel in listSelection:

        bbCenter, bbRadio, bb = bBoxData(oSel)
        lvl = pm.createNode('transform', n=oSel.name().split("_")[0] + "_npo")
        lvlList.append(lvl)
        t = transform.getTransformFromPos(bbCenter)
        lvl.setTransformation(t)

        ctl = ico.create(lvl,
                         oSel.name().split("_")[0] + "_ctl",
                         t,
                         14,
                         icon="circle",
                         w=bbRadio * 2)

        cnsPart(ctl, oSel)

        ctlList.append(ctl)
        for oShape in oSel.listRelatives(ad=True, s=True, type='mesh'):
            pm.connectAttr(ctl + ".visibility", oShape + ".visibility", f=True)
            meshList.append(oShape)

        # Reparenting
        pm.parent(oSel, geo)

        # calculate the global control BB
        if not wCntCtl:
            if not absBB:
                absBB = bb
            else:
                absBB = [
                    [min(bb[0][0], absBB[0][0]),
                     max(bb[0][1], absBB[0][1])],
                    [min(bb[1][0], absBB[1][0]),
                     max(bb[1][1], absBB[1][1])],
                    [min(bb[2][0], absBB[2][0]),
                     max(bb[2][1], absBB[2][1])]
                ]

        userPivots = dag.findChildrenPartial(oSel, PIVOT_EXTENSION)
        # Loop selection
        uPivotCtl = []
        if userPivots:
            for uPivot in userPivots:
                try:
                    pstr = uPivot.name().split('_')[0] + "_" + PGROUP_EXTENSION
                    pgrp = pm.PyNode(pstr)
                except TypeError:
                    pm.displayError("The selected pivot dont have the group"
                                    " contrapart. Review your rig structure")
                    return False
                objList = pgrp.listRelatives(ad=True)
                if objList:
                    bbCenter, bbRadio, bb = bBoxData(objList)
                    t = uPivot.getMatrix(worldSpace=True)
                    lvlParent = pm.listRelatives(
                        uPivot, p=True)[0].name().split("_")[0] + "_ctl"

                    lvl = pm.createNode('transform',
                                        n=uPivot.split("_")[0] + "_npo")
                    lvl.setTransformation(t)
                    icon = iconList[uPivot.attr("ctlIcon").get()]
                    ctlKeyable = []
                    if uPivot.attr("animTranslation").get():
                        ctlKeyable = ctlKeyable + ["tx", "ty", "tz"]
                    if uPivot.attr("animRotation").get():
                        ctlKeyable = ctlKeyable + ["ro", "rx", "ry", "rz"]
                    if uPivot.attr("animScale").get():
                        ctlKeyable = ctlKeyable + ["sx", "sy", "sz"]

                    ctl = ico.create(lvl,
                                     uPivot.split("_")[0] + "_ctl",
                                     t,
                                     15,
                                     icon=icon,
                                     w=bbRadio * 2,
                                     h=bbRadio * 2,
                                     d=bbRadio * 2)

                    attribute.setKeyableAttributes(ctl, ctlKeyable)
                    pm.parent(lvl, lvlParent)
                    attribute.setKeyableAttributes(lvl, [])
                    uPivotCtl.append(ctl)
                    # Constraint
                    cnsPart(ctl, pgrp)

                    for oShape in uPivot.listRelatives(ad=True,
                                                       s=True,
                                                       type='mesh'):
                        pm.connectAttr(ctl + ".visibility",
                                       oShape + ".visibility",
                                       f=True)
                        meshList.append(oShape)

                    # hidde user pivot
                    uPivot.attr("visibility").set(False)

    # setting the global control
    if wCntCtl:
        absCenter = [0, 0, 0]
    else:
        absCenter = [(axis[0] + axis[1]) / 2 for axis in absBB]
        # set the cencter in the floor
        absCenter[1] = absBB[1][0]

        absRadio = max([absBB[0][1] - absBB[0][0], absBB[2][1] - absBB[2][0]
                        ]) / 1.7

    t = transform.getTransformFromPos(absCenter)
    lvl = pm.createNode('transform', n="global_npo")
    lvl.setTransformation(t)
    pm.parent(lvl, rig)

    ctlGlobal = ico.create(lvl,
                           "global_ctl",
                           t,
                           17,
                           icon="square",
                           w=absRadio * 2,
                           d=absRadio * 2)

    pm.parent(lvlList, ctlGlobal)
    ctlList.append(ctlGlobal)
    attribute.setKeyableAttributes(lvl, [])
    for lvl in lvlList:
        attribute.setKeyableAttributes(lvl, [])

    # Create sets
    meshSet = pm.sets(meshList, n="CACHE_grp")
    ctlSet = pm.sets([ctlList, uPivotCtl], n="rig_controllers_grp")
    deformersSet = pm.sets(meshList, n="rig_deformers_grp")
    compGroup = pm.sets(meshList, n="rig_componentsRoots_grp")

    rigSets = pm.sets([meshSet, ctlSet, deformersSet, compGroup],
                      n="rig_Sets_grp")

    pm.connectAttr(rigSets.attr("message"), "rig.rigGroups[0]")
    pm.connectAttr(meshSet.attr("message"), "rig.rigGroups[1]")
    pm.connectAttr(ctlSet.attr("message"), "rig.rigGroups[2]")
    pm.connectAttr(deformersSet.attr("message"), "rig.rigGroups[3]")
    pm.connectAttr(compGroup.attr("message"), "rig.rigGroups[4]")

    if oSel.hasAttr("animSets") and oSel.attr("animSets").get():
        # create anim Sets
        pm.sets(n="animNodes", em=True)
        animNodes_set = pm.PyNode("animNodes")

        pm.sets(n="animSets", em=True)
        animSets_set = pm.PyNode("animSets")

        # adding set
        pm.sets(animSets_set, add=animNodes_set)
        pm.sets(animNodes_set, add=ctlSet.members())

        pm.connectAttr(animSets_set.attr("message"), "rig.rigGroups[5]")
        pm.connectAttr(animNodes_set.attr("message"), "rig.rigGroups[6]")

    # create dagPose
    pm.select(ctlSet)
    o_node = pm.dagPose(save=True, selection=True)
    pm.connectAttr(o_node.message, rig.rigPoses[0])

    return rig
コード例 #14
0
ファイル: __init__.py プロジェクト: AtonLerin/mgear
    def initialHierarchy(self):
    
        mgear.log("Initial Hierarchy")

        # --------------------------------------------------
        # Model
        self.model = pri.addTransformFromPos(None, self.options["rig_name"])
        att.lockAttribute(self.model)

        # --------------------------------------------------
        # Global Ctl
        self.global_ctl = self.addCtl(self.model, "global_C0_ctl", dt.Matrix(), self.options["C_color_fk"], "crossarrow", w=10)
        
        # --------------------------------------------------
        # INFOS
        self.isRig_att       = att.addAttribute(self.model, "is_rig", "bool", True)
        self.rigName_att     = att.addAttribute(self.model, "rig_name", "string", self.options["rig_name"])
        self.user_att        = att.addAttribute(self.model, "user", "string", getpass.getuser())
        self.isWip_att       = att.addAttribute(self.model, "wip", "bool", self.options["mode"] != 0)
        self.date_att        = att.addAttribute(self.model, "date", "string", str(datetime.datetime.now()))
        self.mayaVersion_att = att.addAttribute(self.model, "maya_version", "string", str(mel.eval("getApplicationVersionAsFloat")))
        self.gearVersion_att = att.addAttribute(self.model, "gear_version", "string", mgear.getVersion())
        self.synoptic_att    = att.addAttribute(self.model, "synoptic", "string", str(self.options["synoptic"]))
        self.comments_att    = att.addAttribute(self.model, "comments", "string", str(self.options["comments"]))
        self.ctlVis_att      = att.addAttribute(self.model, "ctl_vis", "bool", True)
        self.shdVis_att      = att.addAttribute(self.model, "shd_vis", "bool", False)
        
        self.qsA_att         = att.addAttribute(self.model, "quickselA", "string", "")
        self.qsB_att         = att.addAttribute(self.model, "quickselB", "string", "")
        self.qsC_att         = att.addAttribute(self.model, "quickselC", "string", "")
        self.qsD_att         = att.addAttribute(self.model, "quickselD", "string", "")
        self.qsE_att         = att.addAttribute(self.model, "quickselE", "string", "")
        self.qsF_att         = att.addAttribute(self.model, "quickselF", "string", "")

        # --------------------------------------------------
        # UI SETUP AND ANIM
        self.oglLevel_att  = att.addAttribute(self.model, "ogl_level", "long", 0, None, None, 0, 3)

        # --------------------------------------------------
        # Basic set of null
        if self.options["shadow_rig"]:
            self.shd_org = pri.addTransformFromPos(self.model, "shd_org")
            connectAttr(self.shdVis_att, self.shd_org.attr("visibility"))
コード例 #15
0
def characterizeBiped(*args):

    try:
        gCtl = pm.PyNode('global_C0_ctl')
        mocapAttach = att.addAttribute(gCtl,
                                       "mocapAttach",
                                       "float",
                                       1.0,
                                       minValue=0.0,
                                       maxValue=1.0)

    except:
        pm.displayWarning("global_C0_ctl: Is not in the scene")
        return

    # Align skeleton
    for a, b in zip(skelFK, gearFK):
        try:
            oA = pm.PyNode(a)
        except:
            pm.displayWarning(a + ": Is not in the scene")
        try:
            oB = pm.PyNode(b)
        except:
            pm.displayWarning(b + ": Is not in the scene")
        tra.matchWorldTransform(oB, oA)

    #constrain FK controls
    for a, b in zip(skelFK, gearFK):
        oA = pm.PyNode(a)
        oB = pm.PyNode(b)
        cns = pm.parentConstraint(oA, oB, mo=True)

        pb_node = pm.createNode("pairBlend")

        pm.connectAttr(cns + ".constraintRotateX", pb_node + ".inRotateX2")
        pm.connectAttr(cns + ".constraintRotateY", pb_node + ".inRotateY2")
        pm.connectAttr(cns + ".constraintRotateZ", pb_node + ".inRotateZ2")
        pm.connectAttr(pb_node + ".outRotateX", oB + ".rotateX", f=True)
        pm.connectAttr(pb_node + ".outRotateY", oB + ".rotateY", f=True)
        pm.connectAttr(pb_node + ".outRotateZ", oB + ".rotateZ", f=True)
        pm.setKeyframe(oB, at="rotateX")
        pm.setKeyframe(oB, at="rotateY")
        pm.setKeyframe(oB, at="rotateZ")

        pm.connectAttr(cns + ".constraintTranslateX",
                       pb_node + ".inTranslateX2")
        pm.connectAttr(cns + ".constraintTranslateY",
                       pb_node + ".inTranslateY2")
        pm.connectAttr(cns + ".constraintTranslateZ",
                       pb_node + ".inTranslateZ2")
        pm.connectAttr(pb_node + ".outTranslateX", oB + ".translateX", f=True)
        pm.connectAttr(pb_node + ".outTranslateY", oB + ".translateY", f=True)
        pm.connectAttr(pb_node + ".outTranslateZ", oB + ".translateZ", f=True)
        pm.setKeyframe(oB, at="translateX")
        pm.setKeyframe(oB, at="translateY")
        pm.setKeyframe(oB, at="translateZ")

        pm.connectAttr(mocapAttach, pb_node.attr("weight"))

    #align IK controls with FK controls
    for a, b in zip(alignIK, alignFK):
        oA = pm.PyNode(a)
        oB = pm.PyNode(b)
        tra.matchWorldTransform(oB, oA)
        if a in [u'arm_L0_upv_ctl', u'arm_R0_upv_ctl']:
            oA.attr("tz").set(-3)
        if a == u'arm_L0_ikcns_ctl':
            oA.attr("rx").set((oA.attr("rx").get() + 90))
        if a == u'arm_R0_ikcns_ctl':
            oA.attr("rx").set((oA.attr("rx").get() - 90))

    # constrain IK controls
    for a, b in zip(skelIK, gearIK):
        oA = pm.PyNode(a)
        oB = pm.PyNode(b)
        print b
        pb_node = pm.createNode("pairBlend")
        try:
            if b in [u'leg_L0_upv_ctl', u'leg_R0_upv_ctl']:
                att.lockAttribute(pm.PyNode(b), lock=False, keyable=True)
            if b in [
                    u'leg_L0_mid_ctl', u'leg_R0_mid_ctl', u'arm_L0_mid_ctl',
                    u'arm_R0_mid_ctl'
            ]:
                cns = pm.pointConstraint(oA, oB, mo=True)
            else:
                cns = pm.parentConstraint(oA, oB, mo=True)
            pm.connectAttr(cns + ".constraintRotateX", pb_node + ".inRotateX2")
            pm.connectAttr(cns + ".constraintRotateY", pb_node + ".inRotateY2")
            pm.connectAttr(cns + ".constraintRotateZ", pb_node + ".inRotateZ2")
            pm.connectAttr(pb_node + ".outRotateX", oB + ".rotateX", f=True)
            pm.connectAttr(pb_node + ".outRotateY", oB + ".rotateY", f=True)
            pm.connectAttr(pb_node + ".outRotateZ", oB + ".rotateZ", f=True)
            pm.setKeyframe(oB, at="rotateX")
            pm.setKeyframe(oB, at="rotateY")
            pm.setKeyframe(oB, at="rotateZ")
        except:
            cns = pm.pointConstraint(oA, oB, mo=True)

        pm.connectAttr(cns + ".constraintTranslateX",
                       pb_node + ".inTranslateX2")
        pm.connectAttr(cns + ".constraintTranslateY",
                       pb_node + ".inTranslateY2")
        pm.connectAttr(cns + ".constraintTranslateZ",
                       pb_node + ".inTranslateZ2")
        pm.connectAttr(pb_node + ".outTranslateX", oB + ".translateX", f=True)
        pm.connectAttr(pb_node + ".outTranslateY", oB + ".translateY", f=True)
        pm.connectAttr(pb_node + ".outTranslateZ", oB + ".translateZ", f=True)
        pm.setKeyframe(oB, at="translateX")
        pm.setKeyframe(oB, at="translateY")
        pm.setKeyframe(oB, at="translateZ")

        pm.connectAttr(mocapAttach, pb_node.attr("weight"))
コード例 #16
0
ファイル: __init__.py プロジェクト: moChen0607/mgear
    def addCtl(self, parent, name, m, color, icon, **kwargs):
        """
        Create the control and apply the shape, if this is alrealdy stored
        in the guide controllers grp.

        Args:
            parent (dagNode): The control parent
            name (str): The control name.
            m (matrix): The transfromation matrix for the control.
            color (int or list of float): The color for the control in idex or RGB.
            icon (str): The controls default shape.
            kwargs (variant): Other arguments for the icon type variations.

        Returns:
            dagNode: The Control.

        """
        fullName = self.getName(name)
        if fullName in self.rig.guide.controllers.keys():
            ctl_ref = self.rig.guide.controllers[fullName]
            ctl = pri.addTransform(parent, fullName, m)
            for shape in ctl_ref.getShapes():
                ctl.addChild(shape, shape=True, add=True)
            ico.setcolor(ctl, color)
        else:
            ctl = ico.create(parent, fullName, m, color, icon, **kwargs)

        # create the attributes to handlde mirror and symetrical pose
        att.addAttribute(ctl, "invTx", "bool", 0,  keyable=False, niceName="Invert Mirror TX")
        att.addAttribute(ctl, "invTy", "bool", 0,  keyable=False, niceName="Invert Mirror TY")
        att.addAttribute(ctl, "invTz", "bool", 0,  keyable=False, niceName="Invert Mirror TZ")
        att.addAttribute(ctl, "invRx", "bool", 0,  keyable=False, niceName="Invert Mirror RX")
        att.addAttribute(ctl, "invRy", "bool", 0,  keyable=False, niceName="Invert Mirror RY")
        att.addAttribute(ctl, "invRz", "bool", 0,  keyable=False, niceName="Invert Mirror RZ")
        att.addAttribute(ctl, "invSx", "bool", 0,  keyable=False, niceName="Invert Mirror SX")
        att.addAttribute(ctl, "invSy", "bool", 0,  keyable=False, niceName="Invert Mirror SY")
        att.addAttribute(ctl, "invSz", "bool", 0,  keyable=False, niceName="Invert Mirror SZ")

        self.addToGroup(ctl, "controllers")

        return ctl
コード例 #17
0
ファイル: __init__.py プロジェクト: milesckt/mgear
    def initialHierarchy(self):
        """
        Create the inital structure for the rig.

        """
        # Root
        self.root = primitive.addTransformFromPos(self.model,
                                                  self.getName("root"),
                                                  self.guide.pos["root"])
        self.addToGroup(self.root, names=["componentsRoots"])

        # infos
        attribute.addAttribute(self.root, "componentType", "string",
                               self.guide.compType)
        attribute.addAttribute(self.root, "componentName", "string",
                               self.guide.compName)
        attribute.addAttribute(self.root, "componentVersion", "string",
                               str(self.guide.version)[1:-1])
        attribute.addAttribute(self.root, "componentAuthor", "string",
                               self.guide.author)
        attribute.addAttribute(self.root, "componentURL", "string",
                               self.guide.url)
        attribute.addAttribute(self.root, "componentEmail", "string",
                               self.guide.email)

        # joint --------------------------------
        if self.options["joint_rig"]:
            self.component_jnt_org = primitive.addTransform(
                self.rig.jnt_org, self.getName("jnt_org"))
            # The initial assigment of the active jnt and the parent relative
            # jnt is the same, later will be updated base in the user options
            self.active_jnt = self.component_jnt_org
            self.parent_relative_jnt = self.component_jnt_org

        return
コード例 #18
0
def _createSoftModTweak(baseCtl,
                        tweakCtl,
                        name,
                        targets,
                        nameExt="softMod",
                        is_asset=False):

    sm = pm.softMod(targets, wn=[tweakCtl, tweakCtl])
    pm.rename(sm[0], "{}_{}".format(name, nameExt))

    # disconnect default connection
    plugs = sm[0].softModXforms.listConnections(p=True)
    for p in plugs:
        pm.disconnectAttr(p, sm[0].softModXforms)
        pm.delete(p.node())

    dm_node = node.createDecomposeMatrixNode(baseCtl.worldMatrix[0])
    pm.connectAttr(dm_node.outputTranslate, sm[0].falloffCenter)
    mul_node = node.createMulNode(dm_node.outputScaleX,
                                  tweakCtl.attr("falloff"))
    pm.connectAttr(mul_node.outputX, sm[0].falloffRadius)
    mulMatrix_node = applyop.gear_mulmatrix_op(tweakCtl.worldMatrix[0],
                                               tweakCtl.parentInverseMatrix[0])
    pm.connectAttr(mulMatrix_node.output, sm[0].weightedMatrix)
    pm.connectAttr(baseCtl.worldInverseMatrix[0], sm[0].postMatrix)
    pm.connectAttr(baseCtl.worldMatrix[0], sm[0].preMatrix)
    if is_asset:
        tag_name = ASSET_TAG
    else:
        tag_name = SHOT_TAG

    attribute.addAttribute(sm[0], tag_name, "bool", False, keyable=False)

    sm[0].addAttr("ctlRoot", at='message', m=False)
    sm[0].addAttr("ctlBase", at='message', m=False)
    sm[0].addAttr("ctlTweak", at='message', m=False)
    pm.connectAttr(baseCtl.getParent().attr("message"), sm[0].attr("ctlRoot"))
    pm.connectAttr(baseCtl.attr("message"), sm[0].attr("ctlBase"))
    pm.connectAttr(tweakCtl.attr("message"), sm[0].attr("ctlTweak"))

    # This connection allow the softTweak to work if we apply the  skin
    # precision fix.
    # TODO: By default only apply to a non asset tweaks.
    if skin.getSkinCluster(targets[0]) and not is_asset:

        skin_cls = skin.getSkinCluster(targets[0])
        cnxs = skin_cls.matrix[0].listConnections()
        if (cnxs and cnxs[0].type() == "mgear_mulMatrix"
                and not sm[0].hasAttr("_fixedSkinFix")):

            # tag the softmod as fixed
            attribute.addAttribute(sm[0], "_fixedSkinFix", "bool")

            # original connections
            matrix_cnx = sm[0].matrix.listConnections(p=True)[0]
            preMatrix_cnx = sm[0].preMatrix.listConnections(p=True)[0]
            wgtMatrix_cnx = sm[0].weightedMatrix.listConnections(p=True)[0]
            postMatrix_cnx = sm[0].postMatrix.listConnections(p=True)[0]

            # pre existing node operators
            mulMtx_node = wgtMatrix_cnx.node()
            dcMtx_node = sm[0].falloffCenter.listConnections(p=True)[0].node()

            # geo offset connnections
            geo_root = targets[0].getParent()
            gr_W = geo_root.worldMatrix[0]
            gr_WI = geo_root.worldInverseMatrix[0]

            # new offset operators
            mmm1 = applyop.gear_mulmatrix_op(preMatrix_cnx, gr_WI)
            mmm2 = applyop.gear_mulmatrix_op(matrix_cnx, gr_WI)
            mmm3 = applyop.gear_mulmatrix_op(gr_W, postMatrix_cnx)

            # re-wire connections
            pm.connectAttr(mmm1.output, dcMtx_node.inputMatrix, f=True)
            pm.connectAttr(mmm1.output, sm[0].preMatrix, f=True)

            pm.connectAttr(mmm2.output, sm[0].matrix, f=True)
            pm.connectAttr(mmm2.output, mulMtx_node.matrixA, f=True)

            pm.connectAttr(mmm3.output, mulMtx_node.matrixB, f=True)
            pm.connectAttr(mmm3.output, sm[0].postMatrix, f=True)

            _neutra_geomMatrix(sm[0])

    return sm[0]
コード例 #19
0
def _createSoftTweakControls(name,
                             parent=None,
                             t=datatypes.Matrix(),
                             grps=None,
                             size=0.5):
    root_name = "{}_{}".format(name, "softTweak_root")
    namespace = None
    try:
        # simple check if exist a tweak with the same name
        exist = pm.PyNode(root_name)
        if exist:
            pm.displayError("the tweak: {} already exist. Please use a "
                            "unique name.".format(name))
            return False, False
    except pm.MayaNodeError:
        if parent:
            try:
                p = pm.PyNode(parent)
                namespace = p.namespace()

            except pm.MayaNodeError:
                pm.displayWarning("{} is not a valid parent or doesn't "
                                  "exist".format(parent))
                p = None
        else:
            p = None
        root = primitive.addTransform(p, root_name, t)
        attribute.addAttribute(root, "iconSize", "float", size, keyable=False)

        baseCtl = icon.create(parent=root,
                              name="{}_{}".format(name, "baseSoftTweak_ctl"),
                              m=t,
                              color=[1, 0.622, 0],
                              icon="square",
                              d=size,
                              w=size)
        tweakCtl = icon.create(parent=baseCtl,
                               name="{}_{}".format(name, "softTweak_ctl"),
                               m=t,
                               color=[0.89, 0.0, 0.143],
                               icon="diamond",
                               w=size * .8)
        attribute.addAttribute(tweakCtl, "falloff", "float", size)

        if grps:
            if not isinstance(grps, list):
                grps = [grps]
            for grp in grps:
                try:
                    # try if exist
                    oGrp = pm.PyNode(grp)
                except pm.MayaNodeError:
                    # create a new grp if does't exist
                    if len(grp.split("_")) >= 3:  # check  name convention
                        name = grp
                    else:
                        name = "rig_{}_grp".format(grp)

                        # namespace basic handling
                        # NOTE: Doesn't support more than one namespace stacked
                        if namespace and len(name.split(":")) < 2:
                            name = namespace + name

                    oGrp = pm.sets(n=name, em=True)

                pm.sets(oGrp, add=[baseCtl, tweakCtl])
        if t:
            root.setMatrix(t, worldSpace=True)

        return baseCtl, tweakCtl
コード例 #20
0
def createRivetTweak(mesh,
                     edgePair,
                     name,
                     parent=None,
                     ctlParent=None,
                     color=[0, 0, 0],
                     size=.04,
                     defSet=None):
    """Create a tweak joint attached to the mesh using a rivet

    Args:
        mesh (mesh): The object to add the tweak
        edgePair (pari list): The edge pairt to create the rivet
        name (str): The name for the tweak
        parent (None or dagNode, optional): The parent for the tweak
        ctlParent (None or dagNode, optional): The parent for the tweak control
        color (list, optional): The color for the control
    """
    blendShape = blendShapes.getBlendShape(mesh)

    inputMesh = blendShape.listConnections(sh=True, t="shape", d=False)[0]

    oRivet = rivet.rivet()
    base = oRivet.create(inputMesh, edgePair[0], edgePair[1], parent)
    # get side
    if base.getTranslation(space='world')[0] < -0.01:
        side = "R"
    elif base.getTranslation(space='world')[0] > 0.01:
        side = "L"
    else:
        side = "C"

    nameSide = name + "_tweak_" + side
    pm.rename(base, nameSide)

    # Joints NPO
    npo = pm.PyNode(
        pm.createNode("transform", n=nameSide + "_npo", p=ctlParent, ss=True))
    pm.pointConstraint(base, npo)

    # set proper orientation
    pos = base.getTranslation(space="world")
    temp = pm.spaceLocator()
    pm.parent(temp, base)
    temp.attr("ty").set(0)
    temp.attr("tz").set(0)
    temp.attr("tx").set(1)
    lookat = temp.getTranslation(space="world")

    up = datatypes.Vector(0, 1, 0)

    t = transform.getTransformLookingAt(pos,
                                        lookat,
                                        up,
                                        axis="xy",
                                        negate=False)
    npo.setMatrix(t, worldSpace=True)
    pm.delete(temp)

    # create joints
    jointBase = primitive.addJoint(npo, nameSide + "_jnt_lvl")
    joint = primitive.addJoint(jointBase, nameSide + "_jnt")

    # hidding joint base by changing the draw mode
    pm.setAttr(jointBase + ".drawStyle", 2)
    if not defSet:
        try:
            defSet = pm.PyNode("rig_deformers_grp")
        except TypeError:
            pm.sets(n="rig_deformers_grp")
            defSet = pm.PyNode("rig_deformers_grp")
    pm.sets(defSet, add=joint)

    controlType = "sphere"
    o_icon = icon.create(jointBase,
                         nameSide + "_ctl",
                         datatypes.Matrix(),
                         color,
                         controlType,
                         w=size)
    for t in [".translate", ".scale", ".rotate"]:
        pm.connectAttr(o_icon + t, joint + t)

    # create the attributes to handlde mirror and symetrical pose
    attribute.addAttribute(o_icon,
                           "invTx",
                           "bool",
                           0,
                           keyable=False,
                           niceName="Invert Mirror TX")
    attribute.addAttribute(o_icon,
                           "invTy",
                           "bool",
                           0,
                           keyable=False,
                           niceName="Invert Mirror TY")
    attribute.addAttribute(o_icon,
                           "invTz",
                           "bool",
                           0,
                           keyable=False,
                           niceName="Invert Mirror TZ")
    attribute.addAttribute(o_icon,
                           "invRx",
                           "bool",
                           0,
                           keyable=False,
                           niceName="Invert Mirror RX")
    attribute.addAttribute(o_icon,
                           "invRy",
                           "bool",
                           0,
                           keyable=False,
                           niceName="Invert Mirror RY")
    attribute.addAttribute(o_icon,
                           "invRz",
                           "bool",
                           0,
                           keyable=False,
                           niceName="Invert Mirror RZ")
    attribute.addAttribute(o_icon,
                           "invSx",
                           "bool",
                           0,
                           keyable=False,
                           niceName="Invert Mirror SX")
    attribute.addAttribute(o_icon,
                           "invSy",
                           "bool",
                           0,
                           keyable=False,
                           niceName="Invert Mirror SY")
    attribute.addAttribute(o_icon,
                           "invSz",
                           "bool",
                           0,
                           keyable=False,
                           niceName="Invert Mirror SZ")

    # magic of doritos connection
    doritosMagic(mesh, joint, jointBase)

    # reset axis and inver behaviour
    for axis in "XYZ":
        pm.setAttr(jointBase + ".jointOrient" + axis, 0)
        pm.setAttr(npo + ".translate" + axis, 0)
        pm.setAttr(jointBase + ".translate" + axis, 0)

    p = o_icon.getParent().getParent()
    pp = p.getParent()
    pm.parent(p, w=True)
    for axis in "xyz":
        p.attr("r" + axis).set(0)
    if side == "R":
        p.attr("ry").set(180)
        p.attr("sz").set(-1)
    pm.parent(p, pp)

    return o_icon
コード例 #21
0
ファイル: mGear_postSpring.py プロジェクト: moChen0607/mgear
def postSpring(dist = 5, hostUI = False,  hostUI2 = False, invertX=False ):

    """
    Create the dynamic spring rig. This spring system use the mgear_spring node. And transfer the position spring
    to rotation spring using an aim constraint.

    Note:
        The selected chain of object should be align with the X axis.

    Args:
        dist (float): The distance of the position spring.
        hostUI (dagNode): The spring active and intensity channel host.
        hostUI2 (dagNode): The daping and stiffness channel host for each object in the chain.
        invertX (bool): reverse the direction of the x axis.

    """
    oSel = pm.selected()

    if not hostUI2:
            hostUI2 = oSel[0]

    aSpring_active = att.addAttribute(hostUI2, "spring_active_%s"%oSel[0].name(), "double", 1.0, "___spring_active_______%s"%oSel[0].name(), "spring_active_%s"%oSel[0].name(), 0, 1)
    aSpring_intensity = att.addAttribute(hostUI2, "spring_intensity_%s"%oSel[0].name(), "double", 1.0, "___spring_intensity_______%s"%oSel[0].name(), "spring_intensity_%s"%oSel[0].name(), 0, 1)

    if invertX:
        dist = dist *-1
        #aim constraint
        aimAxis = "-xy"
    else:
        #aim constraint
        aimAxis = "xy"

    for obj in oSel:

        oParent = obj.getParent()



        oNpo = pm.PyNode(pm.createNode("transform", n= obj.name() + "_npo", p=oParent, ss=True))
        oNpo.setTransformation(obj.getMatrix())
        pm.parent(obj, oNpo)

        oSpring_cns = pm.PyNode(pm.createNode("transform", n= obj.name() + "_spr_cns", p=oNpo, ss=True))
        oSpring_cns.setTransformation(obj.getMatrix())
        pm.parent(obj, oSpring_cns)


        oSpringLvl = pm.PyNode(pm.createNode("transform", n= obj.name() + "_spr_lvl", p=oNpo, ss=True))
        oM = obj.getTransformation()
        oM.addTranslation([dist, 0,0], "object")
        oSpringLvl.setTransformation(oM.asMatrix())

        oSpringDriver = pm.PyNode(pm.createNode("transform", n= obj.name() + "_spr", p=oSpringLvl, ss=True))


        try:
                defSet = pm.PyNode("rig_PLOT_grp")
                pm.sets(defSet, add=oSpring_cns)
        except:
            defSet   =  pm.sets(name="rig_PLOT_grp")
            pm.sets(defSet, remove=obj)
            pm.sets(defSet, add=oSpring_cns)

        #adding attributes:
        if not hostUI:
            hostUI = obj


        aSpring_damping = att.addAttribute(hostUI, "spring_damping_%s"%obj.name(), "double", .5, "damping_%s"%obj.name(), "damping_%s"%obj.name(), 0, 1)
        aSpring_stiffness_ = att.addAttribute(hostUI, "spring_stiffness_%s"%obj.name(), "double", .5, "stiffness_%s"%obj.name(), "stiffness_%s"%obj.name(), 0, 1)




        cns = aop.aimCns(oSpring_cns, oSpringDriver, aimAxis, 2, [0,1,0], oNpo, False)

        #change from fcurves to spring
        pb_node = pm.createNode("pairBlend")

        pm.connectAttr(cns+".constraintRotateX", pb_node+".inRotateX2")
        pm.connectAttr(cns+".constraintRotateY", pb_node+".inRotateY2")
        pm.connectAttr(cns+".constraintRotateZ", pb_node+".inRotateZ2")
        pm.setAttr(pb_node+".translateXMode", 2)
        pm.setAttr(pb_node+".translateYMode", 2)
        pm.setAttr(pb_node+".translateZMode", 2)


        pm.connectAttr( pb_node+".outRotateX", oSpring_cns+".rotateX", f=True)
        pm.connectAttr( pb_node+".outRotateY", oSpring_cns+".rotateY", f=True)
        pm.connectAttr( pb_node+".outRotateZ", oSpring_cns+".rotateZ", f=True)
        pm.setKeyframe( oSpring_cns, at="rotateX")
        pm.setKeyframe( oSpring_cns, at="rotateY")
        pm.setKeyframe( oSpring_cns, at="rotateZ")

        #add sprint op
        springOP = aop.gear_spring_op(oSpringDriver)

        #connecting attributes
        pm.connectAttr(aSpring_active, pb_node+".weight")
        pm.connectAttr(aSpring_intensity, springOP+".intensity")
        pm.connectAttr(aSpring_damping, springOP+".damping")
        pm.connectAttr(aSpring_stiffness_, springOP+".stiffness")
コード例 #22
0
    def addCtl(self, parent, name, m, color, icon, tp=None, **kwargs):
        """
        Create the control and apply the shape, if this is alrealdy stored
        in the guide controllers grp.

        Args:
            parent (dagNode): The control parent
            name (str): The control name.
            m (matrix): The transfromation matrix for the control.
            color (int or list of float): The color for the control in idex or RGB.
            icon (str): The controls default shape.
            tp (dagNode): Tag Parent Control object to connect as a parent controller
            kwargs (variant): Other arguments for the icon type variations.

        Returns:
            dagNode: The Control.

        """
        fullName = self.getName(name)
        bufferName = fullName + "_controlBuffer"
        if bufferName in self.rig.guide.controllers.keys():
            ctl_ref = self.rig.guide.controllers[bufferName]
            ctl = pri.addTransform(parent, fullName, m)
            for shape in ctl_ref.getShapes():
                ctl.addChild(shape, shape=True, add=True)
                pm.rename(shape, fullName + "Shape")
            ico.setcolor(ctl, color)
        else:
            ctl = ico.create(parent, fullName, m, color, icon, **kwargs)

        # create the attributes to handlde mirror and symetrical pose
        att.addAttribute(ctl,
                         "invTx",
                         "bool",
                         0,
                         keyable=False,
                         niceName="Invert Mirror TX")
        att.addAttribute(ctl,
                         "invTy",
                         "bool",
                         0,
                         keyable=False,
                         niceName="Invert Mirror TY")
        att.addAttribute(ctl,
                         "invTz",
                         "bool",
                         0,
                         keyable=False,
                         niceName="Invert Mirror TZ")
        att.addAttribute(ctl,
                         "invRx",
                         "bool",
                         0,
                         keyable=False,
                         niceName="Invert Mirror RX")
        att.addAttribute(ctl,
                         "invRy",
                         "bool",
                         0,
                         keyable=False,
                         niceName="Invert Mirror RY")
        att.addAttribute(ctl,
                         "invRz",
                         "bool",
                         0,
                         keyable=False,
                         niceName="Invert Mirror RZ")
        att.addAttribute(ctl,
                         "invSx",
                         "bool",
                         0,
                         keyable=False,
                         niceName="Invert Mirror SX")
        att.addAttribute(ctl,
                         "invSy",
                         "bool",
                         0,
                         keyable=False,
                         niceName="Invert Mirror SY")
        att.addAttribute(ctl,
                         "invSz",
                         "bool",
                         0,
                         keyable=False,
                         niceName="Invert Mirror SZ")

        if self.settings["ctlGrp"]:
            ctlGrp = self.settings["ctlGrp"]
            self.addToGroup(ctl, ctlGrp, "controllers")
        else:
            ctlGrp = "controllers"
            self.addToGroup(ctl, ctlGrp)

        #lock the control parent attributes if is not a control
        if parent not in self.groups[ctlGrp]:
            self.transform2Lock.append(parent)

        # Set the control shapes isHistoricallyInteresting
        for oShape in ctl.getShapes():
            oShape.isHistoricallyInteresting.set(False)

        #set controller tag
        if versions.current() >= 201650:
            try:
                oldTag = pm.PyNode(ctl.name() + "_tag")
                if not oldTag.controllerObject.connections():
                    # NOTE:  The next line is comment out. Because this will happend alot since maya does't clean
                    # controller tags after deleting the control Object of the tag. This have been log to Autodesk.
                    # If orphane tags are found, it will be clean in silence.
                    # pm.displayWarning("Orphane Tag: %s  will be delete and created new for: %s"%(oldTag.name(), ctl.name()))
                    pm.delete(oldTag)

            except:
                pass
            pm.controller(ctl)

            if tp:
                ctt = pm.PyNode(pm.controller(ctl, q=True)[0])
                tpTagNode = pm.PyNode(pm.controller(tp, q=True)[0])
                tpTagNode.cycleWalkSibling.set(True)
                pm.connectAttr(tpTagNode.prepopulate, ctt.prepopulate, f=True)
                # The connectAttr to the children attribute is giving error
                # i.e:  pm.connectAttr(ctt.attr("parent"), tpTagNode.attr("children"), na=True)
                # if using the next available option tag
                # I was expecting to use ctt.setParent(tp) but doest't work as expected.
                # After reading the documentation this method looks prety useless.
                # Looks like is boolean and works based on selection :(

                # this is a dirty loop workaround. Naaah!
                i = 0
                while True:
                    try:
                        pm.connectAttr(ctt.parent,
                                       tpTagNode.attr("children[%s]" % str(i)))
                        break
                    except:
                        i += 1
                        if i > 100:
                            pm.displayWarning(
                                "The controller tag for %s has reached the limit index of 100 children"
                                % ctl.name())
                            break

        return ctl
コード例 #23
0
    def initialHierarchy(self):
        """Build the initial hierarchy of the rig.

        Create the rig model, the main properties,
        and a couple of base organisation nulls.
        Get the global size of the rig.

        """
        mgear.log("Initial Hierarchy")

        # --------------------------------------------------
        # Model
        self.model = primitive.addTransformFromPos(None,
                                                   self.options["rig_name"])
        attribute.lockAttribute(self.model)

        # --------------------------------------------------
        # INFOS
        self.isRig_att = attribute.addAttribute(self.model, "is_rig", "bool",
                                                True)
        self.rigName_att = attribute.addAttribute(self.model, "rig_name",
                                                  "string",
                                                  self.options["rig_name"])
        self.user_att = attribute.addAttribute(self.model, "user", "string",
                                               getpass.getuser())
        self.isWip_att = attribute.addAttribute(self.model, "wip", "bool",
                                                self.options["mode"] != 0)
        self.date_att = attribute.addAttribute(self.model, "date", "string",
                                               str(datetime.datetime.now()))
        self.mayaVersion_att = attribute.addAttribute(
            self.model, "maya_version", "string",
            str(pm.mel.eval("getApplicationVersionAsFloat")))
        self.gearVersion_att = attribute.addAttribute(self.model,
                                                      "gear_version", "string",
                                                      mgear.getVersion())
        self.synoptic_att = attribute.addAttribute(
            self.model, "synoptic", "string", str(self.options["synoptic"]))
        self.comments_att = attribute.addAttribute(
            self.model, "comments", "string", str(self.options["comments"]))
        self.ctlVis_att = attribute.addAttribute(self.model, "ctl_vis", "bool",
                                                 True)
        if versions.current() >= 201650:
            self.ctlVisPlayback_att = attribute.addAttribute(
                self.model, "ctl_vis_on_playback", "bool", True)
        self.jntVis_att = attribute.addAttribute(self.model, "jnt_vis", "bool",
                                                 True)

        self.qsA_att = attribute.addAttribute(self.model, "quickselA",
                                              "string", "")
        self.qsB_att = attribute.addAttribute(self.model, "quickselB",
                                              "string", "")
        self.qsC_att = attribute.addAttribute(self.model, "quickselC",
                                              "string", "")
        self.qsD_att = attribute.addAttribute(self.model, "quickselD",
                                              "string", "")
        self.qsE_att = attribute.addAttribute(self.model, "quickselE",
                                              "string", "")
        self.qsF_att = attribute.addAttribute(self.model, "quickselF",
                                              "string", "")

        self.rigGroups = self.model.addAttr("rigGroups", at='message', m=1)
        self.rigPoses = self.model.addAttr("rigPoses", at='message', m=1)
        self.rigCtlTags = self.model.addAttr("rigCtlTags", at='message', m=1)

        # ------------------------- -------------------------
        # Global Ctl
        if self.options["worldCtl"]:
            self.global_ctl = self.addCtl(self.model,
                                          "world_ctl",
                                          datatypes.Matrix(),
                                          self.options["C_color_fk"],
                                          "circle",
                                          w=10)
        else:
            self.global_ctl = self.addCtl(self.model,
                                          "global_C0_ctl",
                                          datatypes.Matrix(),
                                          self.options["C_color_fk"],
                                          "crossarrow",
                                          w=10)
        attribute.setRotOrder(self.global_ctl, "ZXY")

        # Connect global visibility
        pm.connectAttr(self.ctlVis_att, self.global_ctl.attr("visibility"))
        if versions.current() >= 201650:
            pm.connectAttr(self.ctlVisPlayback_att,
                           self.global_ctl.attr("hideOnPlayback"))
        attribute.lockAttribute(self.global_ctl, ['v'])

        # --------------------------------------------------
        # Setup in world Space
        self.setupWS = primitive.addTransformFromPos(self.model, "setup")
        attribute.lockAttribute(self.setupWS)
        # --------------------------------------------------
        # Basic set of null
        if self.options["joint_rig"]:
            self.jnt_org = primitive.addTransformFromPos(self.model, "jnt_org")
            pm.connectAttr(self.jntVis_att, self.jnt_org.attr("visibility"))
コード例 #24
0
ファイル: __init__.py プロジェクト: leonsooi/mgear
    def initialHierarchy(self):

        mgear.log("Initial Hierarchy")

        # --------------------------------------------------
        # Model
        self.model = pri.addTransformFromPos(None, self.options["rig_name"])
        att.lockAttribute(self.model)

        # --------------------------------------------------
        # Global Ctl
        self.global_ctl = self.addCtl(self.model,
                                      "global_C0_ctl",
                                      dt.Matrix(),
                                      self.options["C_color_fk"],
                                      "crossarrow",
                                      w=10)

        # --------------------------------------------------
        # INFOS
        self.isRig_att = att.addAttribute(self.model, "is_rig", "bool", True)
        self.rigName_att = att.addAttribute(self.model, "rig_name", "string",
                                            self.options["rig_name"])
        self.user_att = att.addAttribute(self.model, "user", "string",
                                         getpass.getuser())
        self.isWip_att = att.addAttribute(self.model, "wip", "bool",
                                          self.options["mode"] != 0)
        self.date_att = att.addAttribute(self.model, "date", "string",
                                         str(datetime.datetime.now()))
        self.mayaVersion_att = att.addAttribute(
            self.model, "maya_version", "string",
            str(mel.eval("getApplicationVersionAsFloat")))
        self.gearVersion_att = att.addAttribute(self.model, "gear_version",
                                                "string", mgear.getVersion())
        self.synoptic_att = att.addAttribute(self.model, "synoptic", "string",
                                             str(self.options["synoptic"]))
        self.comments_att = att.addAttribute(self.model, "comments", "string",
                                             str(self.options["comments"]))
        self.ctlVis_att = att.addAttribute(self.model, "ctl_vis", "bool", True)
        self.shdVis_att = att.addAttribute(self.model, "shd_vis", "bool",
                                           False)

        self.qsA_att = att.addAttribute(self.model, "quickselA", "string", "")
        self.qsB_att = att.addAttribute(self.model, "quickselB", "string", "")
        self.qsC_att = att.addAttribute(self.model, "quickselC", "string", "")
        self.qsD_att = att.addAttribute(self.model, "quickselD", "string", "")
        self.qsE_att = att.addAttribute(self.model, "quickselE", "string", "")
        self.qsF_att = att.addAttribute(self.model, "quickselF", "string", "")

        # --------------------------------------------------
        # UI SETUP AND ANIM
        self.oglLevel_att = att.addAttribute(self.model, "ogl_level", "long",
                                             0, None, None, 0, 3)

        # --------------------------------------------------
        # Basic set of null
        if self.options["shadow_rig"]:
            self.shd_org = pri.addTransformFromPos(self.model, "shd_org")
            connectAttr(self.shdVis_att, self.shd_org.attr("visibility"))