Beispiel #1
0
    def initialHierarchy(self):

        # Get color
        if self.settings["color"] == 0:
            color = self.color_ik
        elif self.settings["color"] == 1:
            color = self.color_fk
        else:
            color = [self.settings["color_r"], self.settings["color_g"], self.settings["color_b"]]

        # Copy controler from given icon
        self.root = self.guide.prim["icon"].create(self.model, self.getName("ctl"), self.guide.tra["icon"], color)
        par.setRotOrder(self.root, self.settings["rotOrderSel"])
        self.addToCtlGroup(self.root)

        # Shd --------------------------------
        if self.options["shadowRig"] and self.settings["shadow"]:
            self.shd_org = self.rig.shd_org.AddNull(self.getName("shd_org"))
            self.addToGroup(self.shd_org, "hidden")
Beispiel #2
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_ctl = self.addCtl(self.root, "ik0_ctl", t, self.color_ik, "compas", w=self.size)
        par.setKeyableParameters(self.ik0_ctl)
        xsi.SetNeutralPose(self.ik0_ctl)
        par.addLocalParamToCollection(self.inv_params, self.ik0_ctl, ["posx", "roty", "rotz"])
        par.setRotOrder(self.ik0_ctl, "XZY")

        t.SetTranslation(self.guide.apos[1])
        self.ik1_ctl = self.addCtl(self.root, "ik1_ctl", t, self.color_ik, "compas", w=self.size)
        par.setKeyableParameters(self.ik1_ctl)
        xsi.SetNeutralPose(self.ik1_ctl)
        par.addLocalParamToCollection(self.inv_params, self.ik1_ctl, ["posx", "roty", "rotz"])
        par.setRotOrder(self.ik1_ctl, "XZY")

        # Tangent controlers -------------------------------
        t.SetTranslation(vec.linearlyInterpolate(self.guide.apos[0], self.guide.apos[1], .33))
        self.tan0_ctl = self.addCtl(self.ik0_ctl, "tan0_ctl", t, self.color_ik, "sphere", w=self.size*.2)
        par.setKeyableParameters(self.tan0_ctl, self.t_params)
        xsi.SetNeutralPose(self.tan0_ctl, c.siTrn)
        par.addLocalParamToCollection(self.inv_params, self.ik1_ctl, ["posx"])

        t.SetTranslation(vec.linearlyInterpolate(self.guide.apos[0], self.guide.apos[1], .66))
        self.tan1_ctl = self.addCtl(self.ik1_ctl, "tan1_ctl", t, self.color_ik, "sphere", w=self.size*.2)
        par.setKeyableParameters(self.tan1_ctl, self.t_params)
        xsi.SetNeutralPose(self.tan1_ctl, c.siTrn)
        par.addLocalParamToCollection(self.inv_params, self.ik1_ctl, ["posx"])

        # Curves -------------------------------------------
        self.mst_crv = cur.addCnsCurve(self.root, self.getName("mst_crv"), [self.ik0_ctl, self.tan0_ctl, self.tan1_ctl, self.ik1_ctl], False, 3)
        self.slv_crv = cur.addCurve(self.root, self.getName("slv_crv"), [1]*10*4, False, 3)
        self.addToGroup([self.mst_crv, self.slv_crv], "hidden")

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

            # References
            div_cns = parentdiv.AddNull(self.getName("%s_cns"%i))
            pri.setNullDisplay(div_cns, 1, self.size*.05, 10, 0, 0, 0, 1, 1, 2)
            self.addToGroup(div_cns, "hidden")

            self.div_cns.append(div_cns)
            parentdiv = div_cns

            # Controlers (First and last one are fake)
            if i in [0, self.settings["division"] - 1]:
                fk_ctl = pri.addNull(parentctl, self.getName("%s_loc"%i), parentctl.Kinematics.Global.Transform, self.size*.05)
                self.addToGroup(fk_ctl, "hidden")
            else:
                fk_ctl = self.addCtl(parentctl, "fk%s_ctl"%(i-1), parentctl.Kinematics.Global.Transform, self.color_fk, "cube", w=self.size*1, h=self.size*.05, d=self.size*1)
                self.addToGroup(fk_ctl, "controlers_01")
                par.addLocalParamToCollection(self.inv_params, fk_ctl, ["posx", "roty", "rotz"])
                par.setRotOrder(fk_ctl, "XZY")

            self.fk_ctl.append(fk_ctl)
            parentctl = fk_ctl

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

        # Connections (Hooks) ------------------------------
        self.cnx0 = pri.addNull(self.root, self.getName("0_cnx"), self.root.Kinematics.Global.Transform, self.size*.2)
        self.cnx1 = pri.addNull(self.root, self.getName("1_cnx"), self.root.Kinematics.Global.Transform, self.size*.2)
        self.addToGroup([self.cnx0, self.cnx1], "hidden")
