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.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"])
Ejemplo n.º 2
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))
Ejemplo n.º 3
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])