Exemple #1
0
    def addObjects(self):

        self.normal = self.guide.blades["blade"].z*-1
        self.binormal = self.guide.blades["blade"].x

        t = tra.getTransformLookingAt(self.guide.apos[0], self.guide.apos[1], self.normal, axis="yx", negate=self.negate)

        self.ctl_npo = pri.addTransform(self.root, self.getName("ctl_npo"), t)
        self.ctl = self.addCtl(self.ctl_npo, "base_ctl", t, self.color_ik, "square", w=1.0, tp=self.parentCtlTag)
        att.setKeyableAttributes(self.ctl, self.tr_params)

        self.ref_base = pri.addTransform(self.ctl, self.getName("ref_base"), t)

        t = tra.setMatrixPosition(t, self.guide.apos[1])
        self.ik_cns = pri.addTransform(self.root, self.getName("ik_cns"), t)
        self.tip_npo = pri.addTransform(self.ik_cns, self.getName("tip_npo"), t)
        self.tip_ctl = self.addCtl(self.tip_npo, "tip_ctl", t, self.color_ik, "square", w=1.0, tp=self.ctl)
        att.setKeyableAttributes(self.tip_ctl, self.tr_params)

        self.ref_tip = pri.addTransform(self.tip_ctl, self.getName("ref_tip"), t)

        self.div_cns = []

        for i in range(self.settings["div"]):

            div_cns = pri.addTransform(self.root, self.getName("div%s_loc" % i))

            self.div_cns.append(div_cns)
            self.jnt_pos.append([div_cns, i])
Exemple #2
0
def alignToPointsLoop(points=None, loc=None, name=None, *args):
    """Create space locator align to the plain define by at less 3 vertex

    Args:
        points (None or vertex list, optional): The reference vertex to align
            the ref locator
        loc (None or dagNode, optional): If none will create a new locator
        name (None or string, optional): Name of the new locator
        *args: Description

    Returns:
        TYPE: Description

    """
    if not points:
        oSel = pm.selected(fl=True)

        checkType = "<class 'pymel.core.general.MeshVertex'>"
        if (not oSel
                or len(oSel) < 3
                or str(type(oSel[0])) != checkType):
            pm.displayWarning("We need to select a points loop, with at "
                              "less 3 or more points")
            return
        else:
            points = oSel
    if not loc:
        if not name:
            name = "axisCenterRef"
        loc = pm.spaceLocator(n=name)

    oLen = len(points)
    wPos = [0, 0, 0]
    for x in points:
        pos = x.getPosition(space="world")
        wPos[0] += pos[0]
        wPos[1] += pos[1]
        wPos[2] += pos[2]

    centerPosition = datatypes.Vector([wPos[0] / oLen,
                                       wPos[1] / oLen,
                                       wPos[2] / oLen])

    lookat = datatypes.Vector(points[0].getPosition(space="world"))

    # NORMAL
    a = lookat - centerPosition
    a.normalize()

    nextV = datatypes.Vector(points[1].getPosition(space="world"))
    b = nextV - centerPosition
    b.normalize()
    normal = pmu.cross(b, a)
    normal.normalize()

    trans = transform.getTransformLookingAt(
        centerPosition, lookat, normal, axis="xy", negate=False)

    loc.setTransformation(trans)
Exemple #3
0
    def initialHierarchy(self):

        # Root ---------------------------------------------
        # For this component we need the root to be correctly oriented
        t = tra.getTransformLookingAt(self.guide.apos[0], self.guide.apos[1], self.guide.blades["blade"].z, "yx", self.negate)
        self.root = pri.addTransform(self.model, self.getName("root"), t)

        # Shd ----------------------------------------------
        if self.options["shadow_rig"]:
            self.shd_org = pri.addTransform(self.rig.shd_org, self.getName("shd_org"))
Exemple #4
0
    def addObjects(self):

        self.normal = self.guide.blades["blade"].z
        self.binormal = self.guide.blades["blade"].x

        self.isFk = self.settings["mode"] != 1
        self.isIk = self.settings["mode"] != 0
        self.isFkIk = self.settings["mode"] == 2

        # FK controlers ------------------------------------
        if self.isFk:
            self.fk_npo = []
            self.fk_ctl = []
            parent = self.root
            for i, t in enumerate(tra.getChainTransform(self.guide.apos, self.normal, self.negate)):
                dist = vec.getDistance(self.guide.apos[i], self.guide.apos[i+1])
                fk_npo = pri.addTransform(parent, self.getName("fk%s_npo"%i), t)
                fk_ctl = self.addCtl(fk_npo, "fk%s_ctl"%i, t, self.color_fk, "cube", w=dist, h=self.size*.1, d=self.size*.1, po=dt.Vector(dist*.5*self.n_factor,0,0))
                parent = fk_ctl
                self.fk_npo.append(fk_npo)
                self.fk_ctl.append(fk_ctl)

        # IK controlers ------------------------------------
        if self.isIk:

            normal = vec.getTransposedVector(self.normal, [self.guide.apos[0], self.guide.apos[1]], [self.guide.apos[-2], self.guide.apos[-1]])
            t = tra.getTransformLookingAt(self.guide.apos[-2], self.guide.apos[-1], normal, "xy", self.negate)
            t = tra.setMatrixPosition(t, self.guide.apos[-1])

            self.ik_cns = pri.addTransform(self.root, self.getName("ik_cns"), t)
            self.ikcns_ctl = self.addCtl(self.ik_cns, "ikcns_ctl", t, self.color_ik, "null", w=self.size)
            self.ik_ctl = self.addCtl(self.ikcns_ctl, "ik_ctl", t, self.color_ik, "cube", w=self.size*.3, h=self.size*.3, d=self.size*.3)

            v = self.guide.apos[-1] - self.guide.apos[0]
            v = v ^ self.normal
            v.normalize()
            v *= self.size
            v += self.guide.apos[1]
            self.upv_cns = pri.addTransformFromPos(self.root, self.getName("upv_cns"), v)

            self.upv_ctl = self.addCtl(self.upv_cns, "upv_ctl", tra.getTransform(self.upv_cns), self.color_ik, "diamond", w=self.size*.1)

            # Chain
            self.chain = pri.add2DChain(self.root, self.getName("chain"), self.guide.apos, self.normal, self.negate)
            self.ikh = pri.addIkHandle(self.root, self.getName("ikh"), self.chain)

        # Chain of deformers -------------------------------
        self.loc = []
        parent = self.root
        for i, t in enumerate(tra.getChainTransform(self.guide.apos, self.normal, self.negate)):
            loc = pri.addTransform(parent, self.getName("%s_loc"%i), t)
            self.addShadow(loc, i)

            self.loc.append(loc)
            parent = loc
Exemple #5
0
    def initialHierarchy(self):

        # Root ---------------------------------------------
        # For this component we need the root to be correctly oriented
        t = tra.getTransformLookingAt(self.guide.apos[0], self.guide.apos[1],
                                      self.guide.blades["blade"].z, "yx",
                                      self.negate)
        self.root = pri.addTransform(self.model, self.getName("root"), t)

        # Shd ----------------------------------------------
        if self.options["shadow_rig"]:
            self.shd_org = pri.addTransform(self.rig.shd_org,
                                            self.getName("shd_org"))
def alignToPointsLoop(points=None, loc=None, name=None, *args):
    """
    Create space locator align to the plain define by at less 3 vertex
    """

    if not points:
        oSel = pm.selected(fl=True)

        if not oSel or len(oSel) < 3 or str(type(
                oSel[0])) != "<class 'pymel.core.general.MeshVertex'>":
            pm.displayWarning(
                "We need to select a points loop, with at less 3 or more points"
            )
            return
        else:
            points = oSel
    if not loc:
        if not name:
            name = "axisCenterRef"
        loc = pm.spaceLocator(n=name)

    oLen = len(points)
    wPos = [0, 0, 0]
    for x in points:
        pos = x.getPosition(space="world")
        wPos[0] += pos[0]
        wPos[1] += pos[1]
        wPos[2] += pos[2]

    centerPosition = dt.Vector(
        [wPos[0] / oLen, wPos[1] / oLen, wPos[2] / oLen])

    lookat = dt.Vector(points[0].getPosition(space="world"))

    # NORMAL
    a = lookat - centerPosition
    a.normalize()

    nextV = dt.Vector(points[1].getPosition(space="world"))
    b = nextV - centerPosition
    b.normalize()
    normal = pmu.cross(b, a)
    normal.normalize()

    trans = tra.getTransformLookingAt(centerPosition,
                                      lookat,
                                      normal,
                                      axis="xy",
                                      negate=False)

    loc.setTransformation(trans)
Exemple #7
0
    def addObjects(self):
        """Add all the objects needed to create the component."""

        self.normal = self.guide.blades["blade"].z * -1
        self.binormal = self.guide.blades["blade"].x

        self.length0 = vector.getDistance(self.guide.apos[0],
                                          self.guide.apos[1])

        t = transform.getTransformLookingAt(self.guide.apos[0],
                                            self.guide.apos[1],
                                            self.normal,
                                            axis="xy",
                                            negate=self.negate)

        self.ctl_npo = primitive.addTransform(self.root,
                                              self.getName("ctl_npo"), t)

        self.ctl = self.addCtl(self.ctl_npo,
                               "ctl",
                               t,
                               self.color_fk,
                               "cube",
                               w=self.length0,
                               h=self.size * .1,
                               d=self.size * .1,
                               po=datatypes.Vector(
                                   .5 * self.length0 * self.n_factor, 0, 0),
                               tp=self.parentCtlTag)

        t = transform.getTransformFromPos(self.guide.apos[1])
        self.orbit_ref1 = primitive.addTransform(self.ctl,
                                                 self.getName("orbit_ref1"), t)
        self.orbit_ref2 = primitive.addTransform(self.root,
                                                 self.getName("orbit_ref2"), t)
        self.orbit_cns = primitive.addTransform(self.ctl,
                                                self.getName("orbit_cns"), t)

        self.orbit_npo = primitive.addTransform(self.orbit_cns,
                                                self.getName("orbit_npo"), t)

        self.orbit_ctl = self.addCtl(self.orbit_npo,
                                     "orbit_ctl",
                                     t,
                                     self.color_fk,
                                     "sphere",
                                     w=self.length0 / 4,
                                     tp=self.ctl)

        self.jnt_pos.append([self.ctl, "shoulder"])
Exemple #8
0
    def addObjects(self):
        """Add all the objects needed to create the component."""

        self.normal = self.guide.blades["blade"].z * -1
        self.binormal = self.guide.blades["blade"].x

        t = transform.getTransformLookingAt(self.guide.apos[0],
                                            self.guide.apos[1],
                                            self.normal,
                                            axis="yx",
                                            negate=self.negate)
        self.ctl_npo = primitive.addTransform(self.root,
                                              self.getName("ctl_npo"), t)
        self.ctl = self.addCtl(self.ctl_npo,
                               "base_ctl",
                               t,
                               self.color_ik,
                               "square",
                               w=1.0,
                               tp=self.parentCtlTag)

        self.ref_base = primitive.addTransform(self.ctl,
                                               self.getName("ref_base"), t)

        t = transform.setMatrixPosition(t, self.guide.apos[1])

        self.ik_cns = primitive.addTransform(self.ctl, self.getName("ik_cns"),
                                             t)
        self.squash_npo = primitive.addTransform(self.ik_cns,
                                                 self.getName("squash_npo"), t)
        self.squash_ctl = self.addCtl(self.squash_npo,
                                      "squash_ctl",
                                      t,
                                      self.color_ik,
                                      "crossarrow",
                                      w=1.0,
                                      ro=dt.Vector(1.5708, 0, 0),
                                      tp=self.ctl)

        attribute.setKeyableAttributes(self.squash_ctl, ["tx", "ty", "tz"])

        self.ref_squash = primitive.addTransform(self.squash_ctl,
                                                 self.getName("ref_squash"), t)

        self.div_cns = []

        div_cns = primitive.addTransform(self.root, self.getName("div0_loc"))

        self.div_cns.append(div_cns)
        self.jnt_pos.append([div_cns, 0, None, False])
Exemple #9
0
    def addObjects(self):
        """Add all the objects needed to create the component."""

        self.normal = self.guide.blades["blade"].z * -1
        self.binormal = self.guide.blades["blade"].x

        self.length0 = vector.getDistance(self.guide.apos[0],
                                          self.guide.apos[1])

        t = transform.getTransformLookingAt(self.guide.apos[0],
                                            self.guide.apos[1],
                                            self.normal,
                                            axis="xy",
                                            negate=self.negate)

        self.npo = primitive.addTransform(self.root, self.getName("npo"), t)

        self.ctl = self.addCtl(self.npo,
                               "ctl",
                               t,
                               self.color_fk,
                               "cube",
                               w=self.length0,
                               h=self.size * .1,
                               d=self.size * .1,
                               po=datatypes.Vector(
                                   .5 * self.length0 * self.n_factor, 0, 0),
                               tp=self.parentCtlTag)

        self.mtx = primitive.addTransform(self.npo, self.getName("mtx"), t)

        t1 = transform.setMatrixPosition(t, self.guide.apos[1])
        t2 = transform.getInterpolateTransformMatrix(t, t1, blend=0.98)
        self.loc = primitive.addTransform(self.mtx, self.getName("loc"), t2)

        self.end = primitive.addTransform(self.ctl, self.getName("end"), t1)

        self.jnt_pos.append([self.mtx, "root"])
        self.jnt_pos.append([self.loc, 'end'])

        attribute.setKeyableAttributes(self.ctl)
        attribute.setInvertMirror(self.ctl, ["tx", "ty", "tz"])
Exemple #10
0
    def addObjects(self):

        self.normal = self.guide.blades["blade"].z * -1
        self.binormal = self.guide.blades["blade"].x

        self.length0 = vec.getDistance(self.guide.apos[0], self.guide.apos[1])

        t = tra.getTransformLookingAt(self.guide.apos[0],
                                      self.guide.apos[1],
                                      self.normal,
                                      axis="xy",
                                      negate=self.negate)
        self.ctl_npo = pri.addTransform(self.root, self.getName("ctl_npo"), t)
        self.ctl = self.addCtl(self.ctl_npo,
                               "ctl",
                               t,
                               self.color_fk,
                               "cube",
                               w=self.length0,
                               h=self.size * .1,
                               d=self.size * .1,
                               po=dt.Vector(.5 * self.length0 * self.n_factor,
                                            0, 0))
        t = tra.getTransformFromPos(self.guide.apos[1])
        self.orbit_ref1 = pri.addTransform(self.ctl,
                                           self.getName("orbit_ref1"), t)
        self.orbit_ref2 = pri.addTransform(self.root,
                                           self.getName("orbit_ref2"), t)

        self.orbit_cns = pri.addTransform(self.ctl, self.getName("orbit_cns"),
                                          t)

        self.orbit_npo = pri.addTransform(self.orbit_cns,
                                          self.getName("orbit_npo"), t)
        self.orbit_ctl = self.addCtl(self.orbit_npo,
                                     "orbit_ctl",
                                     t,
                                     self.color_fk,
                                     "sphere",
                                     w=self.length0 / 4)

        self.jnt_pos.append([self.ctl, "shoulder"])
Exemple #11
0
    def addObjects(self):
        """Add all the objects needed to create the component."""

        # Auto bend with position controls  --------------------
        if self.settings["autoBend"]:
            self.autoBendChain = primitive.add2DChain(
                self.root,
                self.getName("autoBend%s_jnt"),
                [self.guide.apos[0], self.guide.apos[1]],
                self.guide.blades["blade"].z * -1,
                False,
                True)

            for j in self.autoBendChain:
                j.drawStyle.set(2)

        # Ik Controlers ------------------------------------
        t = transform.getTransformLookingAt(self.guide.apos[0],
                                            self.guide.apos[1],
                                            self.guide.blades["blade"].z * -1,
                                            "yx",
                                            self.negate)

        self.ik0_npo = primitive.addTransform(
            self.root, self.getName("ik0_npo"), t)

        self.ik0_ctl = self.addCtl(self.ik0_npo,
                                   "ik0_ctl",
                                   t,
                                   self.color_ik,
                                   "compas",
                                   w=self.size,
                                   tp=self.parentCtlTag)

        attribute.setKeyableAttributes(self.ik0_ctl, self.tr_params)
        attribute.setRotOrder(self.ik0_ctl, "ZXY")
        attribute.setInvertMirror(self.ik0_ctl, ["tx", "ry", "rz"])

        t = transform.setMatrixPosition(t, self.guide.apos[1])
        if self.settings["autoBend"]:
            self.autoBend_npo = primitive.addTransform(
                self.root, self.getName("spinePosition_npo"), t)

            self.autoBend_ctl = self.addCtl(self.autoBend_npo,
                                            "spinePosition_ctl",
                                            t,
                                            self.color_ik,
                                            "square",
                                            w=self.size,
                                            d=.3 * self.size,
                                            tp=self.parentCtlTag)

            attribute.setKeyableAttributes(self.autoBend_ctl,
                                           ["tx", "ty", "tz", "ry"])

            attribute.setInvertMirror(self.autoBend_ctl, ["tx", "ry"])

            self.ik1_npo = primitive.addTransform(
                self.autoBendChain[0], self.getName("ik1_npo"), t)

            self.ik1autoRot_lvl = primitive.addTransform(
                self.ik1_npo, self.getName("ik1autoRot_lvl"), t)

            self.ik1_ctl = self.addCtl(self.ik1autoRot_lvl,
                                       "ik1_ctl",
                                       t,
                                       self.color_ik,
                                       "compas",
                                       w=self.size,
                                       tp=self.autoBend_ctl)
        else:
            t = transform.setMatrixPosition(t, self.guide.apos[1])
            self.ik1_npo = primitive.addTransform(
                self.root, self.getName("ik1_npo"), t)
            self.ik1_ctl = self.addCtl(self.ik1_npo,
                                       "ik1_ctl",
                                       t,
                                       self.color_ik,
                                       "compas",
                                       w=self.size,
                                       tp=self.ik0_ctl)

        attribute.setKeyableAttributes(self.ik1_ctl, self.tr_params)
        attribute.setRotOrder(self.ik1_ctl, "ZXY")
        attribute.setInvertMirror(self.ik1_ctl, ["tx", "ry", "rz"])

        # Tangent controllers -------------------------------
        if self.settings["centralTangent"]:
            vec_pos = vector.linearlyInterpolate(self.guide.apos[0],
                                                 self.guide.apos[1],
                                                 .33)
            t = transform.setMatrixPosition(t, vec_pos)

            self.tan0_npo = primitive.addTransform(
                self.ik0_ctl, self.getName("tan0_npo"), t)

            self.tan0_off = primitive.addTransform(
                self.tan0_npo, self.getName("tan0_off"), t)

            self.tan0_ctl = self.addCtl(self.tan0_off,
                                        "tan0_ctl",
                                        t,
                                        self.color_ik,
                                        "sphere",
                                        w=self.size * .1,
                                        tp=self.ik0_ctl)

            attribute.setKeyableAttributes(self.tan0_ctl, self.t_params)
            vec_pos = vector.linearlyInterpolate(self.guide.apos[0],
                                                 self.guide.apos[1],
                                                 .66)

            t = transform.setMatrixPosition(t, vec_pos)

            self.tan1_npo = primitive.addTransform(
                self.ik1_ctl, self.getName("tan1_npo"), t)

            self.tan1_off = primitive.addTransform(
                self.tan1_npo, self.getName("tan1_off"), t)

            self.tan1_ctl = self.addCtl(self.tan1_off,
                                        "tan1_ctl",
                                        t,
                                        self.color_ik,
                                        "sphere",
                                        w=self.size * .1,
                                        tp=self.ik0_ctl)

            attribute.setKeyableAttributes(self.tan1_ctl, self.t_params)

            # Tangent mid control
            vec_pos = vector.linearlyInterpolate(self.guide.apos[0],
                                                 self.guide.apos[1],
                                                 .5)
            t = transform.setMatrixPosition(t, vec_pos)

            self.tan_npo = primitive.addTransform(
                self.tan0_npo, self.getName("tan_npo"), t)

            self.tan_ctl = self.addCtl(self.tan_npo,
                                       "tan_ctl",
                                       t,
                                       self.color_fk,
                                       "sphere",
                                       w=self.size * .2,
                                       tp=self.ik1_ctl)

            attribute.setKeyableAttributes(self.tan_ctl, self.t_params)
            attribute.setInvertMirror(self.tan_ctl, ["tx"])

        else:
            vec_pos = vector.linearlyInterpolate(self.guide.apos[0],
                                                 self.guide.apos[1],
                                                 .33)

            t = transform.setMatrixPosition(t, vec_pos)

            self.tan0_npo = primitive.addTransform(
                self.ik0_ctl, self.getName("tan0_npo"), t)

            self.tan0_ctl = self.addCtl(self.tan0_npo,
                                        "tan0_ctl",
                                        t,
                                        self.color_ik,
                                        "sphere",
                                        w=self.size * .2,
                                        tp=self.ik0_ctl)

            attribute.setKeyableAttributes(self.tan0_ctl, self.t_params)

            vec_pos = vector.linearlyInterpolate(self.guide.apos[0],
                                                 self.guide.apos[1],
                                                 .66)

            t = transform.setMatrixPosition(t, vec_pos)

            self.tan1_npo = primitive.addTransform(
                self.ik1_ctl, self.getName("tan1_npo"), t)

            self.tan1_ctl = self.addCtl(self.tan1_npo,
                                        "tan1_ctl",
                                        t,
                                        self.color_ik,
                                        "sphere",
                                        w=self.size * .2,
                                        tp=self.ik1_ctl)

            attribute.setKeyableAttributes(self.tan1_ctl, self.t_params)

        attribute.setInvertMirror(self.tan0_ctl, ["tx"])
        attribute.setInvertMirror(self.tan1_ctl, ["tx"])

        # Curves -------------------------------------------
        self.mst_crv = curve.addCnsCurve(
            self.root,
            self.getName("mst_crv"),
            [self.ik0_ctl, self.tan0_ctl, self.tan1_ctl, self.ik1_ctl],
            3)
        self.slv_crv = curve.addCurve(self.root, self.getName("slv_crv"),
                                      [datatypes.Vector()] * 10,
                                      False,
                                      3)
        self.mst_crv.setAttr("visibility", False)
        self.slv_crv.setAttr("visibility", False)

        # Division -----------------------------------------
        # The user only define how many intermediate division he wants.
        # First and last divisions are an obligation.
        parentdiv = self.root
        parentctl = self.root
        self.div_cns = []
        self.fk_ctl = []
        self.fk_npo = []
        self.scl_transforms = []
        self.twister = []
        self.ref_twist = []

        t = transform.getTransformLookingAt(
            self.guide.apos[0],
            self.guide.apos[1],
            self.guide.blades["blade"].z * -1,
            "yx",
            self.negate)

        parent_twistRef = primitive.addTransform(
            self.root,
            self.getName("reference"),
            transform.getTransform(self.root))

        self.jointList = []
        self.preiviousCtlTag = self.parentCtlTag
        for i in range(self.settings["division"]):

            # References
            div_cns = primitive.addTransform(parentdiv,
                                             self.getName("%s_cns" % i))

            pm.setAttr(div_cns + ".inheritsTransform", False)
            self.div_cns.append(div_cns)
            parentdiv = div_cns

            # Controlers (First and last one are fake)
            # if i in [0]:
            # TODO: add option setting to add or not the first and last
            # controller for the fk
            # if i in [0, self.settings["division"] - 1] and False:
            if i in [0, self.settings["division"] - 1]:
                fk_ctl = primitive.addTransform(
                    parentctl,
                    self.getName("%s_loc" % i),
                    transform.getTransform(parentctl))

                fk_npo = fk_ctl
                if i in [self.settings["division"] - 1]:
                    self.fk_ctl.append(fk_ctl)
            else:
                fk_npo = primitive.addTransform(
                    parentctl,
                    self.getName("fk%s_npo" % (i - 1)),
                    transform.getTransform(parentctl))

                fk_ctl = self.addCtl(fk_npo,
                                     "fk%s_ctl" % (i - 1),
                                     transform.getTransform(parentctl),
                                     self.color_fk,
                                     "cube",
                                     w=self.size,
                                     h=self.size * .05,
                                     d=self.size,
                                     tp=self.preiviousCtlTag)

                attribute.setKeyableAttributes(self.fk_ctl)
                attribute.setRotOrder(fk_ctl, "ZXY")
                self.fk_ctl.append(fk_ctl)
                self.preiviousCtlTag = fk_ctl

            # setAttr(fk_npo+".inheritsTransform", False)
            self.fk_npo.append(fk_npo)
            parentctl = fk_ctl
            scl_ref = primitive.addTransform(parentctl,
                                             self.getName("%s_scl_ref" % i),
                                             transform.getTransform(parentctl))

            self.scl_transforms.append(scl_ref)

            # Deformers (Shadow)
            self.jnt_pos.append([scl_ref, i])

            # Twist references (This objects will replace the spinlookup slerp
            # solver behavior)
            t = transform.getTransformLookingAt(
                self.guide.apos[0],
                self.guide.apos[1],
                self.guide.blades["blade"].z * -1,
                "yx",
                self.negate)

            twister = primitive.addTransform(
                parent_twistRef, self.getName("%s_rot_ref" % i), t)
            ref_twist = primitive.addTransform(
                parent_twistRef, self.getName("%s_pos_ref" % i), t)
            ref_twist.setTranslation(
                datatypes.Vector(1.0, 0, 0), space="preTransform")

            self.twister.append(twister)
            self.ref_twist.append(ref_twist)

            # TODO: update this part with the optiona FK controls update
            for x in self.fk_ctl[:-1]:
                attribute.setInvertMirror(x, ["tx", "rz", "ry"])

        # Connections (Hooks) ------------------------------
        self.cnx0 = primitive.addTransform(self.root, self.getName("0_cnx"))
        self.cnx1 = primitive.addTransform(self.root, self.getName("1_cnx"))