Beispiel #3
0
    def addOperators(self):

        # Visibilities -------------------------------------
        par.addExpression(self.fk0_ctl.Properties("visibility").Parameters("viewvis"), "1 - "+self.pBlend.FullName)
        par.addExpression(self.fk1_ctl.Properties("visibility").Parameters("viewvis"), "1 - "+self.pBlend.FullName)
        par.addExpression(self.fk2_ctl.Properties("visibility").Parameters("viewvis"), "1 - "+self.pBlend.FullName)

        par.addExpression(self.upv_ctl.Properties("visibility").Parameters("viewvis"), self.pBlend.FullName)
        par.addExpression(self.ikcns_ctl.Properties("visibility").Parameters("viewvis"), self.pBlend.FullName +" * "+ self.pIkCns.FullName)
        par.addExpression(self.ik_ctl.Properties("visibility").Parameters("viewvis"), self.pBlend.FullName)

        # Leash --------------------------------------------
        aop.clsCtrOp(self.upv_ctl, self.mid_ctl, [0])

        # IK Solver-----------------------------------------
        out = [self.bone0, self.bone1, None, self.eff_loc]
        op = aop.sn_ikfk2bone_op(out, self.root, self.ik_ctl, self.upv_ctl, self.fk0_ctl, self.fk1_ctl, self.fk2_ctl, self.length0, self.length1, self.negate)

        par.addExpression(op.Parameters("blend"), self.pBlend.FullName)
        par.addExpression(op.Parameters("roll"), self.pIkRoll.FullName)
        par.addExpression(op.Parameters("scaleA"), self.pScale.FullName)
        par.addExpression(op.Parameters("scaleB"), self.pScale.FullName)
        par.addExpression(op.Parameters("maxstretch"), self.pMaxStretch.FullName)
        par.addExpression(op.Parameters("softness"), self.pSoftness.FullName)
        par.addExpression(op.Parameters("slide"), self.pSlide.FullName)
        par.addExpression(op.Parameters("reverse"), self.pReverse.FullName)

        # I'm not using the output of the solver to get the ctrn because it only has a +/-180 degree
        # With this simple expression I have a much better result
        # Also remove scaling from ctrn
        for s in "xyz":
            par.addExpression(self.ctrn_loc.Kinematics.Local.Parameters("rot"+s), self.bone1.Kinematics.Local.Parameters("rot"+s).FullName + " * .5")
            par.addExpression(self.ctrn_loc.Kinematics.Global.Parameters("scl"+s), self.root.Kinematics.Global.Parameters("scl"+s).FullName)

        # Membrane
        par.addExpression(self.memb_loc.Kinematics.Local.Parameters("posy"), self.pStartPos.FullName+" + ("+self.pEndPos.FullName+" - "+self.pStartPos.FullName+") * ( 1 - ( ctr_dist("+self.root.Kinematics.Global.FullName+","+self.eff_loc.Kinematics.Global.FullName+") / "+self.pRestDist.FullName+"))")

        # Twist references ---------------------------------
        self.pRestDist.Value = vec.getDistance2(self.root, self.eff_loc)
        par.addExpression(self.pDriver, "(ctr_dist(%s, %s) + ctr_dist(%s, %s)) / %s"
                                        %(self.tws0_loc.Kinematics.Global.FullName, self.tws1_loc.Kinematics.Global.FullName,
                                          self.tws1_loc.Kinematics.Global.FullName, self.tws2_loc.Kinematics.Global.FullName,
                                          self.root.Kinematics.Global.Parameters("sclx").FullName))

        self.tws0_loc.Kinematics.AddConstraint("Pose", self.root, True)
        aop.dirCns(self.tws0_loc, self.mid_ctl, None, False, self.n_sign+"xy")
        
        self.tws1_loc.Kinematics.AddConstraint("Position", self.mid_ctl)
        self.tws1_loc.Kinematics.AddConstraint("Scaling", self.mid_ctl)
        self.tws1_rot.Kinematics.AddConstraint("Orientation", self.mid_ctl)
        par.addExpression(self.tws1_rot.Parameters("rotx"), 0)
        par.addExpression(self.tws1_rot.Parameters("roty"), 0)
        par.addExpression(self.tws1_rot.Parameters("rotz"), 0)

        self.tws2_loc.Kinematics.AddConstraint("Position", self.eff_loc)
        self.tws2_loc.Kinematics.AddConstraint("Scaling", self.eff_loc)
        aop.poseCns(self.tws2_rot, self.eff_loc, False, False, True, False)
        par.addExpression(self.tws2_rot.Parameters("rotx"), 0)
        par.addExpression(self.tws2_rot.Parameters("roty"), 0)
        par.addExpression(self.tws2_rot.Parameters("rotz"), 0)
        par.setRotOrder(self.tws2_rot, "YZX")

        self.tws0_rot.SclX = .001
        par.addExpression(self.tws1_rot.SclX, self.pRoundness.FullName + " + .001")
        self.tws2_rot.SclX = .001

        # Divisions ----------------------------------------
        # at 0 or 1 the division will follow exactly the rotation of the controler.. and we wont have this nice tangent + roll
        for i, div_cns in enumerate(self.div_cns):

            if i < (self.settings["div0"]+1):
                perc = i*.5 / (self.settings["div0"]+1.0)
            else:
                perc = .5 + (i-self.settings["div0"]-1.0)*.5 / (self.settings["div1"]+1.0)

            perc = max(.001, min(.999, perc))

            # Roll
            if self.negate:
                op = aop.sn_rollsplinekine_op(div_cns, [self.tws2_rot, self.tws1_rot, self.tws0_rot], 1-perc)
            else:
                op = aop.sn_rollsplinekine_op(div_cns, [self.tws0_rot, self.tws1_rot, self.tws2_rot], perc)

            # Squash n Stretch
            op = aop.sn_squashstretch2_op(div_cns, self.root, self.pDriver.Value, "x")
            par.addExpression(op.Parameters("blend"), self.pVolume.FullName)
            par.addExpression(op.Parameters("driver"), self.pDriver.FullName)
            if self.options["mode"] == 1: # wip
                par.addExpression(op.Parameters("stretch"), self.pStretch[i])
                par.addExpression(op.Parameters("squash"), self.pSquash[i])
            else:
                op.Parameters("stretch").Value = self.st_value[i]
                op.Parameters("squash").Value = self.sq_value[i]
Beispiel #4
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.SetTranslation(self.guide.pos["neck"])
        self.ik_cns = pri.addNull(self.root, self.getName("ik_cns"), t,
                                  self.size * .02)
        self.addToGroup(self.ik_cns, "hidden")

        self.ik_ctl = self.addCtl(self.ik_cns,
                                  "ik_ctl",
                                  t,
                                  self.color_ik,
                                  "compas",
                                  w=self.size * .5)
        par.setKeyableParameters(self.ik_ctl)
        xsi.SetNeutralPose(self.ik_ctl, c.siTrn)
        par.setRotOrder(self.ik_ctl, "XZY")

        # Tangents -----------------------------------------
        t.SetTranslation(self.guide.pos["tan1"])
        self.tan1_loc = pri.addNull(self.ik_ctl, self.getName("tan1_loc"), t,
                                    self.size * .1)
        par.setKeyableParameters(self.tan1_loc, self.t_params)
        xsi.SetNeutralPose(self.tan1_loc, c.siTrn)
        self.addToGroup(self.tan1_loc, "hidden")

        t = tra.getTransformLookingAt(self.guide.pos["root"],
                                      self.guide.pos["tan0"],
                                      self.guide.blades["blade"].z, "yx",
                                      self.negate)
        t.SetTranslation(self.guide.pos["tan0"])
        self.tan0_loc = pri.addNull(self.root, self.getName("tan0_loc"), t,
                                    self.size * .1)
        xsi.SetNeutralPose(self.tan0_loc, c.siTrn)
        self.addToGroup(self.tan0_loc, "hidden")

        # Curves -------------------------------------------
        self.mst_crv = cur.addCnsCurve(
            self.root, self.getName("mst_crv"),
            [self.root, self.tan0_loc, self.tan1_loc, self.ik_ctl], False, 3)
        self.slv_crv = cur.addCurve(self.root, self.getName("slv_crv"),
                                    [1] * 10 * 4, False, 3)
        self.addToGroup([self.mst_crv, self.slv_crv], "hidden")

        # 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 = []
        for i in range(self.settings["division"]):

            # References
            div_cns = parentdiv.AddNull(self.getName("%s_cns" % i))
            pri.setNullDisplay(div_cns, 1, self.size * .05, 10, 0, 0, 0, 1, 1,
                               2)
            self.addToGroup(div_cns, "hidden")

            self.div_cns.append(div_cns)
            parentdiv = div_cns

            # Controlers
            if i == self.settings["division"] - 1:
                fk_ctl = pri.addNull(parentctl, self.getName("fk%s_cns" % i),
                                     parentctl.Kinematics.Global.Transform,
                                     self.size * .2)
                self.addToGroup(fk_ctl, "hidden")
            else:
                fk_ctl = self.addCtl(parentctl,
                                     "fk%s_ctl" % i,
                                     parentctl.Kinematics.Global.Transform,
                                     self.color_fk,
                                     "cube",
                                     w=self.size * .5,
                                     h=self.size * .05,
                                     d=self.size * .5)
                par.setRotOrder(fk_ctl, "XZY")

            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.addNull(self.root, self.getName("head_cns"), t,
                                    self.size * .1)
        self.addToGroup(self.head_cns, "hidden")

        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=XSIMath.CreateVector3(0, dist * .5, 0))
        par.setRotOrder(self.head_ctl, "XZY")

        self.addShadow(self.head_ctl, "head")
