Пример #1
0
def gear_crvLenInfo_Execute():

    if not xsi.Selection.Count and xsi.Selection(0).Type == "crvlist":
        gear.log("No selection or first selected object not a crvlist",
        gear.sev_error)
        return

    crv = xsi.Selection(0)
    prop = xsi.gear_PSet_Apply(crv, "Length_Info", False, False )
    pLength = prop.AddParameter3( "Length", c.siDouble, 0, -1000000, 1000000 )
    pOriginalLength = prop.AddParameter3( "Original_Length", c.siDouble, 0, -1000000, 1000000, False, True )
    pLengthRatio = prop.AddParameter3( "Length Ratio", c.siDouble, 0, -1000000, 1000000 )

    layout = r"""layout.AddTab('Length_Info');\
        layout.AddGroup('Default Layout');\
        item = layout.AddItem('Length', 'Length', None);\
        item = layout.AddItem('Original_Length', 'Original_Length', None);\
        item = layout.AddItem('Length_Ratio', 'Length_Ratio', None);\
        layout.EndGroup()"""

    prop.Parameters("layout").Value = layout
    aop.sn_curvelength_op(pLength.FullName, crv)
    pOriginalLength.Value = pLength.Value
    pLengthRatio.AddExpression( pLength.FullName +  "/" + pOriginalLength.FullName)
    xsi.InspectObj(prop)
Пример #2
0
    def addOperators(self):

        # Visibilities -------------------------------------
        par.addExpression(self.ik0_ctl.Properties("visibility").Parameters("viewvis"), self.pShowIk.FullName)
        par.addExpression(self.ik1_ctl.Properties("visibility").Parameters("viewvis"), self.pShowIk.FullName)
        par.addExpression(self.tan0_ctl.Properties("visibility").Parameters("viewvis"), self.pShowIk.FullName)
        par.addExpression(self.tan1_ctl.Properties("visibility").Parameters("viewvis"), self.pShowIk.FullName)
        for fk_ctl in self.fk_ctl[1:-1]:
            par.addExpression(fk_ctl.Properties("visibility").Parameters("viewvis"), self.pShowFk.FullName)

        # Tangent position ---------------------------------
        d = vec.getDistance(self.guide.apos[0], self.guide.apos[1])

        exp = self.pTan0.FullName + " * " + str(self.tan0_ctl.Parameters("nposy").Value)+" * (ctr_dist("+self.ik0_ctl.FullName+","+self.ik1_ctl.FullName+") / "+str(d)+")"
        par.addExpression(self.tan0_ctl.Parameters("nposy"), exp)

        exp = self.pTan1.FullName + " * " + str(self.tan1_ctl.Parameters("nposy").Value)+" * (ctr_dist("+self.ik0_ctl.FullName+","+self.ik1_ctl.FullName+") / "+str(d)+")"
        par.addExpression(self.tan1_ctl.Parameters("nposy"), exp)

        # Curves -------------------------------------------
        op = aop.sn_curveslide2_op(self.slv_crv, self.mst_crv, 0, 1.5, .5, .5)

        par.addExpression(op.Parameters("position"), self.pPosition.FullName)
        par.addExpression(op.Parameters("maxstretch"), self.pMaxStretch.FullName)
        par.addExpression(op.Parameters("maxsquash"), self.pMaxSquash.FullName)
        par.addExpression(op.Parameters("softness"), self.pSoftness.FullName)

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

            # References
            u = i / (self.settings["division"] - 1.0)
            div_cns = self.div_cns[i]

            cns = aop.pathCns(div_cns, self.slv_crv, 0, u*100, True, None, False)

            cns.Parameters("dirx").Value = 0
            cns.Parameters("diry").Value = 1
            cns.Parameters("dirz").Value = 0

            cns.Parameters("upx").Value = 0
            cns.Parameters("upy").Value = 0
            cns.Parameters("upz").Value = -1

            # Roll
            aop.spinePointAtOp(cns, self.ik0_ctl, self.ik1_ctl, u)

            # Squash n Stretch
            op = aop.sn_squashstretch2_op(div_cns, self.slv_crv, self.slv_crv.ActivePrimitive.Geometry.Curves(0).Length, "y")
            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]

            # Controlers
            fk_ctl = self.fk_ctl[i]

            for s in "xyz":
                par.addExpression(fk_ctl.Parameters("npos"+s), div_cns.Parameters("pos"+s).FullName)
                par.addExpression(fk_ctl.Parameters("nrot"+s), div_cns.Parameters("rot"+s).FullName)
                par.addExpression(fk_ctl.Kinematics.Global.Parameters("scl"+s), div_cns.Kinematics.Global.Parameters("scl"+s).FullName)

        # Orientation Lock
        cns = self.div_cns[0].Kinematics.AddConstraint("Orientation", self.ik0_ctl, False)
        par.addExpression(cns.Parameters("blendweight"), self.pLockOri0.FullName)
        cns = self.div_cns[-1].Kinematics.AddConstraint("Orientation", self.ik1_ctl, False)
        par.addExpression(cns.Parameters("blendweight"), self.pLockOri1.FullName)

        # Volume -------------------------------------------
        op = aop.sn_curvelength_op(self.pDriver, self.slv_crv)

        # Connections (Hooks) ------------------------------
        self.cnx0.Kinematics.AddConstraint("Position", self.div_cns[0], False)
        self.cnx0.Kinematics.AddConstraint("Orientation", self.div_cns[0], False)
        self.cnx1.Kinematics.AddConstraint("Position", self.fk_ctl[-1], False)
        self.cnx1.Kinematics.AddConstraint("Orientation", self.fk_ctl[-1], False)
