Esempio n. 1
0
	def addMarkerCamera(self, part, parent=None, matrix=None):
		parent = self.model() if parent is None else parent
		name = self.getMarkerName(part)
		if matrix is None:
			position = self.markerPositions[part]
			matrix = Transformation.fromParts(translation=position)
		return SystemMarker.createCamera(name, self, parent, matrix)
Esempio n. 2
0
def exampleA(mirror=False, showWindow=False):
    '''Built a basic and a chain system. Set the basic to be dynamic and connect the chain to it.
	
	Args:
		mirror (bool): True to duplicate the systems on the right side
		showWindow (bool): True to popup Brigks Main Window
	'''
    # Building Matrix for guide positions
    basicMatrices = dict(
        Part1=Transformation.fromParts(translation=Vector3([2, 2, 0])),
        Part2=Transformation.fromParts(translation=Vector3([4, 2, 0])),
    )
    chainMatrices = dict(
        Part1=Transformation.fromParts(translation=Vector3([2, 3, 0])),
        Part2=Transformation.fromParts(translation=Vector3([4, 4, 0])),
        Part3=Transformation.fromParts(translation=Vector3([6, 3, 0])),
    )

    # Create Guide, add a layer and a couple Systems
    guide = Guide()
    guide.setSettings(hideRig=False)
    guide.setSettings(hideJoints=False)

    layer = guide.addLayer("MyFirstLayer")
    basic = layer.addSystem("basic", "L", "Basic", basicMatrices)
    chain = layer.addSystem("chain", "L", "Chain", chainMatrices)

    # System Settings
    basic.setSettings(dynamic=True, dynamicAnimatable=True, strap=True)

    # Connections
    chain.addConnection("Root", "slotParent", key=basic.key(), slot="Part1")

    if mirror:
        for system in layer.systems().values():
            system.duplicate(mirror=True)

    # Save edit
    guide.commit()

    # Build all rig
    guide.build()

    if showWindow:
        showWindow()

    return guide
Esempio n. 3
0
def _convertTransformToMatrix(translation, rotation, scaling):
	rotation = rotation[1:] + rotation[:1]

	translation = Vector3(translation)
	rotation = Quaternion(rotation)
	scaling = Vector3(scaling)

	transform = Transformation.fromParts(translation, rotation, scaling)
	return transform.asMatrix().flattened()
Esempio n. 4
0
	def addMarker(self, part, parent=None, matrix=None):
		'''Create a single SystemMarker

		Args:
			part (str): Unique part of the system object
			parent (str): Marker to be parented under
			matrix (Matrix): The matrix of the markers
		
		Returns:
			SystemMarker
		'''
		parent = self.model() if parent is None else parent
		name = self.getMarkerName(part)
		if matrix is None and part in self.markerPositions:
			position = self.markerPositions[part]
			matrix = Transformation.fromParts(translation=position)
		return SystemMarker.create(name, self, parent, matrix)