Beispiel #5
0
    def addOperators(self):

        # Visibilities -------------------------------------
        par.addExpression(self.fk0_ctl.Properties("visibility").Parameters("viewvis"), "1 - "+self.pBlend.FullName)
        par.addExpression(self.fk1_ctl.Properties("visibility").Parameters("viewvis"), "1 - "+self.pBlend.FullName)
        par.addExpression(self.fk2_ctl.Properties("visibility").Parameters("viewvis"), "1 - "+self.pBlend.FullName)
        par.addExpression(self.fk3_ctl.Properties("visibility").Parameters("viewvis"), "1 - "+self.pBlend.FullName)

        par.addExpression(self.upv_ctl.Properties("visibility").Parameters("viewvis"), self.pBlend.FullName)
        par.addExpression(self.ikcns_ctl.Properties("visibility").Parameters("viewvis"), self.pBlend.FullName +" * "+ self.pIkCns.FullName)
        par.addExpression(self.ik_ctl.Properties("visibility").Parameters("viewvis"), self.pBlend.FullName)

        if self.settings["roll"] == 0:
            par.addExpression(self.roll_ctl.Properties("visibility").Parameters("viewvis"), self.pBlend.FullName)

        # Leash --------------------------------------------
        aop.clsCtrOp(self.upv_ctl, self.mid0_ctl, [0])

        # IK Solver-----------------------------------------
        self.roll_ctl.Kinematics.AddConstraint("Position", self.ik_ref, False)

        self.ref_chn.eff.Kinematics.AddConstraint("Pose", self.roll_ctl, True)
        self.end_chn.eff.Kinematics.AddConstraint("Pose", self.roll_ctl, True)

        op = xsi.ApplyOp("SkeletonUpVector", self.ref_chn.bones[0].FullName+";"+self.upv_ctl.FullName)[0]
        par.addExpression(self.ref_chn.roll, self.pIkRoll.FullName + " + 180")
        op = xsi.ApplyOp("SkeletonUpVector", self.end_chn.bones[0].FullName+";"+self.upv_ctl.FullName)[0]
        par.addExpression(self.end_chn.roll, self.pIkRoll.FullName + " + 180")

        # ctrn
        for s in "xyz":
            par.addExpression(self.ctrn0_loc.Kinematics.Local.Parameters("rot" + s), self.ref_loc[1].Kinematics.Local.Parameters("rot" + s).FullName + " * .5")
            par.addExpression(self.ctrn0_loc.Kinematics.Global.Parameters("scl" + s), self.root.Kinematics.Global.Parameters("scl" + s).FullName)
            par.addExpression(self.ctrn1_loc.Kinematics.Local.Parameters("rot" + s), self.ref_loc[2].Kinematics.Local.Parameters("rot" + s).FullName + " * .5")
            par.addExpression(self.ctrn1_loc.Kinematics.Global.Parameters("scl" + s), self.root.Kinematics.Global.Parameters("scl" + s).FullName)

        self.ctrn0_loc.Kinematics.AddConstraint("Position", self.ref_loc[1], False)
        self.ctrn1_loc.Kinematics.AddConstraint("Position", self.ref_loc[2], False)

        # References Nulls ---------------------------------
        fk_ref = [self.fk0_ctl, self.fk1_ctl, self.fk2_ctl, self.fk_ref]
        ik_ref = [self.ref_chn.bones[0], self.ref_chn.bones[1], self.end_chn.bones[0], self.ik_ref]
        for i, ref_loc in enumerate(self.ref_loc):

            # fk
            cns = ref_loc.Kinematics.AddConstraint("Orientation", fk_ref[i], False)
            if i != len(self.ref_loc)-1:
                cns = aop.dirCns(ref_loc, fk_ref[i+1], None, False, self.n_sign+"xz")
                par.addExpression(cns.Parameters("blendweight"), "1 - " + self.pBlend.FullName)

            #ik
            cns = ref_loc.Kinematics.AddConstraint("Orientation", ik_ref[i], False)
            par.addExpression(cns.Parameters("blendweight"), self.pBlend.FullName)

            for s in "xyz":
                par.addExpression(ref_loc.Kinematics.Local.Parameters("rot"+s), 0)

        par.addExpression(self.ref_loc[1].Kinematics.Local.Parameters("posx"), self.n_sign+" (ctr_dist(%s.kine.global, %s.kine.global) * (1 - %s) + ctr_dist(%s.kine.global, %s.kine.global) * %s)"%(self.fk0_ctl.FullName, self.fk1_ctl.FullName, self.pBlend.FullName, self.ref_chn.bones[0].FullName, self.ref_chn.bones[1].FullName, self.pBlend.FullName))
        par.addExpression(self.ref_loc[2].Kinematics.Local.Parameters("posx"), self.n_sign+" (ctr_dist(%s.kine.global, %s.kine.global) * (1 - %s) + ctr_dist(%s.kine.global, %s.kine.global) * %s)"%(self.fk1_ctl.FullName, self.fk2_ctl.FullName, self.pBlend.FullName, self.ref_chn.bones[1].FullName, self.end_chn.bones[0], self.pBlend.FullName))
        par.addExpression(self.ref_loc[3].Kinematics.Local.Parameters("posx"), self.n_sign+" (ctr_dist(%s.kine.global, %s.kine.global) * (1 - %s) + ctr_dist(%s.kine.global, %s.kine.global) * %s)"%(self.fk2_ctl.FullName, self.fk3_ctl.FullName, self.pBlend.FullName, self.end_chn.bones[0].FullName, self.end_chn.eff, self.pBlend.FullName))

        # Global Scale
        for s in "xyz":   
            par.addExpression(self.ref_loc[0].Kinematics.Global.Parameters("scl%s"%s), 1)     
            par.addExpression(self.end_ref.Kinematics.Global.Parameters("scl%s"%s), self.root.Kinematics.Global.Parameters("scl%s"%s))

        # Twist references ---------------------------------
        par.addExpression(self.pDriver, "(ctr_dist(%s, %s) + ctr_dist(%s, %s) + ctr_dist(%s, %s)) / %s"
                                        %(self.tws0_loc.Kinematics.Global.FullName, self.tws1_loc.Kinematics.Global.FullName,
                                          self.tws1_loc.Kinematics.Global.FullName, self.tws2_loc.Kinematics.Global.FullName,
                                          self.tws2_loc.Kinematics.Global.FullName, self.tws3_loc.Kinematics.Global.FullName,
                                          self.root.Kinematics.Global.Parameters("sclx").FullName))

        self.tws0_loc.Kinematics.AddConstraint("Pose", self.root, True)
        aop.dirCns(self.tws0_loc, self.mid0_ctl, None, False, self.n_sign+"xy")
        
        self.tws1_loc.Kinematics.AddConstraint("Position", self.mid0_ctl)
        self.tws1_loc.Kinematics.AddConstraint("Scaling", self.mid0_ctl)
        self.tws1_rot.Kinematics.AddConstraint("Orientation", self.mid0_ctl)
        par.addExpression(self.tws1_rot.Parameters("rotx"), 0)
        par.addExpression(self.tws1_rot.Parameters("roty"), 0)
        par.addExpression(self.tws1_rot.Parameters("rotz"), 0)

        self.tws2_loc.Kinematics.AddConstraint("Position", self.mid1_ctl)
        self.tws2_loc.Kinematics.AddConstraint("Scaling", self.mid1_ctl)
        self.tws2_rot.Kinematics.AddConstraint("Orientation", self.mid1_ctl)
        par.addExpression(self.tws2_rot.Parameters("rotx"), 0)
        par.addExpression(self.tws2_rot.Parameters("roty"), 0)
        par.addExpression(self.tws2_rot.Parameters("rotz"), 0)

        self.tws3_loc.Kinematics.AddConstraint("Position", self.ref_loc[-1])
        #self.tws3_loc.Kinematics.AddConstraint("Scaling", self.eff_loc)
        aop.poseCns(self.tws3_rot, self.fk_ref, False, False, True, False)
        cns = aop.poseCns(self.tws3_rot, self.ik_ref, True, False, True, False)
        par.addExpression(cns.Parameters("blendweight"), self.pBlend.FullName)
        par.addExpression(self.tws3_rot.Parameters("rotx"), 0)
        par.addExpression(self.tws3_rot.Parameters("roty"), 0)
        par.addExpression(self.tws3_rot.Parameters("rotz"), 0)
        par.setRotOrder(self.tws3_rot, "YZX")

        self.tws0_rot.SclX = .001
        par.addExpression(self.tws1_rot.SclX, self.pRoundness.FullName + " + .001")
        par.addExpression(self.tws2_rot.SclX, self.pRoundness.FullName + " + .001")
        self.tws3_rot.SclX = .001

        # Divisions ----------------------------------------
        # at 0 or 1 the division will follow exactly the rotation of the controler.. and we wont have this nice tangent + roll
        for i, div_cns in enumerate(self.div_cns):

            if i < (self.settings["div0"]+1):
                perc = i / ((self.settings["div0"]+1.0)*3)
            elif i < (self.settings["div0"]+self.settings["div1"]+2):
                perc = (1/3.0) + ((i-self.settings["div0"]-1.0) / ((self.settings["div1"]+1.0)*3))
            else:
                perc = (2/3.0) + ((i-self.settings["div0"]-self.settings["div1"]-2.0) / ((self.settings["div2"]+1.0)*3))

            perc = max(.001, min(.999, perc))

            if self.negate:
                op = aop.sn_rollsplinekine_op(div_cns, [self.tws3_rot, self.tws2_rot, self.tws1_rot, self.tws0_rot], 1-perc)
            else:
                op = aop.sn_rollsplinekine_op(div_cns, [self.tws0_rot, self.tws1_rot, self.tws2_rot, self.tws3_rot], perc)

            # Squash n Stretch
            op = aop.sn_squashstretch2_op(div_cns, self.root, self.pDriver.Value, "x")
            par.addExpression(op.Parameters("blend"), self.pVolume.FullName)
            par.addExpression(op.Parameters("driver"), self.pDriver.FullName)
            if self.options["mode"] == 1: # wip
                par.addExpression(op.Parameters("stretch"), self.pStretch[i])
                par.addExpression(op.Parameters("squash"), self.pSquash[i])
            else:
                op.Parameters("stretch").Value = self.st_value[i]
                op.Parameters("squash").Value = self.sq_value[i]
