예제 #1
0
def get_set_members(deformer_name="", index=False, uv=False, position=False):
    """
    finds the deformers associated with the mesh name.
    :param deformer_name: <str> the name of the deformer to get set data from.
    :param index: <bool> if True, return index components.
    :param uv: <bool> if True, return UV components.
    :param position: <bool> if True, return position components.
    :return: <dict> setName: (array of components) data.
    """
    deform_fn = OpenMayaAnim.MFnGeometryFilter(
        object_utils.get_m_obj(deformer_name))
    set_obj = deform_fn.deformerSet()
    set_fn = OpenMaya.MFnSet(set_obj)

    members = OpenMaya.MSelectionList()
    set_fn.getMembers(members, False)

    sel_iter = OpenMaya.MItSelectionList(members)
    data_dict = {}
    while not sel_iter.isDone():
        path = OpenMaya.MDagPath()
        components = OpenMaya.MObject()
        sel_iter.getDagPath(path, components)
        data_dict[set_fn.name()] = mesh_utils.get_data(path,
                                                       components,
                                                       index=index,
                                                       uv=uv,
                                                       position=position)
        sel_iter.next()
    return data_dict
예제 #2
0
def is_blendshape(object_name):
    """
    return true if the node object is of type blendShape.
    :return: <bool>
    """
    return bool(
        object_utils.has_fn(object_utils.get_m_obj(object_name), 'blendShape'))
예제 #3
0
def get_mesh_fn(object_name=""):
    """
    returns a OpenMaya.MFnMesh() object.
    :param object_name: <str> object name to get the MeshFn class.
    :return: <OpenMaya.MFnMesh> object.
    """
    return OpenMaya.MFnMesh(get_fn_shape(object_utils.get_m_obj(object_name)))
예제 #4
0
def get_joint_orientation(joint_name):
    """
    joint orientation
    :param joint_name: <str> joint name to get orientation from.
    :return: <OpenMaya.MMatrix> orientation matrix.
    """
    # Factor in Joint Orientation
    j_obj = object_utils.get_m_obj(joint_name)
    j_fn = object_utils.get_fn(j_obj)
    j_quat = OpenMaya.MQuaternion()
    j_fn.getOrientation(j_quat)
    return j_quat.asMatrix()
예제 #5
0
def get_deformer_fn(object_name=""):
    """
    get a blendshape deformer fn
    :param object_name: <str> object name to get get blendShapeDeformer function set from.
    :return: <OpenMaya.MFnBlendShapeDeformer> object type.
    """
    m_blend_obj = None
    if object_utils.is_transform(object_name):
        shape_obj = object_utils.get_shape_name(object_name)[0]
        m_blend_obj = get_connected_blendshape(shape_obj)[0]
    elif is_blendshape(object_name):
        m_blend_obj = object_utils.get_m_obj(object_name)
    return OpenMayaAnim.MFnBlendShapeDeformer(m_blend_obj)
예제 #6
0
def create_blendshape(mesh_objects, name=""):
    """
    creates a new blendShape from the array of mesh objects provided
    :param mesh_objects: <tuple> array of mesh shapes.
    :param name: <str> name of the blendshape.
    :return: <OpenMayaAnim.MFnBlendShapeDeformer>
    """
    blend_fn = OpenMayaAnim.MFnBlendShapeDeformer()
    if isinstance(mesh_objects, (str, unicode)):
        mesh_obj = object_utils.get_m_obj(mesh_objects)
        blend_fn.create(mesh_obj, origin, normal_chain)
    elif len(mesh_objects) > 1 and isinstance(mesh_objects, (tuple, list)):
        mesh_obj_array = object_utils.get_m_obj_array(mesh_objects)
        blend_fn.create(mesh_obj_array, origin, normal_chain)
    else:
        raise ValueError("Could not create blendshape.")

    if name:
        object_utils.rename_node(blend_fn.object(), name)
    return blend_fn
