Ejemplo n.º 1
0
    def addDispCurve(self, name, centers=[], degree=1):
        """
        Add a display curve object to the guide.
        Display curve object is a simple curve to show the connection between different guide element..

        Args:
            name (str): Local name of the element.
            centers (list of dagNode):  List of object to define the curve.
            degree (int): Curve degree. Default 1 = lineal.

        Returns:
            dagNode: The newly creted curve.

        """
        crv = cur.addCnsCurve(centers[0], self.getName(name), centers, degree)
        crv.attr("overrideEnabled").set(1)
        crv.attr("overrideDisplayType").set(1)

        return crv
Ejemplo n.º 2
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"])
Ejemplo n.º 3
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.WIP = self.options["mode"]

        if self.negate and self.settings["overrideNegate"]:
            self.negate = False
            self.n_factor = 1

        if self.settings["overrideNegate"]:
            self.mirror_conf = [0, 0, 1, 1, 1, 0, 0, 0, 0]
        else:
            self.mirror_conf = [0, 0, 0, 0, 0, 0, 0, 0, 0]

        # FK controllers ------------------------------------
        self.fk_npo = []
        self.fk_ctl = []
        self.tweak_ctl = []
        self.upv_curv_lvl = []
        t = self.guide.tra["root"]

        parent = self.root
        tOld = False
        fk_ctl = None
        self.previusTag = self.parentCtlTag
        for i, t in enumerate(
                transform.getChainTransform(self.guide.apos, self.normal,
                                            self.negate)):
            self.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))

            fk_npo = primitive.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=self.dist,
                                 h=self.size * .1,
                                 d=self.size * .1,
                                 po=datatypes.Vector(
                                     self.dist * .5 * self.n_factor, 0, 0),
                                 tp=self.previusTag,
                                 mirrorConf=self.mirror_conf)

            tweak_ctl = self.addCtl(fk_ctl,
                                    "tweak%s_ctl" % i,
                                    t,
                                    self.color_ik,
                                    "square",
                                    w=self.size * .15,
                                    h=self.size * .15,
                                    d=self.size * .15,
                                    ro=datatypes.Vector([0, 0, 1.5708]),
                                    tp=self.previusTag,
                                    mirrorConf=self.mirror_conf)

            upv_curv_lvl = primitive.addTransform(
                tweak_ctl, self.getName("upv%s_lvl" % i), t)
            upv_curv_lvl.attr("tz").set(.01)

            self.fk_npo.append(fk_npo)
            self.fk_ctl.append(fk_ctl)
            self.tweak_ctl.append(tweak_ctl)
            self.upv_curv_lvl.append(upv_curv_lvl)
            tOld = t
            self.previusTag = fk_ctl
            parent = fk_ctl

            # self.jnt_pos.append([fk_ctl, i, None, False])

        # add end control
        tweak_npo = primitive.addTransform(fk_ctl,
                                           self.getName("tweakEnd_npo"), t)
        tweak_ctl = self.addCtl(tweak_npo,
                                "tweakEnd_ctl",
                                t,
                                self.color_ik,
                                "square",
                                w=self.size * .15,
                                h=self.size * .15,
                                d=self.size * .15,
                                ro=datatypes.Vector([0, 0, 1.5708]),
                                tp=self.previusTag,
                                mirrorConf=self.mirror_conf)

        upv_curv_lvl = primitive.addTransform(tweak_ctl,
                                              self.getName("upvEnd_lvl"), t)
        upv_curv_lvl.attr("tz").set(.01)

        if self.negate:
            self.off_dist = self.dist * -1
        else:
            self.off_dist = self.dist
        tweak_npo.attr("tx").set(self.off_dist)

        self.tweak_ctl.append(tweak_ctl)
        self.upv_curv_lvl.append(upv_curv_lvl)

        # add length offset control if keep length
        # This option will be added only if keep length is active
        if self.settings["keepLength"]:
            self.tweakTip_npo = primitive.addTransform(
                tweak_ctl, self.getName("tweakTip_npo"), t)
            tweak_ctl = self.addCtl(self.tweakTip_npo,
                                    "tweakTip_ctl",
                                    t,
                                    self.color_fk,
                                    "square",
                                    w=self.size * .1,
                                    h=self.size * .1,
                                    d=self.size * .1,
                                    ro=datatypes.Vector([0, 0, 1.5708]),
                                    tp=self.previusTag,
                                    mirrorConf=self.mirror_conf)

            upv_curv_lvl = primitive.addTransform(tweak_ctl,
                                                  self.getName("upvTip_lvl"),
                                                  t)
            upv_curv_lvl.attr("tz").set(.01)

            # move to align with the parent
            self.tweakTip_npo.attr("tx").set(0)

            self.tweak_ctl.append(tweak_ctl)
            self.upv_curv_lvl.append(upv_curv_lvl)

            # add visual reference
            self.line_ref = icon.connection_display_curve(
                self.getName("visualRef"),
                [self.tweakTip_npo.getParent(), tweak_ctl])

        # set keyable attr for tweak controls
        [
            attribute.setKeyableAttributes(t_ctl, ["tx", "ty", "tz", "rx"])
            for t_ctl in self.tweak_ctl
        ]

        # Curves -------------------------------------------
        self.mst_crv = curve.addCnsCurve(self.root, self.getName("mst_crv"),
                                         self.tweak_ctl[:], 3)

        self.upv_crv = curve.addCnsCurve(self.root, self.getName("upv_crv"),
                                         self.upv_curv_lvl, 3)

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

        # Divisions
        self.div_cns = []
        self.upv_cns = []

        if self.settings["overrideJntNb"]:
            self.def_number = self.settings["jntNb"]
        else:
            self.def_number = len(self.guide.apos)

        for i in range(self.def_number):
            # References
            div_cns = primitive.addTransform(self.root,
                                             self.getName("%s_cns" % i))

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

            upv_cns = primitive.addTransform(self.root,
                                             self.getName("%s_upv" % i))

            pm.setAttr(upv_cns + ".inheritsTransform", False)
            self.upv_cns.append(upv_cns)

            self.jnt_pos.append([div_cns, i])
Ejemplo n.º 4
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"))
Ejemplo n.º 5
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")
Ejemplo n.º 6
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"))
Ejemplo n.º 7
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"])
Ejemplo n.º 8
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")
Ejemplo n.º 9
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"))