Esempio n. 1
0
 def populate_controller(self):
     """
     populates the controller text edit box.
     :return:
     """
     selected_object = object_utils.get_selected_node(single=True)
     self.WIDGETS['controllerLineEdit'].setText(selected_object)
Esempio n. 2
0
def mirror_transforms(object_name=""):
    """
    mirror the transform controllers. **Must have corresponding left/ right naming.
    :param object_name: <str> the object to get transform values and find the mirror object from.
    :return: <bool> True for success. <bool> False for failure.
    """
    if not object_name:
        object_name = object_utils.get_selected_node(single=True)
    mirror_obj_name = ''
    if '_l_' in object_name:
        mirror_obj_name = object_name.replace('_l_', '_r_')
    if '_r_' in object_name:
        mirror_obj_name = object_name.replace('_r_', '_l_')
    if mirror_obj_name == mirror_obj_name:
        return False
    p_object = object_utils.get_transform_relatives(object_name,
                                                    find_parent=True,
                                                    as_strings=True)[0]
    p_mirror_object = object_utils.get_transform_relatives(mirror_obj_name,
                                                           find_parent=True,
                                                           as_strings=True)[0]
    p_trm = transform_utils.Transform(p_object)
    matrix = p_trm.world_matrix()
    mirror_matrix = p_trm.mirror_matrix(matrix)
    cmds.xform(p_mirror_object, m=mirror_matrix, ws=1)
    return True
Esempio n. 3
0
 def populate_controller(self):
     """
     populates the controller text edit box.
     :return:
     """
     selected_object = object_utils.get_selected_node(single=True)
     self.WIDGETS['controllerLineEdit'].setText(selected_object)
     self.setWindowTitle("{} :: {}".format(window_title, selected_object))
Esempio n. 4
0
def create_bind_joints_at_selection(name):
    """
    creates the joints at selected transform objects.
    :param name: <str> the name to use when creating the joints.
    :return: <tuple> array of joints created.
    """
    objects = object_utils.get_selected_node(single=False)
    return create_joints(objects, name, bind=True)
Esempio n. 5
0
def save_selected_objects_to_file():
    """
    save the mesh objects' skins to directory.
    :return:
    """
    for node in object_utils.get_selected_node(single=False):
        save_to_file(node)
    return True
Esempio n. 6
0
def get_selected_ctrl():
    """
    the joints from current selection.
    :return: <tuple> array of joints from selection.
    """
    selected_obj = object_utils.get_selected_node()
    if selected_obj and object_utils.is_shape_curve(selected_obj):
        return selected_obj
Esempio n. 7
0
def load_selected_objects_from_file():
    """
    save the mesh objects' skins to directory.
    :return:
    """
    for node in object_utils.get_selected_node(single=False):
        data = read_from_file(node)
        set_skin_data(node, data)
    return True
Esempio n. 8
0
def search_replace_hierarchy_in_selection(search_str="", replace_str=""):
    """
    replace names from selected objects. replaces names in hierarchy
    :param search_str: <str> the search string to replace.
    :param replace_str: <str> replace it with this name.
    :return: <tuple> renamed items.
    """
    selected_objects = object_utils.get_selected_node(single=False)
    return search_replace_objects_hierarchy(selected_objects, search_str=search_str, replace_str=replace_str)
Esempio n. 9
0
def add_selected_objects_to_deformer(deformer_name=""):
    """
    add selected objects to a specified deformer.
    :param deformer_name: <str> the deformer to add objects to.
    :return:
    """
    objects = object_utils.get_selected_node(single=False)
    for obj_name in objects:
        add_object_to_deformer(obj_name, deformer_name)
    return True
Esempio n. 10
0
def set_skin_file_data(mesh_obj=''):
    """
    sets the skin data from file.
    :param mesh_obj:
    :return:
    """
    if not mesh_obj:
        mesh_obj = object_utils.get_selected_node()
    skin_data = read_from_file(mesh_obj)
    set_skin_data(mesh_obj, skin_data)
    return True
Esempio n. 11
0
def search_replace_in_selection(search_str="", replace_str=""):
    """
    replace names from selected objects.
    :param search_str: <str> the search string to replace.
    :param replace_str: <str> replace it with this name.
    :return: <tuple> renamed items.
    """
    selected_objects = object_utils.get_selected_node(single=False)
    names = search_replace_names(selected_objects, search_str, replace_str)
    for sel_obj, name in zip(selected_objects, names):
        cmds.rename(sel_obj, name)
    return names
Esempio n. 12
0
def rename_objects(name="", suffix_name=""):
    """
    replace the names with enumeration.
    :return: <bool> True for success.
    """
    selected_objects = object_utils.get_selected_node(single=False)
    new_names = ()
    for idx, obj_name in enumerate(selected_objects):
        # hierarchy_name_array = object_utils.get_transform_relatives(obj_name, find_child=True, as_strings=True)
        new_name = '{}_{}_{}'.format(name, idx, suffix_name)
        new_names += new_name,
        cmds.rename(obj_name, new_name)
    return new_names
Esempio n. 13
0
def save_to_file(mesh_obj=''):
    """
    writes the skinCluster data into a JSON file type.
    :param mesh_obj: <str> the mesh object to query the skinCluster data from.
    :return: <str> the written skinCluster JSON file.
    """
    if not mesh_obj:
        mesh_obj = object_utils.get_selected_node()
    data = get_skin_data(mesh_obj)
    skin_file = file_utils.get_path(file_utils.get_maya_workspace_data_dir(), mesh_obj)
    ft = file_utils.JSONSerializer(skin_file, data)
    ft.write()
    print("Weights saved: {}\n".format(ft.FILE_NAME))
    return skin_file
Esempio n. 14
0
def create_controllers_with_point_constraints(name,
                                              objects_array=(),
                                              shape_name="cube",
                                              maintain_offset=False):
    """
    creates controllers with constraints on the objects in the array.
    :param name: <str>
    :param objects_array: <tuple> (optional) if not given, the objects will depend on your selection.
    :param shape_name: <str>
    :param maintain_offset: <bool> create constraints with maintain offset.
    :return: <tuplw>
    """
    if not objects_array:
        objects_array = object_utils.get_selected_node(single=False)
    return create_controls(objects_array,
                           name,
                           shape_name=shape_name,
                           apply_constraints=['point'],
                           maintain_offset=maintain_offset)