Beispiel #6
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.SetTranslation(self.guide.pos["neck"])
        self.ik_cns = pri.addNull(self.root, self.getName("ik_cns"), t, self.size*.02)
        self.addToGroup(self.ik_cns, "hidden")

        self.ik_ctl = self.addCtl(self.ik_cns, "ik_ctl", t, self.color_ik, "compas", w=self.size*.5)
        par.setKeyableParameters(self.ik_ctl)
        xsi.SetNeutralPose(self.ik_ctl, c.siTrn)
        par.setRotOrder(self.ik_ctl, "XZY")

        # Tangents -----------------------------------------
        t.SetTranslation(self.guide.pos["tan1"])
        self.tan1_loc = pri.addNull(self.ik_ctl, self.getName("tan1_loc"), t, self.size*.1)
        par.setKeyableParameters(self.tan1_loc, self.t_params)
        xsi.SetNeutralPose(self.tan1_loc, c.siTrn)
        self.addToGroup(self.tan1_loc, "hidden")
        
        t = tra.getTransformLookingAt(self.guide.pos["root"], self.guide.pos["tan0"], self.guide.blades["blade"].z, "yx", self.negate)
        t.SetTranslation(self.guide.pos["tan0"])
        self.tan0_loc = pri.addNull(self.root, self.getName("tan0_loc"), t, self.size*.1)
        xsi.SetNeutralPose(self.tan0_loc, c.siTrn)
        self.addToGroup(self.tan0_loc, "hidden")

        # Curves -------------------------------------------
        self.mst_crv = cur.addCnsCurve(self.root, self.getName("mst_crv"), [self.root, self.tan0_loc, self.tan1_loc, self.ik_ctl], False, 3)
        self.slv_crv = cur.addCurve(self.root, self.getName("slv_crv"), [1]*10*4, False, 3)
        self.addToGroup([self.mst_crv, self.slv_crv], "hidden")

        # 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 = []
        for i in range(self.settings["division"]):

            # References
            div_cns = parentdiv.AddNull(self.getName("%s_cns"%i))
            pri.setNullDisplay(div_cns, 1, self.size*.05, 10, 0, 0, 0, 1, 1, 2)
            self.addToGroup(div_cns, "hidden")

            self.div_cns.append(div_cns)
            parentdiv = div_cns

            # Controlers
            if i == self.settings["division"]-1:
                fk_ctl = pri.addNull(parentctl, self.getName("fk%s_cns"%i), parentctl.Kinematics.Global.Transform, self.size*.2)
                self.addToGroup(fk_ctl, "hidden")
            else:
                fk_ctl = self.addCtl(parentctl, "fk%s_ctl"%i, parentctl.Kinematics.Global.Transform, self.color_fk, "cube", w=self.size*.5, h=self.size*.05, d=self.size*.5)
                par.setRotOrder(fk_ctl, "XZY")
        
            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.addNull(self.root, self.getName("head_cns"), t, self.size*.1)
        self.addToGroup(self.head_cns, "hidden")

        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=XSIMath.CreateVector3(0,dist*.5,0))
        par.setRotOrder(self.head_ctl, "XZY")

        self.addShadow(self.head_ctl, "head")