Esempio n. 5
0
    def createObjects(self):

        # TRANSFORMATIONS
        positions = Vector3Array([
            self.translations("Root"),
            self.translations("Knee"),
            self.translations("Ankle"),
            self.translations("Toe")
        ])
        normal = Vector3.planeNormal(*positions[:3])
        oriNormal = normal.copy()
        if self.negate():
            normal *= -1

        d = [(positions[i], positions[i + 1]) for i in range(3)]
        self.lengths = [Vector3.distance(a, b) for a, b in d]
        self.lengths.append(1)
        ratio = self.lengths[0] / sum(self.lengths[:2])
        self.setSettings(lengths=self.lengths[:3])

        # root
        rootTfm = Transformation.fromParts(
            translation=self.translations("Root"))

        # fk
        fkTfm = TransformationArray.chain(positions,
                                          normal,
                                          axis="xz",
                                          negativeSide=self.negate(),
                                          endTransform=False)
        lookAtEff = self.translations("Eff") - self.translations("Toe")
        fk3Tfm = Transformation.lookAt(self.translations("Toe"), lookAtEff,
                                       constants.AXIS_Y, "y-x", self.negate())
        fkTfm = fkTfm.appended(fk3Tfm)
        for tfm, dist in izip(fkTfm, self.lengths):
            tfm.scale = Vector3(
                [dist * self.factor(),
                 self.factor(),
                 self.factor()])
        bfrTfm = [
            tfm.copy(rotation=fkTfm[max(i - 1, 0)].rotation)
            for i, tfm in enumerate(fkTfm)
        ]
        bfrTfm[0] = Transformation.lookAt(self.translations("Root"),
                                          constants.AXIS_NY, constants.AXIS_X,
                                          "x" + self.nsign() + "z",
                                          self.negate())
        scale = bfrTfm[0].scale
        scale.x *= self.lengths[0]
        bfrTfm[0].scale = scale

        # ik
        ikbfrPos = Vector3([
            self.translations("Root").x,
            self.translations("Toe").y,
            self.translations("Root").z
        ])
        ikbfrTfm = Transformation.fromParts(translation=ikbfrPos)
        ikTfm = Transformation.lookAt(self.translations("Toe"), lookAtEff,
                                      constants.AXIS_Y, "zy", False)

        upvbfrTfm = Transformation.fromParts(
            translation=umath.upVector(self.translations("Root"), ikbfrPos,
                                       constants.AXIS_NX, ratio, False))
        upvTfm = Transformation.fromParts(
            translation=umath.upVector(self.translations(
                "Root"), self.translations("Ankle"), oriNormal, ratio))

        rollNormal = Vector3.planeNormal(self.translations("Root"),
                                         upvTfm.translation,
                                         self.translations("Toe"))
        if self.negate():
            rollNormal *= -1
        direction = self.translations("Root") - self.translations("Toe")
        rollbfrTfm = Transformation.lookAt(self.translations("Toe"), direction,
                                           rollNormal, "y-x", self.negate())
        direction = self.translations("Ankle") - self.translations("Toe")
        rollTfm = Transformation.lookAt(self.translations("Toe"), direction,
                                        normal, "y-x", self.negate())

        # extras
        scale = Vector3([self.factor(), self.factor(), self.factor()])
        twisterTfm = {}
        interTfm = {}
        for i, (p, pos) in enumerate(izip(self.twp, positions[1:4])):
            twisterTfm[p] = [
                fkTfm[i].copy(scale=scale), fkTfm[i].copy(translation=pos,
                                                          scale=scale)
            ]
            interPos = twisterTfm[p][0].translation.lerp(
                twisterTfm[p][1].translation, .5)
            interTfm[p] = twisterTfm[p][0].copy(translation=interPos)

        ctrATfm = twisterTfm["Mid"][0]
        ctrBTfm = twisterTfm["Lwr"][0]

        # CONTROLLERS
        # Root
        self.rootBfr = self.addBfr(None, "Root", rootTfm)
        self.rootCtl = self.addCtl(self.rootBfr,
                                   "Root",
                                   rootTfm,
                                   "sphere",
                                   size=4,
                                   color=self.colorIk())
        # self.addToSubControllers(self.rootCtl)
        attributes.setKeyables(self.rootCtl, constants.ATTRS_T)
        # self.setInversedParameters(self.rootCtl, middle=["posx"], side=["posx"])

        # Fk Ref
        # Used as a reference for the upr start twist
        # We cannot use the fk1Bfr cause this one get constrained when fk ref changes
        self.fkRef = self.addRig(self.rootBfr, "FkRef", bfrTfm[0])

        # FK Controlers and Bones
        fkParent = self.fkRef
        boneParent = self.fkRef
        self.fkBfr = []
        self.fkCtl = []
        self.bones = []
        self.stretches = []
        for i, (tfm, btfm) in enumerate(izip(fkTfm, bfrTfm), start=1):

            bfr = self.addBfr(fkParent, "Fk%s" % i, btfm)
            ctl = self.addCtl(bfr,
                              "Fk%s" % i,
                              tfm,
                              "sphere",
                              size=8,
                              so=[0, 1, 1],
                              color=self.colorFk())

            if self.settings("lockKneeRotation") and i == 2:
                keyables = [
                    "posx", "posy", "posz", "rotz", "sclx", "scly", "sclz"
                ]
            else:
                keyables = constants.ATTRS_TRS

            if i == 1:
                attributes.setRotOrder(ctl, "XZY")
            attributes.setKeyables(ctl, keyables)
            # self.setInversedParameters(ctl, middle=["posz", "roty", "rotx"])

            fkParent = ctl
            self.fkBfr.append(bfr)
            self.fkCtl.append(ctl)

            bone = self.addRig(boneParent,
                               "Bone{}".format(i),
                               tfm=tfm,
                               icon="bone",
                               so=(self.factor(), 1, 1))
            boneParent = bone
            self.bones.append(bone)

        # IK Controllers
        self.rollBfr = self.addBfr(self.rootBfr, "Roll", rollbfrTfm)
        self.rollCtl = self.addCtl(self.rollBfr,
                                   "Roll",
                                   rollTfm,
                                   "jaw",
                                   size=1,
                                   ro=(-90, 0, 0),
                                   color=self.colorIk())
        #self.rollCtl = self.addCtl(self.rollBfr, "Roll", rollTfm, "jaw", size=2, po=(4,6,0), color=self.colorIk())
        # self.setNeutralPose(self.rollCtl)
        attributes.setKeyables(self.rollCtl,
                               ["rotx", "roty", "rotz", "rotorder", "scly"])
        self.ikRef = self.addRig(self.rollCtl, "IkRef", fkTfm[-2])

        self.ikBfr = self.addBfr(None, "Ik", ikbfrTfm)
        self.ikCtl = self.addCtl(self.ikBfr,
                                 "Ik",
                                 ikTfm,
                                 "cube",
                                 size=6,
                                 color=self.colorIk())
        attributes.setKeyables(self.ikCtl, constants.ATTRS_TRS)
        # self.setInversedParameters(self.ikCtl, middle=["posx", "rotz", "roty"], side=["posx", "rotz", "roty"])
        attributes.setRotOrder(self.ikCtl, "XZY")

        self.ikoffCtl = self.addCtl(self.ikCtl,
                                    "IkOffset",
                                    ikTfm,
                                    "null",
                                    size=4,
                                    color=self.colorIk())
        # self.addToSubControllers(self.ikoffCtl)
        attributes.setKeyables(self.ikoffCtl, constants.ATTRS_TRS)
        # self.setInversedParameters(self.ikoffCtl, middle=["posx", "rotz", "roty"], side=["posx", "rotz", "roty"])
        attributes.setRotOrder(self.ikoffCtl, "XZY")

        self.upvBfr = self.addBfr(None, "Upv", upvbfrTfm)
        self.upvCtl = self.addCtl(self.upvBfr,
                                  "Upv",
                                  upvTfm,
                                  "diamond",
                                  size=2,
                                  color=self.colorIk())
        attributes.setKeyables(self.upvCtl, constants.ATTRS_T)
        # self.setInversedParameters(self.upvCtl, middle=["posx"], side=["posx"])

        self.ctrABfr = self.addBfr(self.bones[0], "CenterA", ctrATfm)
        self.ctrACtl = self.addCtl(self.ctrABfr,
                                   "CenterA",
                                   ctrATfm,
                                   "sphere",
                                   size=5,
                                   color=self.colorIk())
        # self.addToSubControllers(self.ctrACtl)
        attributes.setKeyables(self.ctrACtl, constants.ATTRS_TRS)
        # self.setInversedParameters(self.ctrACtl, middle=["posz", "roty", "rotx"])

        self.ctrBBfr = self.addBfr(self.bones[1], "CenterB", ctrBTfm)
        self.ctrBCtl = self.addCtl(self.ctrBBfr,
                                   "CenterB",
                                   ctrBTfm,
                                   "sphere",
                                   size=5,
                                   color=self.colorIk())
        # self.addToSubControllers(self.ctrBCtl)
        attributes.setKeyables(self.ctrBCtl, constants.ATTRS_TRS)
        # self.setInversedParameters(self.ctrBCtl, middle=["posz", "roty", "rotx"])

        self.upvCrv = create.cnsCurve(
            self.getObjectName(config.USE_RIG, "UpvCrv"),
            [self.upvCtl, self.ctrACtl])
        cmds.setAttr(self.upvCrv + ".template", True)

        self.footRef = self.addRig(self.ikoffCtl, "FootRef", ikTfm)

        # Twisters
        self.twisters = defaultdict(list)
        for p in self.twp:
            for s, tfm, factor in izip(["Start", "End"], twisterTfm[p],
                                       [1, -1]):
                twister = self.addRig(self.rootBfr,
                                      "Tw" + p + s,
                                      tfm,
                                      "sphere",
                                      po=[factor, 0, 0],
                                      so=[2, 1, 1])
                # self.setNeutralPose(twister)
                self.twisters[p].append(twister)

        # Inter
        self.inters = {}
        for p in self.twp:
            self.inters[p] = self.addRig(self.rootBfr, "Inter" + p,
                                         interTfm[p], "pyramid")
