Esempio n. 1
0
    def _twisterCns(self,
                    tws,
                    pos,
                    aim,
                    pntAt,
                    pntAtRef,
                    axis,
                    distance,
                    pntAtDouble=True):
        attributes.inheritsTransform(tws, False)

        # Position
        node = self.addNode("decomposeMatrix", "TwsDM")
        cmds.connectAttr(pos + ".worldMatrix[0]", node + ".inputMatrix")
        cmds.connectAttr(node + ".outputTranslate", tws + ".translate")

        # Rotation
        if pntAtDouble:
            cns = self.addCompound("aimConstraint",
                                   "TwsAim",
                                   tws,
                                   aim,
                                   axis=axis,
                                   upMaster=None,
                                   upVector=(0, 0, 1),
                                   maintainOffset=False)
            self.addCompound("pointAtDoubleAxisNode",
                             "TwsPtAt",
                             cns,
                             pntAtRef,
                             pntAt,
                             axis="z")
        else:
            self.addCompound("aimConstraint",
                             "TwsAim",
                             tws,
                             aim,
                             axis=axis,
                             upMaster=pntAt,
                             upVector=(0, 0, 1),
                             maintainOffset=False)

        dist_Node = self.addNode("distanceBetween", "twsScaleDist")
        cmds.connectAttr(pos + ".worldMatrix[0]", dist_Node + ".inMatrix1")
        cmds.connectAttr(aim + ".worldMatrix[0]", dist_Node + ".inMatrix2")
        div_Node = self.addNode("multiplyDivide", "twsScaleRatio")
        cmds.setAttr(div_Node + ".operation", 2)  # Division
        cmds.connectAttr(dist_Node + ".distance", div_Node + ".input1X")
        cmds.setAttr(div_Node + ".input2X", distance)
        cmds.connectAttr(div_Node + ".outputX", tws + ".scaleX")
        cmds.connectAttr(self.nodes("local") + ".sx", tws + ".scaleY")
        cmds.connectAttr(self.nodes("local") + ".sx", tws + ".scaleZ")
Esempio n. 2
0
def fkik2Bones(name, iks, fks, bones, lenA, lenB, neg):
    '''	Create a fkik2Bones nodes compound

	Args:
		name (str): Name of the nodes
		iks (list of str): In order - root, effector, upvector
		fks (list of str): In order - fk1, 2 and 3
		lenA (float): Initial length of the first bone
		lenB (float): Initial length of the second bone
		neg (bool): Build for negative side

	Returns:
		str: The FkIk2Bones node
	'''
    if not cmds.pluginInfo("HarbieNodes", q=True, loaded=True):
        cmds.loadPlugin("HarbieNodes")

    fkikNode = cmds.createNode("FkIk2Bones", name=name.format(node="FKIK"))

    for ctl, attr in izip(iks, ["Root", "effector", "upVector"]):
        cmds.connectAttr(ctl + ".worldMatrix[0]",
                         fkikNode + "." + attr + "[0]")

    for ctl, attr in izip(fks, ["FkA", "FkB", "FkC"]):
        cmds.connectAttr(ctl + ".worldMatrix[0]",
                         fkikNode + "." + attr + "[0]")

    cmds.setAttr(fkikNode + ".lengthA", lenA)
    cmds.setAttr(fkikNode + ".lengthB", lenB)
    cmds.setAttr(fkikNode + ".negate", neg)

    for bone, s in izip(bones, "ABC"):
        attributes.inheritsTransform(bone, False)
        cmds.setAttr(bone + ".shearXY", 0)
        cmds.setAttr(bone + ".shearXZ", 0)
        cmds.setAttr(bone + ".shearYZ", 0)

        dmNode = cmds.createNode("decomposeMatrix",
                                 name=name +
                                 "{s}".format(node="FKIKDcpMat", s=s))

        cmds.connectAttr(fkikNode + ".bone{}Tfm".format(s),
                         dmNode + ".inputMatrix")

        cmds.connectAttr(dmNode + ".outputTranslate", bone + ".translate")
        cmds.connectAttr(dmNode + ".outputRotate", bone + ".rotate")
        cmds.connectAttr(dmNode + ".outputScale", bone + ".scale")

    return fkikNode