Exemple #12
0
    def addObjects(self):
        """

        """
        self.WIP = self.options["mode"]

        self.normal = self.getNormalFromPos(self.guide.apos)
        self.binormal = self.getBiNormalFromPos(self.guide.apos)

        self.length0 = vec.getDistance(self.guide.apos[0], self.guide.apos[1])
        self.length1 = vec.getDistance(self.guide.apos[1], self.guide.apos[2])
        self.length2 = vec.getDistance(self.guide.apos[2], self.guide.apos[3])

        # 1 bone chain for upv ref
        self.armChainUpvRef = pri.add2DChain(
            self.root, self.getName("armUpvRef%s_jnt"),
            [self.guide.apos[0], self.guide.apos[2]], self.normal, False,
            self.WIP)
        self.armChainUpvRef[1].setAttr(
            "jointOrientZ",
            self.armChainUpvRef[1].getAttr("jointOrientZ") * -1)

        # FK Controlers -----------------------------------
        t = tra.getTransformLookingAt(self.guide.apos[0], self.guide.apos[1],
                                      self.normal, "xz", self.negate)
        self.fk0_npo = pri.addTransform(self.root, self.getName("fk0_npo"), t)
        self.fk0_ctl = self.addCtl(self.fk0_npo,
                                   "fk0_ctl",
                                   t,
                                   self.color_fk,
                                   "cube",
                                   w=self.length0,
                                   h=self.size * .1,
                                   d=self.size * .1,
                                   po=dt.Vector(
                                       .5 * self.length0 * self.n_factor, 0,
                                       0))
        att.setKeyableAttributes(self.fk0_ctl)

        t = tra.getTransformLookingAt(self.guide.apos[1], self.guide.apos[2],
                                      self.normal, "xz", self.negate)
        self.fk1_npo = pri.addTransform(self.fk0_ctl, self.getName("fk1_npo"),
                                        t)
        self.fk1_ctl = self.addCtl(self.fk1_npo,
                                   "fk1_ctl",
                                   t,
                                   self.color_fk,
                                   "cube",
                                   w=self.length1,
                                   h=self.size * .1,
                                   d=self.size * .1,
                                   po=dt.Vector(
                                       .5 * self.length1 * self.n_factor, 0,
                                       0))
        att.setKeyableAttributes(self.fk1_ctl)

        t = tra.getTransformLookingAt(self.guide.apos[2], self.guide.apos[3],
                                      self.normal, "xz", self.negate)
        self.fk2_npo = pri.addTransform(self.fk1_ctl, self.getName("fk2_npo"),
                                        t)
        self.fk2_ctl = self.addCtl(self.fk2_npo,
                                   "fk2_ctl",
                                   t,
                                   self.color_fk,
                                   "cube",
                                   w=self.length2,
                                   h=self.size * .1,
                                   d=self.size * .1,
                                   po=dt.Vector(
                                       .5 * self.length2 * self.n_factor, 0,
                                       0))
        att.setKeyableAttributes(self.fk2_ctl)

        self.fk_ctl = [self.fk0_ctl, self.fk1_ctl, self.fk2_ctl]

        for x in self.fk_ctl:
            att.setInvertMirror(x, ["tx", "ty", "tz"])

        # IK Controlers -----------------------------------

        self.ik_cns = pri.addTransformFromPos(self.root,
                                              self.getName("ik_cns"),
                                              self.guide.pos["wrist"])

        self.ikcns_ctl = self.addCtl(self.ik_cns,
                                     "ikcns_ctl",
                                     tra.getTransformFromPos(
                                         self.guide.pos["wrist"]),
                                     self.color_ik,
                                     "null",
                                     w=self.size * .12)
        att.setInvertMirror(self.ikcns_ctl, ["tx", "ty", "tz"])

        if self.negate:
            m = tra.getTransformLookingAt(self.guide.pos["wrist"],
                                          self.guide.pos["eff"], self.normal,
                                          "x-y", True)
        else:
            m = tra.getTransformLookingAt(self.guide.pos["wrist"],
                                          self.guide.pos["eff"], self.normal,
                                          "xy", False)
        self.ik_ctl = self.addCtl(self.ikcns_ctl,
                                  "ik_ctl",
                                  m,
                                  self.color_ik,
                                  "cube",
                                  w=self.size * .12,
                                  h=self.size * .12,
                                  d=self.size * .12)
        att.setKeyableAttributes(self.ik_ctl)
        att.setInvertMirror(self.ik_ctl, ["tx", "ry", "rz"])

        # upv
        v = self.guide.apos[2] - self.guide.apos[0]
        v = self.normal ^ v
        v.normalize()
        v *= self.size * .5
        v += self.guide.apos[1]

        self.upv_cns = pri.addTransformFromPos(self.root,
                                               self.getName("upv_cns"), v)

        self.upv_ctl = self.addCtl(self.upv_cns,
                                   "upv_ctl",
                                   tra.getTransform(self.upv_cns),
                                   self.color_ik,
                                   "diamond",
                                   w=self.size * .12)
        att.setKeyableAttributes(self.upv_ctl, self.t_params)
        att.setInvertMirror(self.upv_ctl, ["tx"])

        #IK rotation controls
        if self.settings["ikTR"]:
            self.ikRot_npo = pri.addTransform(self.root,
                                              self.getName("ikRot_npo"), m)
            self.ikRot_cns = pri.addTransform(self.ikRot_npo,
                                              self.getName("ikRot_cns"), m)
            self.ikRot_ctl = self.addCtl(self.ikRot_cns,
                                         "ikRot_ctl",
                                         m,
                                         self.color_ik,
                                         "sphere",
                                         w=self.size * .12)
            att.setKeyableAttributes(self.ikRot_ctl, ["rx", "ry", "rz"])

        # References --------------------------------------
        # Calculate  again the transfor for the IK ref. This way align with FK
        trnIK_ref = tra.getTransformLookingAt(self.guide.pos["wrist"],
                                              self.guide.pos["eff"],
                                              self.normal, "xz", self.negate)
        self.ik_ref = pri.addTransform(self.ik_ctl, self.getName("ik_ref"),
                                       trnIK_ref)
        self.fk_ref = pri.addTransform(self.fk_ctl[2], self.getName("fk_ref"),
                                       trnIK_ref)

        # Chain --------------------------------------------
        # The outputs of the ikfk2bone solver
        self.bone0 = pri.addLocator(self.root, self.getName("0_bone"),
                                    tra.getTransform(self.fk_ctl[0]))
        self.bone0_shp = self.bone0.getShape()
        self.bone0_shp.setAttr("localPositionX", self.n_factor * .5)
        self.bone0_shp.setAttr("localScale", .5, 0, 0)
        self.bone0.setAttr("sx", self.length0)
        self.bone0.setAttr("visibility", False)

        self.bone1 = pri.addLocator(self.root, self.getName("1_bone"),
                                    tra.getTransform(self.fk_ctl[1]))
        self.bone1_shp = self.bone1.getShape()
        self.bone1_shp.setAttr("localPositionX", self.n_factor * .5)
        self.bone1_shp.setAttr("localScale", .5, 0, 0)
        self.bone1.setAttr("sx", self.length1)
        self.bone1.setAttr("visibility", False)

        self.ctrn_loc = pri.addTransformFromPos(self.root,
                                                self.getName("ctrn_loc"),
                                                self.guide.apos[1])
        self.eff_loc = pri.addTransformFromPos(self.root,
                                               self.getName("eff_loc"),
                                               self.guide.apos[2])

        # Mid Controler ------------------------------------
        self.mid_ctl = self.addCtl(self.ctrn_loc,
                                   "mid_ctl",
                                   tra.getTransform(self.ctrn_loc),
                                   self.color_ik,
                                   "sphere",
                                   w=self.size * .2)
        att.setInvertMirror(self.mid_ctl, ["tx", "ty", "tz"])

        #Roll join ref
        self.rollRef = pri.add2DChain(self.root, self.getName("rollChain"),
                                      self.guide.apos[:2], self.normal,
                                      self.negate)
        for x in self.rollRef:
            x.setAttr("visibility", False)

        self.tws0_loc = pri.addTransform(self.rollRef[0],
                                         self.getName("tws0_loc"),
                                         tra.getTransform(self.fk_ctl[0]))
        self.tws0_rot = pri.addTransform(self.tws0_loc,
                                         self.getName("tws0_rot"),
                                         tra.getTransform(self.fk_ctl[0]))

        self.tws1_npo = pri.addTransform(self.ctrn_loc,
                                         self.getName("tws1_npo"),
                                         tra.getTransform(self.ctrn_loc))
        self.tws1_loc = pri.addTransform(self.tws1_npo,
                                         self.getName("tws1_loc"),
                                         tra.getTransform(self.ctrn_loc))
        self.tws1_rot = pri.addTransform(self.tws1_loc,
                                         self.getName("tws1_rot"),
                                         tra.getTransform(self.ctrn_loc))

        self.tws2_npo = pri.addTransform(self.root, self.getName("tws2_npo"),
                                         tra.getTransform(self.fk_ctl[2]))
        self.tws2_loc = pri.addTransform(self.tws2_npo,
                                         self.getName("tws2_loc"),
                                         tra.getTransform(self.fk_ctl[2]))
        self.tws2_rot = pri.addTransform(self.tws2_loc,
                                         self.getName("tws2_rot"),
                                         tra.getTransform(self.fk_ctl[2]))

        # Divisions ----------------------------------------
        # We have at least one division at the start, the end and one for the elbow. + 2 for elbow angle control
        self.divisions = self.settings["div0"] + self.settings["div1"] + 3 + 2

        self.div_cns = []
        for i in range(self.divisions):

            div_cns = pri.addTransform(self.root,
                                       self.getName("div%s_loc" % i))

            self.div_cns.append(div_cns)
            self.jnt_pos.append([div_cns, i])

        # End reference ------------------------------------
        # To help the deformation on the wrist
        self.jnt_pos.append([self.eff_loc, 'end'])
        #match IK FK references
        self.match_fk0_off = pri.addTransform(self.root,
                                              self.getName("matchFk0_npo"),
                                              tra.getTransform(self.fk_ctl[1]))
        # self.match_fk0_off.attr("tx").set(1.0)
        self.match_fk0 = pri.addTransform(self.match_fk0_off,
                                          self.getName("fk0_mth"),
                                          tra.getTransform(self.fk_ctl[0]))
        self.match_fk1_off = pri.addTransform(self.root,
                                              self.getName("matchFk1_npo"),
                                              tra.getTransform(self.fk_ctl[2]))
        # self.match_fk1_off.attr("tx").set(1.0)
        self.match_fk1 = pri.addTransform(self.match_fk1_off,
                                          self.getName("fk1_mth"),
                                          tra.getTransform(self.fk_ctl[1]))
        self.match_fk2 = pri.addTransform(self.ik_ctl, self.getName("fk2_mth"),
                                          tra.getTransform(self.fk_ctl[2]))

        self.match_ik = pri.addTransform(self.fk2_ctl, self.getName("ik_mth"),
                                         tra.getTransform(self.ik_ctl))
        self.match_ikUpv = pri.addTransform(self.fk0_ctl,
                                            self.getName("upv_mth"),
                                            tra.getTransform(self.upv_ctl))
Exemple #13
0
    def addObjects(self):

        self.normal = self.getNormalFromPos(self.guide.apos)

        self.length0 = vec.getDistance(self.guide.apos[0], self.guide.apos[1])
        self.length1 = vec.getDistance(self.guide.apos[1], self.guide.apos[2])
        self.length2 = vec.getDistance(self.guide.apos[2], self.guide.apos[3])

        # FK Controlers -----------------------------------
        t = tra.getTransformLookingAt(self.guide.apos[0], self.guide.apos[1],
                                      self.normal, "xz", self.negate)

        ### FK NEUTRAL POSE IS DIFFERENT
        self.fk0_npo = pri.addTransform(self.root, self.getName("fk0_npo"), t)

        self.fk0_ctl = self.addCtl(self.fk0_npo,
                                   "fk0_ctl",
                                   t,
                                   self.color_fk,
                                   "cube",
                                   w=self.length0,
                                   h=self.size * .1,
                                   d=self.size * .1,
                                   po=dt.Vector(
                                       .5 * self.length0 * self.n_factor, 0,
                                       0))

        t = tra.getTransformLookingAt(self.guide.apos[1], self.guide.apos[2],
                                      self.normal, "xz", self.negate)
        self.fk1_ctl = self.addCtl(self.fk0_ctl,
                                   "fk1_ctl",
                                   t,
                                   self.color_fk,
                                   "cube",
                                   w=self.length1,
                                   h=self.size * .1,
                                   d=self.size * .1,
                                   po=dt.Vector(
                                       .5 * self.length1 * self.n_factor, 0,
                                       0))

        t = tra.getTransformLookingAt(self.guide.apos[2], self.guide.apos[3],
                                      self.normal, "xz", self.negate)
        self.fk2_ctl = self.addCtl(self.fk1_ctl,
                                   "fk2_ctl",
                                   t,
                                   self.color_fk,
                                   "cube",
                                   w=self.length2,
                                   h=self.size * .1,
                                   d=self.size * .1,
                                   po=dt.Vector(
                                       .5 * self.length2 * self.n_factor, 0,
                                       0))
        self.fk_ctl = [self.fk0_ctl, self.fk1_ctl, self.fk2_ctl]

        # IK Controlers -----------------------------------

        self.ik_cns = pri.addTransformFromPos(self.root,
                                              self.getName("ik_cns"),
                                              self.guide.pos["wrist"])

        self.ikcns_ctl = self.addCtl(self.ik_cns,
                                     "ikcns_ctl",
                                     tra.getTransformFromPos(
                                         self.guide.pos["wrist"]),
                                     self.color_ik,
                                     "null",
                                     w=self.size * .12)

        ### IK CONTROLER POSE IS DIFFERENT
        m = tra.getTransformLookingAt(self.guide.pos["wrist"],
                                      self.guide.pos["eff"], self.normal, "xz",
                                      False)
        self.ik_ctl = self.addCtl(self.ikcns_ctl,
                                  "ik_ctl",
                                  m,
                                  self.color_ik,
                                  "cube",
                                  w=self.size * .12,
                                  h=self.size * .12,
                                  d=self.size * .12)

        # upv
        v = self.guide.apos[2] - self.guide.apos[0]
        v = self.normal ^ v
        v.normalize()
        v *= self.size * .5
        v += self.guide.apos[1]

        self.upv_cns = pri.addTransformFromPos(self.root,
                                               self.getName("upv_cns"), v)

        self.upv_ctl = self.addCtl(self.upv_cns,
                                   "upv_ctl",
                                   tra.getTransform(self.upv_cns),
                                   self.color_ik,
                                   "diamond",
                                   w=self.size * .12)
        att.setKeyableAttributes(self.upv_ctl, self.t_params)

        # References --------------------------------------
        self.ik_ref = pri.addTransform(self.ik_ctl, self.getName("ik_ref"),
                                       tra.getTransform(self.ik_ctl))
        self.fk_ref = pri.addTransform(self.fk_ctl[2], self.getName("fk_ref"),
                                       tra.getTransform(self.ik_ctl))

        # Chain --------------------------------------------
        # The outputs of the ikfk2bone solver
        self.bone0 = pri.addLocator(self.root, self.getName("0_jnt"),
                                    tra.getTransform(self.fk_ctl[0]))
        self.bone0_shp = self.bone0.getShape()
        self.bone0_shp.setAttr("localPositionX", self.n_factor * .5)
        self.bone0_shp.setAttr("localScale", .5, 0, 0)
        self.bone0.setAttr("sx", self.length0)
        self.bone0.setAttr("visibility", False)

        self.bone1 = pri.addLocator(self.root, self.getName("1_jnt"),
                                    tra.getTransform(self.fk_ctl[1]))
        self.bone1_shp = self.bone1.getShape()
        self.bone1_shp.setAttr("localPositionX", self.n_factor * .5)
        self.bone1_shp.setAttr("localScale", .5, 0, 0)
        self.bone1.setAttr("sx", self.length1)
        self.bone1.setAttr("visibility", False)

        self.ctrn_loc = pri.addTransformFromPos(self.root,
                                                self.getName("ctrn_loc"),
                                                self.guide.apos[1])
        self.eff_loc = pri.addTransformFromPos(self.root,
                                               self.getName("eff_loc"),
                                               self.guide.apos[2])

        # Mid Controler ------------------------------------
        self.mid_ctl = self.addCtl(self.ctrn_loc,
                                   "mid_ctl",
                                   tra.getTransform(self.ctrn_loc),
                                   self.color_ik,
                                   "sphere",
                                   w=self.size * .2)

        # Twist references ---------------------------------
        x = dt.Vector(0, -1, 0)
        x = x * tra.getTransform(self.eff_loc)
        z = dt.Vector(self.normal.x, self.normal.y, self.normal.z)
        z = z * tra.getTransform(self.eff_loc)

        m = tra.getRotationFromAxis(x, z, "xz", self.negate)
        m = tra.setMatrixPosition(m, tra.getTranslation(self.ik_ctl))

        self.tws0_loc = pri.addTransform(self.root, self.getName("tws0_loc"),
                                         tra.getTransform(self.fk_ctl[0]))
        self.tws0_rot = pri.addTransform(self.tws0_loc,
                                         self.getName("tws0_rot"),
                                         tra.getTransform(self.fk_ctl[0]))

        self.tws1_loc = pri.addTransform(self.ctrn_loc,
                                         self.getName("tws1_loc"),
                                         tra.getTransform(self.ctrn_loc))
        self.tws1_rot = pri.addTransform(self.tws1_loc,
                                         self.getName("tws1_rot"),
                                         tra.getTransform(self.ctrn_loc))

        self.tws2_loc = pri.addTransform(self.root, self.getName("tws2_loc"),
                                         tra.getTransform(self.fk_ctl[2]))
        self.tws2_rot = pri.addTransform(self.tws2_loc,
                                         self.getName("tws2_rot"),
                                         tra.getTransform(self.fk_ctl[2]))
        self.tws2_rot.setAttr("sx", .001)

        # Divisions ----------------------------------------
        # We have at least one division at the start, the end and one for the elbow.
        self.divisions = self.settings["div0"] + self.settings["div1"] + 3

        self.div_cns = []
        for i in range(self.divisions):

            div_cns = pri.addTransform(self.root,
                                       self.getName("div%s_loc" % i))

            self.div_cns.append(div_cns)

            self.addShadow(div_cns, i)

        # End reference ------------------------------------
        # To help the deformation on the wrist
        self.end_ref = pri.addTransform(self.tws2_rot, self.getName("end_ref"),
                                        m)
        self.addShadow(self.end_ref, "end")
Exemple #14
0
    def addObjects(self):

        self.normal = self.guide.blades["blade"].z*-1
        self.binormal = self.guide.blades["blade"].x

        self.isFk = self.settings["mode"] != 1
        self.isIk = self.settings["mode"] != 0
        self.isFkIk = self.settings["mode"] == 2

        self.WIP = self.options["mode"]


        # FK controllers ------------------------------------
        if self.isFk:
            self.fk_npo = []
            self.fk_ctl = []
            t = self.guide.tra["root"]
            self.ik_cns = pri.addTransform(self.root, self.getName("ik_cns"), t)
            parent = self.ik_cns
            tOld = False
            for i, t in enumerate(tra.getChainTransform(self.guide.apos, self.normal, self.negate)):
                dist = vec.getDistance(self.guide.apos[i], self.guide.apos[i+1])
                if self.settings["neutralpose"] or not tOld:
                    tnpo = t
                else:
                    tnpo = tra.setMatrixPosition(tOld, tra.getPositionFromMatrix(t))
                fk_npo = pri.addTransform(parent, self.getName("fk%s_npo"%i), tnpo)
                fk_ctl = self.addCtl(fk_npo, "fk%s_ctl"%i, t, self.color_fk, "cube", w=dist, h=self.size*.1, d=self.size*.1, po=dt.Vector(dist*.5*self.n_factor,0,0))
                parent = fk_ctl
                self.fk_npo.append(fk_npo)
                self.fk_ctl.append(fk_ctl)
                tOld = t

        # IK controllers ------------------------------------
        if self.isIk:

            normal = vec.getTransposedVector(self.normal, [self.guide.apos[0], self.guide.apos[1]], [self.guide.apos[-2], self.guide.apos[-1]])
            t = tra.getTransformLookingAt(self.guide.apos[-2], self.guide.apos[-1], normal, "xy", self.negate)
            t = tra.setMatrixPosition(t, self.guide.apos[-1])

            self.ik_cns = pri.addTransform(self.root, self.getName("ik_cns"), t)
            self.ikcns_ctl = self.addCtl(self.ik_cns, "ikcns_ctl", t, self.color_ik, "null", w=self.size)
            self.ik_ctl = self.addCtl(self.ikcns_ctl, "ik_ctl", t, self.color_ik, "cube", w=self.size*.3, h=self.size*.3, d=self.size*.3)

            v = self.guide.apos[-1] - self.guide.apos[0]
            v = v ^ self.normal
            v.normalize()
            v *= self.size
            v += self.guide.apos[1]
            self.upv_cns = pri.addTransformFromPos(self.root, self.getName("upv_cns"), v)

            self.upv_ctl = self.addCtl(self.upv_cns, "upv_ctl", tra.getTransform(self.upv_cns), self.color_ik, "diamond", w=self.size*.1)

            # Chain
            self.chain = pri.add2DChain(self.root, self.getName("chain"), self.guide.apos, self.normal, self.negate)
            self.chain[0].attr("visibility").set(self.WIP)



        # Chain of deformers -------------------------------
        self.loc = []
        parent = self.root
        for i, t in enumerate(tra.getChainTransform(self.guide.apos, self.normal, self.negate)):
            loc = pri.addTransform(parent, self.getName("%s_loc"%i), t)
            
            self.loc.append(loc)
            self.jnt_pos.append([loc, i])
            parent = loc
Exemple #15
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
Exemple #16
0
    def addObjects(self):

        # Ik Controlers ------------------------------------
        t = tra.getTransformLookingAt(self.guide.pos["tan1"], self.guide.pos["neck"], self.guide.blades["blade"].z, "yx", self.negate)
        t = tra.setMatrixPosition(t, self.guide.pos["neck"])
        self.ik_cns = pri.addTransform(self.root, self.getName("ik_cns"), t)

        self.ik_ctl = self.addCtl(self.ik_cns, "ik_ctl", t, self.color_ik, "compas", w=self.size*.5)
        att.setKeyableAttributes(self.ik_ctl)
        att.setRotOrder(self.ik_ctl, "XZY")

        # Tangents -----------------------------------------
        t = tra.setMatrixPosition(t, self.guide.pos["tan1"])
        self.tan1_loc = pri.addTransform(self.ik_ctl, self.getName("tan1_loc"), t)

        t = tra.getTransformLookingAt(self.guide.pos["root"], self.guide.pos["tan0"], self.guide.blades["blade"].z, "yx", self.negate)
        t = tra.setMatrixPosition(t, self.guide.pos["tan0"])
        self.tan0_loc = pri.addTransform(self.root, self.getName("tan0_loc"), t)

        # Curves -------------------------------------------
        self.mst_crv = cur.addCnsCurve(self.root, self.getName("mst_crv"), [self.root, self.tan0_loc, self.tan1_loc, self.ik_ctl], 3)
        self.slv_crv = cur.addCurve(self.root, self.getName("slv_crv"), [dt.Vector()]*10, False, 3)
        self.mst_crv.setAttr("visibility", False)
        self.slv_crv.setAttr("visibility", False)

        # Division -----------------------------------------
        # The user only define how many intermediate division he wants.
        # First and last divisions are an obligation.
        parentdiv = self.root
        parentctl = self.root
        self.div_cns = []
        self.fk_ctl = []
        self.fk_npo = []
        self.scl_npo = []
        for i in range(self.settings["division"]):

            # References
            div_cns = pri.addTransform(parentdiv, self.getName("%s_cns"%i))
            setAttr(div_cns+".inheritsTransform", False)
            self.div_cns.append(div_cns)
            parentdiv = div_cns

            scl_npo = pri.addTransform(parentctl, self.getName("%s_scl_npo"%i), tra.getTransform(parentctl))

            # Controlers (First and last one are fake)
            if i in [0, self.settings["division"] - 1]:
                fk_ctl = pri.addTransform(scl_npo, self.getName("%s_loc"%i), tra.getTransform(parentctl))
                fk_npo = fk_ctl
            else:
                fk_npo = pri.addTransform(scl_npo, self.getName("fk%s_npo"%(i-1)), tra.getTransform(parentctl))
                fk_ctl = self.addCtl(fk_npo, "fk%s_ctl"%(i-1), tra.getTransform(parentctl), self.color_fk, "cube", w=self.size*.2, h=self.size*.05, d=self.size*.2)
                att.setKeyableAttributes(self.fk_ctl)
                att.setRotOrder(fk_ctl, "XZY")


            # setAttr(fk_npo+".inheritsTransform", False)
            self.scl_npo.append(scl_npo)
            self.fk_npo.append(fk_npo)
            self.fk_ctl.append(fk_ctl)
            parentctl = fk_ctl

            # Deformers (Shadow)
            self.addShadow(fk_ctl, i)

        # Head ---------------------------------------------
        t = tra.getTransformLookingAt(self.guide.pos["head"], self.guide.pos["eff"], self.guide.blades["blade"].z, "yx", self.negate)
        self.head_cns = pri.addTransform(self.root, self.getName("head_cns"), t)

        dist = vec.getDistance(self.guide.pos["head"], self.guide.pos["eff"])
        self.head_ctl = self.addCtl(self.head_cns, "head_ctl", t, self.color_fk, "cube", w=self.size*.5, h=dist, d=self.size*.5, po=dt.Vector(0,dist*.5,0))
        att.setRotOrder(self.head_ctl, "XZY")

        self.addShadow(self.head_ctl, "head")