Esempio n. 6
0
    def createObjects(self):
        # Settings
        self.isFk = "FK" in self.settings("kinematic")
        self.isIk = "IK" in self.settings("kinematic")
        self.isFkIk = self.isFk and self.isIk

        # TRANSFORMATION
        # Positions
        positions = self.translations("Part")

        # Normal
        if self.count("Part") > 2:
            normal = Vector3.planeNormal(*positions[:3])
            if normal.length() < 1E-6:
                normal = self.directions("Part1", "z")
            if self.negate():
                normal *= -1
        else:
            normal = self.directions("Part1", "z")

        boneTfm = TransformationArray.chain(positions,
                                            normal,
                                            axis="xz",
                                            negativeSide=self.negate(),
                                            endTransform=False)
        d = [(positions[i], positions[i + 1])
             for i in range(self.count("Part") - 1)]
        boneLen = [Vector3.distance(a, b) for a, b in d]

        self.setSettings(count=len(boneLen), lengths=boneLen)

        if self.settings("setNeutralPose"):
            bfrTfm = boneTfm
        else:
            bfrTfm = [
                tfm.copy(rotation=boneTfm[max(i - 1, 0)].rotation)
                for i, tfm in enumerate(boneTfm)
            ]

        if self.isIk:
            ikTfm = boneTfm[-1].copy(translation=positions[-1])

            # Up Vector
            if self.count("Part") > 2:
                upvTfm = Transformation.fromParts(
                    translation=umath.upVector(positions[0],
                                               positions[2],
                                               normal,
                                               ratio=1,
                                               negate=self.negate()))
            else:
                upvTfm = Transformation.fromParts(
                    translation=umath.upVector(positions[0],
                                               positions[1],
                                               normal,
                                               ratio=1,
                                               negate=self.negate()))

        if self.settings("dynamic"):
            tgtTfm = boneTfm[1:]
            tgtTfm = tgtTfm.appended(
                boneTfm[-1].copy(translation=positions[-1]))

        # OBJECTS

        # Root
        self._root = self.addRig(None, "Root", tfm=boneTfm[0])

        # FK Controllers -----------------------------------------
        if self.isFk:
            self.fkBfr = []
            self.fkCtl = []
            self.fkDir = []
            parent = self._root
            for i, (tfm, btfm, dist) in enumerate(izip(boneTfm, bfrTfm,
                                                       boneLen),
                                                  start=1):

                fkBfr = self.addBfr(parent, "Fk{}".format(i), tfm=btfm)
                fkCtl = self.addCtl(fkBfr,
                                    "Fk{}".format(i),
                                    tfm,
                                    "sphere",
                                    so=[0, 1, 1],
                                    color=self.colorFk())

                # self.setInversedsettings(fkCtl, middle=["posz", "rotx", "roty"])
                attributes.setRotOrder(fkCtl,
                                       self.settings("defaultRotationOrder"))

                parent = fkCtl

                self.fkBfr.append(fkBfr)
                self.fkCtl.append(fkCtl)

                bone = self.addRig(fkCtl,
                                   "Dir{}".format(i),
                                   tfm,
                                   "pyramid",
                                   size=1,
                                   ro=[0, 0, -90],
                                   so=[.5, self.factor() * dist, .5])

                self.fkDir.append(bone)

            # Add the end reference for ikfk matching
            tfm = boneTfm[-1].copy(translation=positions[-1])
            self._tip = self.addRig(self.fkCtl[-1], "Tip", tfm)

        # IK Controllers --------------------------------------
        if self.isIk:
            # Ik Controller
            self.ikBfr = self.addBfr(self._root, "Ik", tfm=ikTfm)
            self.ikCtl = self.addCtl(self.ikBfr,
                                     "Ik",
                                     ikTfm,
                                     "cube",
                                     size=2,
                                     color=self.colorIk())
            attributes.setKeyables(self.ikCtl, constants.ATTRS_TR)

            # UpVector Controller
            self.upvBfr = self.addBfr(self._root, "UpV", upvTfm)
            self.upvCtl = self.addCtl(self.upvBfr,
                                      "UpV",
                                      upvTfm,
                                      "diamond",
                                      color=self.colorIk())
            attributes.setKeyables(self.upvCtl, constants.ATTRS_T)

            # Ik Chain
            self.ikBones, self.effector, self.handle = create.chain(
                self.getObjectName(config.USE_RIG, "Ik"),
                self._root,
                positions,
                normal,
                negate=self.negate())

            self.upvCrv = create.cnsCurve(
                [self.ikChn.root(), self.upvCtl,
                 self.ikChn.effector()], "UpvCrv")
            cmds.setAttr(self.upvCrv + ".template", True)

        # Bones -------------------------------
        if self.isFkIk:  # or (self.isFk and self.settings("dynamic")):
            self.bones = []
            parent = self._root
            for i, (tfm, dist) in enumerate(izip(boneTfm, boneLen), start=1):
                bone = self.addRig(parent,
                                   "Bone{}".format(i),
                                   tfm,
                                   "cube",
                                   size=1,
                                   po=[self.factor() * dist * .5, 0, 0],
                                   so=[dist, .5, .5])

                self.bones.append(bone)
                parent = bone

        elif self.isFk:
            self.bones = self.fkCtl
        else:
            self.bones = self.ikChn.bones()

        # Dynamic ----------------------------
        if self.settings("dynamic"):
            self.dfmHost = []
            self.dynCns = []
            self.target = []
            self.harmonic = []
            self.dynBone = []
            parent = self._root
            for i, (bone, tfmA,
                    tfmB) in enumerate(izip(self.bones, boneTfm, tgtTfm),
                                       start=1):

                dynCns = self.addRig(parent,
                                     "DynCns{}".format(i),
                                     tfmA,
                                     "cube",
                                     size=1)
                self.dynCns.append(dynCns)
                target = self.addRig(dynCns,
                                     "Target{}".format(i),
                                     tfmB,
                                     "null",
                                     size=1)
                self.target.append(target)
                harmonic = self.addRig(target,
                                       "Harmonic{}".format(i),
                                       tfmB,
                                       "diamond",
                                       size=1)
                self.harmonic.append(harmonic)

                dynBone = self.addRig(parent,
                                      "Dynamic{}".format(i),
                                      tfmA,
                                      "pyramid",
                                      size=1,
                                      ro=[0, 0, -90],
                                      so=[1, self.factor(), 1])
                self.dynBone.append(dynBone)
                parent = dynBone
                self.dfmHost.append(dynBone)
        else:
            self.dfmHost = self.bones

        # Strap ----------------------------
        if self.settings("strap"):
            endTfm = boneTfm[-1].copy(translation=positions[-1])
            self.end = self.addRig(self.dfmHost[-1], "End", endTfm)