Beispiel #7
0
    def addOperators(self):

        # Visibilities -------------------------------------
        par.addExpression(self.fk0_ctl.Properties("visibility").Parameters("viewvis"), "1 - "+self.pBlend.FullName)
        par.addExpression(self.fk1_ctl.Properties("visibility").Parameters("viewvis"), "1 - "+self.pBlend.FullName)
        par.addExpression(self.fk2_ctl.Properties("visibility").Parameters("viewvis"), "1 - "+self.pBlend.FullName)

        par.addExpression(self.upv_ctl.Properties("visibility").Parameters("viewvis"), self.pBlend.FullName)
        par.addExpression(self.leash_crv.Properties("visibility").Parameters("viewvis"), self.pBlend.FullName)
        par.addExpression(self.ikcns_ctl.Properties("visibility").Parameters("viewvis"), self.pBlend.FullName +" * "+ self.pIkCns.FullName)
        par.addExpression(self.ik_ctl.Properties("visibility").Parameters("viewvis"), self.pBlend.FullName)

        # Twist --------------------------------------------
        for i, div_loc in enumerate(self.div0_loc):

            if i == 0:
                cns = aop.gear_dualUpVDirCns(div_loc, self.chain.root, self.chain.bones[1])
                # cns = aop.dirCns(div_loc, self.chain.bones[1], None, False, "xy")
                # aop.gear_pointAtObjectAxis(cns, self.chain.root, [0,1,0])
            elif i == self.settings["division0"]-1:
                continue
            else:
                d = i/(self.settings["division0"]-1.0)

                cns = aop.dirCns(div_loc, self.chain.bones[1], None, False, "xy")
                op = aop.spinePointAtOp(cns, self.div0_loc[0], self.chain.bones[0], d)

        for i, div_loc in enumerate(self.div_loc):
            d = i/(self.settings["division1"]-1.0)
            par.addExpression(div_loc.Parameters("rotx"), self.end_ref.Parameters("rotx").FullName+" * "+str(d))

        # IK Solver-----------------------------------------
        # cns
        self.chain.eff.Kinematics.AddConstraint("Position", self.ik_ref, False)
        aop.chainUpvOp(self.chain, self.upv_ctl)

        for bone, fk_ctl, length, div in zip(self.chain.bones, [self.fk0_ctl, self.fk1_ctl], [self.length0, self.length1], self.div_loc):
        # for bone, fk in zip(self.chain.bones, [self.fk0_ctl, self.fk1_ctl]):
            # ik/fk orientation
            cns = bone.Kinematics.AddConstraint("Orientation", fk_ctl, False)
            par.addExpression(cns.Parameters("blendweight"), "1 - "+self.pBlend.FullName)

            # stretch
            fk_st = fk_ctl.Parameters("sclx").FullName + " * (1 - "+self.pBlend.FullName+")"
            root_eff_dist = "ctr_dist(%s.kine.global, %s.kine.global)"%(self.root.FullName, self.ik_ctl.FullName)
            ik_st = "cond("+root_eff_dist+" > "+str(self.chain.length)+", "+root_eff_dist+" / "+str(self.chain.length)+", 1) * "+self.pBlend.FullName

            parent_scl = bone.Parent3DObject.Parameters("sclx").FullName
            par.addExpression(bone.Parameters("sclx"), "("+fk_st+" + "+ik_st+")/"+parent_scl)

            # par.addExpression(div.Parameters("sclx"), bone.Parameters("length").FullName+"/"+str(length))

        # blend / roll
        par.addExpression(self.chain.blend, self.pBlend)
        par.addExpression(self.chain.roll, self.pIkRoll)

        # ctr_loc
        self.ctrn_loc.Kinematics.AddConstraint("Position", self.chain.bones[1], False)
        for s in "xyz":
            par.addExpression(self.ctrn_loc.Kinematics.Local.Parameters("rot"+s), self.chain.bones[1].Kinematics.Local.Parameters("rot" + s).FullName + " * .5")

        # Stretch -----------------------------------------
        # root_eff = "ctr_dist(%s.kine.global, %s.kine.global)"%(self.chain.root, self.ik_ref)
        # st_value = "(%s/%s)"%(root_eff,self.chain.length)
        # for bone in self.chain.bones:
            # par.addExpression(bone.Parameters("length"),
                              # "cond(%s>%s,%s*%s,%s)*%s + %s*(1 - %s)"%(root_eff,
                                                                     # self.chain.length,
                                                                     # bone.Parameters("length").Value,
                                                                     # st_value, bone.Parameters("length").Value,
                                                                     # self.pBlend.FullName,
                                                                     # bone.Parameters("length").Value,
                                                                     # self.pBlend.FullName))

        # Hook
        self.end_ref.Kinematics.AddConstraint("Position", self.chain.eff)
        self.end_ref.Kinematics.AddConstraint("Scaling", self.chain.eff)
        aop.poseCns(self.end_ref, self.fk2_ctl, True, False, True, False)
        cns = aop.poseCns(self.end_ref, self.ik_ref, True, False, True, False)
        par.addExpression(cns.Parameters("blendweight"), self.pBlend.fullName)
        par.addExpression(self.end_ref.Parameters("rotx"), 0)
        par.addExpression(self.end_ref.Parameters("roty"), 0)
        par.addExpression(self.end_ref.Parameters("rotz"), 0)
        par.setRotOrder(self.end_ref, "YZX")

        # Shape Reference ---------------------------------
        # shoulder
        aop.gear_rotationToPose(self.end_ref, self.chain.bones[1], self.ankle_outputs, "x", 0)