Exemple #17
0
    def addObjects(self):
        """Add all the objects needed to create the component."""

        self.normal = self.getNormalFromPos(self.guide.apos)
        self.binormal = self.getBiNormalFromPos(self.guide.apos)

        self.length0 = vector.getDistance(self.guide.apos[0],
                                          self.guide.apos[1])
        self.length1 = vector.getDistance(self.guide.apos[1],
                                          self.guide.apos[2])
        self.length2 = vector.getDistance(self.guide.apos[2],
                                          self.guide.apos[3])

        # FK Controlers -----------------------------------
        # *ms* set npo @ Tpose, to make the fk rotation work
        # best with rot order"yzx"

        self.fk_cns = primitive.addTransformFromPos(self.root,
                                                    self.getName("fk_cns"),
                                                    self.guide.apos[0])

        vec_offset = ((self.guide.apos[1] - self.guide.apos[0]) * [1, 0, 0])
        tpv = self.guide.apos[0] + vec_offset

        t = transform.getTransformLookingAt(self.guide.apos[0], tpv,
                                            self.normal, "xz", self.negate)
        # *ms* add FK isolation
        self.fk0_npo = primitive.addTransform(self.fk_cns,
                                              self.getName("fk0_npo"), t)

        t = transform.getTransformLookingAt(self.guide.apos[0],
                                            self.guide.apos[1], self.normal,
                                            "xz", self.negate)

        po_off = datatypes.Vector(.35 * self.length0 * self.n_factor, 0, 0)

        self.fk0_ctl = self.addCtl(self.fk0_npo,
                                   "fk0_ctl",
                                   t,
                                   self.color_fk,
                                   "cube",
                                   w=self.length0 * .7,
                                   h=self.size * .1,
                                   d=self.size * .1,
                                   po=po_off,
                                   tp=self.parentCtlTag)
        attribute.setKeyableAttributes(self.fk0_ctl)
        # *ms* add fk roll control Simage style
        po_off = datatypes.Vector(.85 * self.length0 * self.n_factor, 0, 0)
        self.fk0_roll_ctl = self.addCtl(self.fk0_ctl,
                                        "fk0_roll_ctl",
                                        t,
                                        self.color_fk,
                                        "cube",
                                        w=self.length0 * .3,
                                        h=self.size * .1,
                                        d=self.size * 0.1,
                                        po=po_off,
                                        tp=self.fk0_ctl)

        attribute.setRotOrder(self.fk0_roll_ctl, "YZX")
        attribute.setKeyableAttributes(self.fk0_roll_ctl, ["rx"])
        self.fk0_mtx = primitive.addTransform(self.root,
                                              self.getName("fk0_mtx"), t)

        t = transform.setMatrixPosition(t, self.guide.apos[1])

        self.fk1_ref = primitive.addTransform(self.fk0_roll_ctl,
                                              self.getName("fk1_ref"), t)

        self.fk1_loc = primitive.addTransform(self.root,
                                              self.getName("fk1_loc"), t)

        t = transform.getTransformLookingAt(self.guide.apos[1],
                                            self.guide.apos[2], self.normal,
                                            "xz", self.negate)

        self.fk1_npo = primitive.addTransform(self.fk1_loc,
                                              self.getName("fk1_npo"), t)

        po_off = datatypes.Vector(.35 * self.length1 * self.n_factor, 0, 0)
        self.fk1_ctl = self.addCtl(self.fk1_npo,
                                   "fk1_ctl",
                                   t,
                                   self.color_fk,
                                   "cube",
                                   w=self.length1 * .7,
                                   h=self.size * .1,
                                   d=self.size * .1,
                                   po=po_off,
                                   tp=self.fk0_roll_ctl)

        attribute.setKeyableAttributes(self.fk1_ctl)

        self.fk1_mtx = primitive.addTransform(self.fk1_ctl,
                                              self.getName("fk1_mtx"), t)

        po_off = datatypes.Vector(.85 * self.length1 * self.n_factor, 0, 0)
        self.fk1_roll_ctl = self.addCtl(self.fk1_ctl,
                                        "fk1_roll_ctl",
                                        t,
                                        self.color_fk,
                                        "cube",
                                        w=self.length1 * .3,
                                        h=self.size * .1,
                                        d=self.size * .1,
                                        po=po_off,
                                        tp=self.fk1_ctl)
        attribute.setRotOrder(self.fk1_roll_ctl, "XYZ")
        attribute.setKeyableAttributes(self.fk1_roll_ctl, ["rx"])

        t = transform.getTransformLookingAt(self.guide.apos[2],
                                            self.guide.apos[3], self.normal,
                                            "xz", self.negate)
        # *ms* buffer object to feed into ikfk solver for hand seperation
        self.fk2_mtx = primitive.addTransform(self.fk1_roll_ctl,
                                              self.getName("fk2_mtx"), t)

        # fk2_loc is need to take the effector position + bone1 rotation
        t1 = transform.getTransformLookingAt(self.guide.apos[2],
                                             self.guide.apos[1], self.normal,
                                             "-xz", self.negate)

        self.fk2_loc = primitive.addTransform(self.root,
                                              self.getName("fk2_loc"), t1)

        self.fk2_npo = primitive.addTransform(self.fk2_loc,
                                              self.getName("fk2_npo"), t)
        po_off = datatypes.Vector(.5 * self.length2 * self.n_factor, 0, 0)
        self.fk2_ctl = self.addCtl(self.fk2_npo,
                                   "fk2_ctl",
                                   t,
                                   self.color_fk,
                                   "cube",
                                   w=self.length2,
                                   h=self.size * .1,
                                   d=self.size * .1,
                                   po=po_off,
                                   tp=self.fk1_roll_ctl)
        attribute.setKeyableAttributes(self.fk2_ctl)

        self.fk_ctl = [self.fk0_roll_ctl, self.fk1_mtx, self.fk2_ctl]
        self.fk_ctls = [
            self.fk0_ctl, self.fk0_roll_ctl, self.fk1_ctl, self.fk1_roll_ctl,
            self.fk2_ctl
        ]

        for x in self.fk_ctls:
            attribute.setInvertMirror(x, ["tx", "ty", "tz"])

        # IK Controlers -----------------------------------

        self.ik_cns = primitive.addTransformFromPos(self.root,
                                                    self.getName("ik_cns"),
                                                    self.guide.pos["wrist"])

        self.ikcns_ctl = self.addCtl(self.ik_cns,
                                     "ikcns_ctl",
                                     transform.getTransformFromPos(
                                         self.guide.pos["wrist"]),
                                     self.color_ik,
                                     "null",
                                     w=self.size * .12,
                                     tp=self.parentCtlTag)
        attribute.setInvertMirror(self.ikcns_ctl, ["tx", "ty", "tz"])

        if self.negate:
            m = transform.getTransformLookingAt(self.guide.pos["wrist"],
                                                self.guide.pos["eff"],
                                                self.normal, "x-y", True)
        else:
            m = transform.getTransformLookingAt(self.guide.pos["wrist"],
                                                self.guide.pos["eff"],
                                                self.normal, "xy", False)
        self.ik_ctl = self.addCtl(self.ikcns_ctl,
                                  "ik_ctl",
                                  m,
                                  self.color_ik,
                                  "cube",
                                  w=self.size * .12,
                                  h=self.size * .12,
                                  d=self.size * .12,
                                  tp=self.ikcns_ctl)
        attribute.setKeyableAttributes(self.ik_ctl)
        attribute.setInvertMirror(self.ik_ctl, ["tx", "ry", "rz"])

        # upv
        v = self.guide.apos[2] - self.guide.apos[0]
        v = self.normal ^ v
        v.normalize()
        v *= self.size * .5
        v += self.guide.apos[1]
        # *ms* auto up vector ------------------------------
        self.upv_cns = primitive.addTransformFromPos(self.root,
                                                     self.getName("upv_cns"),
                                                     self.guide.apos[0])
        self.upv_auv = primitive.addTransformFromPos(self.root,
                                                     self.getName("upv_auv"),
                                                     self.guide.apos[0])
        self.upv_mtx = primitive.addTransformFromPos(self.upv_cns,
                                                     self.getName("upv_mtx"),
                                                     self.guide.apos[0])

        self.upv_npo = primitive.addTransformFromPos(self.upv_mtx,
                                                     self.getName("upv_npo"),
                                                     v)
        self.upv_ctl = self.addCtl(self.upv_npo,
                                   "upv_ctl",
                                   transform.getTransform(self.upv_npo),
                                   self.color_ik,
                                   "diamond",
                                   w=self.size * .12,
                                   tp=self.parentCtlTag)
        attribute.setKeyableAttributes(self.upv_ctl, self.t_params)
        attribute.setInvertMirror(self.upv_ctl, ["tx"])

        # References --------------------------------------
        # Calculate  again the transfor for the IK ref. This way align with FK
        trnIK_ref = transform.getTransformLookingAt(self.guide.pos["wrist"],
                                                    self.guide.pos["eff"],
                                                    self.normal, "xz",
                                                    self.negate)
        self.ik_ref = primitive.addTransform(self.ik_ctl,
                                             self.getName("ik_ref"), trnIK_ref)
        self.fk_ref = primitive.addTransform(self.fk_ctl[2],
                                             self.getName("fk_ref"), trnIK_ref)

        # Chain --------------------------------------------
        # take outputs of the ikfk2bone solver
        self.bone0 = primitive.addLocator(
            self.root, self.getName("0_bone"),
            transform.getTransform(self.fk_ctl[0]))

        self.bone0_shp = self.bone0.getShape()
        self.bone0_shp.setAttr("localPositionX", self.n_factor * .5)
        self.bone0_shp.setAttr("localScale", .5, 0, 0)
        self.bone0.setAttr("sx", self.length0)
        self.bone0.setAttr("visibility", False)

        self.bone1 = primitive.addLocator(
            self.root, self.getName("1_bone"),
            transform.getTransform(self.fk_ctl[1]))

        self.bone1_shp = self.bone1.getShape()
        self.bone1_shp.setAttr("localPositionX", self.n_factor * .5)
        self.bone1_shp.setAttr("localScale", .5, 0, 0)
        self.bone1.setAttr("sx", self.length1)
        self.bone1.setAttr("visibility", False)

        self.ctrn_loc = primitive.addTransformFromPos(self.root,
                                                      self.getName("ctrn_loc"),
                                                      self.guide.apos[1])
        # eff npo --- take the effector output of gear ik solver
        self.eff_npo = primitive.addTransformFromPos(self.root,
                                                     self.getName("eff_npo"),
                                                     self.guide.apos[2])
        # eff loc --- take the fk ik blend result
        self.eff_loc = primitive.addTransformFromPos(self.eff_npo,
                                                     self.getName("eff_loc"),
                                                     self.guide.apos[2])

        # Mid Controler ------------------------------------
        self.mid_ctl = self.addCtl(self.ctrn_loc,
                                   "mid_ctl",
                                   transform.getTransform(self.ctrn_loc),
                                   self.color_ik,
                                   "sphere",
                                   w=self.size * .2,
                                   tp=self.parentCtlTag)
        attribute.setInvertMirror(self.mid_ctl, ["tx", "ty", "tz"])
        # *ms* add elbow thickness

        # Roll join ref

        self.tws0_npo = primitive.addTransform(
            self.root, self.getName("tws0_npo"),
            transform.getTransform(self.fk_ctl[0]))
        self.tws0_loc = primitive.addTransform(
            self.tws0_npo, self.getName("tws0_loc"),
            transform.getTransform(self.fk_ctl[0]))
        self.tws0_rot = primitive.addTransform(
            self.tws0_loc, self.getName("tws0_rot"),
            transform.getTransform(self.fk_ctl[0]))

        self.tws1_npo = primitive.addTransform(
            self.ctrn_loc, self.getName("tws1_npo"),
            transform.getTransform(self.ctrn_loc))
        self.tws1_loc = primitive.addTransform(
            self.tws1_npo, self.getName("tws1_loc"),
            transform.getTransform(self.ctrn_loc))
        self.tws1_rot = primitive.addTransform(
            self.tws1_loc, self.getName("tws1_rot"),
            transform.getTransform(self.ctrn_loc))

        self.tws2_loc = primitive.addTransform(
            self.tws1_npo, self.getName("tws2_loc"),
            transform.getTransform(self.ctrn_loc))
        self.tws2_rot = primitive.addTransform(
            self.tws2_loc, self.getName("tws2_rot"),
            transform.getTransform(self.ctrn_loc))

        self.tws3_npo = primitive.addTransform(
            self.root, self.getName("tws3_npo"),
            transform.getTransform(self.fk_ctl[2]))
        self.tws3_loc = primitive.addTransform(
            self.tws3_npo, self.getName("tws3_loc"),
            transform.getTransform(self.fk_ctl[2]))
        self.tws3_rot = primitive.addTransform(
            self.tws3_loc, self.getName("tws3_rot"),
            transform.getTransform(self.fk_ctl[2]))

        # Divisions ----------------------------------------
        # We have at least one division at the start, the end and one for the
        # elbow. + 2 for elbow angle control
        # separate up and dn limb
        self.divisions = self.settings["div0"] + self.settings["div1"] + 3 + 2
        self.divisions0 = self.settings["div0"] + 2
        self.divisions1 = self.settings["div1"] + 2

        self.div_cns = []
        self.div_cnsUp = []
        self.div_cnsDn = []
        self.div_ctls = []

        self.div_org = primitive.addTransform(
            self.root, self.getName("div_org"),
            transform.getTransform(self.root))
        self.previousTag = self.parentCtlTag
        for i in range(self.divisions0):

            div_cns = primitive.addTransform(self.div_org,
                                             self.getName("div%s_loc" % i))

            if self.negate:
                div_ctl = self.addCtl(
                    div_cns,
                    self.getName("div%s_ctl" % i),
                    transform.getTransform(div_cns),
                    self.color_fk,
                    "square",
                    d=self.size * .05,
                    w=self.size * .1,
                    po=datatypes.Vector(0, self.size * -0.05, 0),
                    ro=datatypes.Vector(0, 0, datatypes.radians(90)),
                    tp=self.previousTag)
            else:
                div_ctl = self.addCtl(
                    div_cns,
                    self.getName("div%s_ctl" % i),
                    transform.getTransform(div_cns),
                    self.color_fk,
                    "square",
                    d=self.size * .05,
                    w=self.size * .1,
                    po=datatypes.Vector(0, self.size * 0.05, 0),
                    ro=datatypes.Vector(0, 0, datatypes.radians(90)),
                    tp=self.previousTag)
            attribute.setKeyableAttributes(div_ctl)
            self.previousTag = div_ctl
            self.div_cns.append(div_cns)
            self.div_cnsUp.append(div_cns)
            self.jnt_pos.append([div_ctl, i])
            self.div_ctls.append(div_ctl)
        # mid division
        d = self.divisions0
        self.div_mid = primitive.addTransform(
            self.div_org, self.getName("div%s_loc" % d),
            transform.getTransform(self.mid_ctl))
        if self.negate:
            self.div_mid_ctl = self.addCtl(
                self.div_mid,
                self.getName("div%s_ctl" % d),
                transform.getTransform(self.div_mid),
                self.color_fk,
                "square",
                d=self.size * .05,
                w=self.size * .1,
                po=datatypes.Vector(0, self.size * -0.05, 0),
                ro=datatypes.Vector(0, 0, datatypes.radians(90)),
                tp=self.previousTag)
        else:
            self.div_mid_ctl = self.addCtl(
                self.div_mid,
                self.getName("div%s_ctl" % d),
                transform.getTransform(self.div_mid),
                self.color_fk,
                "square",
                d=self.size * .05,
                w=self.size * .1,
                po=datatypes.Vector(0, self.size * 0.05, 0),
                ro=datatypes.Vector(0, 0, datatypes.radians(90)),
                tp=self.previousTag)
        attribute.setKeyableAttributes(self.div_mid_ctl)
        self.previousTag = div_ctl

        self.div_cns.append(self.div_mid)
        self.jnt_pos.append([self.div_mid_ctl, self.divisions0])
        self.div_ctls.append(self.div_mid_ctl)
        # down division
        for i in range(self.divisions1):

            dd = i + self.divisions1 + 1
            div_cns = primitive.addTransform(self.div_org,
                                             self.getName("div%s_loc" % dd))
            if self.negate:
                div_ctl = self.addCtl(
                    div_cns,
                    self.getName("div%s_ctl" % dd),
                    transform.getTransform(div_cns),
                    self.color_fk,
                    "square",
                    d=self.size * .05,
                    w=self.size * .1,
                    po=datatypes.Vector(0, self.size * -0.05, 0),
                    ro=datatypes.Vector(0, 0, datatypes.radians(90)),
                    tp=self.previousTag)
            else:
                div_ctl = self.addCtl(
                    div_cns,
                    self.getName("div%s_ctl" % dd),
                    transform.getTransform(div_cns),
                    self.color_fk,
                    "square",
                    d=self.size * .05,
                    w=self.size * .1,
                    po=datatypes.Vector(0, self.size * 0.05, 0),
                    ro=datatypes.Vector(0, 0, datatypes.radians(90)),
                    tp=self.previousTag)
            attribute.setKeyableAttributes(div_ctl)
            self.previousTag = div_ctl

            self.div_cns.append(div_cns)
            self.div_cnsDn.append(div_cns)
            self.jnt_pos.append([div_ctl, i + self.divisions0 + 1])
            self.div_ctls.append(div_ctl)

        # End reference ------------------------------------
        # To help the deformation on the wrist
        self.jnt_pos.append([self.eff_loc, 'end'])

        # match IK FK references

        self.match_fk0 = primitive.addTransform(
            self.root, self.getName("fk0_mth"),
            transform.getTransform(self.fk_ctl[0]))
        self.match_fk1 = primitive.addTransform(
            self.root, self.getName("fk1_mth"),
            transform.getTransform(self.fk_ctl[1]))
        self.match_fk2 = primitive.addTransform(
            self.ik_ctl, self.getName("fk2_mth"),
            transform.getTransform(self.fk_ctl[2]))

        self.match_ik = primitive.addTransform(
            self.fk2_ctl, self.getName("ik_mth"),
            transform.getTransform(self.ik_ctl))
        self.match_ikUpv = primitive.addTransform(
            self.fk0_roll_ctl, self.getName("upv_mth"),
            transform.getTransform(self.upv_ctl))
Exemple #18
0
    def addObjects(self):

        # Ik Controlers ------------------------------------
        t = tra.getTransformLookingAt(self.guide.pos["tan1"],
                                      self.guide.pos["neck"],
                                      self.guide.blades["blade"].z, "yx",
                                      self.negate)
        t = tra.setMatrixPosition(t, self.guide.pos["neck"])
        self.ik_cns = pri.addTransform(self.root, self.getName("ik_cns"), t)

        self.ik_ctl = self.addCtl(self.ik_cns,
                                  "ik_ctl",
                                  t,
                                  self.color_ik,
                                  "compas",
                                  w=self.size * .5)
        att.setKeyableAttributes(self.ik_ctl)
        att.setRotOrder(self.ik_ctl, "XZY")

        # Tangents -----------------------------------------
        t = tra.setMatrixPosition(t, self.guide.pos["tan1"])
        self.tan1_loc = pri.addTransform(self.ik_ctl, self.getName("tan1_loc"),
                                         t)

        t = tra.getTransformLookingAt(self.guide.pos["root"],
                                      self.guide.pos["tan0"],
                                      self.guide.blades["blade"].z, "yx",
                                      self.negate)
        t = tra.setMatrixPosition(t, self.guide.pos["tan0"])
        self.tan0_loc = pri.addTransform(self.root, self.getName("tan0_loc"),
                                         t)

        # Curves -------------------------------------------
        self.mst_crv = cur.addCnsCurve(
            self.root, self.getName("mst_crv"),
            [self.root, self.tan0_loc, self.tan1_loc, self.ik_ctl], 3)
        self.slv_crv = cur.addCurve(self.root, self.getName("slv_crv"),
                                    [dt.Vector()] * 10, False, 3)
        self.mst_crv.setAttr("visibility", False)
        self.slv_crv.setAttr("visibility", False)

        # Division -----------------------------------------
        # The user only define how many intermediate division he wants.
        # First and last divisions are an obligation.
        parentdiv = self.root
        parentctl = self.root
        self.div_cns = []
        self.fk_ctl = []
        self.fk_npo = []
        self.scl_npo = []
        for i in range(self.settings["division"]):

            # References
            div_cns = pri.addTransform(parentdiv, self.getName("%s_cns" % i))
            setAttr(div_cns + ".inheritsTransform", False)
            self.div_cns.append(div_cns)
            parentdiv = div_cns

            scl_npo = pri.addTransform(parentctl,
                                       self.getName("%s_scl_npo" % i),
                                       tra.getTransform(parentctl))

            # Controlers (First and last one are fake)
            if i in [0, self.settings["division"] - 1]:
                fk_ctl = pri.addTransform(scl_npo, self.getName("%s_loc" % i),
                                          tra.getTransform(parentctl))
                fk_npo = fk_ctl
            else:
                fk_npo = pri.addTransform(scl_npo,
                                          self.getName("fk%s_npo" % (i - 1)),
                                          tra.getTransform(parentctl))
                fk_ctl = self.addCtl(fk_npo,
                                     "fk%s_ctl" % (i - 1),
                                     tra.getTransform(parentctl),
                                     self.color_fk,
                                     "cube",
                                     w=self.size * .2,
                                     h=self.size * .05,
                                     d=self.size * .2)
                att.setKeyableAttributes(self.fk_ctl)
                att.setRotOrder(fk_ctl, "XZY")

            # setAttr(fk_npo+".inheritsTransform", False)
            self.scl_npo.append(scl_npo)
            self.fk_npo.append(fk_npo)
            self.fk_ctl.append(fk_ctl)
            parentctl = fk_ctl

            # Deformers (Shadow)
            self.addShadow(fk_ctl, i)

        # Head ---------------------------------------------
        t = tra.getTransformLookingAt(self.guide.pos["head"],
                                      self.guide.pos["eff"],
                                      self.guide.blades["blade"].z, "yx",
                                      self.negate)
        self.head_cns = pri.addTransform(self.root, self.getName("head_cns"),
                                         t)

        dist = vec.getDistance(self.guide.pos["head"], self.guide.pos["eff"])
        self.head_ctl = self.addCtl(self.head_cns,
                                    "head_ctl",
                                    t,
                                    self.color_fk,
                                    "cube",
                                    w=self.size * .5,
                                    h=dist,
                                    d=self.size * .5,
                                    po=dt.Vector(0, dist * .5, 0))
        att.setRotOrder(self.head_ctl, "XZY")

        self.addShadow(self.head_ctl, "head")
Exemple #19
0
    def addObjects(self):

        self.normal = self.guide.blades["blade"].z*-1

        # Ik Controlers ------------------------------------
        t = tra.getTransformLookingAt(self.guide.pos["tan1"], self.guide.pos["neck"], self.normal, "yx", self.negate)
        t = tra.setMatrixPosition(t, self.guide.pos["neck"])
        self.ik_cns = pri.addTransform(self.root, self.getName("ik_cns"), t)

        self.ik_ctl = self.addCtl(self.ik_cns, "ik_ctl", t, self.color_ik, "compas", w=self.size*.5)
        att.setKeyableAttributes(self.ik_ctl)
        att.setRotOrder(self.ik_ctl, "ZXY")

        # Tangents -----------------------------------------
        t = tra.setMatrixPosition(t, self.guide.pos["tan1"])
        self.tan1_loc = pri.addTransform(self.ik_ctl, self.getName("tan1_loc"), t)

        t = tra.getTransformLookingAt(self.guide.pos["root"], self.guide.pos["tan0"], self.normal, "yx", self.negate)
        t = tra.setMatrixPosition(t, self.guide.pos["tan0"])
        self.tan0_loc = pri.addTransform(self.root, self.getName("tan0_loc"), t)

        # Curves -------------------------------------------
        self.mst_crv = cur.addCnsCurve(self.root, self.getName("mst_crv"), [self.root, self.tan0_loc, self.tan1_loc, self.ik_ctl], 3)
        self.slv_crv = cur.addCurve(self.root, self.getName("slv_crv"), [dt.Vector()]*10, False, 3)
        self.mst_crv.setAttr("visibility", False)
        self.slv_crv.setAttr("visibility", False)

        # Division -----------------------------------------
        # The user only define how many intermediate division he wants.
        # First and last divisions are an obligation.
        parentdiv = self.root
        parentctl = self.root
        self.div_cns = []
        self.fk_ctl = []
        self.fk_npo = []
        self.scl_npo = []

        self.twister = []
        self.ref_twist = []

        parent_twistRef = pri.addTransform(self.root, self.getName("reference"), tra.getTransform(self.root))

        for i in range(self.settings["division"]):

            # References
            div_cns = pri.addTransform(parentdiv, self.getName("%s_cns"%i))
            pm.setAttr(div_cns+".inheritsTransform", False)
            self.div_cns.append(div_cns)
            parentdiv = div_cns

            scl_npo = pri.addTransform(parentctl, self.getName("%s_scl_npo"%i), tra.getTransform(parentctl))

            # Controlers (First and last one are fake)

            if i in [ self.settings["division"] - 1]: # 0,
                fk_ctl = pri.addTransform(scl_npo, self.getName("%s_loc"%i), tra.getTransform(parentctl))
                fk_npo = fk_ctl
            else:
                fk_npo = pri.addTransform(scl_npo, self.getName("fk%s_npo"%i), tra.getTransform(parentctl))
                fk_ctl = self.addCtl(fk_npo, "fk%s_ctl"%i, tra.getTransform(parentctl), self.color_fk, "cube", w=self.size*.2, h=self.size*.05, d=self.size*.2)
                att.setKeyableAttributes(self.fk_ctl)
                att.setRotOrder(fk_ctl, "ZXY")


            self.scl_npo.append(scl_npo)
            self.fk_npo.append(fk_npo)
            self.fk_ctl.append(fk_ctl)
            parentctl = fk_ctl

            self.jnt_pos.append([fk_ctl, i])

            #Twist references (This objects will replace the spinlookup slerp solver behavior)
            twister = pri.addTransform(parent_twistRef, self.getName("%s_rot_ref"%i), tra.getTransform(parent_twistRef))
            t = tra.getTransform(self.root)
            t[3] = [t[3][0], t[3][1], 1.0, 1.0]

            ref_twist = pri.addTransform(parent_twistRef, self.getName("%s_pos_ref"%i), t)

            self.twister.append(twister)
            self.ref_twist.append(ref_twist)

        # Head ---------------------------------------------
        t = tra.getTransformLookingAt(self.guide.pos["head"], self.guide.pos["eff"], self.normal, "yx", self.negate)
        self.head_cns = pri.addTransform(self.root, self.getName("head_cns"), t)

        dist = vec.getDistance(self.guide.pos["head"], self.guide.pos["eff"])
        self.head_ctl = self.addCtl(self.head_cns, "head_ctl", t, self.color_fk, "cube", w=self.size*.5, h=dist, d=self.size*.5, po=dt.Vector(0,dist*.5,0))
        att.setRotOrder(self.head_ctl, "ZXY")

        self.jnt_pos.append([self.head_ctl, "head"])