Esempio n. 7
0
def chain(name,
          parent,
          positions,
          normal=None,
          axis="xz",
          negate=False,
          size=1,
          color=None):
    '''	Creates an Ik chain of joints

	Args:
		name (str): Name of the newly created Node
		parent (str): parent of the node. None if no parent
		positions (list of triplet): position of the node
		normal (triplet of float):
		axis (str):
		size (int): size off the text. Default is 40 which is close to 1 maya unit high.
		color (list of float): Color of the curve.

	Returns:
		(str, str, str): joints, effector, handle
	'''
    if normal is None:
        if len(positions) >= 3:
            normal = Vector3.planeNormal(positions, normalize=True)
        else:
            normal = Vector(0, 0, -1)

    # Transform.setMirrorMethod(Transform.inversedRotation)
    transforms = TransformationArray.chain(positions,
                                           normal,
                                           axis,
                                           negate,
                                           endTransform=True)
    d = [(positions[i], positions[i + 1]) for i in range(len(positions) - 1)]
    lengths = [Vector3.distance(a, b) for a, b in d] + [1]

    joints = []
    jointParent = parent
    for i, tfm in enumerate(transforms, start=1):
        jnt = joint(name + "%02d" % i,
                    jointParent,
                    tfm,
                    color,
                    useJointOrient=True)

        jointParent = jnt
        joints.append(jnt)

    handle, effector = cmds.ikHandle(startJoint=joints[0],
                                     endEffector=joints[-1])

    if negate:
        upv = Vector3([0, -1, 0]) * transforms[0].asMatrix()
        tfm = Transformation.fromParts(translation=transforms[0].translation)
        upv = upv * tfm.asMatrix().inverse()

        cmds.setAttr(handle + ".poleVectorX", upv.x)
        cmds.setAttr(handle + ".poleVectorY", upv.y)
        cmds.setAttr(handle + ".poleVectorZ", upv.z)

    effector = cmds.rename(effector, name + "Eff")
    handle = cmds.rename(handle, name + "Hdl")
    if parent:
        handle = cmds.parent(handle, parent, absolute=True)[0]

    cmds.delete(joints.pop(-1))

    return joints, effector, handle