Esempio n. 3
0
    def createOperators(self):
        # Visibility
        fkCompare = self.addCompound("compare", "FkViz", self.blendAttr, 1,
                                     "<")
        ikCompare = self.addCompound("compare", "IkViz", self.blendAttr, 0,
                                     ">")

        cmds.connectAttr(self.showCtrlAttr, fkCompare + ".colorIfFalseR")
        cmds.connectAttr(self.showCtrlAttr, ikCompare + ".colorIfFalseR")

        for ctl in self.fkCtl:
            for shp in cmds.listRelatives(ctl, shapes=True):
                cmds.connectAttr(fkCompare + ".outColorR", shp + ".visibility")

        ikCtls = [
            self.rootCtl, self.ikCtl, self.ikoffCtl, self.upvCtl, self.upvCrv,
            self.rollCtl
        ]
        if self.settings("rollUpVController"):
            ikCtls.append(self.rollUpvCtl)
        for ctl in ikCtls:
            for shp in cmds.listRelatives(ctl, shapes=True):
                cmds.connectAttr(ikCompare + ".outColorR", shp + ".visibility")

        #Fk Ik Solver
        iks = [self.rootCtl, self.ikRef, self.upvCtl]
        ikfkNode = self.addCompound("fkik2Bones", "ZLeg", iks, self.fkCtl,
                                    self.bones, self.lengths[0],
                                    self.lengths[1], self.negate())
        cmds.connectAttr(self.blendAttr, ikfkNode + ".blend")
        cmds.connectAttr(self.rollAttr, ikfkNode + ".roll")
        cmds.connectAttr(self.scaleAAttr, ikfkNode + ".scaleA")
        cmds.connectAttr(self.scaleBAttr, ikfkNode + ".scaleB")
        cmds.connectAttr(self.maxStretchAttr, ikfkNode + ".maxStretch")
        cmds.connectAttr(self.slideAttr, ikfkNode + ".slide")
        cmds.connectAttr(self.reverseAttr, ikfkNode + ".reverse")
        cmds.connectAttr(self.softnessAttr, ikfkNode + ".softness")
        cmds.connectAttr(self.lengthAAttr, ikfkNode + ".lengthA")
        cmds.connectAttr(self.lengthBAttr, ikfkNode + ".lengthB")

        # Roll
        self.addCompound("blendMatrix",
                         "RollCns",
                         self.rollBfr, [self.footRef],
                         maintainOffset=True)
        axis = "{s}y{s}z".format(s=self.sign())
        if self.settings("rollUpVController"):
            self.addCompound("aimConstraint",
                             "RollAim",
                             self.rollBfr,
                             self.rollUpvCtl,
                             axis=axis,
                             upMaster=self.upvCtl,
                             maintainOffset=False)
        else:
            self.addCompound("aimConstraint",
                             "RollAim",
                             self.rollBfr,
                             self.rootCtl,
                             axis=axis,
                             upMaster=self.upvCtl,
                             maintainOffset=False)

        # Last Bone
        cns = self.addCompound("blendMatrix",
                               "BoneCns",
                               self.bones[-1], [self.fkCtl[-1], self.footRef],
                               maintainOffset=True)
        cmds.connectAttr(self.blendAttr, cns + ".target[1].weight")

        # Center
        for i, ctrBfr in enumerate([self.ctrABfr, self.ctrBBfr]):
            posBone = self.bones[i + 1]
            oriBones = self.bones[i:i + 2]
            attributes.inheritsTransform(ctrBfr, False)
            node = self.addNode("decomposeMatrix", "CtrDM")
            cmds.connectAttr(posBone + ".worldMatrix[0]",
                             node + ".inputMatrix")
            cmds.connectAttr(node + ".outputTranslate", ctrBfr + ".translate")
            self.addCompound("orientConstraint", "CtrOri", ctrBfr, oriBones)
            cmds.connectAttr(self.nodes("local") + ".scale", ctrBfr + ".scale")

        # Twisters
        self._twisterCns(self.twisters["Upr"][0],
                         self.bones[0],
                         self.ctrACtl,
                         self.fkRef,
                         self.bones[0],
                         self.sign() + "xz",
                         self.lengths[0],
                         pntAtDouble=False)
        self._twisterCns(self.twisters["Upr"][1],
                         self.ctrACtl,
                         self.bones[0],
                         self.ctrACtl,
                         self.ctrABfr,
                         self.nsign() + "xz",
                         self.lengths[0],
                         pntAtDouble=False)

        self._twisterCns(self.twisters["Mid"][0],
                         self.ctrACtl,
                         self.ctrBCtl,
                         self.ctrACtl,
                         self.ctrABfr,
                         self.sign() + "xz",
                         self.lengths[1],
                         pntAtDouble=False)
        self._twisterCns(self.twisters["Mid"][1],
                         self.ctrBCtl,
                         self.ctrACtl,
                         self.ctrBCtl,
                         self.ctrBBfr,
                         self.nsign() + "xz",
                         self.lengths[1],
                         pntAtDouble=False)

        self._twisterCns(self.twisters["Lwr"][0],
                         self.ctrBCtl,
                         self.bones[-1],
                         self.ctrBCtl,
                         self.ctrBBfr,
                         self.sign() + "xz",
                         self.lengths[2],
                         pntAtDouble=False)
        self._twisterCns(self.twisters["Lwr"][1],
                         self.bones[-1],
                         self.ctrBCtl,
                         self.bones[3],
                         self.bones[2],
                         self.nsign() + "xy",
                         self.lengths[2],
                         pntAtDouble=False)

        # Inter
        for p in self.twp:
            cmds.pointConstraint(self.twisters[p], self.inters[p])
            cns = self.addCompound("aimConstraint",
                                   p + "InterAim",
                                   self.inters[p],
                                   self.twisters[p][1],
                                   axis="x-z")
            self.addCompound("spinePointAt",
                             p + "InterPtAt",
                             cns,
                             self.twisters[p][0],
                             self.twisters[p][1],
                             blend=.5,
                             solver=1)
