def _build(self, *args):
        """
        Builds the joints on the curve.
        """
        # naming convention
        asset = self.asset
        side = self.side
        part = self.part
        joints = self.joints
        suffix = self.suffix

        if self.gui:
            asset = self.asset_name.text()
            side = self.side.currentText()
            part = self.part_name.text()
            joints = self.joints_box.value()
            suffix = self.suffix.currentText()
        try:
            curve = pm.ls(sl=True)[0]
            curve_name = NameUtils.get_unique_name(asset, side, part, "crv")
            self.curve = pm.rename(curve, curve_name)
        except IndexError:
            pm.warning("Please select a curve")
            return

        length_of_curve = pm.arclen(self.curve)
        equal_spacing = length_of_curve / float(joints)

        # clear the selection
        pm.select(cl=True)

        # # create the joints
        curve_joints = list()
        for x in xrange(int(joints) + 1):
            name = NameUtils.get_unique_name(asset, side, part, suffix)
            joint = pm.joint(n=name)
            curve_joints.append(joint)

            joint_position = (x * equal_spacing)
            pm.move(0, joint_position, 0)
        
        # rename last joint
        last_joint = curve_joints[-1]
        pm.rename(last_joint, last_joint + "End")

        root_joint = pm.selected()[0].root()
        end_joint = pm.ls(sl=True)[0]
        solver = 'ikSplineSolver'

        # attach joints to curve
        ik_name = NameUtils.get_unique_name(asset, side, part, "ikHandle")
        self.ikHandle = pm.ikHandle(sj=root_joint, ee=end_joint, sol=solver,
                        c=self.curve, pcv=True, roc=True, ccv=False, n=ik_name)
        joint_chain = pm.ls(root_joint, dag=True)

        # delete history
        pm.makeIdentity(root_joint, apply=True)

        # cleanup
        self._cleanup()
Пример #2
0
    def rename(self, asset, side, part, suffix, selected=None, end_joint=None):
        """
        Renames joint hierarchy.
        """
        new_joints = list()
        tmp_joints = list()

        # get joints
        joint_chain = cmds.ls(sl=True, dag=True, sn=True, type="joint")
        if selected:
            joint_chain = cmds.ls(sl=True, type="joint")

        # check for selection
        if not joint_chain:
            return cmds.warning("No Joints selected")

        # for rebuilding
        for joint in joint_chain:
            random = randint(10000, 99999)
            tmp_name = joint + str(random)
            tmp_joint = cmds.rename(joint, tmp_name)
            tmp_joints.append(tmp_joint)

        # rename
        for joint in tmp_joints:
            new_name = NameUtils.get_unique_name(asset, side, part, suffix)
            if cmds.objExists(joint):
                new_joint = cmds.rename(joint, new_name)
                new_joints.append(new_joint)

        # end joint
        if end_joint:
            last_joint = new_joints[-1]
            last_joint = cmds.rename(last_joint, last_joint + "End")
Пример #3
0
 def _build_name(self):
     """
     Builds the name of the control.
     """
     self.ctrl_name = NameUtils.get_unique_name(self.asset,
                                                self.side,
                                                self.part,
                                                "ctrl")
Пример #4
0
    def rename(self, asset, side, part, suffix):
        """
        Renames joint hierarchy.
        """
        # get joints
        joint_chain = cmds.ls(sl=True, dag=True, sn=True, type="joint")

        # check for selection
        if not joint_chain:
            return cmds.warning("No Joints selected")

        # rename
        for joint in joint_chain:
            new_name = NameUtils.get_unique_name(asset, side, part, suffix)
            if joint == joint_chain[-1]:
                cmds.rename(joint, new_name + "End")
                continue
            cmds.rename(joint, new_name)