Esempio n. 8
0
    def createObjects(self):
        # SIZE
        size = self.translations("Root").distance(self.translations("Knee"))
        fkSize = size * .25
        ikSize = size * .25
        upvSize = size * .1
        rootSize = size * .15

        # TRANSFORMATIONS
        positions = Vector3Array([
            self.translations("Root"),
            self.translations("Knee"),
            self.translations("Ankle")
        ])
        normal = Vector3.planeNormal(*positions)
        oriNormal = normal.copy()
        if self.negate():
            normal *= -1

        isInversed = constants.AXIS_X.dot(oriNormal) >= 0

        d = [(positions[i], positions[i + 1]) for i in range(2)]
        self.lengths = [Vector3.distance(a, b) for a, b in d]
        self.lengths.append(1)
        ratio = self.lengths[0] / sum(self.lengths[:2])
        self.setSettings(lengths=self.lengths[:2])

        # root
        rootTfm = Transformation.fromParts(
            translation=self.translations("Root"))

        # fk
        fkTfm = TransformationArray.chain(positions,
                                          normal,
                                          axis="xz",
                                          negativeSide=self.negate(),
                                          endTransform=False)
        axis = "-y-x" if isInversed else "y-x"
        if self.settings("ankleUpVector") == "World Y":
            upaxis = constants.AXIS_Y
        else:
            upaxis = -1 * self.directions("Ankle", "z")

        direction = self.translations("Eff") - self.translations("Ankle")
        fk2Tfm = Transformation.lookAt(self.translations("Ankle"), direction,
                                       upaxis, axis, self.negate())
        fkTfm = fkTfm.appended(fk2Tfm)

        bfrTfm = [
            tfm.copy(rotation=fkTfm[max(i - 1, 0)].rotation)
            for i, tfm in enumerate(fkTfm)
        ]
        xaxis = constants.AXIS_NX if isInversed else constants.AXIS_X
        bfrTfm[0] = Transformation.lookAt(self.translations("Root"),
                                          constants.AXIS_NY, xaxis,
                                          "x" + self.nsign() + "z",
                                          self.negate())

        # ik
        ikbfr_pos = Vector3([
            self.translations("Root").x,
            self.translations("Ankle").y,
            self.translations("Root").z
        ])

        ikbfrTfm = Transformation.fromParts(translation=ikbfr_pos)
        ikTfm = Transformation.lookAt(self.translations("Ankle"), direction,
                                      upaxis, "zy", False)

        upvbfrTfm = Transformation.fromParts(
            translation=umath.upVector(self.translations("Root"), ikbfr_pos,
                                       constants.AXIS_NX, ratio, False))
        upvTfm = Transformation.fromParts(
            translation=umath.upVector(self.translations(
                "Root"), self.translations("Ankle"), oriNormal, ratio))

        # extras
        scale = Vector3([1, 1, 1])
        twisterTfm = {}
        interTfm = {}
        for i, (p, pos) in enumerate(izip(self.twp, positions[1:3])):
            twisterTfm[p] = [
                fkTfm[i].copy(scale=scale), fkTfm[i].copy(translation=pos,
                                                          scale=scale)
            ]
            inter_pos = twisterTfm[p][0].translation.lerp(
                twisterTfm[p][1].translation, .5)
            interTfm[p] = twisterTfm[p][0].copy(translation=inter_pos)

        ctrTfm = twisterTfm["Lwr"][0]

        # CONTROLLERS
        # Root
        self.rootBfr = self.addBfr(None, "Root", rootTfm)
        self.rootCtl = self.addCtl(self.rootBfr,
                                   "Root",
                                   rootTfm,
                                   "sphere",
                                   color=self.colorIk(),
                                   size=rootSize)
        # self.addToSubControllers(self.rootCtl)
        attributes.setKeyables(self.rootCtl, constants.ATTRS_T)

        # Fk Ref
        # Used as a reference for the upr start twist
        # We cannot use the fk1Bfr cause this one get constrained when fk ref changes
        self.fkRef = self.addRig(self.rootBfr, "FkRef", bfrTfm[0])

        # FK Controlers and Bones
        fkParent = self.fkRef
        boneParent = self.fkRef
        self.fkBfr = []
        self.fkCtl = []
        self.bones = []
        self.stretches = []
        for i, (tfm, btfm) in enumerate(izip(fkTfm, bfrTfm), start=1):

            bfr = self.addBfr(fkParent, "Fk%s" % i, btfm)
            ctl = self.addCtl(bfr,
                              "Fk%s" % i,
                              tfm,
                              "sphere",
                              color=self.colorFk(),
                              size=fkSize,
                              so=(0, 1, 1))
            if self.settings("lockKneeRotation") and i == 2:
                keyableParams = [
                    "posx", "posy", "posz", "rotz", "sclx", "scly", "sclz"
                ]
            else:
                keyableParams = constants.ATTRS_TRS

            attributes.setKeyables(ctl, keyableParams)

            fkParent = ctl
            self.fkBfr.append(bfr)
            self.fkCtl.append(ctl)

            bone = self.addRig(boneParent,
                               "Bone{}".format(i),
                               tfm=tfm,
                               icon="bone",
                               so=(self.factor(), 1, 1))
            boneParent = bone
            self.bones.append(bone)

        # IK Controllers
        self.ikBfr = self.addBfr(None, "Ik", ikbfrTfm)
        self.ikCtl = self.addCtl(self.ikBfr,
                                 "Ik",
                                 ikTfm,
                                 "cube",
                                 color=self.colorIk(),
                                 size=ikSize)
        attributes.setKeyables(self.ikCtl, constants.ATTRS_TRS)

        attributes.setRotOrder(self.ikCtl, "XZY")

        self.ikoffCtl = self.addCtl(self.ikCtl,
                                    "IkOffset",
                                    ikTfm,
                                    "cube",
                                    color=self.colorIk(),
                                    size=ikSize)
        # self.addToSubControllers(self.ikoffCtl)
        attributes.setKeyables(self.ikoffCtl, constants.ATTRS_TRS)
        self.ikRef = self.addRig(self.ikoffCtl, "IkRef", fkTfm[-1])

        attributes.setRotOrder(self.ikoffCtl, "XZY")

        self.upvBfr = self.addBfr(None, "Upv", upvbfrTfm)
        self.upvCtl = self.addCtl(self.upvBfr,
                                  "Upv",
                                  upvTfm,
                                  "diamond",
                                  color=self.colorIk(),
                                  size=upvSize)
        attributes.setKeyables(self.upvCtl, constants.ATTRS_T)

        self.ctrBfr = self.addBfr(self.bones[0], "Center", ctrTfm)
        self.ctrCtl = self.addCtl(self.ctrBfr,
                                  "Center",
                                  ctrTfm,
                                  "sphere",
                                  size=rootSize,
                                  color=self.colorIk())
        # self.addToSubControllers(self.ctrCtl)
        attributes.setKeyables(self.ctrCtl, constants.ATTRS_TRS)

        self.upvCrv = create.cnsCurve(
            self.getObjectName(config.USE_RIG, "UpvCrv"),
            [self.upvCtl, self.ctrCtl])

        # Twisters
        self.twisters = defaultdict(list)
        for p in self.twp:
            for s, tfm, factor in izip(["Start", "End"], twisterTfm[p],
                                       [1, -1]):
                twisterBfr = self.addBfr(self.rootBfr, "Tw" + p + s, tfm)
                twister = self.addRig(twisterBfr, "Tw" + p + s, tfm, "pyramid")
                self.twisters[p].append(twister)

        # Inter
        self.inters = {}
        for p in self.twp:
            self.inters[p] = self.addRig(self.rootBfr, "Inter" + p,
                                         interTfm[p], "cube")