Beispiel #8
0
    def addOperators(self):

        # Visibilities -------------------------------------
        par.addExpression(
            self.fk0_ctl.Properties("visibility").Parameters("viewvis"),
            "1 - " + self.pBlend.FullName)
        par.addExpression(
            self.fk1_ctl.Properties("visibility").Parameters("viewvis"),
            "1 - " + self.pBlend.FullName)
        par.addExpression(
            self.fk2_ctl.Properties("visibility").Parameters("viewvis"),
            "1 - " + self.pBlend.FullName)
        par.addExpression(
            self.fk3_ctl.Properties("visibility").Parameters("viewvis"),
            "1 - " + self.pBlend.FullName)

        par.addExpression(
            self.upv_ctl.Properties("visibility").Parameters("viewvis"),
            self.pBlend.FullName)
        par.addExpression(
            self.ikcns_ctl.Properties("visibility").Parameters("viewvis"),
            self.pBlend.FullName + " * " + self.pIkCns.FullName)
        par.addExpression(
            self.ik_ctl.Properties("visibility").Parameters("viewvis"),
            self.pBlend.FullName)

        if self.settings["roll"] == 0:
            par.addExpression(
                self.roll_ctl.Properties("visibility").Parameters("viewvis"),
                self.pBlend.FullName)

        # Leash --------------------------------------------
        aop.clsCtrOp(self.upv_ctl, self.mid0_ctl, [0])

        # IK Solver-----------------------------------------
        self.roll_ctl.Kinematics.AddConstraint("Position", self.ik_ref, False)

        self.ref_chn.eff.Kinematics.AddConstraint("Pose", self.roll_ctl, True)
        self.end_chn.eff.Kinematics.AddConstraint("Pose", self.roll_ctl, True)

        op = xsi.ApplyOp(
            "SkeletonUpVector",
            self.ref_chn.bones[0].FullName + ";" + self.upv_ctl.FullName)[0]
        par.addExpression(self.ref_chn.roll, self.pIkRoll.FullName + " + 180")
        op = xsi.ApplyOp(
            "SkeletonUpVector",
            self.end_chn.bones[0].FullName + ";" + self.upv_ctl.FullName)[0]
        par.addExpression(self.end_chn.roll, self.pIkRoll.FullName + " + 180")

        # ctrn
        for s in "xyz":
            par.addExpression(
                self.ctrn0_loc.Kinematics.Local.Parameters("rot" + s),
                self.ref_loc[1].Kinematics.Local.Parameters("rot" + s).FullName
                + " * .5")
            par.addExpression(
                self.ctrn0_loc.Kinematics.Global.Parameters("scl" + s),
                self.root.Kinematics.Global.Parameters("scl" + s).FullName)
            par.addExpression(
                self.ctrn1_loc.Kinematics.Local.Parameters("rot" + s),
                self.ref_loc[2].Kinematics.Local.Parameters("rot" + s).FullName
                + " * .5")
            par.addExpression(
                self.ctrn1_loc.Kinematics.Global.Parameters("scl" + s),
                self.root.Kinematics.Global.Parameters("scl" + s).FullName)

        self.ctrn0_loc.Kinematics.AddConstraint("Position", self.ref_loc[1],
                                                False)
        self.ctrn1_loc.Kinematics.AddConstraint("Position", self.ref_loc[2],
                                                False)

        # References Nulls ---------------------------------
        fk_ref = [self.fk0_ctl, self.fk1_ctl, self.fk2_ctl, self.fk_ref]
        ik_ref = [
            self.ref_chn.bones[0], self.ref_chn.bones[1],
            self.end_chn.bones[0], self.ik_ref
        ]
        for i, ref_loc in enumerate(self.ref_loc):

            # fk
            cns = ref_loc.Kinematics.AddConstraint("Orientation", fk_ref[i],
                                                   False)
            if i != len(self.ref_loc) - 1:
                cns = aop.dirCns(ref_loc, fk_ref[i + 1], None, False,
                                 self.n_sign + "xz")
                par.addExpression(cns.Parameters("blendweight"),
                                  "1 - " + self.pBlend.FullName)

            #ik
            cns = ref_loc.Kinematics.AddConstraint("Orientation", ik_ref[i],
                                                   False)
            par.addExpression(cns.Parameters("blendweight"),
                              self.pBlend.FullName)

            for s in "xyz":
                par.addExpression(
                    ref_loc.Kinematics.Local.Parameters("rot" + s), 0)

        par.addExpression(
            self.ref_loc[1].Kinematics.Local.Parameters("posx"), self.n_sign +
            " (ctr_dist(%s.kine.global, %s.kine.global) * (1 - %s) + ctr_dist(%s.kine.global, %s.kine.global) * %s)"
            % (self.fk0_ctl.FullName, self.fk1_ctl.FullName,
               self.pBlend.FullName, self.ref_chn.bones[0].FullName,
               self.ref_chn.bones[1].FullName, self.pBlend.FullName))
        par.addExpression(
            self.ref_loc[2].Kinematics.Local.Parameters("posx"), self.n_sign +
            " (ctr_dist(%s.kine.global, %s.kine.global) * (1 - %s) + ctr_dist(%s.kine.global, %s.kine.global) * %s)"
            % (self.fk1_ctl.FullName, self.fk2_ctl.FullName,
               self.pBlend.FullName, self.ref_chn.bones[1].FullName,
               self.end_chn.bones[0], self.pBlend.FullName))
        par.addExpression(
            self.ref_loc[3].Kinematics.Local.Parameters("posx"), self.n_sign +
            " (ctr_dist(%s.kine.global, %s.kine.global) * (1 - %s) + ctr_dist(%s.kine.global, %s.kine.global) * %s)"
            % (self.fk2_ctl.FullName, self.fk3_ctl.FullName,
               self.pBlend.FullName, self.end_chn.bones[0].FullName,
               self.end_chn.eff, self.pBlend.FullName))

        # Global Scale
        for s in "xyz":
            par.addExpression(
                self.ref_loc[0].Kinematics.Global.Parameters("scl%s" % s), 1)
            par.addExpression(
                self.end_ref.Kinematics.Global.Parameters("scl%s" % s),
                self.root.Kinematics.Global.Parameters("scl%s" % s))

        # Twist references ---------------------------------
        par.addExpression(
            self.pDriver,
            "(ctr_dist(%s, %s) + ctr_dist(%s, %s) + ctr_dist(%s, %s)) / %s" %
            (self.tws0_loc.Kinematics.Global.FullName,
             self.tws1_loc.Kinematics.Global.FullName,
             self.tws1_loc.Kinematics.Global.FullName,
             self.tws2_loc.Kinematics.Global.FullName,
             self.tws2_loc.Kinematics.Global.FullName,
             self.tws3_loc.Kinematics.Global.FullName,
             self.root.Kinematics.Global.Parameters("sclx").FullName))

        self.tws0_loc.Kinematics.AddConstraint("Pose", self.root, True)
        aop.dirCns(self.tws0_loc, self.mid0_ctl, None, False,
                   self.n_sign + "xy")

        self.tws1_loc.Kinematics.AddConstraint("Position", self.mid0_ctl)
        self.tws1_loc.Kinematics.AddConstraint("Scaling", self.mid0_ctl)
        self.tws1_rot.Kinematics.AddConstraint("Orientation", self.mid0_ctl)
        par.addExpression(self.tws1_rot.Parameters("rotx"), 0)
        par.addExpression(self.tws1_rot.Parameters("roty"), 0)
        par.addExpression(self.tws1_rot.Parameters("rotz"), 0)

        self.tws2_loc.Kinematics.AddConstraint("Position", self.mid1_ctl)
        self.tws2_loc.Kinematics.AddConstraint("Scaling", self.mid1_ctl)
        self.tws2_rot.Kinematics.AddConstraint("Orientation", self.mid1_ctl)
        par.addExpression(self.tws2_rot.Parameters("rotx"), 0)
        par.addExpression(self.tws2_rot.Parameters("roty"), 0)
        par.addExpression(self.tws2_rot.Parameters("rotz"), 0)

        self.tws3_loc.Kinematics.AddConstraint("Position", self.ref_loc[-1])
        #self.tws3_loc.Kinematics.AddConstraint("Scaling", self.eff_loc)
        aop.poseCns(self.tws3_rot, self.fk_ref, False, False, True, False)
        cns = aop.poseCns(self.tws3_rot, self.ik_ref, True, False, True, False)
        par.addExpression(cns.Parameters("blendweight"), self.pBlend.FullName)
        par.addExpression(self.tws3_rot.Parameters("rotx"), 0)
        par.addExpression(self.tws3_rot.Parameters("roty"), 0)
        par.addExpression(self.tws3_rot.Parameters("rotz"), 0)
        par.setRotOrder(self.tws3_rot, "YZX")

        self.tws0_rot.SclX = .001
        par.addExpression(self.tws1_rot.SclX,
                          self.pRoundness.FullName + " + .001")
        par.addExpression(self.tws2_rot.SclX,
                          self.pRoundness.FullName + " + .001")
        self.tws3_rot.SclX = .001

        # Divisions ----------------------------------------
        # at 0 or 1 the division will follow exactly the rotation of the controler.. and we wont have this nice tangent + roll
        for i, div_cns in enumerate(self.div_cns):

            if i < (self.settings["div0"] + 1):
                perc = i / ((self.settings["div0"] + 1.0) * 3)
            elif i < (self.settings["div0"] + self.settings["div1"] + 2):
                perc = (1 / 3.0) + ((i - self.settings["div0"] - 1.0) /
                                    ((self.settings["div1"] + 1.0) * 3))
            else:
                perc = (2 / 3.0) + (
                    (i - self.settings["div0"] - self.settings["div1"] - 2.0) /
                    ((self.settings["div2"] + 1.0) * 3))

            perc = max(.001, min(.999, perc))

            if self.negate:
                op = aop.sn_rollsplinekine_op(div_cns, [
                    self.tws3_rot, self.tws2_rot, self.tws1_rot, self.tws0_rot
                ], 1 - perc)
            else:
                op = aop.sn_rollsplinekine_op(div_cns, [
                    self.tws0_rot, self.tws1_rot, self.tws2_rot, self.tws3_rot
                ], perc)

            # Squash n Stretch
            op = aop.sn_squashstretch2_op(div_cns, self.root,
                                          self.pDriver.Value, "x")
            par.addExpression(op.Parameters("blend"), self.pVolume.FullName)
            par.addExpression(op.Parameters("driver"), self.pDriver.FullName)
            if self.options["mode"] == 1:  # wip
                par.addExpression(op.Parameters("stretch"), self.pStretch[i])
                par.addExpression(op.Parameters("squash"), self.pSquash[i])
            else:
                op.Parameters("stretch").Value = self.st_value[i]
                op.Parameters("squash").Value = self.sq_value[i]
