Example #1
0
def create_shapes_joint(blendshapes, parent, name="shapes"):
    """Create a joint with a weight attribute per each blendshape target.

    This is used to export blendshape animation with the skeleton.

    :param blendshapes: List of blendshape nodes.
    :param parent: Joint to parent the new joint under.
    :param name: Name of the new joint. "shapes" by default.
    :return: The new joint name
    """
    joint = cmds.createNode("joint", name=name)
    common.snap_to(joint, parent)
    cmds.parent(joint, parent)
    cmds.makeIdentity(joint, t=True, r=True, s=True, apply=True)
    if isinstance(blendshapes, string_types):
        blendshapes = [blendshapes]

    for blendshape in blendshapes:
        targets = get_target_list(blendshape)
        for t in targets:
            attr = "{}.{}".format(joint, t)
            if not cmds.objExists(attr):
                cmds.addAttr(joint, ln=t, keyable=True)
            if not cmds.listConnections(attr, d=False):
                cmds.connectAttr("{}.{}".format(blendshape, t), attr)
    return joint
Example #2
0
 def __create_fk(self):
     ik_switch = cmds.listConnections("{}.ikBlend".format(
         self.two_bone_ik.ik_handle),
                                      d=False,
                                      plugs=True)[0]
     for ikh in [self.ik_handle_ball, self.ik_handle_toe]:
         cmds.connectAttr(ik_switch, "{}.ikBlend".format(ikh))
     self.ball_fk_ctrl = cmds.createNode("transform",
                                         name="{}_fk_ctrl".format(
                                             self.ball_joint))
     common.snap_to(self.ball_fk_ctrl, self.ball_joint)
     common.lock_and_hide(self.ball_fk_ctrl, "sv")
     cmds.parent(self.ball_fk_ctrl, self.two_bone_ik.end_fk_control)
     common.freeze_to_parent_offset(self.ball_fk_ctrl)
     ori = cmds.orientConstraint(self.ball_fk_ctrl, self.ball_joint)[0]
     cmds.connectAttr(
         "{}.ikFk".format(self.two_bone_ik.config_control),
         "{}.{}W0".format(ori, self.ball_fk_ctrl),
     )
Example #3
0
    def __create_fk(self):
        ik_switch = cmds.listConnections("{}.ikBlend".format(
            self.two_bone_ik.ik_handle),
                                         d=False,
                                         plugs=True)[0]
        for ikh in [self.ik_handle_ball, self.ik_handle_toe]:
            if ikh:
                cmds.connectAttr(ik_switch, "{}.ikBlend".format(ikh))
        self.ball_fk_ctrl = cmds.createNode("transform",
                                            name="{}_fk_ctrl".format(
                                                self.ball_joint))
        common.snap_to(self.ball_fk_ctrl, self.ball_joint)
        common.lock_and_hide(self.ball_fk_ctrl, "sv")
        cmds.parent(self.ball_fk_ctrl, self.two_bone_ik.end_fk_control)
        common.freeze_to_parent_offset(self.ball_fk_ctrl)

        if self.ik_handle_toe:
            ori = cmds.orientConstraint(self.ball_fk_ctrl, self.ball_joint)[0]
        else:
            # Without a toe joint, like in the UE4 Mannequin, use a constraint instead of ik
            ori_target = cmds.duplicate(
                self.hierarchy.toe_ctrl,
                name="{}_ori".format(self.hierarchy.toe_pivot_ctrl),
                po=True,
            )[0]
            cmds.parent(ori_target, self.hierarchy.toe_ctrl)
            common.snap_to(ori_target, self.ball_joint)

            ori = cmds.orientConstraint(
                self.ball_fk_ctrl,
                ori_target,
                self.ball_joint,
            )[0]
            cmds.connectAttr(ik_switch, "{}.{}W1".format(ori, ori_target))

        cmds.connectAttr(
            "{}.ikFk".format(self.two_bone_ik.config_control),
            "{}.{}W0".format(ori, self.ball_fk_ctrl),
        )
Example #4
0
    def __create_fk(self, parent):
        for name, joint in [
            ("start_fk_control", self.start_joint),
            ("mid_fk_control", self.mid_joint),
            ("end_fk_control", self.end_joint),
        ]:
            control = cmds.createNode("transform",
                                      name="{}_fk_ctrl".format(joint))
            common.snap_to(control, joint)
            common.lock_and_hide(control, "sv")
            setattr(self, name, control)
            if parent:
                cmds.parent(control, parent)
            common.freeze_to_parent_offset(control)
            parent = control
            ori = cmds.orientConstraint(control, joint)[0]
            cmds.connectAttr("{}.ikFk".format(self.config_control),
                             "{}.{}W0".format(ori, control))

            # Drive visibility
            visibility = "{}.v".format(control)
            locked = cmds.getAttr(visibility, lock=True)
            cmds.setAttr(visibility, lock=False)
            cmds.connectAttr("{}.ikFk".format(self.config_control), visibility)
            if locked:
                cmds.setAttr(visibility, lock=True)

        for joint, node in [
            (self.start_joint, self.start_fk_control),
            (self.mid_joint, self.mid_fk_control),
        ]:
            cmds.addAttr(node,
                         ln="length",
                         minValue=0,
                         defaultValue=1,
                         keyable=True)
            scale = cmds.listConnections("{}.sx".format(joint),
                                         d=False,
                                         plugs=True)[0]
            dge(
                "sx = lerp(scale, length, ikFk)",
                sx="{}.sx".format(joint),
                scale=scale,
                length="{}.length".format(node),
                ikFk="{}.ikFk".format(self.config_control),
            )

        for control in [self.mid_fk_control, self.end_fk_control]:
            parent_control = cmds.listRelatives(control,
                                                parent=True,
                                                path=True)[0]
            compose = cmds.createNode("composeMatrix")
            offset = common.local_offset(control)
            dge(
                "x = (length - 1.0) * tx",
                container="{}_length_offset".format(control),
                x="{}.inputTranslateX".format(compose),
                length="{}.length".format(parent_control),
                tx=offset.getElement(3, 0),
            )

            mult = cmds.createNode("multMatrix")
            cmds.connectAttr("{}.outputMatrix".format(compose),
                             "{}.matrixIn[0]".format(mult))
            cmds.setAttr(
                "{}.matrixIn[1]".format(mult),
                cmds.getAttr("{}.offsetParentMatrix".format(control)),
                type="matrix",
            )
            cmds.connectAttr(
                "{}.matrixSum".format(mult),
                "{}.offsetParentMatrix".format(control),
            )