Ejemplo n.º 1
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

        # FK controllers ------------------------------------
        self.fk_npo = []
        self.fk_ctl = []
        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)):
            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=dist,
                                 h=self.size * .1,
                                 d=self.size * .1,
                                 po=datatypes.Vector(dist * .5 * self.n_factor,
                                                     0, 0),
                                 tp=self.previusTag)

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

            self.jnt_pos.append([fk_ctl, i, None, False])
Ejemplo n.º 2
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.º 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.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])
Ejemplo n.º 4
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