Beispiel #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_ctl = self.addCtl(self.root,
                                   "ik0_ctl",
                                   t,
                                   self.color_ik,
                                   "compas",
                                   w=self.size)
        par.setKeyableParameters(self.ik0_ctl)
        xsi.SetNeutralPose(self.ik0_ctl)
        par.addLocalParamToCollection(self.inv_params, self.ik0_ctl,
                                      ["posx", "roty", "rotz"])
        par.setRotOrder(self.ik0_ctl, "XZY")

        t.SetTranslation(self.guide.apos[1])
        self.ik1_ctl = self.addCtl(self.root,
                                   "ik1_ctl",
                                   t,
                                   self.color_ik,
                                   "compas",
                                   w=self.size)
        par.setKeyableParameters(self.ik1_ctl)
        xsi.SetNeutralPose(self.ik1_ctl)
        par.addLocalParamToCollection(self.inv_params, self.ik1_ctl,
                                      ["posx", "roty", "rotz"])
        par.setRotOrder(self.ik1_ctl, "XZY")

        # Tangent controlers -------------------------------
        t.SetTranslation(
            vec.linearlyInterpolate(self.guide.apos[0], self.guide.apos[1],
                                    .33))
        self.tan0_ctl = self.addCtl(self.ik0_ctl,
                                    "tan0_ctl",
                                    t,
                                    self.color_ik,
                                    "sphere",
                                    w=self.size * .2)
        par.setKeyableParameters(self.tan0_ctl, self.t_params)
        xsi.SetNeutralPose(self.tan0_ctl, c.siTrn)
        par.addLocalParamToCollection(self.inv_params, self.ik1_ctl, ["posx"])

        t.SetTranslation(
            vec.linearlyInterpolate(self.guide.apos[0], self.guide.apos[1],
                                    .66))
        self.tan1_ctl = self.addCtl(self.ik1_ctl,
                                    "tan1_ctl",
                                    t,
                                    self.color_ik,
                                    "sphere",
                                    w=self.size * .2)
        par.setKeyableParameters(self.tan1_ctl, self.t_params)
        xsi.SetNeutralPose(self.tan1_ctl, c.siTrn)
        par.addLocalParamToCollection(self.inv_params, self.ik1_ctl, ["posx"])

        # Curves -------------------------------------------
        self.mst_crv = cur.addCnsCurve(
            self.root, self.getName("mst_crv"),
            [self.ik0_ctl, self.tan0_ctl, self.tan1_ctl, self.ik1_ctl], False,
            3)
        self.slv_crv = cur.addCurve(self.root, self.getName("slv_crv"),
                                    [1] * 10 * 4, False, 3)
        self.addToGroup([self.mst_crv, self.slv_crv], "hidden")

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

            # References
            div_cns = parentdiv.AddNull(self.getName("%s_cns" % i))
            pri.setNullDisplay(div_cns, 1, self.size * .05, 10, 0, 0, 0, 1, 1,
                               2)
            self.addToGroup(div_cns, "hidden")

            self.div_cns.append(div_cns)
            parentdiv = div_cns

            # Controlers (First and last one are fake)
            if i in [0, self.settings["division"] - 1]:
                fk_ctl = pri.addNull(parentctl, self.getName("%s_loc" % i),
                                     parentctl.Kinematics.Global.Transform,
                                     self.size * .05)
                self.addToGroup(fk_ctl, "hidden")
            else:
                fk_ctl = self.addCtl(parentctl,
                                     "fk%s_ctl" % (i - 1),
                                     parentctl.Kinematics.Global.Transform,
                                     self.color_fk,
                                     "cube",
                                     w=self.size * 1,
                                     h=self.size * .05,
                                     d=self.size * 1)
                self.addToGroup(fk_ctl, "controlers_01")
                par.addLocalParamToCollection(self.inv_params, fk_ctl,
                                              ["posx", "roty", "rotz"])
                par.setRotOrder(fk_ctl, "XZY")

            self.fk_ctl.append(fk_ctl)
            parentctl = fk_ctl

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

        # Connections (Hooks) ------------------------------
        self.cnx0 = pri.addNull(self.root, self.getName("0_cnx"),
                                self.root.Kinematics.Global.Transform,
                                self.size * .2)
        self.cnx1 = pri.addNull(self.root, self.getName("1_cnx"),
                                self.root.Kinematics.Global.Transform,
                                self.size * .2)
        self.addToGroup([self.cnx0, self.cnx1], "hidden")
