(file_name, **kwargs)
return callback_func(faces)
Reads .obj files and generates faces.

    Keyword Arguments:
        * ``callback``: reference to the function that processes the faces for customized output

    The structure of the callback function is shown below:

    .. code-block:: python

        def my_callback_function(face_list):
            # "face_list" will be a list of elements.Face class instances
            # The function should return a list
            return list()

    :param file_name: file name
    :type file_name: str
    :return: output of the callback function (default is a list of faces)
    :rtype: list
Reads .obj files and generates faces.
Reads . obj files and generates faces .
def import_obj(file_name, **kwargs):
    """ Reads .obj files and generates faces.

    Keyword Arguments:
        * ``callback``: reference to the function that processes the faces for customized output

    The structure of the callback function is shown below:

    .. code-block:: python

        def my_callback_function(face_list):
            # "face_list" will be a list of elements.Face class instances
            # The function should return a list
            return list()

    :param file_name: file name
    :type file_name: str
    :return: output of the callback function (default is a list of faces)
    :rtype: list
    """
    def default_callback(face_list):
        return face_list

    # Keyword arguments
    callback_func = kwargs.get('callback', default_callback)

    # Read and process the input file
    content = exch.read_file(file_name)
    content_arr = content.split("\n")

    # Initialize variables
    on_face = False
    vertices = []
    triangles = []
    faces = []

    # Index values
    vert_idx = 1
    tri_idx = 1
    face_idx = 1

    # Loop through the data
    for carr in content_arr:
        carr = carr.strip()
        data = carr.split(" ")
        data = [d.strip() for d in data]
        if data[0] == "v":
            if on_face:
                on_face = not on_face
                face = elements.Face(*triangles, id=face_idx)
                faces.append(face)
                face_idx += 1
                vertices[:] = []
                triangles[:] = []
                vert_idx = 1
                tri_idx = 1
            vertex = elements.Vertex(*data[1:], id=vert_idx)
            vertices.append(vertex)
            vert_idx += 1
        if data[0] == "f":
            on_face = True
            triangle = elements.Triangle(*[vertices[int(fidx) - 1] for fidx in data[1:]], id=tri_idx)
            triangles.append(triangle)
            tri_idx += 1

    # Process he final face
    if triangles:
        face = elements.Face(*triangles, id=face_idx)
        faces.append(face)

    # Return the output of the callback function
    return callback_func(faces)
def import_obj ( file_name , * * kwargs ) : def default_callback ( face_list ) : return face_list # Keyword arguments callback_func = kwargs . get ( 'callback' , default_callback ) # Read and process the input file content = exch . read_file ( file_name ) content_arr = content . split ( "\n" ) # Initialize variables on_face = False vertices = [ ] triangles = [ ] faces = [ ] # Index values vert_idx = 1 tri_idx = 1 face_idx = 1 # Loop through the data for carr in content_arr : carr = carr . strip ( ) data = carr . split ( " " ) data = [ d . strip ( ) for d in data ] if data [ 0 ] == "v" : if on_face : on_face = not on_face face = elements . Face ( * triangles , id = face_idx ) faces . append ( face ) face_idx += 1 vertices [ : ] = [ ] triangles [ : ] = [ ] vert_idx = 1 tri_idx = 1 vertex = elements . Vertex ( * data [ 1 : ] , id = vert_idx ) vertices . append ( vertex ) vert_idx += 1 if data [ 0 ] == "f" : on_face = True triangle = elements . Triangle ( * [ vertices [ int ( fidx ) - 1 ] for fidx in data [ 1 : ] ] , id = tri_idx ) triangles . append ( triangle ) tri_idx += 1 # Process he final face if triangles : face = elements . Face ( * triangles , id = face_idx ) faces . append ( face ) # Return the output of the callback function return callback_func ( faces )