Exemple #20
0
    def addObjects(self):

        # Ik Controlers ------------------------------------
        t = tra.getTransformLookingAt(self.guide.apos[0], self.guide.apos[1],
                                      self.guide.blades["blade"].z, "yx",
                                      self.negate)
        self.ik0_npo = pri.addTransform(self.root, self.getName("ik0_npo"), t)
        self.ik0_ctl = self.addCtl(self.ik0_npo,
                                   "ik0_ctl",
                                   t,
                                   self.color_ik,
                                   "compas",
                                   w=self.size)
        att.setKeyableAttributes(self.ik0_ctl)
        att.setRotOrder(self.ik0_ctl, "XZY")

        t = tra.setMatrixPosition(t, self.guide.apos[1])
        self.ik1_npo = pri.addTransform(self.root, self.getName("ik1_npo"), t)
        self.ik1_ctl = self.addCtl(self.ik1_npo,
                                   "ik1_ctl",
                                   t,
                                   self.color_ik,
                                   "compas",
                                   w=self.size)
        att.setKeyableAttributes(self.ik1_ctl)
        att.setRotOrder(self.ik1_ctl, "XZY")

        # Tangent controlers -------------------------------
        t = tra.setMatrixPosition(
            t,
            vec.linearlyInterpolate(self.guide.apos[0], self.guide.apos[1],
                                    .33))
        self.tan0_npo = pri.addTransform(self.ik0_ctl,
                                         self.getName("tan0_npo"), t)
        self.tan0_ctl = self.addCtl(self.tan0_npo,
                                    "tan0_ctl",
                                    t,
                                    self.color_ik,
                                    "sphere",
                                    w=self.size * .2)
        att.setKeyableAttributes(self.tan0_ctl, self.t_params)

        t = tra.setMatrixPosition(
            t,
            vec.linearlyInterpolate(self.guide.apos[0], self.guide.apos[1],
                                    .66))
        self.tan1_npo = pri.addTransform(self.ik1_ctl,
                                         self.getName("tan1_npo"), t)
        self.tan1_ctl = self.addCtl(self.tan1_npo,
                                    "tan1_ctl",
                                    t,
                                    self.color_ik,
                                    "sphere",
                                    w=self.size * .2)
        att.setKeyableAttributes(self.tan1_ctl, self.t_params)

        # Curves -------------------------------------------
        self.mst_crv = cur.addCnsCurve(
            self.root, self.getName("mst_crv"),
            [self.ik0_ctl, self.tan0_ctl, self.tan1_ctl, self.ik1_ctl], 3)
        self.slv_crv = cur.addCurve(self.root, self.getName("slv_crv"),
                                    [dt.Vector()] * 10, False, 3)
        self.mst_crv.setAttr("visibility", False)
        self.slv_crv.setAttr("visibility", False)

        # Division -----------------------------------------
        # The user only define how many intermediate division he wants.
        # First and last divisions are an obligation.
        parentdiv = self.root
        parentctl = self.root
        self.div_cns = []
        self.fk_ctl = []
        self.fk_npo = []
        self.scl_npo = []
        for i in range(self.settings["division"]):

            # References
            div_cns = pri.addTransform(parentdiv, self.getName("%s_cns" % i))
            setAttr(div_cns + ".inheritsTransform", False)
            self.div_cns.append(div_cns)
            parentdiv = div_cns

            scl_npo = pri.addTransform(parentctl,
                                       self.getName("%s_scl_npo" % i),
                                       tra.getTransform(parentctl))

            # Controlers (First and last one are fake)
            if i in [0, self.settings["division"] - 1]:
                fk_ctl = pri.addTransform(scl_npo, self.getName("%s_loc" % i),
                                          tra.getTransform(parentctl))
                fk_npo = fk_ctl
            else:
                fk_npo = pri.addTransform(scl_npo,
                                          self.getName("fk%s_npo" % (i - 1)),
                                          tra.getTransform(parentctl))
                fk_ctl = self.addCtl(fk_npo,
                                     "fk%s_ctl" % (i - 1),
                                     tra.getTransform(parentctl),
                                     self.color_fk,
                                     "cube",
                                     w=self.size,
                                     h=self.size * .05,
                                     d=self.size)
                att.setKeyableAttributes(self.fk_ctl)
                att.setRotOrder(fk_ctl, "XZY")

            # setAttr(fk_npo+".inheritsTransform", False)
            self.scl_npo.append(scl_npo)
            self.fk_npo.append(fk_npo)
            self.fk_ctl.append(fk_ctl)
            parentctl = fk_ctl

            # Deformers (Shadow)
            self.addShadow(fk_ctl, i)

        # Connections (Hooks) ------------------------------
        self.cnx0 = pri.addTransform(self.root, self.getName("0_cnx"))
        self.cnx1 = pri.addTransform(self.root, self.getName("1_cnx"))
Exemple #21
0
    def addObjects(self):

        self.normal = self.getNormalFromPos(self.guide.apos)

        self.length0 = vec.getDistance(self.guide.apos[0], self.guide.apos[1])
        self.length1 = vec.getDistance(self.guide.apos[1], self.guide.apos[2])
        self.length2 = vec.getDistance(self.guide.apos[2], self.guide.apos[3])

        # FK Controlers -----------------------------------
        t = tra.getTransformLookingAt(self.guide.apos[0], self.guide.apos[1], self.normal, "xz", self.negate)
        
        ### FK NEUTRAL POSE IS DIFFERENT
        self.fk0_npo = pri.addTransform(self.root, self.getName("fk0_npo"), t)
        
        self.fk0_ctl = self.addCtl(self.fk0_npo, "fk0_ctl", t, self.color_fk, "cube", w=self.length0, h=self.size*.1, d=self.size*.1, po=dt.Vector(.5*self.length0*self.n_factor,0,0))

        t = tra.getTransformLookingAt(self.guide.apos[1], self.guide.apos[2], self.normal, "xz", self.negate)
        self.fk1_ctl = self.addCtl(self.fk0_ctl, "fk1_ctl", t, self.color_fk, "cube", w=self.length1, h=self.size*.1, d=self.size*.1, po=dt.Vector(.5*self.length1*self.n_factor,0,0))

        t = tra.getTransformLookingAt(self.guide.apos[2], self.guide.apos[3], self.normal, "xz", self.negate)
        self.fk2_ctl = self.addCtl(self.fk1_ctl, "fk2_ctl", t, self.color_fk, "cube", w=self.length2, h=self.size*.1, d=self.size*.1, po=dt.Vector(.5*self.length2*self.n_factor,0,0))
        self.fk_ctl = [self.fk0_ctl, self.fk1_ctl, self.fk2_ctl]

        # IK Controlers -----------------------------------

        self.ik_cns = pri.addTransformFromPos(self.root, self.getName("ik_cns"), self.guide.pos["wrist"])

        self.ikcns_ctl = self.addCtl(self.ik_cns, "ikcns_ctl", tra.getTransformFromPos(self.guide.pos["wrist"]), self.color_ik, "null", w=self.size*.12)

        ### IK CONTROLER POSE IS DIFFERENT
        m = tra.getTransformLookingAt(self.guide.pos["wrist"], self.guide.pos["eff"], self.normal, "xz", False)
        self.ik_ctl = self.addCtl(self.ikcns_ctl, "ik_ctl", m, self.color_ik, "cube", w=self.size*.12, h=self.size*.12, d=self.size*.12)

        # upv
        v = self.guide.apos[2] - self.guide.apos[0]
        v = self.normal ^ v
        v.normalize()
        v *= self.size*.5
        v += self.guide.apos[1]

        self.upv_cns = pri.addTransformFromPos(self.root, self.getName("upv_cns"), v)

        self.upv_ctl = self.addCtl(self.upv_cns, "upv_ctl", tra.getTransform(self.upv_cns), self.color_ik, "diamond", w=self.size*.12)
        att.setKeyableAttributes(self.upv_ctl, self.t_params)

        # References --------------------------------------
        self.ik_ref = pri.addTransform(self.ik_ctl, self.getName("ik_ref"), tra.getTransform(self.ik_ctl))
        self.fk_ref = pri.addTransform(self.fk_ctl[2], self.getName("fk_ref"), tra.getTransform(self.ik_ctl))

        # Chain --------------------------------------------
        # The outputs of the ikfk2bone solver
        self.bone0 = pri.addLocator(self.root, self.getName("0_jnt"), tra.getTransform(self.fk_ctl[0]))
        self.bone0_shp = self.bone0.getShape()
        self.bone0_shp.setAttr("localPositionX", self.n_factor*.5)
        self.bone0_shp.setAttr("localScale", .5, 0, 0)
        self.bone0.setAttr("sx", self.length0)
        self.bone0.setAttr("visibility", False)

        self.bone1 = pri.addLocator(self.root, self.getName("1_jnt"), tra.getTransform(self.fk_ctl[1]))
        self.bone1_shp = self.bone1.getShape()
        self.bone1_shp.setAttr("localPositionX", self.n_factor*.5)
        self.bone1_shp.setAttr("localScale", .5, 0, 0)
        self.bone1.setAttr("sx", self.length1)
        self.bone1.setAttr("visibility", False)

        self.ctrn_loc = pri.addTransformFromPos(self.root, self.getName("ctrn_loc"), self.guide.apos[1])
        self.eff_loc  = pri.addTransformFromPos(self.root, self.getName("eff_loc"), self.guide.apos[2])

        # Mid Controler ------------------------------------
        self.mid_ctl = self.addCtl(self.ctrn_loc, "mid_ctl", tra.getTransform(self.ctrn_loc), self.color_ik, "sphere", w=self.size*.2)

        # Twist references ---------------------------------
        x = dt.Vector(0,-1,0)
        x = x * tra.getTransform(self.eff_loc)
        z = dt.Vector(self.normal.x,self.normal.y,self.normal.z)
        z = z * tra.getTransform(self.eff_loc)

        m = tra.getRotationFromAxis(x, z, "xz", self.negate)
        m = tra.setMatrixPosition(m, tra.getTranslation(self.ik_ctl))

        self.tws0_loc = pri.addTransform(self.root, self.getName("tws0_loc"), tra.getTransform(self.fk_ctl[0]))
        self.tws0_rot = pri.addTransform(self.tws0_loc, self.getName("tws0_rot"), tra.getTransform(self.fk_ctl[0]))

        self.tws1_loc = pri.addTransform(self.ctrn_loc, self.getName("tws1_loc"), tra.getTransform(self.ctrn_loc))
        self.tws1_rot = pri.addTransform(self.tws1_loc, self.getName("tws1_rot"), tra.getTransform(self.ctrn_loc))

        self.tws2_loc = pri.addTransform(self.root, self.getName("tws2_loc"), tra.getTransform(self.fk_ctl[2]))
        self.tws2_rot = pri.addTransform(self.tws2_loc, self.getName("tws2_rot"), tra.getTransform(self.fk_ctl[2]))
        self.tws2_rot.setAttr("sx", .001)

        # Divisions ----------------------------------------
        # We have at least one division at the start, the end and one for the elbow.
        self.divisions = self.settings["div0"] + self.settings["div1"] + 3

        self.div_cns = []
        for i in range(self.divisions):

            div_cns = pri.addTransform(self.root, self.getName("div%s_loc" % i))

            self.div_cns.append(div_cns)

            self.addShadow(div_cns, i)

        # End reference ------------------------------------
        # To help the deformation on the wrist
        self.end_ref = pri.addTransform(self.tws2_rot, self.getName("end_ref"), m)
        self.addShadow(self.end_ref, "end")
Exemple #22
0
    def addObjects(self):
        """Add all the objects needed to create the component."""

        self.WIP = self.options["mode"]

        self.normal = self.getNormalFromPos(self.guide.apos)

        self.length0 = vector.getDistance(self.guide.apos[0],
                                          self.guide.apos[1])
        self.length1 = vector.getDistance(self.guide.apos[1],
                                          self.guide.apos[2])
        self.length2 = vector.getDistance(self.guide.apos[2],
                                          self.guide.apos[3])

        # 1 bone chain for upv ref
        self.legChainUpvRef = primitive.add2DChain(
            self.root, self.getName("legUpvRef%s_jnt"),
            [self.guide.apos[0], self.guide.apos[2]], self.normal, False,
            self.WIP)

        self.legChainUpvRef[1].setAttr(
            "jointOrientZ",
            self.legChainUpvRef[1].getAttr("jointOrientZ") * -1)

        # extra neutral pose
        t = transform.getTransformFromPos(self.guide.apos[0])

        self.root_npo = primitive.addTransform(self.root,
                                               self.getName("root_npo"), t)
        self.root_ctl = self.addCtl(self.root_npo,
                                    "root_ctl",
                                    t,
                                    self.color_fk,
                                    "circle",
                                    w=self.length0 / 6,
                                    tp=self.parentCtlTag)

        # FK Controlers -----------------------------------
        t = transform.getTransformLookingAt(self.guide.apos[0],
                                            self.guide.apos[1], self.normal,
                                            "xz", self.negate)
        self.fk0_npo = primitive.addTransform(self.root_ctl,
                                              self.getName("fk0_npo"), t)
        po_vec = datatypes.Vector(.5 * self.length0 * self.n_factor, 0, 0)
        self.fk0_ctl = self.addCtl(self.fk0_npo,
                                   "fk0_ctl",
                                   t,
                                   self.color_fk,
                                   "cube",
                                   w=self.length0,
                                   h=self.size * .1,
                                   d=self.size * .1,
                                   po=po_vec,
                                   tp=self.root_ctl)
        attribute.setKeyableAttributes(
            self.fk0_ctl, ["tx", "ty", "tz", "ro", "rx", "ry", "rz", "sx"])

        t = transform.getTransformLookingAt(self.guide.apos[1],
                                            self.guide.apos[2], self.normal,
                                            "xz", self.negate)

        self.fk1_npo = primitive.addTransform(self.fk0_ctl,
                                              self.getName("fk1_npo"), t)

        po_vec = datatypes.Vector(.5 * self.length1 * self.n_factor, 0, 0)
        self.fk1_ctl = self.addCtl(self.fk1_npo,
                                   "fk1_ctl",
                                   t,
                                   self.color_fk,
                                   "cube",
                                   w=self.length1,
                                   h=self.size * .1,
                                   d=self.size * .1,
                                   po=po_vec,
                                   tp=self.fk0_ctl)

        attribute.setKeyableAttributes(
            self.fk1_ctl, ["tx", "ty", "tz", "ro", "rx", "ry", "rz", "sx"])

        t = transform.getTransformLookingAt(self.guide.apos[2],
                                            self.guide.apos[3], self.normal,
                                            "xz", self.negate)

        self.fk2_npo = primitive.addTransform(self.fk1_ctl,
                                              self.getName("fk2_npo"), t)

        po_vec = datatypes.Vector(.5 * self.length2 * self.n_factor, 0, 0)
        self.fk2_ctl = self.addCtl(self.fk2_npo,
                                   "fk2_ctl",
                                   t,
                                   self.color_fk,
                                   "cube",
                                   w=self.length2,
                                   h=self.size * .1,
                                   d=self.size * .1,
                                   po=po_vec,
                                   tp=self.fk1_ctl)
        attribute.setKeyableAttributes(self.fk2_ctl)

        self.fk_ctl = [self.fk0_ctl, self.fk1_ctl, self.fk2_ctl]

        for x in self.fk_ctl:
            attribute.setInvertMirror(x, ["tx", "ty", "tz"])

        # IK Controlers -----------------------------------

        self.ik_cns = primitive.addTransformFromPos(self.root_ctl,
                                                    self.getName("ik_cns"),
                                                    self.guide.pos["ankle"])

        self.ikcns_ctl = self.addCtl(self.ik_cns,
                                     "ikcns_ctl",
                                     transform.getTransformFromPos(
                                         self.guide.pos["ankle"]),
                                     self.color_ik,
                                     "null",
                                     w=self.size * .12,
                                     tp=self.root_ctl)
        attribute.setInvertMirror(self.ikcns_ctl, ["tx"])

        m = transform.getTransformLookingAt(self.guide.pos["ankle"],
                                            self.guide.pos["eff"], self.x_axis,
                                            "zx", False)

        self.ik_ctl = self.addCtl(self.ikcns_ctl,
                                  "ik_ctl",
                                  transform.getTransformFromPos(
                                      self.guide.pos["ankle"]),
                                  self.color_ik,
                                  "cube",
                                  w=self.size * .12,
                                  h=self.size * .12,
                                  d=self.size * .12,
                                  tp=self.ikcns_ctl)
        attribute.setKeyableAttributes(self.ik_ctl)
        attribute.setRotOrder(self.ik_ctl, "XZY")
        attribute.setInvertMirror(self.ik_ctl, ["tx", "ry", "rz"])

        # upv
        v = self.guide.apos[2] - self.guide.apos[0]
        v = self.normal ^ v
        v.normalize()
        v *= self.size * .5
        v += self.guide.apos[1]

        self.upv_cns = primitive.addTransformFromPos(self.ik_ctl,
                                                     self.getName("upv_cns"),
                                                     v)

        self.upv_ctl = self.addCtl(self.upv_cns,
                                   "upv_ctl",
                                   transform.getTransform(self.upv_cns),
                                   self.color_ik,
                                   "diamond",
                                   w=self.size * .12,
                                   tp=self.root_ctl)
        if self.settings["mirrorMid"]:
            if self.negate:
                self.upv_cns.rz.set(180)
                self.upv_cns.sy.set(-1)
        else:
            attribute.setInvertMirror(self.upv_ctl, ["tx"])
        attribute.setKeyableAttributes(self.upv_ctl, self.t_params)

        # References --------------------------------------
        self.ik_ref = primitive.addTransform(
            self.ik_ctl, self.getName("ik_ref"),
            transform.getTransform(self.ik_ctl))
        self.fk_ref = primitive.addTransform(
            self.fk_ctl[2], self.getName("fk_ref"),
            transform.getTransform(self.ik_ctl))

        # Chain --------------------------------------------
        # The outputs of the ikfk2bone solver
        self.bone0 = primitive.addLocator(
            self.root_ctl, self.getName("0_bone"),
            transform.getTransform(self.fk_ctl[0]))

        self.bone0_shp = self.bone0.getShape()
        self.bone0_shp.setAttr("localPositionX", self.n_factor * .5)
        self.bone0_shp.setAttr("localScale", .5, 0, 0)
        self.bone0.setAttr("sx", self.length0)
        self.bone0.setAttr("visibility", False)

        self.bone1 = primitive.addLocator(
            self.root_ctl, self.getName("1_bone"),
            transform.getTransform(self.fk_ctl[1]))
        self.bone1_shp = self.bone1.getShape()
        self.bone1_shp.setAttr("localPositionX", self.n_factor * .5)
        self.bone1_shp.setAttr("localScale", .5, 0, 0)
        self.bone1.setAttr("sx", self.length1)
        self.bone1.setAttr("visibility", False)

        self.ctrn_loc = primitive.addTransformFromPos(self.root_ctl,
                                                      self.getName("ctrn_loc"),
                                                      self.guide.apos[1])
        self.eff_loc = primitive.addTransformFromPos(self.root_ctl,
                                                     self.getName("eff_loc"),
                                                     self.guide.apos[2])

        # tws_ref
        t = transform.getRotationFromAxis(datatypes.Vector(0, -1, 0),
                                          self.normal, "xz", self.negate)
        t = transform.setMatrixPosition(t, self.guide.pos["ankle"])

        self.tws_ref = primitive.addTransform(self.eff_loc,
                                              self.getName("tws_ref"), t)

        # Mid Controler ------------------------------------
        t = transform.getTransform(self.ctrn_loc)
        self.mid_cns = primitive.addTransform(self.ctrn_loc,
                                              self.getName("mid_cns"), t)
        self.mid_ctl = self.addCtl(self.mid_cns,
                                   "mid_ctl",
                                   t,
                                   self.color_ik,
                                   "sphere",
                                   w=self.size * .2,
                                   tp=self.root_ctl)

        if self.settings["mirrorMid"]:
            if self.negate:
                self.mid_cns.rz.set(180)
                self.mid_cns.sz.set(-1)
        else:
            attribute.setInvertMirror(self.mid_ctl, ["tx", "ty", "tz"])

        # Twist references ---------------------------------
        x = datatypes.Vector(0, -1, 0)
        x = x * transform.getTransform(self.eff_loc)
        z = datatypes.Vector(self.normal.x, self.normal.y, self.normal.z)
        z = z * transform.getTransform(self.eff_loc)

        m = transform.getRotationFromAxis(x, z, "xz", self.negate)
        m = transform.setMatrixPosition(m,
                                        transform.getTranslation(self.ik_ctl))

        self.rollRef = primitive.add2DChain(self.root,
                                            self.getName("rollChain"),
                                            self.guide.apos[:2], self.normal,
                                            self.negate, self.WIP)

        self.tws0_loc = primitive.addTransform(
            self.rollRef[0], self.getName("tws0_loc"),
            transform.getTransform(self.fk_ctl[0]))

        self.tws0_rot = primitive.addTransform(
            self.tws0_loc, self.getName("tws0_rot"),
            transform.getTransform(self.fk_ctl[0]))

        self.tws1_loc = primitive.addTransform(
            self.ctrn_loc, self.getName("tws1_loc"),
            transform.getTransform(self.ctrn_loc))

        self.tws1_rot = primitive.addTransform(
            self.tws1_loc, self.getName("tws1_rot"),
            transform.getTransform(self.ctrn_loc))

        self.tws2_loc = primitive.addTransform(
            self.root_ctl, self.getName("tws2_loc"),
            transform.getTransform(self.tws_ref))

        self.tws2_rot = primitive.addTransform(
            self.tws2_loc, self.getName("tws2_rot"),
            transform.getTransform(self.tws_ref))

        self.tws2_rot.setAttr("sx", .001)

        # Divisions ----------------------------------------
        # We have at least one division at the start, the end and one for
        # the elbow. + 2 for knee angle control
        self.divisions = self.settings["div0"] + self.settings["div1"] + 3 + 2

        self.div_cns = []
        for i in range(self.divisions):

            div_cns = primitive.addTransform(self.root_ctl,
                                             self.getName("div%s_loc" % i))

            self.div_cns.append(div_cns)
            self.jnt_pos.append([div_cns, i])

        # End reference ------------------------------------
        # To help the deformation on the ankle
        self.end_ref = primitive.addTransform(self.tws2_rot,
                                              self.getName("end_ref"), m)
        self.jnt_pos.append([self.end_ref, 'end'])

        # match IK FK references
        self.match_fk0_off = primitive.addTransform(
            self.root, self.getName("matchFk0_npo"),
            transform.getTransform(self.fk_ctl[1]))

        self.match_fk0 = primitive.addTransform(
            self.match_fk0_off, self.getName("fk0_mth"),
            transform.getTransform(self.fk_ctl[0]))

        self.match_fk1_off = primitive.addTransform(
            self.root, self.getName("matchFk1_npo"),
            transform.getTransform(self.fk_ctl[2]))

        self.match_fk1 = primitive.addTransform(
            self.match_fk1_off, self.getName("fk1_mth"),
            transform.getTransform(self.fk_ctl[1]))

        self.match_fk2 = primitive.addTransform(
            self.ik_ctl, self.getName("fk2_mth"),
            transform.getTransform(self.fk_ctl[2]))

        self.match_ik = primitive.addTransform(
            self.fk2_ctl, self.getName("ik_mth"),
            transform.getTransform(self.ik_ctl))

        self.match_ikUpv = primitive.addTransform(
            self.fk0_ctl, self.getName("upv_mth"),
            transform.getTransform(self.upv_ctl))