Beispiel #10
0
    def addObjects(self):

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

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

        # FK Controlers ------------------------------------
        t = tra.getTransformLookingAt(self.guide.apos[0], self.guide.apos[1], self.normal, "xz", self.negate)
        self.fk0_ctl = self.addCtl(self.root, "fk0_ctl", t, self.color_fk, "cube", h=self.size*.1, w=1, d=self.size*.1, po=XSIMath.CreateVector3(.5*self.n_factor,0,0))
        self.fk0_ctl.Parameters("SclX").Value = self.length0
        par.setRotOrder(self.fk0_ctl, "XZY")
        tra.setRefPose(self.fk0_ctl, [-90,0,0], self.negate)
        xsi.SetNeutralPose(self.fk0_ctl, c.siST)
        par.setKeyableParameters(self.fk0_ctl)
        par.addLocalParamToCollection(self.inv_params, self.fk0_ctl, ["posx", "posy", "posz"])

        t = tra.getTransformLookingAt(self.guide.apos[1], self.guide.apos[2], self.normal, "xz", self.negate)
        self.fk1_ctl = self.addCtl(self.fk0_ctl, "fk1_ctl", t, self.color_fk, "cube", h=self.size*.1, w=1, d=self.size*.1, po=XSIMath.CreateVector3(.5*self.n_factor,0,0))
        self.fk1_ctl.Parameters("SclX").Value = self.length1/self.length0
        xsi.SetNeutralPose(self.fk1_ctl, c.siST)
        par.setKeyableParameters(self.fk1_ctl)
        par.addLocalParamToCollection(self.inv_params, self.fk1_ctl, ["posx", "posy", "posz"])

        t = tra.getTransformLookingAt(self.guide.apos[2], self.guide.apos[3], self.normal, "xz", self.negate)
        self.fk2_ctl = self.addCtl(self.fk1_ctl, "fk2_ctl", t, self.color_fk, "cube", h=self.size*.1, w=self.length2, d=self.size*.1, po=XSIMath.CreateVector3(self.length2*.5*self.n_factor,0,0))
        par.setRotOrder(self.fk2_ctl, "XZY")
        xsi.SetNeutralPose(self.fk2_ctl, c.siST)
        par.setKeyableParameters(self.fk2_ctl)
        par.addLocalParamToCollection(self.inv_params, self.fk2_ctl, ["posx", "posy", "posz"])

        # IK Controlers ------------------------------------
        self.ik_cns = pri.addNullFromPos(self.root, self.getName("ik_cns"), self.guide.apos[2], self.size*.02)
        self.addToGroup(self.ik_cns, "hidden")

        self.ikcns_ctl = self.addCtl(self.ik_cns, "ikcns_ctl", self.ik_cns.Kinematics.Global.Transform, self.color_ik, "null", h=self.size*.2)
        par.setKeyableParameters(self.ikcns_ctl)
        par.addLocalParamToCollection(self.inv_params, self.ikcns_ctl, ["posx", "rotx", "rotz"])

        t = tra.getTransformLookingAt(self.guide.apos[2], self.guide.apos[3], self.normal, "xz", self.negate)
        self.ik_ctl = self.addCtl(self.ikcns_ctl, "ik_ctl", t, self.color_ik, "cube", h=self.size*.12, w=self.length2, d=self.size*.12, po=XSIMath.CreateVector3(self.length2*.5*self.n_factor,0,0))
        tra.setRefPose(self.ik_ctl, [-90,0,0], self.negate)
        par.setRotOrder(self.ik_ctl, "XZY")
        par.setKeyableParameters(self.ik_ctl)
        par.addLocalParamToCollection(self.inv_params, self.ik_ctl, ["posx"])

        v = XSIMath.CreateVector3()
        v.Sub(self.guide.apos[2], self.guide.apos[0])
        v.Cross(self.normal, v)
        v.NormalizeInPlace()
        v.ScaleInPlace(self.size*.5)
        v.AddInPlace(self.guide.apos[1])
        self.upv_cns = pri.addNullFromPos(self.root, self.getName("upv_cns"), v, self.size*.02)
        self.addToGroup(self.upv_cns, "hidden")

        self.upv_ctl = self.addCtl(self.upv_cns, "upv_ctl", self.upv_cns.Kinematics.Global.Transform, self.color_ik, "leash", h=self.size*.05, ap=self.guide.apos[1])
        par.setKeyableParameters(self.upv_ctl, self.t_params)
        par.addLocalParamToCollection(self.inv_params, self.upv_ctl, ["posx"])

        # Chain --------------------------------------------
        self.bone0 = pri.addNull(self.root, self.getName("0_jnt"), self.fk0_ctl.Kinematics.Global.Transform)
        pri.setNullDisplay(self.bone0, 0, 1, 4, self.n_factor*.5, 0, 0, 1, self.size*.01, self.size*.01)
        self.bone0.Kinematics.Global.Parameters("sclx").Value = self.length0
        self.bone1 = pri.addNull(self.bone0, self.getName("1_jnt"), self.fk1_ctl.Kinematics.Global.Transform)
        pri.setNullDisplay(self.bone1, 0, 1, 4, self.n_factor*.5, 0, 0, 1, self.size*.01, self.size*.01)
        self.bone1.Kinematics.Global.Parameters("sclx").Value = self.length1

        self.ctrn_loc = pri.addNullFromPos(self.bone0, self.getName("ctrn_loc"), self.guide.apos[1], self.size*.05)
        self.eff_loc  = pri.addNullFromPos(self.root, self.getName("eff_loc"), self.guide.apos[2], self.size*.05)

        self.addToGroup([self.bone0, self.bone1, self.ctrn_loc, self.eff_loc], "hidden")

        # wrist Tangent ________________________Miquel modification

        self.wristCtl = self.addCtl(self.eff_loc, "wristTang_ctl", self.eff_loc.Kinematics.Global.Transform, self.color_ik, "circle", w=self.size*.2)
        self.addShadow(self.wristCtl, "end")






        # Mid Controler ------------------------------------
        self.mid_ctl = self.addCtl(self.ctrn_loc, "mid_ctl", self.ctrn_loc.Kinematics.Global.Transform, self.color_ik, "sphere", h=self.size*.2)
        par.addLocalParamToCollection(self.inv_params, self.mid_ctl, ["posx", "posy", "posz"])


        # Twist references ---------------------------------
        t = tra.getFilteredTransform(self.fk0_ctl.Kinematics.Global.Transform, True, True, False)
        self.tws0_loc = pri.addNull(self.root, self.getName("tws0_loc"), t, self.size*.05)

        # shoulder Tangent ________________________Miquel modification

        self.shoulderCtl = self.addCtl(self.tws0_loc, "shoulderTang_ctl", self.tws0_loc.Kinematics.Global.Transform, self.color_ik, "circle", w=self.size*.2)

        self.tws0_rot = pri.addNull(self.shoulderCtl, self.getName("tws0_rot"), t)
        pri.setNullDisplay(self.tws0_rot, 0, self.size*.05, 2, 0, 0, 0, self.size*.01)

        self.tws1_loc = pri.addNull(self.ctrn_loc, self.getName("tws1_loc"), self.ctrn_loc.Kinematics.Global.Transform, self.size*.05)
        self.tws1_rot = pri.addNull(self.tws1_loc, self.getName("tws1_rot"), self.ctrn_loc.Kinematics.Global.Transform)
        pri.setNullDisplay(self.tws1_rot, 0, self.size*.05, 2, 0, 0, 0, self.size*.01)

        t = tra.getFilteredTransform(self.bone1.Kinematics.Global.Transform, True, True, False)
        t.SetTranslation(self.guide.apos[2])
        self.tws2_loc = pri.addNull(self.bone1, self.getName("tws2_loc"), t, self.size*.05)
        self.tws2_rot = pri.addNull(self.tws2_loc, self.getName("tws2_rot"),t)
        self.tws2_rot.Kinematics.Global.Parameters("SclX").Value = .001
        pri.setNullDisplay(self.tws2_rot, 0, self.size*.05, 2, 0, 0, 0, self.size*.01)

        self.addToGroup([self.tws0_loc, self.tws0_rot, self.tws1_loc, self.tws1_rot, self.tws2_loc, self.tws2_rot], "hidden")

        # End reference ------------------------------------
        t = tra.getFilteredTransform(self.tws2_rot.Kinematics.Global.Transform, True, True, False)
        self.end_ref = pri.addNull(self.tws2_rot, self.getName("end_ref"), t, self.size*.2)
        self.addToGroup(self.end_ref, "hidden")


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

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

            div_cns = pri.addNull(self.tws0_loc, self.getName("div%s_loc"%i), XSIMath.CreateTransform())
            pri.setNullDisplay(div_cns, 1, self.size*.02, 10, 0, 0, 0, 1, 1, 2)
            self.addToGroup(div_cns, "hidden")

            self.div_cns.append(div_cns)

            self.lastShadow = self.addShadow(div_cns, i)