Пример #5
0
    def _build(self, *args):
        """
        Builds the joints on the curve.
        """
        # naming convention
        asset = self.asset
        side = self.side
        part = self.part
        joints = self.joints
        suffix = self.suffix

        if self.gui:
            asset = self.asset_name.text()
            side = self.side.currentText()
            part = self.part_name.text()
            joints = self.joints_box.value()
            suffix = self.suffix.currentText()
        try:
            curve = pm.ls(sl=True)[0]
            curve_name = NameUtils.get_unique_name(asset, side, part, "crv")
            self.curve = pm.rename(curve, curve_name)
        except IndexError:
            pm.warning("Please select a curve")
            return

        length_of_curve = pm.arclen(self.curve)
        equal_spacing = length_of_curve / float(joints)

        # clear the selection
        pm.select(cl=True)

        # # create the joints
        curve_joints = list()
        for x in xrange(int(joints) + 1):
            name = NameUtils.get_unique_name(asset, side, part, suffix)
            joint = pm.joint(n=name)
            curve_joints.append(joint)

            joint_position = (x * equal_spacing)
            pm.move(0, joint_position, 0)

        # rename last joint
        last_joint = curve_joints[-1]
        pm.rename(last_joint, last_joint + "End")

        root_joint = pm.selected()[0].root()
        end_joint = pm.ls(sl=True)[0]
        solver = 'ikSplineSolver'

        # attach joints to curve
        ik_name = NameUtils.get_unique_name(asset, side, part, "ikHandle")
        self.ikHandle = pm.ikHandle(sj=root_joint,
                                    ee=end_joint,
                                    sol=solver,
                                    c=self.curve,
                                    pcv=True,
                                    roc=True,
                                    ccv=False,
                                    n=ik_name)
        joint_chain = pm.ls(root_joint, dag=True)

        # delete history
        pm.makeIdentity(root_joint, apply=True)

        # cleanup
        self._cleanup()
Пример #6
0
    def build_forearm_twist(cls, elbow_joint=None, hand_joint=None, *args):

        """
        Builds twist joints for a forearm twist.
        @ARGS:
            asset, side, part, suffix (see pipe_utils.name_utils.NameUtils)
        NOTES:
            Build with or without args.
            args = ("fortniteSmasher", "r", "arm", "twistJnt")
            tools.RigTools.build_forearm_twist("lowerarm_r", "hand_r", *args)
        """
        # if args
        if not args:
            args = ("asset", "ud", "limb")

        # grab necissary joints
        if not elbow_joint and not hand_joint:
            selection = cmds.ls(sl=True)
            elbow_joint = selection[0]
            hand_joint = selection[1]

        # get values
        joint_distance_value = cmds.getAttr("{0}.tx".format(hand_joint))
        split_tuple = (.25, .5, .75)

        # build joints
        twist_joints = list()
        for value in split_tuple:
            twist_joint_name = NameUtils.get_unique_name(*args, suffix="twistJnt")
            temp_joint = cmds.duplicate(elbow_joint, rr=True, po=True)[0]
            twist_joint = cmds.rename(temp_joint, twist_joint_name)
            # cmds.delete(cmds.listRelatives(twist_joint, f=True, ad=True, c=True))
            cmds.parent(twist_joint, elbow_joint)
            position = joint_distance_value * value
            cmds.setAttr("{0}.tx".format(twist_joint), position)
            twist_joints.append(twist_joint)

        # apply orient contraints
        for count, joint in enumerate(twist_joints):
            if count > 1:
                break
            contraint = cmds.orientConstraint(elbow_joint, twist_joints[-1],
                                              twist_joints[count])[0]
            if count == 0:
                cmds.setAttr("{0}.{1}W0".format(contraint, elbow_joint), 2)
            elif count == 1:
                cmds.setAttr("{0}.{1}W1".format(contraint, twist_joints[-1]), 2)

        ori_joint = None
        local_joint = None
        for gimbal in ("ORI", "LOCAL"):
            joint_name = NameUtils.get_unique_name(*args, suffix=gimbal)
            joint = cmds.duplicate(hand_joint, n=joint_name, po=True)[0]
            if joint.endswith("ORI"):
                ori_joint = joint
            elif joint.endswith("LOCAL"):
                local_joint = joint

        # prevent gimbal lock
        cmds.orientConstraint(hand_joint, local_joint, ori_joint, sk=("y","z"))

        # connect final twist joint
        hand_connect = "{0}.rx".format(hand_joint)
        twist_connect = "{0}.rx".format(twist_joints[-1])
        cmds.connectAttr(hand_connect, twist_connect)
Пример #7
0
 def _build_name(self):
     """
     Builds the name of the control.
     """
     self.ctrl_name = NameUtils.get_unique_name(self.asset, self.side,
                                                self.part, "ctrl")