Exemple #23
0
    def addObjects(self):

        self.div_count = len(self.guide.apos) - 5

        plane = [self.guide.apos[0], self.guide.apos[-4], self.guide.apos[-3]]
        self.normal = self.getNormalFromPos(plane)
        self.binormal = self.getBiNormalFromPos(plane)

        # Heel ---------------------------------------------
        # bank pivot
        t = tra.getTransformLookingAt(self.guide.pos["heel"], self.guide.apos[-4], self.normal, "xz", self.negate)
        t = tra.setMatrixPosition(t, self.guide.pos["inpivot"])
        self.in_piv = pri.addTransform(self.root, self.getName("in_piv"), t)
        t = tra.setMatrixPosition(t, self.guide.pos["outpivot"])
        self.out_piv = pri.addTransform(self.in_piv, self.getName("out_piv"), t)

        # heel
        t = tra.getTransformLookingAt(self.guide.pos["heel"], self.guide.apos[-4], self.normal, "xz", self.negate)

        self.heel_loc = pri.addTransform(self.out_piv, self.getName("heel_loc"), t)
        att.setRotOrder(self.heel_loc, "YZX")
        self.heel_ctl = self.addCtl(self.heel_loc, "heel_ctl", t, self.color_ik, "sphere", w=self.size*.1)
        att.setKeyableAttributes(self.heel_ctl, self.r_params)

        # Tip ----------------------------------------------
        v = dt.Vector(self.guide.apos[-5].x,self.guide.apos[-1].y,self.guide.apos[-5].z)
        t = tra.setMatrixPosition(t, v)
        self.tip_ctl = self.addCtl(self.heel_ctl, "tip_ctl", t, self.color_ik, "circle", w=self.size)
        att.setKeyableAttributes(self.tip_ctl, self.r_params)

        # Roll ---------------------------------------------
        if self.settings["roll"] == 0:
            t = tra.getRotationFromAxis(self.y_axis, self.normal, "yz", self.negate)
            t = tra.setMatrixPosition(t, self.guide.pos["root"])

            self.roll_np = pri.addTransform(self.root, self.getName("roll_np"), t)
            self.roll_ctl = self.addCtl(self.roll_np, "roll_ctl", t, self.color_ik, "cylinder", w=self.size*.5, h=self.size*.5, ro=dt.Vector(3.1415*.5,0,0))
            att.setKeyableAttributes(self.roll_ctl, ["rx", "rz"])

        # Backward Controlers ------------------------------
        bk_pos = self.guide.apos[1:-3]
        bk_pos.reverse()
        parent = self.tip_ctl
        self.bk_ctl = []
        self.bk_loc = []
        for i, pos in enumerate(bk_pos):

            if i == 0:
                t = tra.getTransform(self.heel_ctl)
                t = tra.setMatrixPosition(t, pos)
            else:
                dir = bk_pos[i-1]
                t = tra.getTransformLookingAt(pos, dir, self.normal, "xz", self.negate)

            bk_loc = pri.addTransform(parent, self.getName("bk%s_loc"%i), t)
            bk_ctl = self.addCtl(bk_loc, "bk%s_ctl"%i, t, self.color_ik, "sphere", w=self.size*.15)
            att.setKeyableAttributes(bk_ctl, self.r_params)

            self.bk_loc.append(bk_loc)
            self.bk_ctl.append(bk_ctl)
            parent = bk_ctl

        # FK Reference ------------------------------------
        self.fk_ref = pri.addTransformFromPos(self.bk_ctl[-1], self.getName("fk_ref"), self.guide.apos[0])
        self.fk_npo = pri.addTransform(self.fk_ref, self.getName("fk0_npo"), tra.getTransform(self.bk_ctl[-1]))

        # Forward Controlers ------------------------------
        self.fk_ctl = []
        self.fk_loc = []
        parent = self.fk_npo
        for i, bk_ctl in enumerate(reversed(self.bk_ctl[1:])):
            t = tra.getTransform(bk_ctl)
            dist = vec.getDistance(self.guide.apos[i+1], self.guide.apos[i+2])

            # fk_npo = pri.addTransform(parent, self.getName("fk%s_npo"%i), t)
            fk_loc = pri.addTransform(parent, self.getName("fk%s_loc"%i), t)
            fk_ctl = self.addCtl(fk_loc, "fk%s_ctl"%i, t, self.color_fk, "cube", w=dist, h=self.size*.5, d=self.size*.5, po=dt.Vector(dist*.5*self.n_factor,0,0))
            att.setKeyableAttributes(fk_ctl)
            self.addShadow(fk_ctl, i)

            parent = fk_ctl
            self.fk_ctl.append(fk_ctl)
            self.fk_loc.append(fk_loc)
Exemple #24
0
    def addObjects(self):

        self.normal = self.getNormalFromPos(self.guide.apos)
        self.binormal = self.getBiNormalFromPos(self.guide.apos)

        self.length0 = vec.getDistance(self.guide.apos[0], self.guide.apos[1])
        self.length1 = vec.getDistance(self.guide.apos[1], self.guide.apos[2])
        self.length2 = vec.getDistance(self.guide.apos[2], self.guide.apos[3])

        # FK Controlers -----------------------------------
        # *ms* set npo @ Tpose, to make the fk rotation work best with rot order"yzx"

        self.fk_cns = pri.addTransformFromPos(self.root,
                                              self.getName("fk_cns"),
                                              self.guide.apos[0])

        tpv = self.guide.apos[0] + (
            (self.guide.apos[1] - self.guide.apos[0]) * [1, 0, 0])
        t = tra.getTransformLookingAt(self.guide.apos[0], tpv, self.normal,
                                      "xz", self.negate)
        # *ms* add FK isolation
        self.fk0_npo = pri.addTransform(self.fk_cns, self.getName("fk0_npo"),
                                        t)

        t = tra.getTransformLookingAt(self.guide.apos[0], self.guide.apos[1],
                                      self.normal, "xz", self.negate)
        self.fk0_ctl = self.addCtl(self.fk0_npo,
                                   "fk0_ctl",
                                   t,
                                   self.color_fk,
                                   "cube",
                                   w=self.length0 * .55,
                                   h=self.size * .1,
                                   d=self.size * .1,
                                   po=dt.Vector(
                                       .35 * self.length0 * self.n_factor, 0,
                                       0))
        att.setKeyableAttributes(self.fk0_ctl)
        # *ms* add fk roll control Simage style
        self.fk0_roll_ctl = self.addCtl(self.fk0_ctl,
                                        "fk0_roll_ctl",
                                        t,
                                        self.color_fk,
                                        "cube",
                                        w=self.length0 * .45,
                                        h=self.size * .1,
                                        d=self.size * .1,
                                        po=dt.Vector(
                                            .85 * self.length0 * self.n_factor,
                                            0, 0))
        att.setKeyableAttributes(self.fk0_roll_ctl)

        t = tra.getTransformLookingAt(self.guide.apos[1], self.guide.apos[2],
                                      self.normal, "xz", self.negate)
        self.fk1_npo = pri.addTransform(self.fk0_roll_ctl,
                                        self.getName("fk1_npo"), t)
        self.fk1_ctl = self.addCtl(self.fk1_npo,
                                   "fk1_ctl",
                                   t,
                                   self.color_fk,
                                   "cube",
                                   w=self.length1,
                                   h=self.size * .1,
                                   d=self.size * .1,
                                   po=dt.Vector(
                                       .5 * self.length1 * self.n_factor, 0,
                                       0))
        att.setKeyableAttributes(self.fk1_ctl)

        t = tra.getTransformLookingAt(self.guide.apos[2], self.guide.apos[3],
                                      self.normal, "xz", self.negate)
        # *ms* buffer object to feed into ikfk solver for hand seperation
        self.fk2_mtx = pri.addTransform(self.fk1_ctl, self.getName("fk2_mtx"),
                                        t)

        # fk2_npo is need to take the effector position
        self.fk2_npo = pri.addTransform(self.fk1_ctl, self.getName("fk2_npo"),
                                        t)
        self.fk2_ctl = self.addCtl(self.fk2_npo,
                                   "fk2_ctl",
                                   t,
                                   self.color_fk,
                                   "cube",
                                   w=self.length2,
                                   h=self.size * .1,
                                   d=self.size * .1,
                                   po=dt.Vector(
                                       .5 * self.length2 * self.n_factor, 0,
                                       0))
        att.setKeyableAttributes(self.fk2_ctl)

        self.fk_ctl = [self.fk0_roll_ctl, self.fk1_ctl, self.fk2_ctl]

        for x in self.fk_ctl:
            att.setInvertMirror(x, ["tx", "ty", "tz"])

        # IK Controlers -----------------------------------

        self.ik_cns = pri.addTransformFromPos(self.root,
                                              self.getName("ik_cns"),
                                              self.guide.pos["wrist"])

        self.ikcns_ctl = self.addCtl(self.ik_cns,
                                     "ikcns_ctl",
                                     tra.getTransformFromPos(
                                         self.guide.pos["wrist"]),
                                     self.color_ik,
                                     "null",
                                     w=self.size * .12)
        att.setInvertMirror(self.ikcns_ctl, ["tx", "ty", "tz"])

        if self.negate:
            m = tra.getTransformLookingAt(self.guide.pos["wrist"],
                                          self.guide.pos["eff"], self.normal,
                                          "x-y", True)
        else:
            m = tra.getTransformLookingAt(self.guide.pos["wrist"],
                                          self.guide.pos["eff"], self.normal,
                                          "xy", False)
        self.ik_ctl = self.addCtl(self.ikcns_ctl,
                                  "ik_ctl",
                                  m,
                                  self.color_ik,
                                  "cube",
                                  w=self.size * .12,
                                  h=self.size * .12,
                                  d=self.size * .12)
        att.setKeyableAttributes(self.ik_ctl)
        att.setInvertMirror(self.ik_ctl, ["tx", "ry", "rz"])

        # upv
        v = self.guide.apos[2] - self.guide.apos[0]
        v = self.normal ^ v
        v.normalize()
        v *= self.size * .5
        v += self.guide.apos[1]
        # *ms* auto up vector ------------------------------
        self.upv_cns = pri.addTransformFromPos(self.root,
                                               self.getName("upv_cns"),
                                               self.guide.apos[0])
        self.upv_auv = pri.addTransformFromPos(self.upv_cns,
                                               self.getName("upv_auv"),
                                               self.guide.apos[0])
        self.upv_mtx = pri.addTransformFromPos(self.upv_cns,
                                               self.getName("upv_mtx"),
                                               self.guide.apos[0])

        self.upv_npo = pri.addTransformFromPos(self.upv_mtx,
                                               self.getName("upv_npo"), v)
        self.upv_ctl = self.addCtl(self.upv_npo,
                                   "upv_ctl",
                                   tra.getTransform(self.upv_npo),
                                   self.color_ik,
                                   "diamond",
                                   w=self.size * .12)
        att.setKeyableAttributes(self.upv_ctl, self.t_params)
        att.setInvertMirror(self.upv_ctl, ["tx"])

        # References --------------------------------------
        # Calculate  again the transfor for the IK ref. This way align with FK
        trnIK_ref = tra.getTransformLookingAt(self.guide.pos["wrist"],
                                              self.guide.pos["eff"],
                                              self.normal, "xz", self.negate)
        self.ik_ref = pri.addTransform(self.ik_ctl, self.getName("ik_ref"),
                                       trnIK_ref)
        self.fk_ref = pri.addTransform(self.fk_ctl[2], self.getName("fk_ref"),
                                       trnIK_ref)

        # Chain --------------------------------------------
        # The outputs of the ikfk2bone solver
        self.bone0 = pri.addLocator(self.root, self.getName("0_bone"),
                                    tra.getTransform(self.fk_ctl[0]))
        self.bone0_shp = self.bone0.getShape()
        self.bone0_shp.setAttr("localPositionX", self.n_factor * .5)
        self.bone0_shp.setAttr("localScale", .5, 0, 0)
        self.bone0.setAttr("sx", self.length0)
        self.bone0.setAttr("visibility", False)

        self.bone1 = pri.addLocator(self.root, self.getName("1_bone"),
                                    tra.getTransform(self.fk_ctl[1]))
        self.bone1_shp = self.bone1.getShape()
        self.bone1_shp.setAttr("localPositionX", self.n_factor * .5)
        self.bone1_shp.setAttr("localScale", .5, 0, 0)
        self.bone1.setAttr("sx", self.length1)
        self.bone1.setAttr("visibility", False)

        self.ctrn_loc = pri.addTransformFromPos(self.root,
                                                self.getName("ctrn_loc"),
                                                self.guide.apos[1])
        self.eff_npo = pri.addTransformFromPos(self.root,
                                               self.getName("eff_npo"),
                                               self.guide.apos[2])
        self.eff_loc = pri.addTransformFromPos(self.eff_npo,
                                               self.getName("eff_loc"),
                                               self.guide.apos[2])

        # Mid Controler ------------------------------------
        self.mid_ctl = self.addCtl(self.ctrn_loc,
                                   "mid_ctl",
                                   tra.getTransform(self.ctrn_loc),
                                   self.color_ik,
                                   "sphere",
                                   w=self.size * .2)
        att.setInvertMirror(self.mid_ctl, ["tx", "ty", "tz"])
        # *ms* add elbow thickness

        # # Twist references ---------------------------------
        # x = dt.Vector(0,-1,0)
        # x = x * tra.getTransform(self.eff_loc)
        # z = dt.Vector(self.normal.x,self.normal.y,self.normal.z)
        # z = z * tra.getTransform(self.eff_loc)

        # m = tra.getRotationFromAxis(x, z, "xz", self.negate)
        # m = tra.setMatrixPosition(m, tra.getTranslation(self.ik_ctl))

        #Roll join ref
        #self.rollRef = pri.add2DChain(self.root, self.getName("rollChain"), self.guide.apos[:2], self.normal, self.negate)
        #for x in self.rollRef:
        #   x.setAttr("visibility", False)

        self.tws0_npo = pri.addTransform(self.root, self.getName("tws0_npo"),
                                         tra.getTransform(self.fk_ctl[0]))
        self.tws0_loc = pri.addTransform(self.tws0_npo,
                                         self.getName("tws0_loc"),
                                         tra.getTransform(self.fk_ctl[0]))
        self.tws0_rot = pri.addTransform(self.tws0_loc,
                                         self.getName("tws0_rot"),
                                         tra.getTransform(self.fk_ctl[0]))

        self.tws1_npo = pri.addTransform(self.ctrn_loc,
                                         self.getName("tws1_npo"),
                                         tra.getTransform(self.ctrn_loc))
        self.tws1_loc = pri.addTransform(self.tws1_npo,
                                         self.getName("tws1_loc"),
                                         tra.getTransform(self.ctrn_loc))
        self.tws1_rot = pri.addTransform(self.tws1_loc,
                                         self.getName("tws1_rot"),
                                         tra.getTransform(self.ctrn_loc))

        self.tws2_npo = pri.addTransform(self.root, self.getName("tws2_npo"),
                                         tra.getTransform(self.fk_ctl[2]))
        self.tws2_loc = pri.addTransform(self.tws2_npo,
                                         self.getName("tws2_loc"),
                                         tra.getTransform(self.fk_ctl[2]))
        self.tws2_rot = pri.addTransform(self.tws2_loc,
                                         self.getName("tws2_rot"),
                                         tra.getTransform(self.fk_ctl[2]))

        # Divisions ----------------------------------------
        # We have at least one division at the start, the end and one for the elbow. + 2 for elbow angle control
        self.divisions = self.settings["div0"] + self.settings["div1"] + 3 + 2

        self.div_cns = []
        for i in range(self.divisions):

            div_cns = pri.addTransform(self.root,
                                       self.getName("div%s_loc" % i))

            self.div_cns.append(div_cns)
            self.jnt_pos.append([div_cns, i])

        # End reference ------------------------------------
        # To help the deformation on the wrist
        self.jnt_pos.append([self.eff_loc, 'end'])
        # self.end_ref = pri.addTransform(self.eff_loc, self.getName("end_ref"), m)
        # for a in "xyz":
        #         self.end_ref.attr("s%s"%a).set(1.0)
        #         self.end_ref.attr("r%s"%a).set(0.0)
        # self.jnt_pos.append([self.end_ref, 'end'])

        #match IK FK references
        self.match_fk0_off = pri.addTransform(self.root,
                                              self.getName("matchFk0_npo"),
                                              tra.getTransform(self.fk_ctl[1]))
        # self.match_fk0_off.attr("tx").set(1.0)
        self.match_fk0 = pri.addTransform(self.match_fk0_off,
                                          self.getName("fk0_mth"),
                                          tra.getTransform(self.fk_ctl[0]))

        self.match_fk1_off = pri.addTransform(self.root,
                                              self.getName("matchFk1_npo"),
                                              tra.getTransform(self.fk_ctl[2]))
        # self.match_fk1_off.attr("tx").set(1.0)
        self.match_fk1 = pri.addTransform(self.match_fk1_off,
                                          self.getName("fk1_mth"),
                                          tra.getTransform(self.fk_ctl[1]))
        self.match_fk2 = pri.addTransform(self.ik_ctl, self.getName("fk2_mth"),
                                          tra.getTransform(self.fk_ctl[2]))

        self.match_ik = pri.addTransform(self.fk2_ctl, self.getName("ik_mth"),
                                         tra.getTransform(self.ik_ctl))
        self.match_ikUpv = pri.addTransform(self.fk0_ctl,
                                            self.getName("upv_mth"),
                                            tra.getTransform(self.upv_ctl))