Esempio n. 9
0
    def createObjects(self):
        north = self.settings("north")
        south = self.settings("south")
        east = self.settings("east")
        west = self.settings("west")

        # TRANSFORMATION
        tfm = Transformation.lookAt(self.translations("Root"),
                                    self.directions("Root", "y"),
                                    self.directions("Root", "z"),
                                    axis="y" + self.sign() + "z",
                                    negativeSide=False)
        tfm.scale *= .5
        if north != south and False in [
                east, west
        ] or east != west and False in [north, south]:
            tfm.scale *= 2

        # Label
        if not north and not south:
            dirn = .20
            dirs = -.20
        else:
            dirn = int(north)
            dirs = -int(south)
        if not east and not west:
            dire = .20
            dirw = -.20
        else:
            dire = int(east)
            dirw = -int(west)

        if self.settings("labelPosition") == "North":
            labelTfm = Transformation.fromParts(
                translation=Vector3([(dire + dirw) * .5, dirn + .1, 0]))
            align = "center"
        elif self.settings("labelPosition") == "South":
            labelTfm = Transformation.fromParts(
                translation=Vector3([(dire + dirw) * .5, dirs - .5, 0]))
            align = "center"
        elif self.settings("labelPosition") == "East":
            labelTfm = Transformation.fromParts(
                translation=Vector3([dire + .1, -.15, 0]))
            align = "left"
        elif self.settings("labelPosition") == "West":
            labelTfm = Transformation.fromParts(
                translation=Vector3([dirw - .1, -.15, 0]))
            align = "right"

        labelTfm *= tfm

        # CREATE OBJECTS
        # Frame
        scly = 1 * (north + south) if (north or south) else 0
        sclx = 1 * (east + west) if (east or west) else 0
        offy = .5 * (north - south)
        offx = .5 * (east - west)
        frame = self.addRig(None,
                            "Frame",
                            tfm,
                            "cube",
                            size=1,
                            po=(offx, offy, 0),
                            so=(sclx, scly, 0))

        # Controller
        self.ctl = self.addCtl(frame,
                               "1",
                               tfm,
                               "cube",
                               size=1,
                               so=(.5, .5, 0),
                               color=self.colorFk())
        attributes.setKeyables(
            self.ctl, ["posx", "posy"]
        )  # Faceware doesn't like if the posx is not keyable, so we make it keyable all the time...

        # Label
        labelText = self.settings("label") if (
            self.settings("customLabel")
            and self.settings("label") != "") else self.settings("name")
        label = create.text(self.getObjectName(config.USE_RIG, "Label"),
                            frame,
                            labelTfm,
                            labelText,
                            size=.2,
                            align=align)

        # RECONNECT
        for source, destination in self._connections:
            cmds.connectAttr(source, destination)
