def transfer_uvs_to_skinned_geometry(source_mesh=None,
                                     target_mesh=None,
                                     use_intermediate_shape=False,
                                     **kwargs):

    out_dict = {'success': False, 'result': None}

    selection = dcc.selected_nodes_of_type('transform')
    source_transform = source_mesh or (
        selection[0] if python.index_exists_in_list(selection, 0) else None)
    target_transform = target_mesh or (
        selection[1] if python.index_exists_in_list(selection, 1) else None)
    if not source_transform or not target_transform:
        out_dict[
            'msg'] = 'Select source mesh and target mesh before executing Transfers UVs to skinned geometry.'
        return out_dict

    try:
        result = skin_utils.transfer_uvs_to_skinned_geometry(
            source_mesh=source_mesh,
            target_mesh=target_mesh,
            use_intermediate_shape=use_intermediate_shape,
            **kwargs)
        out_dict['result'] = result
    except Exception as exc:
        out_dict[
            'msg'] = 'Was not possible to transfers UVs to skinned geometry: {}'.format(
                exc)
        return out_dict

    out_dict['success'] = True

    return out_dict
def swap_skin_weights(source_joint=None, target_joint=None, mesh=None):

    out_dict = {'success': False, 'result': None}

    selection = dcc.selected_nodes()
    source_joint = source_joint or (
        selection[0] if python.index_exists_in_list(selection, 0) else None)
    if not source_joint:
        out_dict['msg'] = 'No source joint found to swap skin weights from.'
        return out_dict

    target_joint = target_joint or (
        selection[1] if python.index_exists_in_list(selection, 1) else None)
    if not target_joint:
        out_dict['msg'] = 'No target joint found to swap skin weights to.'
        return out_dict

    mesh = mesh or (selection[2]
                    if python.index_exists_in_list(selection, 2) else None)
    if not mesh:
        out_dict['msg'] = 'No mesh with skinning information found'
        return out_dict

    try:
        result = skin_utils.swap_skin_weights(source_joint, target_joint, mesh)
        out_dict['result'] = result
    except Exception as exc:
        out_dict['msg'] = 'Was not possible to swap skin weights: {}'.format(
            exc)
        return out_dict

    out_dict['success'] = True

    return out_dict
def copy_skin_weights(source_mesh=None,
                      target_mesh=None,
                      show_options=False,
                      **kwargs):

    out_dict = {'success': False, 'result': None}

    selection = dcc.selected_nodes_of_type('transform')
    source_transform = source_mesh or (
        selection[0] if python.index_exists_in_list(selection, 1) else None)
    target_transform = target_mesh or (
        selection[1] if python.index_exists_in_list(selection, 1) else None)
    if not source_transform or not target_transform:
        out_dict[
            'msg'] = 'Select source mesh and target mesh before executing Copy Skin Weights.'
        return out_dict

    try:
        result = skin_utils.copy_skin_weights(source_mesh=source_mesh,
                                              target_mesh=target_mesh,
                                              show_options=show_options,
                                              **kwargs)
        out_dict['result'] = result
    except Exception as exc:
        out_dict['msg'] = 'Was not possible to copy skin weights: {}'.format(
            exc)
        return out_dict

    out_dict['success'] = True

    return out_dict
Beispiel #4
0
def match_rotation(source_transform=None, target_transform=None):
    """
    Matches rotation of the source node to the rotation of the given target node(s)
    """

    out_dict = {'success': False, 'result': list()}

    selection = dcc.selected_nodes_of_type(node_type='transform')
    source_transform = source_transform or selection[
        0] if python.index_exists_in_list(selection, 0) else None
    if not source_transform:
        out_dict[
            'msg'] = 'No source transform given to match against target rotation.'
        return out_dict
    target_transform = target_transform or selection[1:] if len(
        selection) > 1 else None
    if not source_transform:
        out_dict[
            'msg'] = 'No target transform(s) given to match source rotation against.'
        return out_dict
    source_transform = python.force_list(source_transform)
    target_transform = python.force_list(target_transform)

    percentage = 100.0 / len(source_transform)

    for i, source in enumerate(source_transform):
        library.Command.progressCommand.emit(
            percentage * (i + 1), 'Matching rotation: {}'.format(source))
        try:
            maya.cmds.delete(
                maya.cmds.orientConstraint(target_transform,
                                           source,
                                           maintainOffset=False))

            # For joints, we store now rotation data in jointOrient attribute
            if dcc.node_type(source) == 'joint':
                for axis in 'XYZ':
                    joint_orient_attr = 'jointOrient{}'.format(axis)
                    joint_rotation_attr = 'rotate{}'.format(axis)
                    dcc.set_attribute_value(source, joint_orient_attr, 0.0)
                    joint_rotation = dcc.get_attribute_value(
                        source, joint_rotation_attr)
                    dcc.set_attribute_value(source, joint_orient_attr,
                                            joint_rotation)
                    dcc.set_attribute_value(source, joint_rotation_attr, 0.0)

            out_dict['result'].append(source)
        except Exception as exc:
            out_dict[
                'msg'] = 'Was not possible to match node "{}" rotation to "{}" : {}'.format(
                    source_transform, target_transform, exc)
            return out_dict

    matched_nodes = out_dict.get('result', None)
    if matched_nodes:
        dcc.select_node(matched_nodes)

    out_dict['success'] = True

    return out_dict
Beispiel #5
0
def match_scale(source_transform=None, target_transform=None):
    """
    Matches scale of the source node to the scale of the given target node(s)
    """

    out_dict = {'success': False, 'result': list()}

    selection = dcc.selected_nodes_of_type(node_type='transform')
    source_transform = source_transform or selection[
        0] if python.index_exists_in_list(selection, 0) else None
    if not source_transform:
        out_dict[
            'msg'] = 'No source transform given to match against target scale.'
        return out_dict
    target_transform = target_transform or selection[1:] if len(
        selection) > 1 else None
    if not source_transform:
        out_dict[
            'msg'] = 'No target transform(s) given to match source scale against.'
        return out_dict
    source_transform = python.force_list(source_transform)
    target_transform = python.force_list(target_transform)

    percentage = 100.0 / len(source_transform)

    for i, source in enumerate(source_transform):
        library.Command.progressCommand.emit(
            percentage * (i + 1), 'Matching scale: {}'.format(source))
        try:
            maya.cmds.delete(
                maya.cmds.scaleConstraint(target_transform,
                                          source,
                                          maintainOffset=False))
            out_dict['result'].append(source)
        except Exception as exc:
            out_dict[
                'msg'] = 'Was not possible to match node "{}" scale to "{}" : {}'.format(
                    source_transform, target_transform, exc)
            return out_dict

    matched_nodes = out_dict.get('result', None)
    if matched_nodes:
        dcc.select_node(matched_nodes)

    out_dict['success'] = True

    return out_dict