Exemple #25
0
    def addObjects(self):
        """Add all the objects needed to create the component."""

        self.WIP = self.options["mode"]

        self.normal = self.getNormalFromPos(self.guide.apos)

        self.length0 = vector.getDistance(self.guide.apos[0],
                                          self.guide.apos[1])
        self.length1 = vector.getDistance(self.guide.apos[1],
                                          self.guide.apos[2])
        self.length2 = vector.getDistance(self.guide.apos[2],
                                          self.guide.apos[3])

        # 1 bone chain for upv ref
        self.legChainUpvRef = primitive.add2DChain(
            self.root, self.getName("legUpvRef%s_jnt"),
            [self.guide.apos[0], self.guide.apos[2]], self.normal, False,
            self.WIP)
        self.legChainUpvRef[1].setAttr(
            "jointOrientZ",
            self.legChainUpvRef[1].getAttr("jointOrientZ") * -1)

        # extra neutral pose
        t = transform.getTransformFromPos(self.guide.apos[0])

        self.root_npo = primitive.addTransform(self.root,
                                               self.getName("root_npo"), t)
        self.root_ctl = self.addCtl(self.root_npo,
                                    "root_ctl",
                                    t,
                                    self.color_fk,
                                    "circle",
                                    w=self.length0 / 6,
                                    tp=self.parentCtlTag)

        # FK Controlers -----------------------------------
        t = transform.getTransformLookingAt(self.guide.apos[0],
                                            self.guide.apos[1], self.normal,
                                            "xz", self.negate)
        self.fk0_npo = primitive.addTransform(self.root_ctl,
                                              self.getName("fk0_npo"), t)
        self.fk0_ctl = self.addCtl(self.fk0_npo,
                                   "fk0_ctl",
                                   t,
                                   self.color_fk,
                                   "cube",
                                   w=self.length0,
                                   h=self.size * .1,
                                   d=self.size * .1,
                                   po=datatypes.Vector(
                                       .5 * self.length0 * self.n_factor, 0,
                                       0),
                                   tp=self.root_ctl)
        attribute.setKeyableAttributes(
            self.fk0_ctl, ["tx", "ty", "tz", "ro", "rx", "ry", "rz", "sx"])

        t = transform.getTransformLookingAt(self.guide.apos[1],
                                            self.guide.apos[2], self.normal,
                                            "xz", self.negate)
        self.fk1_npo = primitive.addTransform(self.fk0_ctl,
                                              self.getName("fk1_npo"), t)
        self.fk1_ctl = self.addCtl(self.fk1_npo,
                                   "fk1_ctl",
                                   t,
                                   self.color_fk,
                                   "cube",
                                   w=self.length1,
                                   h=self.size * .1,
                                   d=self.size * .1,
                                   po=datatypes.Vector(
                                       .5 * self.length1 * self.n_factor, 0,
                                       0),
                                   tp=self.fk0_ctl)

        attribute.setKeyableAttributes(
            self.fk1_ctl, ["tx", "ty", "tz", "ro", "rx", "ry", "rz", "sx"])

        t = transform.getTransformLookingAt(self.guide.apos[2],
                                            self.guide.apos[3], self.normal,
                                            "xz", self.negate)

        self.fk2_npo = primitive.addTransform(self.fk1_ctl,
                                              self.getName("fk2_npo"), t)

        self.fk2_ctl = self.addCtl(self.fk2_npo,
                                   "fk2_ctl",
                                   t,
                                   self.color_fk,
                                   "cube",
                                   w=self.length2,
                                   h=self.size * .1,
                                   d=self.size * .1,
                                   po=datatypes.Vector(
                                       .5 * self.length2 * self.n_factor, 0,
                                       0),
                                   tp=self.fk1_ctl)
        attribute.setKeyableAttributes(self.fk2_ctl)

        self.fk_ctl = [self.fk0_ctl, self.fk1_ctl, self.fk2_ctl]

        for x in self.fk_ctl:
            attribute.setInvertMirror(x, ["tx", "ty", "tz"])

        # IK Controlers -----------------------------------

        self.ik_cns = primitive.addTransformFromPos(self.root_ctl,
                                                    self.getName("ik_cns"),
                                                    self.guide.pos["ankle"])

        self.ikcns_ctl = self.addCtl(self.ik_cns,
                                     "ikcns_ctl",
                                     transform.getTransformFromPos(
                                         self.guide.pos["ankle"]),
                                     self.color_ik,
                                     "null",
                                     w=self.size * .12,
                                     tp=self.root_ctl)
        attribute.setInvertMirror(self.ikcns_ctl, ["tx"])

        m = transform.getTransformLookingAt(self.guide.pos["ankle"],
                                            self.guide.pos["eff"], self.x_axis,
                                            "zx", False)

        self.ik_ctl = self.addCtl(self.ikcns_ctl,
                                  "ik_ctl",
                                  transform.getTransformFromPos(
                                      self.guide.pos["ankle"]),
                                  self.color_ik,
                                  "cube",
                                  w=self.size * .12,
                                  h=self.size * .12,
                                  d=self.size * .12,
                                  tp=self.ikcns_ctl)
        attribute.setKeyableAttributes(self.ik_ctl)
        attribute.setRotOrder(self.ik_ctl, "XZY")
        attribute.setInvertMirror(self.ik_ctl, ["tx", "ry", "rz"])

        # upv
        v = self.guide.apos[2] - self.guide.apos[0]
        v = self.normal ^ v
        v.normalize()
        v *= self.size * .5
        v += self.guide.apos[1]

        self.upv_cns = primitive.addTransformFromPos(self.ik_ctl,
                                                     self.getName("upv_cns"),
                                                     v)

        self.upv_ctl = self.addCtl(self.upv_cns,
                                   "upv_ctl",
                                   transform.getTransform(self.upv_cns),
                                   self.color_ik,
                                   "diamond",
                                   w=self.size * .12,
                                   tp=self.root_ctl)

        if self.settings["mirrorMid"]:
            if self.negate:
                self.upv_cns.rz.set(180)
                self.upv_cns.sy.set(-1)
        else:
            attribute.setInvertMirror(self.upv_ctl, ["tx"])
        attribute.setKeyableAttributes(self.upv_ctl, self.t_params)

        # References --------------------------------------
        self.ik_ref = primitive.addTransform(
            self.ik_ctl, self.getName("ik_ref"),
            transform.getTransform(self.ik_ctl))
        self.fk_ref = primitive.addTransform(
            self.fk_ctl[2], self.getName("fk_ref"),
            transform.getTransform(self.ik_ctl))

        # Chain --------------------------------------------
        # The outputs of the ikfk2bone solver
        self.bone0 = primitive.addLocator(
            self.root_ctl, self.getName("0_bone"),
            transform.getTransform(self.fk_ctl[0]))

        self.bone0_shp = self.bone0.getShape()
        self.bone0_shp.setAttr("localPositionX", self.n_factor * .5)
        self.bone0_shp.setAttr("localScale", .5, 0, 0)
        self.bone0.setAttr("sx", self.length0)
        self.bone0.setAttr("visibility", False)

        self.bone1 = primitive.addLocator(
            self.root_ctl, self.getName("1_bone"),
            transform.getTransform(self.fk_ctl[1]))

        self.bone1_shp = self.bone1.getShape()
        self.bone1_shp.setAttr("localPositionX", self.n_factor * .5)
        self.bone1_shp.setAttr("localScale", .5, 0, 0)
        self.bone1.setAttr("sx", self.length1)
        self.bone1.setAttr("visibility", False)

        tA = transform.getTransformLookingAt(self.guide.apos[0],
                                             self.guide.apos[1], self.normal,
                                             "xz", self.negate)
        tA = transform.setMatrixPosition(tA, self.guide.apos[1])
        tB = transform.getTransformLookingAt(self.guide.apos[1],
                                             self.guide.apos[2], self.normal,
                                             "xz", self.negate)
        t = transform.getInterpolateTransformMatrix(tA, tB)
        self.ctrn_loc = primitive.addTransform(self.root,
                                               self.getName("ctrn_loc"), t)
        self.eff_loc = primitive.addTransformFromPos(self.root_ctl,
                                                     self.getName("eff_loc"),
                                                     self.guide.apos[2])

        # tws_ref
        t = transform.getRotationFromAxis(datatypes.Vector(0, -1, 0),
                                          self.normal, "xz", self.negate)
        t = transform.setMatrixPosition(t, self.guide.pos["ankle"])

        self.tws_ref = primitive.addTransform(self.eff_loc,
                                              self.getName("tws_ref"), t)

        # Mid Controler ------------------------------------
        t = transform.getTransform(self.ctrn_loc)
        self.mid_cns = primitive.addTransform(self.ctrn_loc,
                                              self.getName("mid_cns"), t)
        self.mid_ctl = self.addCtl(self.mid_cns,
                                   "mid_ctl",
                                   t,
                                   self.color_ik,
                                   "sphere",
                                   w=self.size * .2,
                                   tp=self.root_ctl)
        if self.settings["mirrorMid"]:
            if self.negate:
                self.mid_cns.rz.set(180)
                self.mid_cns.sz.set(-1)
        else:
            attribute.setInvertMirror(self.mid_ctl, ["tx", "ty", "tz"])
        attribute.setKeyableAttributes(self.mid_ctl, self.t_params)

        # Twist references ---------------------------------
        x = datatypes.Vector(0, -1, 0)
        x = x * transform.getTransform(self.eff_loc)
        z = datatypes.Vector(self.normal.x, self.normal.y, self.normal.z)
        z = z * transform.getTransform(self.eff_loc)

        m = transform.getRotationFromAxis(x, z, "xz", self.negate)
        m = transform.setMatrixPosition(m,
                                        transform.getTranslation(self.ik_ctl))

        self.tws0_loc = primitive.addTransform(
            self.root_ctl, self.getName("tws0_loc"),
            transform.getTransform(self.fk_ctl[0]))
        self.tws0_rot = primitive.addTransform(
            self.tws0_loc, self.getName("tws0_rot"),
            transform.getTransform(self.fk_ctl[0]))

        self.tws1_loc = primitive.addTransform(
            self.ctrn_loc, self.getName("tws1_loc"),
            transform.getTransform(self.ctrn_loc))
        self.tws1_rot = primitive.addTransform(
            self.tws1_loc, self.getName("tws1_rot"),
            transform.getTransform(self.ctrn_loc))

        self.tws1A_npo = primitive.addTransform(self.mid_ctl,
                                                self.getName("tws1A_npo"), tA)
        self.tws1A_loc = primitive.addTransform(self.tws1A_npo,
                                                self.getName("tws1A_loc"), tA)
        self.tws1B_npo = primitive.addTransform(self.mid_ctl,
                                                self.getName("tws1B_npo"), tB)
        self.tws1B_loc = primitive.addTransform(self.tws1B_npo,
                                                self.getName("tws1B_loc"), tB)

        self.tws2_npo = primitive.addTransform(
            self.root, self.getName("tws2_npo"),
            transform.getTransform(self.fk_ctl[2]))
        self.tws2_loc = primitive.addTransform(
            self.tws2_npo, self.getName("tws2_loc"),
            transform.getTransform(self.fk_ctl[2]))
        self.tws2_rot = primitive.addTransform(
            self.tws2_npo, self.getName("tws2_rot"),
            transform.getTransform(self.fk_ctl[2]))

        # Roll twist chain ---------------------------------
        # Arm
        self.uplegChainPos = []
        ii = 1.0 / (self.settings["div0"] + 1)
        i = 0.0
        for p in range(self.settings["div0"] + 2):
            self.uplegChainPos.append(
                vector.linearlyInterpolate(self.guide.pos["root"],
                                           self.guide.pos["knee"],
                                           blend=i))
            i = i + ii

        self.uplegTwistChain = primitive.add2DChain(
            self.root, self.getName("uplegTwist%s_jnt"), self.uplegChainPos,
            self.normal, False, self.WIP)

        # Forearm
        self.lowlegChainPos = []
        ii = 1.0 / (self.settings["div1"] + 1)
        i = 0.0
        for p in range(self.settings["div1"] + 2):
            self.lowlegChainPos.append(
                vector.linearlyInterpolate(self.guide.pos["knee"],
                                           self.guide.pos["ankle"],
                                           blend=i))
            i = i + ii

        self.lowlegTwistChain = primitive.add2DChain(
            self.root, self.getName("lowlegTwist%s_jnt"), self.lowlegChainPos,
            self.normal, False, self.WIP)
        pm.parent(self.lowlegTwistChain[0], self.mid_ctl)

        # Hand Aux chain and nonroll
        self.auxChainPos = []
        ii = .5
        i = 0.0
        for p in range(3):
            self.auxChainPos.append(
                vector.linearlyInterpolate(self.guide.pos["ankle"],
                                           self.guide.pos["eff"],
                                           blend=i))
            i = i + ii
        t = self.root.getMatrix(worldSpace=True)

        self.aux_npo = primitive.addTransform(self.root,
                                              self.getName("aux_npo"), t)
        self.auxTwistChain = primitive.add2DChain(
            self.aux_npo, self.getName("auxTwist%s_jnt"),
            self.lowlegChainPos[:3], self.normal, False, self.WIP)
        # Non Roll join ref ---------------------------------
        self.uplegRollRef = primitive.add2DChain(
            self.root, self.getName("uplegRollRef%s_jnt"),
            self.uplegChainPos[:2], self.normal, False, self.WIP)

        self.lowlegRollRef = primitive.add2DChain(
            self.aux_npo, self.getName("lowlegRollRef%s_jnt"),
            self.lowlegChainPos[:2], self.normal, False, self.WIP)
        # Divisions ----------------------------------------
        # We have at least one division at the start, the end and one for the
        # elbow. + 2 for knee angle control
        self.divisions = self.settings["div0"] + self.settings["div1"] + 4

        self.div_cns = []
        for i in range(self.divisions):

            div_cns = primitive.addTransform(self.root_ctl,
                                             self.getName("div%s_loc" % i))

            self.div_cns.append(div_cns)

            self.jnt_pos.append([div_cns, i])

        # End reference ------------------------------------
        # To help the deformation on the ankle
        self.end_ref = primitive.addTransform(self.eff_loc,
                                              self.getName("end_ref"), m)
        for a in "xyz":
            self.end_ref.attr("s%s" % a).set(1.0)
        if self.negate:
            self.end_ref.attr("ry").set(-180.0)
        self.jnt_pos.append([self.end_ref, 'end'])

        # Tangent controls
        t = transform.getInterpolateTransformMatrix(self.fk_ctl[0],
                                                    self.tws1A_npo, .5)
        self.uplegTangentA_loc = primitive.addTransform(
            self.root_ctl, self.getName("uplegTangentA_loc"),
            self.fk_ctl[0].getMatrix(worldSpace=True))

        self.uplegTangentA_npo = primitive.addTransform(
            self.uplegTangentA_loc, self.getName("uplegTangentA_npo"), t)

        self.uplegTangentA_ctl = self.addCtl(self.uplegTangentA_npo,
                                             "uplegTangentA_ctl",
                                             t,
                                             self.color_ik,
                                             "circle",
                                             w=self.size * .2,
                                             ro=datatypes.Vector(
                                                 0, 0, 1.570796),
                                             tp=self.mid_ctl)

        if self.negate:
            self.uplegTangentA_npo.rz.set(180)
            self.uplegTangentA_npo.sz.set(-1)
        attribute.setKeyableAttributes(self.uplegTangentA_ctl, self.t_params)

        t = transform.getInterpolateTransformMatrix(self.fk_ctl[0],
                                                    self.tws1A_npo, .9)
        self.uplegTangentB_npo = primitive.addTransform(
            self.tws1A_loc, self.getName("uplegTangentB_npo"), t)

        self.uplegTangentB_ctl = self.addCtl(self.uplegTangentB_npo,
                                             "uplegTangentB_ctl",
                                             t,
                                             self.color_ik,
                                             "circle",
                                             w=self.size * .1,
                                             ro=datatypes.Vector(
                                                 0, 0, 1.570796),
                                             tp=self.mid_ctl)

        if self.negate:
            self.uplegTangentB_npo.rz.set(180)
            self.uplegTangentB_npo.sz.set(-1)
        attribute.setKeyableAttributes(self.uplegTangentB_ctl, self.t_params)

        tC = self.tws1B_npo.getMatrix(worldSpace=True)
        tC = transform.setMatrixPosition(tC, self.guide.apos[2])
        t = transform.getInterpolateTransformMatrix(self.tws1B_npo, tC, .1)
        self.lowlegTangentA_npo = primitive.addTransform(
            self.tws1B_loc, self.getName("lowlegTangentA_npo"), t)

        self.lowlegTangentA_ctl = self.addCtl(self.lowlegTangentA_npo,
                                              "lowlegTangentA_ctl",
                                              t,
                                              self.color_ik,
                                              "circle",
                                              w=self.size * .1,
                                              ro=datatypes.Vector(
                                                  0, 0, 1.570796),
                                              tp=self.mid_ctl)

        if self.negate:
            self.lowlegTangentA_npo.rz.set(180)
            self.lowlegTangentA_npo.sz.set(-1)
        attribute.setKeyableAttributes(self.lowlegTangentA_ctl, self.t_params)

        t = transform.getInterpolateTransformMatrix(self.tws1B_npo, tC, .5)

        self.lowlegTangentB_loc = primitive.addTransform(
            self.root, self.getName("lowlegTangentB_loc"), tC)

        self.lowlegTangentB_npo = primitive.addTransform(
            self.lowlegTangentB_loc, self.getName("lowlegTangentB_npo"), t)

        self.lowlegTangentB_ctl = self.addCtl(self.lowlegTangentB_npo,
                                              "lowlegTangentB_ctl",
                                              t,
                                              self.color_ik,
                                              "circle",
                                              w=self.size * .2,
                                              ro=datatypes.Vector(
                                                  0, 0, 1.570796),
                                              tp=self.mid_ctl)

        if self.negate:
            self.lowlegTangentB_npo.rz.set(180)
            self.lowlegTangentB_npo.sz.set(-1)
        attribute.setKeyableAttributes(self.lowlegTangentB_ctl, self.t_params)

        t = self.mid_ctl.getMatrix(worldSpace=True)
        self.kneeTangent_npo = primitive.addTransform(
            self.mid_ctl, self.getName("kneeTangent_npo"), t)

        self.kneeTangent_ctl = self.addCtl(self.kneeTangent_npo,
                                           "kneeTangent_ctl",
                                           t,
                                           self.color_fk,
                                           "circle",
                                           w=self.size * .25,
                                           ro=datatypes.Vector(0, 0, 1.570796),
                                           tp=self.mid_ctl)

        if self.negate:
            self.kneeTangent_npo.rz.set(180)
            self.kneeTangent_npo.sz.set(-1)
        attribute.setKeyableAttributes(self.kneeTangent_ctl, self.t_params)

        # match IK FK references
        self.match_fk0_off = primitive.addTransform(
            self.root, self.getName("matchFk0_npo"),
            transform.getTransform(self.fk_ctl[1]))

        self.match_fk0 = primitive.addTransform(
            self.match_fk0_off, self.getName("fk0_mth"),
            transform.getTransform(self.fk_ctl[0]))

        self.match_fk1_off = primitive.addTransform(
            self.root, self.getName("matchFk1_npo"),
            transform.getTransform(self.fk_ctl[2]))

        self.match_fk1 = primitive.addTransform(
            self.match_fk1_off, self.getName("fk1_mth"),
            transform.getTransform(self.fk_ctl[1]))

        self.match_fk2 = primitive.addTransform(
            self.ik_ctl, self.getName("fk2_mth"),
            transform.getTransform(self.fk_ctl[2]))

        self.match_ik = primitive.addTransform(
            self.fk2_ctl, self.getName("ik_mth"),
            transform.getTransform(self.ik_ctl))

        self.match_ikUpv = primitive.addTransform(
            self.fk0_ctl, self.getName("upv_mth"),
            transform.getTransform(self.upv_ctl))

        # add visual reference
        self.line_ref = icon.connection_display_curve(
            self.getName("visalRef"), [self.upv_ctl, self.mid_ctl])
Exemple #26
0
    def addObjects(self):
        """Add all the objects needed to create the component."""

        self.setup = primitive.addTransformFromPos(self.setupWS,
                                                   self.getName("WS"))
        attribute.lockAttribute(self.setup)

        self.WIP = self.options["mode"]

        self.normal = self.getNormalFromPos(self.guide.apos)

        self.length0 = vector.getDistance(self.guide.apos[0],
                                          self.guide.apos[1])
        self.length1 = vector.getDistance(self.guide.apos[1],
                                          self.guide.apos[2])
        self.length2 = vector.getDistance(self.guide.apos[2],
                                          self.guide.apos[3])
        self.length3 = vector.getDistance(self.guide.apos[3],
                                          self.guide.apos[4])

        # 3bones chain
        self.chain3bones = primitive.add2DChain(
            self.setup, self.getName("chain3bones%s_jnt"),
            self.guide.apos[0:4], self.normal, False, self.WIP)

        # 2bones chain
        self.chain2bones = primitive.add2DChain(
            self.setup, self.getName("chain2bones%s_jnt"),
            self.guide.apos[0:3], self.normal, False, self.WIP)

        # Leg chain
        self.legBones = primitive.add2DChain(self.root,
                                             self.getName("legBones%s_jnt"),
                                             self.guide.apos[0:4], self.normal,
                                             False, self.WIP)

        # Leg chain FK ref
        self.legBonesFK = primitive.add2DChain(self.root,
                                               self.getName("legFK%s_jnt"),
                                               self.guide.apos[0:4],
                                               self.normal, False, self.WIP)

        # Leg chain IK ref
        self.legBonesIK = primitive.add2DChain(self.root,
                                               self.getName("legIK%s_jnt"),
                                               self.guide.apos[0:4],
                                               self.normal, False, self.WIP)

        # 1 bone chain for upv ref
        self.legChainUpvRef = primitive.add2DChain(
            self.root, self.getName("legUpvRef%s_jnt"),
            [self.guide.apos[0], self.guide.apos[3]], self.normal, False,
            self.WIP)

        # mid joints
        self.mid1_jnt = primitive.addJoint(
            self.legBones[0], self.getName("mid1_jnt"),
            self.legBones[1].getMatrix(worldSpace=True), self.WIP)

        self.mid1_jnt.attr("radius").set(3)
        self.mid1_jnt.setAttr("jointOrient", 0, 0, 0)

        self.mid2_jnt = primitive.addJoint(
            self.legBones[1], self.getName("mid2_jnt"),
            self.legBones[2].getMatrix(worldSpace=True), self.WIP)

        self.mid2_jnt.attr("radius").set(3)
        self.mid2_jnt.setAttr("jointOrient", 0, 0, 0)

        # base Controlers -----------------------------------
        t = transform.getTransformFromPos(self.guide.apos[0])
        self.root_npo = primitive.addTransform(self.root,
                                               self.getName("root_npo"), t)

        self.root_ctl = self.addCtl(self.root_npo,
                                    "root_ctl",
                                    t,
                                    self.color_fk,
                                    "circle",
                                    w=self.length0 / 6,
                                    tp=self.parentCtlTag)
        attribute.lockAttribute(self.root_ctl, ["sx", "sy", "sz", "v"])

        # FK Controlers -----------------------------------
        t = transform.getTransformLookingAt(self.guide.apos[0],
                                            self.guide.apos[1], self.normal,
                                            "xz", self.negate)

        self.fk0_npo = primitive.addTransform(self.root_ctl,
                                              self.getName("fk0_npo"), t)

        self.fk0_ctl = self.addCtl(self.fk0_npo,
                                   "fk0_ctl",
                                   t,
                                   self.color_fk,
                                   "cube",
                                   w=self.length0,
                                   h=self.size * .1,
                                   d=self.size * .1,
                                   po=datatypes.Vector(
                                       .5 * self.length0 * self.n_factor, 0,
                                       0),
                                   tp=self.root_ctl)
        attribute.setKeyableAttributes(self.fk0_ctl)

        t = transform.getTransformLookingAt(self.guide.apos[1],
                                            self.guide.apos[2], self.normal,
                                            "xz", self.negate)
        self.fk1_npo = primitive.addTransform(self.fk0_ctl,
                                              self.getName("fk1_npo"), t)
        self.fk1_ctl = self.addCtl(self.fk1_npo,
                                   "fk1_ctl",
                                   t,
                                   self.color_fk,
                                   "cube",
                                   w=self.length1,
                                   h=self.size * .1,
                                   d=self.size * .1,
                                   po=datatypes.Vector(
                                       .5 * self.length1 * self.n_factor, 0,
                                       0),
                                   tp=self.fk0_ctl)
        attribute.setKeyableAttributes(self.fk1_ctl)

        t = transform.getTransformLookingAt(self.guide.apos[2],
                                            self.guide.apos[3], self.normal,
                                            "xz", self.negate)

        self.fk2_npo = primitive.addTransform(self.fk1_ctl,
                                              self.getName("fk2_npo"), t)

        self.fk2_ctl = self.addCtl(self.fk2_npo,
                                   "fk2_ctl",
                                   t,
                                   self.color_fk,
                                   "cube",
                                   w=self.length2,
                                   h=self.size * .1,
                                   d=self.size * .1,
                                   po=datatypes.Vector(
                                       .5 * self.length2 * self.n_factor, 0,
                                       0),
                                   tp=self.fk1_ctl)

        attribute.setKeyableAttributes(self.fk2_ctl)

        t = transform.getTransformLookingAt(self.guide.apos[3],
                                            self.guide.apos[4], self.normal,
                                            "xz", self.negate)

        self.fk3_npo = primitive.addTransform(self.fk2_ctl,
                                              self.getName("fk3_npo"), t)

        self.fk3_ctl = self.addCtl(self.fk3_npo,
                                   "fk3_ctl",
                                   t,
                                   self.color_fk,
                                   "cube",
                                   w=self.length3,
                                   h=self.size * .1,
                                   d=self.size * .1,
                                   po=datatypes.Vector(
                                       .5 * self.length3 * self.n_factor, 0,
                                       0),
                                   tp=self.fk2_ctl)

        attribute.setKeyableAttributes(self.fk3_ctl)

        self.fk_ctl = [self.fk0_ctl, self.fk1_ctl, self.fk2_ctl, self.fk3_ctl]

        for x in self.fk_ctl:
            attribute.setInvertMirror(x, ["tx", "ty", "tz"])

        # Mid Controlers ------------------------------------
        self.knee_lvl = primitive.addTransform(
            self.root, self.getName("knee_lvl"),
            transform.getTransform(self.mid1_jnt))

        self.knee_ctl = self.addCtl(self.knee_lvl,
                                    "knee_ctl",
                                    transform.getTransform(self.mid1_jnt),
                                    self.color_ik,
                                    "sphere",
                                    w=self.size * .2,
                                    tp=self.root_ctl)

        attribute.setInvertMirror(self.knee_ctl, ["tx", "ty", "tz"])
        attribute.lockAttribute(self.knee_ctl, ["sx", "sy", "sz", "v"])

        self.ankle_lvl = primitive.addTransform(
            self.root, self.getName("ankle_lvl"),
            transform.getTransform(self.mid2_jnt))

        self.ankle_ctl = self.addCtl(self.ankle_lvl,
                                     "ankle_ctl",
                                     transform.getTransform(self.mid2_jnt),
                                     self.color_ik,
                                     "sphere",
                                     w=self.size * .2,
                                     tp=self.knee_ctl)

        attribute.setInvertMirror(self.ankle_ctl, ["tx", "ty", "tz"])
        attribute.lockAttribute(self.ankle_ctl, ["sx", "sy", "sz", "v"])

        # IK controls --------------------------------------------------------

        # foot IK

        if self.settings["ikOri"]:
            t = transform.getTransformLookingAt(self.guide.pos["foot"],
                                                self.guide.pos["eff"],
                                                self.x_axis, "zx", False)
        else:
            t = transform.getTransformLookingAt(self.guide.apos[3],
                                                self.guide.apos[4],
                                                self.normal, "z-x", False)

        self.ik_cns = primitive.addTransform(self.root_ctl,
                                             self.getName("ik_cns"), t)

        self.ikcns_ctl = self.addCtl(self.ik_cns,
                                     "ikcns_ctl",
                                     t,
                                     self.color_ik,
                                     "null",
                                     w=self.size * .12,
                                     tp=self.ankle_ctl)

        attribute.setInvertMirror(self.ikcns_ctl, ["tx"])
        attribute.lockAttribute(self.ikcns_ctl, ["sx", "sy", "sz", "v"])

        self.ik_ctl = self.addCtl(self.ikcns_ctl,
                                  "ik_ctl",
                                  t,
                                  self.color_ik,
                                  "cube",
                                  w=self.size * .12,
                                  h=self.size * .12,
                                  d=self.size * .12,
                                  tp=self.ikcns_ctl)
        attribute.setKeyableAttributes(self.ik_ctl)
        attribute.setRotOrder(self.ik_ctl, "XZY")
        attribute.setInvertMirror(self.ik_ctl, ["tx", "ry", "rz"])
        attribute.lockAttribute(self.ik_ctl, ["sx", "sy", "sz", "v"])

        # 2 bones ik layer
        self.ik2b_ikCtl_ref = primitive.addTransform(
            self.ik_ctl, self.getName("ik2B_A_ref"), t)
        self.ik2b_bone_ref = primitive.addTransform(self.chain3bones[3],
                                                    self.getName("ik2B_B_ref"),
                                                    t)
        self.ik2b_blend = primitive.addTransform(self.ik_ctl,
                                                 self.getName("ik2B_blend"), t)

        self.roll_ctl = self.addCtl(self.ik2b_blend,
                                    "roll_ctl",
                                    t,
                                    self.color_ik,
                                    "crossarrow",
                                    w=self.length2 * .5 * self.n_factor,
                                    tp=self.ik_ctl)

        self.ik2b_ik_npo = primitive.addTransform(
            self.roll_ctl, self.getName("ik2B_ik_npo"),
            transform.getTransform(self.chain3bones[-1]))

        self.ik2b_ik_ref = primitive.addTransformFromPos(
            self.ik2b_ik_npo, self.getName("ik2B_ik_ref"),
            self.guide.pos["ankle"])

        attribute.lockAttribute(self.roll_ctl,
                                ["tx", "ty", "tz", "sx", "sy", "sz", "v"])

        # upv
        v = self.guide.apos[2] - self.guide.apos[0]
        v = self.normal ^ v
        v.normalize()
        v *= self.size * .5
        v += self.guide.apos[1]

        self.upv_lvl = primitive.addTransformFromPos(self.root,
                                                     self.getName("upv_lvl"),
                                                     v)
        self.upv_cns = primitive.addTransformFromPos(self.upv_lvl,
                                                     self.getName("upv_cns"),
                                                     v)

        self.upv_ctl = self.addCtl(self.upv_cns,
                                   "upv_ctl",
                                   transform.getTransform(self.upv_cns),
                                   self.color_ik,
                                   "diamond",
                                   w=self.size * .12,
                                   tp=self.ik_ctl)

        attribute.setInvertMirror(self.upv_ctl, ["tx"])
        attribute.setKeyableAttributes(self.upv_ctl, ["tx", "ty", "tz"])

        # Soft IK objects 3 bones chain --------------------------------
        t = transform.getTransformLookingAt(self.guide.pos["root"],
                                            self.guide.pos["foot"],
                                            self.x_axis, "zx", False)

        self.aim_tra = primitive.addTransform(self.root_ctl,
                                              self.getName("aimSoftIK"), t)

        t = transform.getTransformFromPos(self.guide.pos["foot"])
        self.wristSoftIK = primitive.addTransform(self.aim_tra,
                                                  self.getName("wristSoftIK"),
                                                  t)

        self.softblendLoc = primitive.addTransform(
            self.root, self.getName("softblendLoc"), t)

        # Soft IK objects 2 Bones chain ----------------------------
        t = transform.getTransformLookingAt(self.guide.pos["root"],
                                            self.guide.pos["ankle"],
                                            self.x_axis, "zx", False)

        self.aim_tra2 = primitive.addTransform(self.root_ctl,
                                               self.getName("aimSoftIK2"), t)

        t = transform.getTransformFromPos(self.guide.pos["ankle"])

        self.ankleSoftIK = primitive.addTransform(self.aim_tra2,
                                                  self.getName("ankleSoftIK"),
                                                  t)

        self.softblendLoc2 = primitive.addTransform(
            self.root, self.getName("softblendLoc2"), t)

        # References --------------------------------------
        self.ik_ref = primitive.addTransform(
            self.ik_ctl, self.getName("ik_ref"),
            transform.getTransform(self.ik_ctl))

        self.fk_ref = primitive.addTransform(
            self.fk_ctl[3], self.getName("fk_ref"),
            transform.getTransform(self.ik_ctl))

        # twist references --------------------------------------
        self.rollRef = primitive.add2DChain(self.root,
                                            self.getName("rollChain"),
                                            self.guide.apos[:2], self.normal,
                                            False, self.WIP)

        self.tws0_loc = primitive.addTransform(
            self.rollRef[0], self.getName("tws0_loc"),
            transform.getTransform(self.legBones[0]))

        self.tws0_rot = primitive.addTransform(
            self.tws0_loc, self.getName("tws0_rot"),
            transform.getTransform(self.legBones[0]))

        self.tws0_rot.setAttr("sx", .001)

        self.tws1_loc = primitive.addTransform(
            self.mid1_jnt, self.getName("tws1_loc"),
            transform.getTransform(self.mid1_jnt))

        self.tws1_rot = primitive.addTransform(
            self.tws1_loc, self.getName("tws1_rot"),
            transform.getTransform(self.mid1_jnt))

        self.tws1_rot.setAttr("sx", .001)

        self.tws2_loc = primitive.addTransform(
            self.mid2_jnt, self.getName("tws2_loc"),
            transform.getTransform(self.mid2_jnt))

        self.tws2_rot = primitive.addTransform(
            self.tws2_loc, self.getName("tws2_rot"),
            transform.getTransform(self.mid2_jnt))

        self.tws2_rot.setAttr("sx", .001)

        self.tws3_loc = primitive.addTransform(
            self.legBones[3], self.getName("tws3_loc"),
            transform.getTransform(self.legBones[3]))

        self.tws3_rot = primitive.addTransform(
            self.tws3_loc, self.getName("tws3_rot"),
            transform.getTransform(self.legBones[3]))

        self.tws3_rot.setAttr("sx", .001)

        # Divisions ----------------------------------------
        # We have at least one division at the start, the end and one for
        # the knee and one ankle
        o_set = self.settings
        self.divisions = o_set["div0"] + o_set["div1"] + o_set["div2"] + 4

        self.div_cns = []
        for i in range(self.divisions):
            div_cns = primitive.addTransform(self.root_ctl,
                                             self.getName("div%s_loc" % i))
            self.div_cns.append(div_cns)
            self.jnt_pos.append([div_cns, i])

        # End reference ------------------------------------
        # To help the deformation on the foot
        self.end_ref = primitive.addTransform(
            self.tws3_rot, self.getName("end_ref"),
            transform.getTransform(self.legBones[3]))
        self.jnt_pos.append([self.end_ref, 'end'])
