Exemplo n.º 1
0
def aboutMgear(*args):
    """About mgear"""
    version = mgear.getVersion()
    note = """

    mGear version: {}

    MGEAR is under the terms of the MIT License

    Copyright (c) 2011-2018 Jeremie Passerin, Miquel Campos
    Copyright (c) 2018-2021 The mGear-Dev Organization

    Permission is hereby granted, free of charge, to any person obtaining a
    copy of this software and associated documentation files (the "Software"),
    to deal in the Software without restriction, including without limitation
    the rights to use, copy, modify, merge, publish, distribute, sublicense,
    and/or sell copies of the Software, and to permit persons to whom the
    Software is furnished to do so, subject to the following conditions:

    The above copyright notice and this permission notice shall be included in
    all copies or substantial portions of the Software.

    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
    THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
    OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
    ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
    OR OTHER DEALINGS IN THE SOFTWARE.

    """.format(version)
    pm.confirmDialog(title='About mGear', message=note, button=["OK"],
                     defaultButton='OK', cancelButton='OK', dismissString='OK')
Exemplo n.º 2
0
    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"))
Exemplo n.º 3
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"))
Exemplo n.º 4
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
Exemplo n.º 5
0
    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"))