Esempio n. 10
0
	def createObjects(self):
		# Settings
		self.isFk = "FK" in self.settings("kinematic")
		self.isIk = "IK" in self.settings("kinematic")
		self.isFkIk = self.isFk and self.isIk
		self.isNotIk = self.isFk and not self.isIk
		self.isNotFk = not self.isFk and self.isIk


		# TRANSFORMATIONS
		positions = Vector3Array([self.translations("Root"), self.translations("Head"), self.translations("Eff")])
		normal = Vector3.planeNormal(*positions)
		if self.negate():
			normal *= -1
		self.neckLength = self.translations("Root").distance(self.translations("Head"))
		headLength = self.translations("Head").distance(self.translations("Eff"))
		
		direction = self.translations("Eff") - self.translations("Head")
		ikTfm = Transformation.lookAt(self.translations("Head"), direction, normal, "yx", self.negate())
		if self.settings("orientToWorld"):
			headTfm = Transformation.fromParts(translation=self.translations("Head"))
		else:
			headTfm = ikTfm
		
		crvPos = Vector3Array([self.translations("Root").lerp(self.translations("Head"), i/3.0) for i in xrange(4)])
		refPos = Vector3Array([self.translations("Root").lerp(self.translations("Head"), i/2.0) for i in xrange(3)])
		direction = self.translations("Head") - self.translations("Root")
		rootTfm = Transformation.lookAt(self.translations("Root"), direction, normal, "yx", self.negate())
		midTfm = rootTfm.copy(translation=refPos[1])
		endTfm = rootTfm.copy(translation=refPos[2])
		tan0Tfm = rootTfm.copy(translation=crvPos[1])
		tan1Tfm = ikTfm.copy(translation=crvPos[-2])
		
		bonePos = refPos.appended(self.translations("Eff"))
		boneTfm = TransformationArray.chain(bonePos, normal, axis="yx", negativeSide=self.negate(), endTransform=False)


		# CONTROLLERS
		# Root
		self.rootRig = self.addRig(None, "Root", rootTfm)
		self.tan0 = self.addRig(self.rootRig, "Tan0", tan0Tfm)
		
		# Ik 
		self.ikBfr = self.addBfr(self.rootRig, "Ik", headTfm)
		self.ikOri = self.addBfr(self.ikBfr, "IkOri", headTfm) # Maya requires an extra object for the ori cns
		self.ikCtl = self.addCtl(self.ikOri, "Ik", ikTfm, "cube", size=1, 
			po=(0,headLength*.5,0), so=(8, headLength, 8),color=self.colorIk())   
		# self.setInversedsettings(self.ikCtl, middle=["posx", "roty", "rotz"])
		attributes.setRotOrder(self.ikCtl, "XZY")
		self.tan1 = self.addRig(self.ikCtl, "Tan1", tan1Tfm)

		if self.settings("gimbalControllers"):
			self.ikOffCtl = self.addCtl(self.ikCtl, "IkOff", ikTfm, "cube", size=.9, 
				po=(0,headLength*.5,0), so=(8, headLength, 8),color=self.colorIk())   
			# self.setInversedsettings(self.ikOffCtl, middle=["posx", "roty", "rotz"])
			attributes.setKeyables(self.ikOffCtl, constants.ATTRS_R)
			attributes.setRotOrder(self.ikOffCtl, "XZY")
			self.lastIkCtl = self.ikOffCtl
			# self.addToSubControllers(self.ikOffCtl)
		else:
			self.lastIkCtl = self.ikCtl
		
		# Curve
		self.crv = create.curve(self.getObjectName(config.USE_RIG,"Crv"), crvPos, closed=False, degree=3, parent=self.rootRig)

		# References
		self.baseBfr = self.addBfr(self.rootRig, "Base", rootTfm)
		self.baseCtl = self.addCtl(self.baseBfr, "Base", rootTfm, "sphere", size=4, so=(1,0,1), color=self.colorIk())
		# self.setInversedsettings(self.baseCtl, middle=["posx", "roty", "rotz"])
		attributes.setRotOrder(self.baseCtl, "XZY")
		
		self.midBfr = self.addBfr(self.crv, "Mid", midTfm)
		self.midCtl = self.addCtl(self.midBfr, "Mid", midTfm, "sphere", size=4, so=(1,0,1), color=self.colorIk())
		attributes.setKeyables(self.midCtl, constants.ATTRS_TS)
		# self.setInversedsettings(self.midCtl, middle=["posx"])
		
		self.headBfr = self.addBfr(self.crv, "Head", endTfm)
		if self.settings("extraHeadController"):
			self.headCtl = self.addCtl(self.headBfr, "Head", rootTfm, "sphere", so=(1,0,1), color=self.colorIk())
			# self.addToSubControllers(self.headCtl)
			# self.setInversedsettings(self.headCtl, middle=["posx", "roty", "rotz"])
			attributes.setRotOrder(self.headCtl, "XZY")
			self.headRef = self.headCtl
		else:
			self.headRef = self.headBfr
		
		# Fk
		if self.isFk:
			self.fkCtl = []
			parent = self.rootRig
			for i, tfm in enumerate(boneTfm, start=1):
				if self.settings("orientToWorld") and i == len(boneTfm):
					bfr = self.addBfr(parent, "Fk%s"%i, headTfm)
				else:
					bfr = self.addBfr(parent, "Fk%s"%i, tfm)
				ctl = self.addCtl(bfr, "Fk%s"%i, tfm, "cube", size=8, so=(1,.1,1), color=self.colorFk())
				attributes.setRotOrder(ctl, "XZY")
				
				parent = ctl

				self.fkCtl.append(ctl)

			if self.settings("gimbalControllers"):
				self.fkOffCtl = self.addCtl(self.fkCtl[-1], "fkOffCtl", boneTfm[-1], "cube", size=7.5, so=(1,.1,1), color=self.colorFk())
				attributes.setKeyables(self.fkOffCtl, constants.ATTRS_R)
				attributes.setRotOrder(self.fkOffCtl, "XZY")

		# Hooks
		self.ikParents = [self.baseCtl, self.midCtl, self.headRef]
		self.hooks = []
		for i, (tfm, parent) in enumerate(izip(boneTfm, self.ikParents), start=1):

			hk = self.addRig(parent, "Hook%s"%i, tfm)
			self.hooks.append(hk)
Esempio n. 11
0
def createTransform(t=None, r=None, s=None):
    return Transformation.fromParts(translation=t, rotation=r, scale=s)