Esempio n. 4
0
    def createOperators(self):
        # Visibility
        fkCompare = self.addCompound("compare", "FkViz", self.blendAttr, 1,
                                     "<")
        ikCompare = self.addCompound("compare", "IkViz", self.blendAttr, 0,
                                     ">")

        cmds.connectAttr(self.showCtrlAttr, fkCompare + ".colorIfFalseR")
        cmds.connectAttr(self.showCtrlAttr, ikCompare + ".colorIfFalseR")

        for ctl in self.fkCtl:
            for shp in cmds.listRelatives(ctl, shapes=True):
                cmds.connectAttr(fkCompare + ".outColorR", shp + ".visibility")

        for ctl in [
                self.rootCtl, self.ikCtl, self.ikoffCtl, self.upvCtl,
                self.upvCrv
        ]:
            for shp in cmds.listRelatives(ctl, shapes=True):
                cmds.connectAttr(ikCompare + ".outColorR", shp + ".visibility")

        # Center
        attributes.inheritsTransform(self.ctrBfr, False)
        node = self.addNode("decomposeMatrix", "CtrDM")
        cmds.connectAttr(self.bones[1] + ".worldMatrix[0]",
                         node + ".inputMatrix")
        cmds.connectAttr(node + ".outputTranslate", self.ctrBfr + ".translate")
        cns = self.addCompound("blendMatrix",
                               "Center",
                               self.ctrBfr,
                               self.bones[:2],
                               maintainOffset=False,
                               translate=False,
                               rotate=True,
                               scale=False)
        cmds.setAttr(cns + ".target[1].weight", .5)
        cmds.connectAttr(
            self.nodes("local") + ".scale", self.ctrBfr + ".scale")

        #Fk Ik Solver
        iks = [self.rootCtl, self.ikRef, self.upvCtl]
        ikfkNode = self.addCompound("fkik2Bones", "Leg", iks, self.fkCtl,
                                    self.bones, self.lengths[0],
                                    self.lengths[1], self.negate())
        cmds.connectAttr(self.blendAttr, ikfkNode + ".blend")
        cmds.connectAttr(self.rollAttr, ikfkNode + ".roll")
        cmds.connectAttr(self.scaleAAttr, ikfkNode + ".scaleA")
        cmds.connectAttr(self.scaleBAttr, ikfkNode + ".scaleB")
        cmds.connectAttr(self.maxStretchAttr, ikfkNode + ".maxStretch")
        cmds.connectAttr(self.slideAttr, ikfkNode + ".slide")
        cmds.connectAttr(self.reverseAttr, ikfkNode + ".reverse")
        cmds.connectAttr(self.softnessAttr, ikfkNode + ".softness")
        cmds.connectAttr(self.lengthAAttr, ikfkNode + ".lengthA")
        cmds.connectAttr(self.lengthBAttr, ikfkNode + ".lengthB")

        # Twisters
        # it seems that the new twisting is actually not always giving nice result even if it's more stable
        # The old one is flipping but closer to want we would need.
        self._twisterCns(self.twisters["Upr"][0],
                         self.bones[0],
                         self.ctrCtl,
                         self.fkRef,
                         self.bones[0],
                         self.sign() + "xz",
                         self.lengths[0],
                         pntAtDouble=False)
        self._twisterCns(self.twisters["Upr"][1],
                         self.ctrCtl,
                         self.bones[0],
                         self.ctrCtl,
                         self.ctrBfr,
                         self.nsign() + "xz",
                         self.lengths[0],
                         pntAtDouble=False,
                         scaleComp=True)
        self._twisterCns(self.twisters["Lwr"][0],
                         self.ctrCtl,
                         self.bones[-1],
                         self.ctrCtl,
                         self.ctrBfr,
                         self.sign() + "xz",
                         self.lengths[1],
                         pntAtDouble=False,
                         scaleComp=True)
        self._twisterCns(self.twisters["Lwr"][1], self.bones[-1], self.ctrCtl,
                         self.bones[2], self.bones[1],
                         self.nsign() + "xz", self.lengths[1])

        # Inter
        for p in self.twp:
            cmds.pointConstraint(self.twisters[p], self.inters[p])
            cns = self.addCompound("aimConstraint",
                                   p + "InterAim",
                                   self.inters[p],
                                   self.twisters[p][1],
                                   axis="x-z")
            self.addCompound("spinePointAt",
                             p + "InterPtAt",
                             cns,
                             self.twisters[p][0],
                             self.twisters[p][1],
                             blend=.5,
                             solver=1)