Exemple #27
0
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')
Exemple #28
0
    def addObjects(self):
        """Add all the objects needed to create the component."""

        self.WIP = self.options["mode"]

        self.normal = self.getNormalFromPos(self.guide.apos)
        self.binormal = self.getBiNormalFromPos(self.guide.apos)

        self.length0 = vector.getDistance(self.guide.apos[0],
                                          self.guide.apos[1])
        self.length1 = vector.getDistance(self.guide.apos[1],
                                          self.guide.apos[2])
        self.length2 = vector.getDistance(self.guide.apos[2],
                                          self.guide.apos[3])

        # 1 bone chain for upv ref
        self.armChainUpvRef = primitive.add2DChain(
            self.root,
            self.getName("armUpvRef%s_jnt"),
            [self.guide.apos[0], self.guide.apos[2]],
            self.normal, False, self.WIP)

        negateOri = self.armChainUpvRef[1].getAttr("jointOrientZ") * -1
        self.armChainUpvRef[1].setAttr("jointOrientZ", negateOri)

        # FK Controlers -----------------------------------
        t = transform.getTransformLookingAt(self.guide.apos[0],
                                            self.guide.apos[1],
                                            self.normal, "xz",
                                            self.negate)

        self.fk0_npo = primitive.addTransform(self.root,
                                              self.getName("fk0_npo"),
                                              t)

        vec_po = datatypes.Vector(.5 * self.length0 * self.n_factor, 0, 0)
        self.fk0_ctl = self.addCtl(self.fk0_npo,
                                   "fk0_ctl",
                                   t,
                                   self.color_fk,
                                   "cube",
                                   w=self.length0,
                                   h=self.size * .1,
                                   d=self.size * .1,
                                   po=vec_po,
                                   tp=self.parentCtlTag)

        attribute.setKeyableAttributes(
            self.fk0_ctl,
            ["tx", "ty", "tz", "ro", "rx", "ry", "rz", "sx"])

        t = transform.getTransformLookingAt(self.guide.apos[1],
                                            self.guide.apos[2],
                                            self.normal,
                                            "xz",
                                            self.negate)

        self.fk1_npo = primitive.addTransform(self.fk0_ctl,
                                              self.getName("fk1_npo"),
                                              t)
        vec_po = datatypes.Vector(.5 * self.length1 * self.n_factor, 0, 0)
        self.fk1_ctl = self.addCtl(self.fk1_npo,
                                   "fk1_ctl",
                                   t,
                                   self.color_fk,
                                   "cube",
                                   w=self.length1,
                                   h=self.size * .1,
                                   d=self.size * .1,
                                   po=vec_po,
                                   tp=self.fk0_ctl)

        attribute.setKeyableAttributes(
            self.fk1_ctl,
            ["tx", "ty", "tz", "ro", "rx", "ry", "rz", "sx"])

        t = transform.getTransformLookingAt(self.guide.apos[2],
                                            self.guide.apos[3],
                                            self.normal,
                                            "xz",
                                            self.negate)

        self.fk2_npo = primitive.addTransform(self.fk1_ctl,
                                              self.getName("fk2_npo"),
                                              t)

        vec_po = datatypes.Vector(.5 * self.length2 * self.n_factor, 0, 0)
        self.fk2_ctl = self.addCtl(self.fk2_npo,
                                   "fk2_ctl",
                                   t,
                                   self.color_fk,
                                   "cube",
                                   w=self.length2,
                                   h=self.size * .1,
                                   d=self.size * .1,
                                   po=vec_po,
                                   tp=self.fk1_ctl)

        attribute.setKeyableAttributes(self.fk2_ctl)

        self.fk_ctl = [self.fk0_ctl, self.fk1_ctl, self.fk2_ctl]

        for x in self.fk_ctl:
            attribute.setInvertMirror(x, ["tx", "ty", "tz"])

        # IK upv ---------------------------------
        v = self.guide.apos[2] - self.guide.apos[0]
        v = self.normal ^ v
        v.normalize()
        v *= self.size * .5
        v += self.guide.apos[1]

        self.upv_cns = primitive.addTransformFromPos(self.root,
                                                     self.getName("upv_cns"),
                                                     v)

        self.upv_ctl = self.addCtl(self.upv_cns,
                                   "upv_ctl",
                                   transform.getTransform(self.upv_cns),
                                   self.color_ik,
                                   "diamond",
                                   w=self.size * .12,
                                   tp=self.parentCtlTag)

        if self.settings["mirrorMid"]:
            if self.negate:
                self.upv_cns.rz.set(180)
                self.upv_cns.sy.set(-1)
        else:
            attribute.setInvertMirror(self.upv_ctl, ["tx"])
        attribute.setKeyableAttributes(self.upv_ctl, self.t_params)

        # IK Controlers -----------------------------------

        self.ik_cns = primitive.addTransformFromPos(
            self.root, self.getName("ik_cns"), self.guide.pos["wrist"])

        t = transform.getTransformFromPos(self.guide.pos["wrist"])
        self.ikcns_ctl = self.addCtl(self.ik_cns,
                                     "ikcns_ctl",
                                     t,
                                     self.color_ik,
                                     "null",
                                     w=self.size * .12,
                                     tp=self.parentCtlTag)

        attribute.setInvertMirror(self.ikcns_ctl, ["tx", "ty", "tz"])

        if self.negate:
            m = transform.getTransformLookingAt(self.guide.pos["wrist"],
                                                self.guide.pos["eff"],
                                                self.normal,
                                                "x-y",
                                                True)
        else:
            m = transform.getTransformLookingAt(self.guide.pos["wrist"],
                                                self.guide.pos["eff"],
                                                self.normal,
                                                "xy",
                                                False)

        self.ik_ctl = self.addCtl(self.ikcns_ctl,
                                  "ik_ctl",
                                  m,
                                  self.color_ik,
                                  "cube",
                                  w=self.size * .12,
                                  h=self.size * .12,
                                  d=self.size * .12,
                                  tp=self.upv_ctl)

        if self.settings["mirrorIK"]:
            if self.negate:
                self.ik_cns.sx.set(-1)
                self.ik_ctl.rz.set(self.ik_ctl.rz.get() * -1)
        else:
            attribute.setInvertMirror(self.ik_ctl, ["tx", "ry", "rz"])
        attribute.setKeyableAttributes(self.ik_ctl)
        self.ik_ctl_ref = primitive.addTransform(self.ik_ctl,
                                                 self.getName("ikCtl_ref"),
                                                 m)

        # IK rotation controls
        if self.settings["ikTR"]:
            self.ikRot_npo = primitive.addTransform(self.root,
                                                    self.getName("ikRot_npo"),
                                                    m)
            self.ikRot_cns = primitive.addTransform(self.ikRot_npo,
                                                    self.getName("ikRot_cns"),
                                                    m)
            self.ikRot_ctl = self.addCtl(self.ikRot_cns,
                                         "ikRot_ctl",
                                         m,
                                         self.color_ik,
                                         "sphere",
                                         w=self.size * .12,
                                         tp=self.ik_ctl)

            attribute.setKeyableAttributes(self.ikRot_ctl, self.r_params)

        # References --------------------------------------
        # Calculate  again the transfor for the IK ref. This way align with FK
        trnIK_ref = transform.getTransformLookingAt(self.guide.pos["wrist"],
                                                    self.guide.pos["eff"],
                                                    self.normal,
                                                    "xz",
                                                    self.negate)
        self.ik_ref = primitive.addTransform(self.ik_ctl_ref,
                                             self.getName("ik_ref"),
                                             trnIK_ref)
        self.fk_ref = primitive.addTransform(self.fk_ctl[2],
                                             self.getName("fk_ref"),
                                             trnIK_ref)

        # Chain --------------------------------------------
        # The outputs of the ikfk2bone solver
        self.bone0 = primitive.addLocator(
            self.root,
            self.getName("0_bone"),
            transform.getTransform(self.fk_ctl[0]))
        self.bone0_shp = self.bone0.getShape()
        self.bone0_shp.setAttr("localPositionX", self.n_factor * .5)
        self.bone0_shp.setAttr("localScale", .5, 0, 0)
        self.bone0.setAttr("sx", self.length0)
        self.bone0.setAttr("visibility", False)

        self.bone1 = primitive.addLocator(
            self.root,
            self.getName("1_bone"),
            transform.getTransform(self.fk_ctl[1]))
        self.bone1_shp = self.bone1.getShape()
        self.bone1_shp.setAttr("localPositionX", self.n_factor * .5)
        self.bone1_shp.setAttr("localScale", .5, 0, 0)
        self.bone1.setAttr("sx", self.length1)
        self.bone1.setAttr("visibility", False)

        self.ctrn_loc = primitive.addTransformFromPos(self.root,
                                                      self.getName("ctrn_loc"),
                                                      self.guide.apos[1])
        self.eff_loc = primitive.addTransformFromPos(self.root,
                                                     self.getName("eff_loc"),
                                                     self.guide.apos[2])

        # Mid Controler ------------------------------------
        t = transform.getTransform(self.ctrn_loc)

        self.mid_cns = primitive.addTransform(self.ctrn_loc,
                                              self.getName("mid_cns"),
                                              t)

        self.mid_ctl = self.addCtl(self.mid_cns,
                                   "mid_ctl",
                                   t,
                                   self.color_ik,
                                   "sphere",
                                   w=self.size * .2,
                                   tp=self.parentCtlTag)

        attribute.setKeyableAttributes(self.mid_ctl,
                                       params=["tx", "ty", "tz",
                                               "ro", "rx", "ry", "rz",
                                               "sx"])

        if self.settings["mirrorMid"]:
            if self.negate:
                self.mid_cns.rz.set(180)
                self.mid_cns.sz.set(-1)
            self.mid_ctl_twst_npo = primitive.addTransform(
                self.mid_ctl,
                self.getName("mid_twst_npo"),
                t)
            self.mid_ctl_twst_ref = primitive.addTransform(
                self.mid_ctl_twst_npo,
                self.getName("mid_twst_ref"),
                t)
        else:
            self.mid_ctl_twst_ref = self.mid_ctl
            attribute.setInvertMirror(self.mid_ctl, ["tx", "ty", "tz"])

        # Roll join ref
        self.rollRef = primitive.add2DChain(self.root, self.getName(
            "rollChain"), self.guide.apos[:2], self.normal, self.negate)
        for x in self.rollRef:
            x.setAttr("visibility", False)

        self.tws0_loc = primitive.addTransform(
            self.rollRef[0],
            self.getName("tws0_loc"),
            transform.getTransform(self.fk_ctl[0]))
        self.tws0_rot = primitive.addTransform(
            self.tws0_loc,
            self.getName("tws0_rot"),
            transform.getTransform(self.fk_ctl[0]))

        self.tws1_npo = primitive.addTransform(
            self.ctrn_loc,
            self.getName("tws1_npo"),
            transform.getTransform(self.ctrn_loc))
        self.tws1_loc = primitive.addTransform(
            self.tws1_npo,
            self.getName("tws1_loc"),
            transform.getTransform(self.ctrn_loc))
        self.tws1_rot = primitive.addTransform(
            self.tws1_loc,
            self.getName("tws1_rot"),
            transform.getTransform(self.ctrn_loc))

        self.tws2_npo = primitive.addTransform(
            self.root,
            self.getName("tws2_npo"),
            transform.getTransform(self.fk_ctl[2]))
        self.tws2_loc = primitive.addTransform(
            self.tws2_npo,
            self.getName("tws2_loc"),
            transform.getTransform(self.fk_ctl[2]))
        self.tws2_rot = primitive.addTransform(
            self.tws2_loc,
            self.getName("tws2_rot"),
            transform.getTransform(self.fk_ctl[2]))

        # Divisions ----------------------------------------
        # We have at least one division at the start, the end and one for the
        # elbow. + 2 for elbow angle control
        self.divisions = self.settings["div0"] + self.settings["div1"] + 3 + 2

        self.div_cns = []

        if self.settings["extraTweak"]:
            tagP = self.parentCtlTag
            self.tweak_ctl = []

        for i in range(self.divisions):

            div_cns = primitive.addTransform(self.root,
                                             self.getName("div%s_loc" % i))

            self.div_cns.append(div_cns)

            if self.settings["extraTweak"]:
                t = transform.getTransform(div_cns)
                tweak_ctl = self.addCtl(div_cns,
                                        "tweak%s_ctl" % i,
                                        t,
                                        self.color_fk,
                                        "square",
                                        w=self.size * .15,
                                        d=self.size * .15,
                                        ro=datatypes.Vector([0, 0, 1.5708]),
                                        tp=tagP)
                attribute.setKeyableAttributes(tweak_ctl)

                tagP = tweak_ctl
                self.tweak_ctl.append(tweak_ctl)
                self.jnt_pos.append([tweak_ctl, i, None, False])
            else:
                self.jnt_pos.append([div_cns, i])

        # End reference ------------------------------------
        # To help the deformation on the wrist
        self.jnt_pos.append([self.eff_loc, 'end'])
        # match IK FK references
        self.match_fk0_off = primitive.addTransform(
            self.root,
            self.getName("matchFk0_npo"),
            transform.getTransform(self.fk_ctl[1]))
        self.match_fk0 = primitive.addTransform(
            self.match_fk0_off,
            self.getName("fk0_mth"),
            transform.getTransform(self.fk_ctl[0]))
        self.match_fk1_off = primitive.addTransform(
            self.root, self.getName(
                "matchFk1_npo"), transform.getTransform(self.fk_ctl[2]))
        self.match_fk1 = primitive.addTransform(
            self.match_fk1_off,
            self.getName("fk1_mth"),
            transform.getTransform(self.fk_ctl[1]))

        if self.settings["ikTR"]:
            reference = self.ikRot_ctl
            self.match_ikRot = primitive.addTransform(
                self.fk2_ctl,
                self.getName("ikRot_mth"),
                transform.getTransform(self.ikRot_ctl))
        else:
            reference = self.ik_ctl

        self.match_fk2 = primitive.addTransform(
            reference,
            self.getName("fk2_mth"),
            transform.getTransform(self.fk_ctl[2]))

        self.match_ik = primitive.addTransform(
            self.fk2_ctl,
            self.getName("ik_mth"),
            transform.getTransform(self.ik_ctl))
        self.match_ikUpv = primitive.addTransform(
            self.fk0_ctl,
            self.getName("upv_mth"),
            transform.getTransform(self.upv_ctl))
Exemple #29
0
    def addObjects(self):
        """Add all the objects needed to create the component."""

        self.div_count = len(self.guide.apos) - 5

        plane = [self.guide.apos[0], self.guide.apos[-4], self.guide.apos[-3]]
        self.normal = self.getNormalFromPos(plane)
        self.binormal = self.getBiNormalFromPos(plane)

        # Heel ---------------------------------------------
        # bank pivot

        t = transform.getTransformLookingAt(self.guide.pos["heel"],
                                            self.guide.apos[-4],
                                            self.normal,
                                            "xz",
                                            self.negate)

        t = transform.setMatrixPosition(t, self.guide.pos["inpivot"])

        self.in_npo = primitive.addTransform(
            self.root, self.getName("in_npo"), t)

        self.in_piv = primitive.addTransform(
            self.in_npo, self.getName("in_piv"), t)

        t = transform.setMatrixPosition(t, self.guide.pos["outpivot"])

        self.out_piv = primitive.addTransform(
            self.in_piv, self.getName("out_piv"), t)

        # heel
        t = transform.getTransformLookingAt(self.guide.pos["heel"],
                                            self.guide.apos[-4],
                                            self.normal,
                                            "xz",
                                            self.negate)

        self.heel_loc = primitive.addTransform(
            self.out_piv, self.getName("heel_loc"), t)

        attribute.setRotOrder(self.heel_loc, "YZX")
        self.heel_ctl = self.addCtl(self.heel_loc,
                                    "heel_ctl",
                                    t,
                                    self.color_ik,
                                    "sphere",
                                    w=self.size * .1,
                                    tp=self.parentCtlTag)

        attribute.setKeyableAttributes(self.heel_ctl, self.r_params)

        # Tip ----------------------------------------------
        v = datatypes.Vector(self.guide.apos[-5].x,
                             self.guide.apos[-1].y,
                             self.guide.apos[-5].z)
        t = transform.setMatrixPosition(t, v)
        self.tip_ctl = self.addCtl(self.heel_ctl,
                                   "tip_ctl",
                                   t,
                                   self.color_ik,
                                   "circle",
                                   w=self.size,
                                   tp=self.heel_ctl)
        attribute.setKeyableAttributes(self.tip_ctl, self.r_params)

        # Roll ---------------------------------------------
        if self.settings["useRollCtl"]:
            t = transform.getTransformLookingAt(self.guide.pos["heel"],
                                                self.guide.apos[-4],
                                                self.normal,
                                                "xz",
                                                self.negate)
            t = transform.setMatrixPosition(t, self.guide.pos["root"])

            self.roll_np = primitive.addTransform(
                self.root, self.getName("roll_npo"), t)

            self.roll_ctl = self.addCtl(self.roll_np,
                                        "roll_ctl",
                                        t,
                                        self.color_ik,
                                        "cylinder",
                                        w=self.size * .5,
                                        h=self.size * .5,
                                        ro=datatypes.Vector(3.1415 * .5, 0, 0),
                                        tp=self.tip_ctl)

            attribute.setKeyableAttributes(self.roll_ctl, ["rx", "rz"])

        # Backward Controlers ------------------------------
        bk_pos = self.guide.apos[1:-3]
        bk_pos.reverse()
        parent = self.tip_ctl
        self.bk_ctl = []
        self.bk_loc = []
        self.previousTag = self.tip_ctl
        for i, pos in enumerate(bk_pos):

            if i == 0:
                t = transform.getTransform(self.heel_ctl)
                t = transform.setMatrixPosition(t, pos)
            else:
                dir = bk_pos[i - 1]
                t = transform.getTransformLookingAt(
                    pos, dir, self.normal, "xz", self.negate)

            bk_loc = primitive.addTransform(
                parent, self.getName("bk%s_loc" % i), t)
            bk_ctl = self.addCtl(bk_loc,
                                 "bk%s_ctl" % i,
                                 t,
                                 self.color_ik,
                                 "sphere",
                                 w=self.size * .15,
                                 tp=self.previousTag)
            attribute.setKeyableAttributes(bk_ctl, self.r_params)
            self.previousTag = bk_ctl

            self.bk_loc.append(bk_loc)
            self.bk_ctl.append(bk_ctl)
            parent = bk_ctl

        # FK Reference ------------------------------------
        self.fk_ref = primitive.addTransformFromPos(self.bk_ctl[-1],
                                                    self.getName("fk_ref"),
                                                    self.guide.apos[0])
        self.fk_npo = primitive.addTransform(
            self.fk_ref,
            self.getName("fk0_npo"),
            transform.getTransform(self.bk_ctl[-1]))

        # Forward Controlers ------------------------------
        self.fk_ctl = []
        self.fk_loc = []
        parent = self.fk_npo
        self.previousTag = self.tip_ctl
        for i, bk_ctl in enumerate(reversed(self.bk_ctl[1:])):
            t = transform.getTransform(bk_ctl)
            dist = vector.getDistance(self.guide.apos[i + 1],
                                      self.guide.apos[i + 2])

            fk_loc = primitive.addTransform(
                parent, self.getName("fk%s_loc" % i), t)

            po_vec = datatypes.Vector(dist * .5 * self.n_factor, 0, 0)
            fk_ctl = self.addCtl(fk_loc,
                                 "fk%s_ctl" % i,
                                 t,
                                 self.color_fk,
                                 "cube",
                                 w=dist,
                                 h=self.size * .5,
                                 d=self.size * .5,
                                 po=po_vec,
                                 tp=self.previousTag)

            self.previousTag = fk_ctl
            attribute.setKeyableAttributes(fk_ctl)
            self.jnt_pos.append([fk_ctl, i])

            parent = fk_ctl
            self.fk_ctl.append(fk_ctl)
            self.fk_loc.append(fk_loc)