Пример #3
0
    def addOperators(self):

        # Visibilities -------------------------------------
        par.addExpression(
            self.ik_ctl.Properties("visibility").Parameters("viewvis"),
            self.pShowIk.FullName)
        for fk_ctl in self.fk_ctl:
            par.addExpression(
                fk_ctl.Properties("visibility").Parameters("viewvis"),
                self.pShowFk.FullName)

        # Tangent position ---------------------------------
        d = vec.getDistance(self.guide.pos["root"], self.guide.pos["neck"])

        exp = self.pTan0.FullName + " * " + str(
            self.tan0_loc.Parameters("nposy").Value
        ) + " * (ctr_dist(" + self.root.FullName + "," + self.ik_ctl.FullName + ") / " + str(
            d) + ")"
        par.addExpression(self.tan0_loc.Parameters("nposy"), exp)

        exp = self.pTan1.FullName + " * " + str(
            self.tan1_loc.Parameters("nposy").Value
        ) + " * (ctr_dist(" + self.root.FullName + "," + self.ik_ctl.FullName + ") / " + str(
            d) + ")"
        par.addExpression(self.tan1_loc.Parameters("nposy"), exp)

        # Curves -------------------------------------------
        op = aop.sn_curveslide2_op(self.slv_crv, self.mst_crv, 0, 1.5, .5, .5)

        par.addExpression(op.Parameters("position"), 0)
        par.addExpression(op.Parameters("maxstretch"),
                          self.pMaxStretch.FullName)
        par.addExpression(op.Parameters("maxsquash"), self.pMaxSquash.FullName)
        par.addExpression(op.Parameters("softness"), self.pSoftness.FullName)

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

            # References
            u = i / (self.settings["division"] - 1.0)
            div_cns = self.div_cns[i]

            cns = aop.pathCns(div_cns, self.slv_crv, 0, u * 100, True, None,
                              False)

            cns.Parameters("dirx").Value = 0
            cns.Parameters("diry").Value = 1
            cns.Parameters("dirz").Value = 0

            cns.Parameters("upx").Value = 0
            cns.Parameters("upy").Value = 0
            cns.Parameters("upz").Value = -1

            # Roll
            aop.spinePointAtOp(cns, self.root, self.ik_ctl, u)

            # Squash n Stretch
            op = aop.sn_squashstretch2_op(
                div_cns, self.slv_crv,
                self.slv_crv.ActivePrimitive.Geometry.Curves(0).Length, "y")
            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:
                import gear
                op.Parameters("stretch").Value = self.st_value[i]
                op.Parameters("squash").Value = self.sq_value[i]

            # Controlers
            fk_ctl = self.fk_ctl[i]

            for s in "xyz":
                par.addExpression(fk_ctl.Parameters("npos" + s),
                                  div_cns.Parameters("pos" + s).FullName)
                par.addExpression(fk_ctl.Parameters("nrot" + s),
                                  div_cns.Parameters("rot" + s).FullName)
                par.addExpression(
                    fk_ctl.Kinematics.Global.Parameters("scl" + s),
                    div_cns.Kinematics.Global.Parameters("scl" + s).FullName)

        # Orientation Lock
        cns = self.div_cns[-1].Kinematics.AddConstraint(
            "Orientation", self.ik_ctl, False)
        par.addExpression(cns.Parameters("blendweight"),
                          self.pLockOri.FullName)

        # Volume -------------------------------------------
        op = aop.sn_curvelength_op(self.pDriver, self.slv_crv)

        # Head ---------------------------------------------
        self.fk_ctl[-1].AddChild(self.head_cns)
        if self.headref_count > 0:
            cns = self.head_cns.Kinematics.AddConstraint(
                "Orientation", self.fk_ctl[-1], True)
            par.addExpression(cns.Parameters("active"),
                              self.pHeadRef.FullName + " == 0")