예제 #7
0
def get_point_data(blend_name=""):
    """
    grabs the weight data.
    :param blend_name:
    :return:
    """
    m_blend_obj = object_utils.get_m_obj(blend_name)
    m_blend_node_fn = object_utils.get_fn(m_blend_obj)

    m_plug = m_blend_node_fn.findPlug('inputTarget').elementByPhysicalIndex(
        0).child(0).elementByPhysicalIndex(0).child(0).elementByPhysicalIndex(
            0)

    # if connected, retrieves the input target object and queries his points
    if m_plug.child(0).isConnected():
        input_geom_obj = m_plug.child(0).asMObject()
        target_points = OpenMaya.MPointArray()
        mesh_fn = OpenMaya.MFnMesh(input_geom_obj)
        mesh_fn.getPoints(target_points)
        return target_points

    # if not connected, retrieves the deltas and the affected component list
    else:
        input_point_target = m_plug.child(1).asMObject()
        input_comp_target = m_plug.child(2).asMObject()

        # to read the offset data, I had to use a MFnPointArrayData
        points_fn = OpenMaya.MFnPointArrayData(input_point_target)
        target_points = OpenMaya.MPointArray()
        points_fn.copyTo(target_points)

        # read the component list data was the trickiest part,
        # since I had to use MFnSingleIndexedComponent to extract (finally), an MIntArray
        # with the indices of the affected vertices

        component_list = OpenMaya.MFnComponentListData(input_comp_target)[0]
        index_fn = OpenMaya.MFnSingleIndexedComponent(component_list)
        target_indices = OpenMaya.MIntArray()
        index_fn.getElements(target_indices)
        if target_indices.length() == target_points.length():
            return target_points
예제 #8
0
def get_m_object(object_name=""):
    return object_utils.get_m_obj(object_name)
예제 #9
0
def create_joint(name,
                 prefix_name="",
                 num_joints=1,
                 as_strings=False,
                 guide_joint=False,
                 bound_joint=False,
                 suffix_name="",
                 use_name=False,
                 use_transform="",
                 use_position=()):
    """
    creates a joint and names it using OpenMaya.
    :param name: <str> the name of the joint to create !important.
    :param num_joints: the number of joints created.
    :param prefix_name: <str> the prefix name to use.
    :param guide_joint: <str> create joint with '_bnd_jnt' name.
    :param bound_joint: <str> create joint with '__guide_jnt' name.
    :param as_strings: <bool> returns <str> objects instead of <OpenMaya.MObject> objects.
    :param use_name: <str> use the name that is coming in.
    :param use_transform: <str> use this object's transform co-ordinates.
    :param use_position: <tuple, list> array of floats to use as transform or matrix.
    :param suffix_name: <str> uses a custom suffix name string.
    :return: <tuple> array of created joint objects.
    """
    if not name:
        name = 'joint'
    dag_mod = OpenMaya.MDagModifier()

    # create the joint MObjects we will be manipulating.
    jnt_objects = ()
    jnt_names = ()

    # grabs the joint names
    joint_names = get_joint_names(prefix_name=prefix_name,
                                  name=name,
                                  num_joints=num_joints,
                                  use_name=use_name,
                                  guide_joint=guide_joint,
                                  bound_joint=bound_joint,
                                  suffix_name=suffix_name)

    for i in xrange(0, num_joints):
        # only create new if the objects's names do not exist
        new_name = joint_names[i]

        # create only when the name does not exist
        if name and not object_utils.is_exists(new_name):
            jnt_names += new_name,
            if i == 0:
                # The first joint has no parent.
                jnt_obj = dag_mod.createNode('joint')
            else:
                # Assign the new joint as a child to the previous joint.
                jnt_obj = dag_mod.createNode('joint', jnt_objects[i - 1])

            # rename the joint using OpenMaya
            dag_mod.renameNode(jnt_obj, new_name)
            dag_mod.doIt()

            # keep track of all the joints created.
            jnt_objects += jnt_obj,

        elif name and object_utils.is_exists(new_name):
            jnt_names += new_name,
            jnt_objects += object_utils.get_m_obj(new_name),

        # snap the joint to the transform
        if use_transform and object_utils.is_exists(new_name):
            object_utils.snap_to_transform(new_name,
                                           use_transform,
                                           matrix=True)

        # set the position of the newly created joint
        if use_position:
            if isinstance(use_position[0], (int, float)):
                set_position(new_name, use_position)
            else:
                set_position(new_name, use_position[i])

    if not as_strings:
        return jnt_objects
    elif as_strings:
        return jnt_names