Exemple #30
0
    def addObjects(self):

        self.WIP = self.options["mode"]

        self.normal = self.getNormalFromPos(self.guide.apos)
        self.binormal = self.getBiNormalFromPos(self.guide.apos)

        self.length0 = vec.getDistance(self.guide.apos[0], self.guide.apos[1])
        self.length1 = vec.getDistance(self.guide.apos[1], self.guide.apos[2])
        self.length2 = vec.getDistance(self.guide.apos[2], self.guide.apos[3])

        # FK Controlers -----------------------------------
        t = tra.getTransformLookingAt(self.guide.apos[0], self.guide.apos[1],
                                      self.normal, "xz", self.negate)
        self.fk0_npo = pri.addTransform(self.root, self.getName("fk0_npo"), t)
        self.fk0_ctl = self.addCtl(self.fk0_npo,
                                   "fk0_ctl",
                                   t,
                                   self.color_fk,
                                   "cube",
                                   w=self.length0,
                                   h=self.size * .1,
                                   d=self.size * .1,
                                   po=dt.Vector(
                                       .5 * self.length0 * self.n_factor, 0,
                                       0))
        att.setKeyableAttributes(self.fk0_ctl)

        t = tra.getTransformLookingAt(self.guide.apos[1], self.guide.apos[2],
                                      self.normal, "xz", self.negate)
        self.fk1_npo = pri.addTransform(self.fk0_ctl, self.getName("fk1_npo"),
                                        t)
        self.fk1_ctl = self.addCtl(self.fk1_npo,
                                   "fk1_ctl",
                                   t,
                                   self.color_fk,
                                   "cube",
                                   w=self.length1,
                                   h=self.size * .1,
                                   d=self.size * .1,
                                   po=dt.Vector(
                                       .5 * self.length1 * self.n_factor, 0,
                                       0))
        att.setKeyableAttributes(self.fk1_ctl)

        t = tra.getTransformLookingAt(self.guide.apos[2], self.guide.apos[3],
                                      self.normal, "xz", self.negate)
        self.fk2_npo = pri.addTransform(self.fk1_ctl, self.getName("fk2_npo"),
                                        t)
        self.fk2_ctl = self.addCtl(self.fk2_npo,
                                   "fk2_ctl",
                                   t,
                                   self.color_fk,
                                   "cube",
                                   w=self.length2,
                                   h=self.size * .1,
                                   d=self.size * .1,
                                   po=dt.Vector(
                                       .5 * self.length2 * self.n_factor, 0,
                                       0))
        att.setKeyableAttributes(self.fk2_ctl)

        self.fk_ctl = [self.fk0_ctl, self.fk1_ctl, self.fk2_ctl]

        for x in self.fk_ctl:
            att.setInvertMirror(x, ["tx", "ty", "tz"])

        # IK Controlers -----------------------------------

        self.ik_cns = pri.addTransformFromPos(self.root,
                                              self.getName("ik_cns"),
                                              self.guide.pos["wrist"])

        self.ikcns_ctl = self.addCtl(self.ik_cns,
                                     "ikcns_ctl",
                                     tra.getTransformFromPos(
                                         self.guide.pos["wrist"]),
                                     self.color_ik,
                                     "null",
                                     w=self.size * .12)
        att.setInvertMirror(self.ikcns_ctl, ["tx", "ty", "tz"])

        if self.negate:
            m = tra.getTransformLookingAt(self.guide.pos["wrist"],
                                          self.guide.pos["eff"], self.normal,
                                          "x-y", True)
        else:
            m = tra.getTransformLookingAt(self.guide.pos["wrist"],
                                          self.guide.pos["eff"], self.normal,
                                          "xy", False)
        self.ik_ctl = self.addCtl(self.ikcns_ctl,
                                  "ik_ctl",
                                  m,
                                  self.color_ik,
                                  "cube",
                                  w=self.size * .12,
                                  h=self.size * .12,
                                  d=self.size * .12)
        att.setKeyableAttributes(self.ik_ctl)
        att.setInvertMirror(self.ik_ctl, ["tx", "ry", "rz"])

        # upv
        v = self.guide.apos[2] - self.guide.apos[0]
        v = self.normal ^ v
        v.normalize()
        v *= self.size * .5
        v += self.guide.apos[1]

        self.upv_cns = pri.addTransformFromPos(self.root,
                                               self.getName("upv_cns"), v)

        self.upv_ctl = self.addCtl(self.upv_cns,
                                   "upv_ctl",
                                   tra.getTransform(self.upv_cns),
                                   self.color_ik,
                                   "diamond",
                                   w=self.size * .12)
        att.setInvertMirror(self.upv_ctl, ["tx"])

        # References --------------------------------------
        # Calculate  again the transfor for the IK ref. This way align with FK
        trnIK_ref = tra.getTransformLookingAt(self.guide.pos["wrist"],
                                              self.guide.pos["eff"],
                                              self.normal, "xz", self.negate)
        self.ik_ref = pri.addTransform(self.ik_ctl, self.getName("ik_ref"),
                                       trnIK_ref)
        self.fk_ref = pri.addTransform(self.fk_ctl[2], self.getName("fk_ref"),
                                       trnIK_ref)

        # Chain --------------------------------------------
        # The outputs of the ikfk2bone solver
        self.bone0 = pri.addLocator(self.root, self.getName("0_bone"),
                                    tra.getTransform(self.fk_ctl[0]))
        self.bone0_shp = self.bone0.getShape()
        self.bone0_shp.setAttr("localPositionX", self.n_factor * .5)
        self.bone0_shp.setAttr("localScale", .5, 0, 0)
        self.bone0.setAttr("sx", self.length0)
        bShape = self.bone0.getShape()
        bShape.setAttr("visibility", False)

        self.bone1 = pri.addLocator(self.root, self.getName("1_bone"),
                                    tra.getTransform(self.fk_ctl[1]))
        self.bone1_shp = self.bone1.getShape()
        self.bone1_shp.setAttr("localPositionX", self.n_factor * .5)
        self.bone1_shp.setAttr("localScale", .5, 0, 0)
        self.bone1.setAttr("sx", self.length1)
        bShape = self.bone1.getShape()
        bShape.setAttr("visibility", False)

        #Elbow control

        tA = tra.getTransformLookingAt(self.guide.apos[0], self.guide.apos[1],
                                       self.normal, "xz", self.negate)
        tA = tra.setMatrixPosition(tA, self.guide.apos[1])
        tB = tra.getTransformLookingAt(self.guide.apos[1], self.guide.apos[2],
                                       self.normal, "xz", self.negate)
        t = tra.getInterpolateTransformMatrix(tA, tB)
        self.ctrn_loc = pri.addTransform(self.root, self.getName("ctrn_loc"),
                                         t)

        #match IK FK references
        self.match_fk0_off = pri.addTransform(self.root,
                                              self.getName("matchFk0_npo"),
                                              tra.getTransform(self.fk_ctl[1]))
        # self.match_fk0_off.attr("tx").set(1.0)
        self.match_fk0 = pri.addTransform(self.match_fk0_off,
                                          self.getName("fk0_mth"),
                                          tra.getTransform(self.fk_ctl[0]))
        self.match_fk1_off = pri.addTransform(self.root,
                                              self.getName("matchFk1_npo"),
                                              tra.getTransform(self.fk_ctl[2]))
        # self.match_fk1_off.attr("tx").set(1.0)
        self.match_fk1 = pri.addTransform(self.match_fk1_off,
                                          self.getName("fk1_mth"),
                                          tra.getTransform(self.fk_ctl[1]))
        self.match_fk2 = pri.addTransform(self.ik_ctl, self.getName("fk2_mth"),
                                          tra.getTransform(self.fk_ctl[2]))

        self.match_ik = pri.addTransform(self.fk2_ctl, self.getName("ik_mth"),
                                         tra.getTransform(self.ik_ctl))
        self.match_ikUpv = pri.addTransform(self.fk0_ctl,
                                            self.getName("upv_mth"),
                                            tra.getTransform(self.upv_ctl))

        # Eff locator
        self.eff_loc = pri.addTransformFromPos(self.root,
                                               self.getName("eff_loc"),
                                               self.guide.apos[2])

        # Mid Controler ------------------------------------
        self.mid_ctl = self.addCtl(self.ctrn_loc,
                                   "mid_ctl",
                                   tra.getTransform(self.ctrn_loc),
                                   self.color_ik,
                                   "sphere",
                                   w=self.size * .2)
        att.setInvertMirror(self.mid_ctl, ["tx", "ty", "tz"])

        #Roll join ref---------------------------------
        self.tws0_loc = pri.addTransform(self.root, self.getName("tws0_loc"),
                                         tra.getTransform(self.fk_ctl[0]))

        self.tws1_npo = pri.addTransform(self.ctrn_loc,
                                         self.getName("tws1_npo"),
                                         tra.getTransform(self.ctrn_loc))
        self.tws1_loc = pri.addTransform(self.tws1_npo,
                                         self.getName("tws1_loc"),
                                         tra.getTransform(self.ctrn_loc))

        self.tws1A_npo = pri.addTransform(self.mid_ctl,
                                          self.getName("tws1A_npo"), tA)
        self.tws1A_loc = pri.addTransform(self.tws1A_npo,
                                          self.getName("tws1A_loc"), tA)
        self.tws1B_npo = pri.addTransform(self.mid_ctl,
                                          self.getName("tws1B_npo"), tB)
        self.tws1B_loc = pri.addTransform(self.tws1B_npo,
                                          self.getName("tws1B_loc"), tB)

        self.tws2_npo = pri.addTransform(self.root, self.getName("tws2_npo"),
                                         tra.getTransform(self.fk_ctl[2]))
        self.tws2_loc = pri.addTransform(self.tws2_npo,
                                         self.getName("tws2_loc"),
                                         tra.getTransform(self.fk_ctl[2]))

        # Roll twist chain ---------------------------------
        #Arm
        self.armChainPos = []
        ii = 1.0 / (self.settings["div0"] + 1)
        i = 0.0
        for p in range(self.settings["div0"] + 2):
            self.armChainPos.append(
                vec.linearlyInterpolate(self.guide.pos["root"],
                                        self.guide.pos["elbow"],
                                        blend=i))
            i = i + ii

        self.armTwistChain = pri.add2DChain(self.root,
                                            self.getName("armTwist%s_jnt"),
                                            self.armChainPos, self.normal,
                                            False, self.WIP)

        #Forearm
        self.forearmChainPos = []
        ii = 1.0 / (self.settings["div1"] + 1)
        i = 0.0
        for p in range(self.settings["div1"] + 2):
            self.forearmChainPos.append(
                vec.linearlyInterpolate(self.guide.pos["elbow"],
                                        self.guide.pos["wrist"],
                                        blend=i))
            i = i + ii

        self.forearmTwistChain = pri.add2DChain(
            self.root, self.getName("forearmTwist%s_jnt"),
            self.forearmChainPos, self.normal, False, self.WIP)
        pm.parent(self.forearmTwistChain[0], self.mid_ctl)

        #Hand Aux chain and nonroll
        self.auxChainPos = []
        ii = .5
        i = 0.0
        for p in range(3):
            self.auxChainPos.append(
                vec.linearlyInterpolate(self.guide.pos["wrist"],
                                        self.guide.pos["eff"],
                                        blend=i))
            i = i + ii
        t = self.root.getMatrix(worldSpace=True)
        self.aux_npo = pri.addTransform(self.root, self.getName("aux_npo"), t)
        self.auxTwistChain = pri.add2DChain(self.aux_npo,
                                            self.getName("auxTwist%s_jnt"),
                                            self.auxChainPos, self.normal,
                                            False, self.WIP)

        #Non Roll join ref ---------------------------------
        self.armRollRef = pri.add2DChain(self.root,
                                         self.getName("armRollRef%s_jnt"),
                                         self.armChainPos[:2], self.normal,
                                         False, self.WIP)

        self.forearmRollRef = pri.add2DChain(
            self.aux_npo, self.getName("forearmRollRef%s_jnt"),
            self.auxChainPos[:2], self.normal, False, self.WIP)

        # Divisions ----------------------------------------
        # We have at least one division at the start, the end and one for the elbow. + 2 for elbow angle control
        self.divisions = self.settings["div0"] + self.settings["div1"] + 4

        self.div_cns = []
        for i in range(self.divisions):

            div_cns = pri.addTransform(self.root,
                                       self.getName("div%s_loc" % i))

            self.div_cns.append(div_cns)

            self.jnt_pos.append([div_cns, i])

        # End reference ------------------------------------
        # To help the deformation on the wrist
        self.end_ref = pri.addTransform(self.eff_loc, self.getName("end_ref"),
                                        tra.getTransform(self.eff_loc))
        if self.negate:
            self.end_ref.attr("rz").set(180.0)

        self.jnt_pos.append([self.end_ref, "end"])

        # Tangent controls
        t = tra.getInterpolateTransformMatrix(self.fk_ctl[0], self.tws1A_npo,
                                              .3333)
        self.armTangentA_loc = pri.addTransform(
            self.root, self.getName("armTangentA_loc"),
            self.fk_ctl[0].getMatrix(worldSpace=True))
        self.armTangentA_npo = pri.addTransform(
            self.armTangentA_loc, self.getName("armTangentA_npo"), t)
        self.armTangentA_ctl = self.addCtl(self.armTangentA_npo,
                                           "armTangentA_ctl",
                                           t,
                                           self.color_ik,
                                           "circle",
                                           w=self.size * .2,
                                           ro=dt.Vector(0, 0, 1.570796))

        t = tra.getInterpolateTransformMatrix(self.fk_ctl[0], self.tws1A_npo,
                                              .6666)
        self.armTangentB_npo = pri.addTransform(
            self.tws1A_loc, self.getName("armTangentB_npo"), t)
        self.armTangentB_ctl = self.addCtl(self.armTangentB_npo,
                                           "armTangentB_ctl",
                                           t,
                                           self.color_ik,
                                           "circle",
                                           w=self.size * .2,
                                           ro=dt.Vector(0, 0, 1.570796))

        tC = self.tws1B_npo.getMatrix(worldSpace=True)
        tC = tra.setMatrixPosition(tC, self.guide.apos[2])
        t = tra.getInterpolateTransformMatrix(self.tws1B_npo, tC, .3333)
        self.forearmTangentA_npo = pri.addTransform(
            self.tws1B_loc, self.getName("forearmTangentA_npo"), t)
        self.forearmTangentA_ctl = self.addCtl(self.forearmTangentA_npo,
                                               "forearmTangentA_ctl",
                                               t,
                                               self.color_ik,
                                               "circle",
                                               w=self.size * .2,
                                               ro=dt.Vector(0, 0, 1.570796))

        t = tra.getInterpolateTransformMatrix(self.tws1B_npo, tC, .6666)
        self.forearmTangentB_loc = pri.addTransform(
            self.root, self.getName("forearmTangentB_loc"), tC)
        self.forearmTangentB_npo = pri.addTransform(
            self.forearmTangentB_loc, self.getName("forearmTangentB_npo"), t)
        self.forearmTangentB_ctl = self.addCtl(self.forearmTangentB_npo,
                                               "forearmTangentB_ctl",
                                               t,
                                               self.color_ik,
                                               "circle",
                                               w=self.size * .2,
                                               ro=dt.Vector(0, 0, 1.570796))

        t = self.mid_ctl.getMatrix(worldSpace=True)
        self.elbowTangent_npo = pri.addTransform(
            self.mid_ctl, self.getName("elbowTangent_npo"), t)
        self.elbowTangent_ctl = self.addCtl(self.elbowTangent_npo,
                                            "elbowTangent_ctl",
                                            t,
                                            self.color_fk,
                                            "circle",
                                            w=self.size * .25,
                                            ro=dt.Vector(0, 0, 1.570796))
Exemple #31
0
    def addObjects(self):
        """Add all the objects needed to create the component."""

        self.normal = self.guide.blades["blade"].z * -1
        self.binormal = self.guide.blades["blade"].x

        self.isFk = self.settings["mode"] != 1
        self.isIk = self.settings["mode"] != 0
        self.isFkIk = self.settings["mode"] == 2

        self.WIP = self.options["mode"]

        # FK controllers ------------------------------------
        if self.isFk:
            self.fk_npo = []
            self.fk_ctl = []
            self.fk_ref = []
            self.fk_off = []
            t = self.guide.tra["root"]
            self.ik_cns = primitive.addTransform(self.root,
                                                 self.getName("ik_cns"), t)
            parent = self.ik_cns
            tOld = False
            fk_ctl = None
            self.previusTag = self.parentCtlTag
            for i, t in enumerate(
                    transform.getChainTransform(self.guide.apos, self.normal,
                                                self.negate)):
                dist = vector.getDistance(self.guide.apos[i],
                                          self.guide.apos[i + 1])
                if self.settings["neutralpose"] or not tOld:
                    tnpo = t
                else:
                    tnpo = transform.setMatrixPosition(
                        tOld, transform.getPositionFromMatrix(t))
                if i:
                    tref = transform.setMatrixPosition(
                        tOld, transform.getPositionFromMatrix(t))
                    fk_ref = primitive.addTransform(
                        fk_ctl, self.getName("fk%s_ref" % i), tref)
                    self.fk_ref.append(fk_ref)
                else:
                    tref = t
                fk_off = primitive.addTransform(parent,
                                                self.getName("fk%s_off" % i),
                                                tref)
                fk_npo = primitive.addTransform(fk_off,
                                                self.getName("fk%s_npo" % i),
                                                tnpo)
                fk_ctl = self.addCtl(fk_npo,
                                     "fk%s_ctl" % i,
                                     t,
                                     self.color_fk,
                                     "cube",
                                     w=dist,
                                     h=self.size * .1,
                                     d=self.size * .1,
                                     po=datatypes.Vector(
                                         dist * .5 * self.n_factor, 0, 0),
                                     tp=self.previusTag)

                self.fk_off.append(fk_off)
                self.fk_npo.append(fk_npo)
                self.fk_ctl.append(fk_ctl)
                tOld = t
                self.previusTag = fk_ctl

        # IK controllers ------------------------------------
        if self.isIk:

            normal = vector.getTransposedVector(
                self.normal, [self.guide.apos[0], self.guide.apos[1]],
                [self.guide.apos[-2], self.guide.apos[-1]])
            t = transform.getTransformLookingAt(self.guide.apos[-2],
                                                self.guide.apos[-1], normal,
                                                "xy", self.negate)
            t = transform.setMatrixPosition(t, self.guide.apos[-1])

            self.ik_cns = primitive.addTransform(self.root,
                                                 self.getName("ik_cns"), t)
            self.ikcns_ctl = self.addCtl(self.ik_cns,
                                         "ikcns_ctl",
                                         t,
                                         self.color_ik,
                                         "null",
                                         w=self.size,
                                         tp=self.parentCtlTag)
            self.ik_ctl = self.addCtl(self.ikcns_ctl,
                                      "ik_ctl",
                                      t,
                                      self.color_ik,
                                      "cube",
                                      w=self.size * .3,
                                      h=self.size * .3,
                                      d=self.size * .3,
                                      tp=self.ikcns_ctl)
            attribute.setKeyableAttributes(self.ik_ctl, self.t_params)

            v = self.guide.apos[-1] - self.guide.apos[0]
            v = v ^ self.normal
            v.normalize()
            v *= self.size
            v += self.guide.apos[1]
            self.upv_cns = primitive.addTransformFromPos(
                self.root, self.getName("upv_cns"), v)

            self.upv_ctl = self.addCtl(self.upv_cns,
                                       "upv_ctl",
                                       transform.getTransform(self.upv_cns),
                                       self.color_ik,
                                       "diamond",
                                       w=self.size * .1,
                                       tp=self.parentCtlTag)
            attribute.setKeyableAttributes(self.upv_ctl, self.t_params)

            # Chain
            self.chain = primitive.add2DChain(self.root, self.getName("chain"),
                                              self.guide.apos, self.normal,
                                              self.negate)
            self.chain[0].attr("visibility").set(self.WIP)

        # Chain of deformers -------------------------------
        self.loc = []
        parent = self.root
        for i, t in enumerate(
                transform.getChainTransform(self.guide.apos, self.normal,
                                            self.negate)):
            loc = primitive.addTransform(parent, self.getName("%s_loc" % i), t)

            self.loc.append(loc)
            self.jnt_pos.append([loc, i, None, False])
Exemple #32
0
    def addObjects(self):
        """Add all the objects needed to create the component."""

        self.normal = self.guide.blades["blade"].z * -1

        # Ik Controlers ------------------------------------
        t = transform.getTransformLookingAt(self.guide.pos["tan1"],
                                            self.guide.pos["neck"],
                                            self.normal, "yx", self.negate)

        t = transform.setMatrixPosition(t, self.guide.pos["neck"])

        self.ik_cns = primitive.addTransform(self.root, self.getName("ik_cns"),
                                             t)

        self.ik_ctl = self.addCtl(self.ik_cns,
                                  "ik_ctl",
                                  t,
                                  self.color_ik,
                                  "compas",
                                  w=self.size * .5,
                                  tp=self.parentCtlTag)

        attribute.setKeyableAttributes(self.ik_ctl, self.tr_params)
        attribute.setRotOrder(self.ik_ctl, "ZXY")
        attribute.setInvertMirror(self.ik_ctl, ["tx", "ry", "rz"])

        # Tangents -----------------------------------------
        if self.settings["tangentControls"]:
            t = transform.setMatrixPosition(t, self.guide.pos["tan1"])

            self.tan1_loc = primitive.addTransform(self.ik_ctl,
                                                   self.getName("tan1_loc"), t)

            self.tan1_ctl = self.addCtl(self.tan1_loc,
                                        "tan1_ctl",
                                        t,
                                        self.color_ik,
                                        "sphere",
                                        w=self.size * .2,
                                        tp=self.ik_ctl)

            attribute.setKeyableAttributes(self.tan1_ctl, self.t_params)
            attribute.setInvertMirror(self.tan1_ctl, ["tx"])

            t = transform.getTransformLookingAt(self.guide.pos["root"],
                                                self.guide.pos["tan0"],
                                                self.normal, "yx", self.negate)

            t = transform.setMatrixPosition(t, self.guide.pos["tan0"])

            self.tan0_loc = primitive.addTransform(self.root,
                                                   self.getName("tan0_loc"), t)

            self.tan0_ctl = self.addCtl(self.tan0_loc,
                                        "tan0_ctl",
                                        t,
                                        self.color_ik,
                                        "sphere",
                                        w=self.size * .2,
                                        tp=self.ik_ctl)

            attribute.setKeyableAttributes(self.tan0_ctl, self.t_params)
            attribute.setInvertMirror(self.tan0_ctl, ["tx"])

            # Curves -------------------------------------------
            self.mst_crv = curve.addCnsCurve(
                self.root, self.getName("mst_crv"),
                [self.root, self.tan0_ctl, self.tan1_ctl, self.ik_ctl], 3)

            self.slv_crv = curve.addCurve(self.root, self.getName("slv_crv"),
                                          [datatypes.Vector()] * 10, False, 3)

            self.mst_crv.setAttr("visibility", False)

        else:
            t = transform.setMatrixPosition(t, self.guide.pos["tan1"])
            self.tan1_loc = primitive.addTransform(self.ik_ctl,
                                                   self.getName("tan1_loc"), t)

            t = transform.getTransformLookingAt(self.guide.pos["root"],
                                                self.guide.pos["tan0"],
                                                self.normal, "yx", self.negate)

            t = transform.setMatrixPosition(t, self.guide.pos["tan0"])

            self.tan0_loc = primitive.addTransform(self.root,
                                                   self.getName("tan0_loc"), t)

            # Curves -------------------------------------------
            self.mst_crv = curve.addCnsCurve(
                self.root, self.getName("mst_crv"),
                [self.root, self.tan0_loc, self.tan1_loc, self.ik_ctl], 3)

            self.slv_crv = curve.addCurve(self.root, self.getName("slv_crv"),
                                          [datatypes.Vector()] * 10, False, 3)

        self.mst_crv.setAttr("visibility", False)
        self.slv_crv.setAttr("visibility", False)

        # Division -----------------------------------------
        # The user only define how many intermediate division he wants.
        # First and last divisions are an obligation.
        parentdiv = self.root
        parentctl = self.root
        self.div_cns = []
        self.fk_ctl = []
        self.fk_npo = []
        self.scl_npo = []

        self.twister = []
        self.ref_twist = []

        parent_twistRef = primitive.addTransform(
            self.root, self.getName("reference"),
            transform.getTransform(self.root))

        t = transform.getTransformLookingAt(self.guide.pos["root"],
                                            self.guide.pos["neck"],
                                            self.normal, "yx", self.negate)

        self.intMRef = primitive.addTransform(self.root,
                                              self.getName("intMRef"), t)

        self.previousCtlTag = self.parentCtlTag
        for i in range(self.settings["division"]):

            # References
            div_cns = primitive.addTransform(parentdiv,
                                             self.getName("%s_cns" % i), t)

            pm.setAttr(div_cns + ".inheritsTransform", False)
            self.div_cns.append(div_cns)
            parentdiv = div_cns

            scl_npo = primitive.addTransform(parentctl,
                                             self.getName("%s_scl_npo" % i),
                                             transform.getTransform(parentctl))

            # Controlers (First and last one are fake)

            if i in [self.settings["division"] - 1]:  # 0,
                fk_ctl = primitive.addTransform(
                    scl_npo, self.getName("%s_loc" % i),
                    transform.getTransform(parentctl))

                fk_npo = fk_ctl
            else:
                fk_npo = primitive.addTransform(
                    scl_npo, self.getName("fk%s_npo" % i),
                    transform.getTransform(parentctl))

                fk_ctl = self.addCtl(fk_npo,
                                     "fk%s_ctl" % i,
                                     transform.getTransform(parentctl),
                                     self.color_fk,
                                     "cube",
                                     w=self.size * .2,
                                     h=self.size * .05,
                                     d=self.size * .2,
                                     tp=self.previousCtlTag)

                attribute.setKeyableAttributes(self.fk_ctl)
                attribute.setRotOrder(fk_ctl, "ZXY")

                self.previousCtlTag = fk_ctl

            self.fk_ctl.append(fk_ctl)

            self.scl_npo.append(scl_npo)
            self.fk_npo.append(fk_npo)
            parentctl = fk_ctl

            self.jnt_pos.append([fk_ctl, i])

            t = transform.getTransformLookingAt(
                self.guide.pos["root"], self.guide.pos["neck"],
                self.guide.blades["blade"].z * -1, "yx", self.negate)

            twister = primitive.addTransform(parent_twistRef,
                                             self.getName("%s_rot_ref" % i), t)

            ref_twist = primitive.addTransform(parent_twistRef,
                                               self.getName("%s_pos_ref" % i),
                                               t)

            ref_twist.setTranslation(datatypes.Vector(0.0, 0, 1.0),
                                     space="preTransform")

            self.twister.append(twister)
            self.ref_twist.append(ref_twist)

        for x in self.fk_ctl[:-1]:
            attribute.setInvertMirror(x, ["tx", "rz", "ry"])

        # Head ---------------------------------------------
        t = transform.getTransformLookingAt(self.guide.pos["head"],
                                            self.guide.pos["eff"], self.normal,
                                            "yx", self.negate)

        self.head_cns = primitive.addTransform(self.root,
                                               self.getName("head_cns"), t)

        dist = vector.getDistance(self.guide.pos["head"],
                                  self.guide.pos["eff"])

        self.head_ctl = self.addCtl(self.head_cns,
                                    "head_ctl",
                                    t,
                                    self.color_fk,
                                    "cube",
                                    w=self.size * .5,
                                    h=dist,
                                    d=self.size * .5,
                                    po=datatypes.Vector(0, dist * .5, 0),
                                    tp=self.previousCtlTag)

        attribute.setRotOrder(self.head_ctl, "ZXY")
        attribute.setInvertMirror(self.head_ctl, ["tx", "rz", "ry"])

        self.jnt_pos.append([self.head_ctl, "head"])
Exemple #33
0
    def addObjects(self):

        # Ik Controlers ------------------------------------
        t = tra.getTransformLookingAt(self.guide.apos[0], self.guide.apos[1], self.guide.blades["blade"].z, "yx", self.negate)
        self.ik0_npo = pri.addTransform(self.root, self.getName("ik0_npo"), t)
        self.ik0_ctl = self.addCtl(self.ik0_npo, "ik0_ctl", t, self.color_ik, "compas", w=self.size)
        att.setKeyableAttributes(self.ik0_ctl)
        att.setRotOrder(self.ik0_ctl, "XZY")

        t = tra.setMatrixPosition(t, self.guide.apos[1])
        self.ik1_npo = pri.addTransform(self.root, self.getName("ik1_npo"), t)
        self.ik1_ctl = self.addCtl(self.ik1_npo, "ik1_ctl", t, self.color_ik, "compas", w=self.size)
        att.setKeyableAttributes(self.ik1_ctl)
        att.setRotOrder(self.ik1_ctl, "XZY")

        # Tangent controlers -------------------------------
        t = tra.setMatrixPosition(t, vec.linearlyInterpolate(self.guide.apos[0], self.guide.apos[1], .33))
        self.tan0_npo = pri.addTransform(self.ik0_ctl, self.getName("tan0_npo"), t)
        self.tan0_ctl = self.addCtl(self.tan0_npo, "tan0_ctl", t, self.color_ik, "sphere", w=self.size*.2)
        att.setKeyableAttributes(self.tan0_ctl, self.t_params)

        t = tra.setMatrixPosition(t, vec.linearlyInterpolate(self.guide.apos[0], self.guide.apos[1], .66))
        self.tan1_npo = pri.addTransform(self.ik1_ctl, self.getName("tan1_npo"), t)
        self.tan1_ctl = self.addCtl(self.tan1_npo, "tan1_ctl", t, self.color_ik, "sphere", w=self.size*.2)
        att.setKeyableAttributes(self.tan1_ctl, self.t_params)

        # Curves -------------------------------------------
        self.mst_crv = cur.addCnsCurve(self.root, self.getName("mst_crv"), [self.ik0_ctl, self.tan0_ctl, self.tan1_ctl, self.ik1_ctl], 3)
        self.slv_crv = cur.addCurve(self.root, self.getName("slv_crv"), [dt.Vector()]*10, False, 3)
        self.mst_crv.setAttr("visibility", False)
        self.slv_crv.setAttr("visibility", False)

        # Division -----------------------------------------
        # The user only define how many intermediate division he wants.
        # First and last divisions are an obligation.
        parentdiv = self.root
        parentctl = self.root
        self.div_cns = []
        self.fk_ctl = []
        self.fk_npo = []
        self.scl_npo = []
        for i in range(self.settings["division"]):

            # References
            div_cns = pri.addTransform(parentdiv, self.getName("%s_cns"%i))
            setAttr(div_cns+".inheritsTransform", False)
            self.div_cns.append(div_cns)
            parentdiv = div_cns

            scl_npo = pri.addTransform(parentctl, self.getName("%s_scl_npo"%i), tra.getTransform(parentctl))
            
            # Controlers (First and last one are fake)
            if i in [0, self.settings["division"] - 1]:
                fk_ctl = pri.addTransform(scl_npo, self.getName("%s_loc"%i), tra.getTransform(parentctl))
                fk_npo = fk_ctl
            else:
                fk_npo = pri.addTransform(scl_npo, self.getName("fk%s_npo"%(i-1)), tra.getTransform(parentctl))
                fk_ctl = self.addCtl(fk_npo, "fk%s_ctl"%(i-1), tra.getTransform(parentctl), self.color_fk, "cube", w=self.size, h=self.size*.05, d=self.size)
                att.setKeyableAttributes(self.fk_ctl)
                att.setRotOrder(fk_ctl, "XZY")

            # setAttr(fk_npo+".inheritsTransform", False)
            self.scl_npo.append(scl_npo)
            self.fk_npo.append(fk_npo)
            self.fk_ctl.append(fk_ctl)
            parentctl = fk_ctl

            # Deformers (Shadow)
            self.addShadow(fk_ctl, i)

        # Connections (Hooks) ------------------------------
        self.cnx0 = pri.addTransform(self.root, self.getName("0_cnx"))
        self.cnx1 = pri.addTransform(self.root, self.getName("1_cnx"))