Exemplo n.º 1
0
    def setUp(self):
        meshes = deque()
        for filename in os.listdir(TEST_DIR):
            ext = os.path.splitext(filename)[-1][1:].lower() 
            if not ext in trimesh.available_formats():
                continue

            log.info('Attempting to load %s', filename)
            location = os.path.abspath(os.path.join(TEST_DIR, filename))
            meshes.append(trimesh.load_mesh(location))
            meshes[-1].metadata['filename'] = filename
        self.meshes = list(meshes)
Exemplo n.º 2
0
    def setUp(self):
        meshes = deque()
        for filename in os.listdir(TEST_DIR):
            ext = os.path.splitext(filename)[-1][1:].lower()
            if not ext in trimesh.available_formats():
                continue

            log.info('Attempting to load %s', filename)
            location = os.path.abspath(os.path.join(TEST_DIR, filename))
            meshes.append(trimesh.load_mesh(location))
            meshes[-1].metadata['filename'] = filename
        self.meshes = list(meshes)
Exemplo n.º 3
0
def get_meshes(count=None):
    ls = os.listdir(dir_models)
    if count is None:
        count = len(ls)
    meshes = deque()
    for file_name in ls:
        extension = os.path.splitext(file_name)[-1][1:].lower()
        if extension in trimesh.available_formats():
            meshes.append(get_mesh(file_name))
        else:
            log.warning('%s has no loader, not running test on!', file_name)
            
        if len(meshes) >= count:
            break
    return list(meshes)
Exemplo n.º 4
0
def get_meshes(count=np.inf,
               raise_error=False,
               only_watertight=True):
    """
    Get meshes to test with.

    Parameters
    ----------
    count : int
      Approximate number of meshes you want
    raise_error : bool
      If True raise a ValueError if a mesh
      that should be loadable returns a non- Trimesh object.

    Returns
    ----------
    meshes : list
      Trimesh objects from models folder
    """
    # use deterministic file name order
    file_names = sorted(os.listdir(dir_models))

    meshes = []
    for file_name in file_names:
        extension = trimesh.util.split_extension(file_name).lower()
        if extension in trimesh.available_formats():
            loaded = trimesh.util.make_sequence(get_mesh(file_name))
            for m in loaded:
                # is the loaded mesh a Geometry object or a subclass:
                # Trimesh, PointCloud, Scene
                type_ok = isinstance(m, trimesh.parent.Geometry)
                if raise_error and not type_ok:
                    raise ValueError('%s returned a non- Trimesh object!',
                                     file_name)
                if not isinstance(m, trimesh.Trimesh) or (
                        only_watertight and not m.is_watertight):
                    continue
                meshes.append(m)
                yield m
        else:
            log.warning('%s has no loader, not running test on!',
                        file_name)

        if len(meshes) >= count:
            break
Exemplo n.º 5
0
def get_2D(count=None):
    """
    Get Path2D objects to test with.

    Parameters
    --------------
    count : int
      Number of 2D drawings to return

    Yields
    --------------
    path : trimesh.path.Path2D
      Drawing from models folder
    """
    # if no path loading return empty list
    if not has_path:
        raise StopIteration

    # all files in the 2D models directory
    listdir = sorted(os.listdir(dir_2D))
    # if count isn't passed return all files
    if count is None:
        count = len(listdir)
    # save resulting loaded paths
    paths = []
    for file_name in listdir:
        # check to see if the file is loadable
        ext = trimesh.util.split_extension(file_name)
        if ext not in trimesh.available_formats():
            continue
        # full path
        location = os.path.join(dir_2D, file_name)
        try:
            paths.append(trimesh.load(location))
        except BaseException as E:
            log.error('failed on: {}'.format(file_name),
                      exc_info=True)
            raise E

        yield paths[-1]

        # if we don't need every path break
        if len(paths) >= count:
            break
Exemplo n.º 6
0
def get_2D(count=None):
    """
    Get Path2D objects to test with.

    Parameters
    --------------
    count : int
      Number of 2D drawings to return

    Yields
    --------------
    path : trimesh.path.Path2D
      Drawing from models folder
    """
    # if no path loading return empty list
    if not has_path:
        raise StopIteration

    # all files in the 2D models directory
    listdir = sorted(os.listdir(dir_2D))
    # if count isn't passed return all files
    if count is None:
        count = len(listdir)
    # save resulting loaded paths
    paths = []
    for file_name in listdir:
        # check to see if the file is loadable
        ext = trimesh.util.split_extension(file_name)
        if ext not in trimesh.available_formats():
            continue
        # full path
        location = os.path.join(dir_2D, file_name)
        try:
            paths.append(trimesh.load(location))
        except BaseException as E:
            log.error('failed on: {}'.format(file_name),
                      exc_info=True)
            raise E

        yield paths[-1]

        # if we don't need every path break
        if len(paths) >= count:
            break
Exemplo n.º 7
0
def get_meshes(count=np.inf,
               raise_error=False,
               only_watertight=True):
    """
    Get meshes to test with.

    Parameters
    ----------
    count : int
      Approximate number of meshes you want
    raise_error : bool
      If True raise a ValueError if a mesh
      that should be loadable returns a non- Trimesh object.

    Returns
    ----------
    meshes : list
      Trimesh objects from models folder
    """
    # use deterministic file name order
    file_names = sorted(os.listdir(dir_models))

    meshes = []
    for file_name in file_names:
        extension = trimesh.util.split_extension(file_name).lower()
        if extension in trimesh.available_formats():
            loaded = trimesh.util.make_sequence(get_mesh(file_name))
            for m in loaded:
                is_mesh = trimesh.util.is_instance_named(m, 'Trimesh')
                is_scene = trimesh.util.is_instance_named(m, 'Scene')
                if raise_error and not is_mesh and not is_scene:
                    raise ValueError('%s returned a non- Trimesh object!',
                                     file_name)
                if not is_mesh or (only_watertight and not m.is_watertight):
                    continue
                meshes.append(m)
                yield m
        else:
            log.warning('%s has no loader, not running test on!',
                        file_name)

        if len(meshes) >= count:
            break
Exemplo n.º 8
0
def get_meshes(count=None):
    ls = os.listdir(dir_models)
    if count is None:
        count = len(ls)
    meshes = deque()
    for file_name in ls:
        extension = os.path.splitext(file_name)[-1][1:].lower()
        if extension in trimesh.available_formats():
            loaded = get_mesh(file_name)
            if trimesh.util.is_instance_named(loaded, 'Trimesh'):
                meshes.append(loaded)
            else:
                log.error('file %s loaded garbage!', file_name)
        else:
            log.warning('%s has no loader, not running test on!', file_name)

        if len(meshes) >= count:
            break
    return list(meshes)
Exemplo n.º 9
0
def get_meshes(count=None):
    file_names = np.random.permutation(os.listdir(dir_models))
    if count is None:
        count = len(file_names)

    meshes = deque()
    for file_name in file_names:
        extension = trimesh.util.split_extension(file_name).lower()
        if extension in trimesh.available_formats():
            loaded = get_mesh(file_name)
            if trimesh.util.is_instance_named(loaded, 'Trimesh'):
                meshes.append(loaded)
            else:
                log.error('file %s didn\'t load a Trimesh object!', file_name)
        else:
            log.warning('%s has no loader, not running test on!', file_name)
        if len(meshes) >= count:
            break
    return list(meshes)
Exemplo n.º 10
0
def get_meshes(count=np.inf,
               raise_error=False,
               only_watertight=True):
    '''
    Get a list of meshes to test with.

    Arguments
    ----------
    count: int, approximate number of meshes you want
    raise_error: bool, if True raise a ValueError if a mesh
                 that should be loadable returns a non- Trimesh object.

    Returns
    ----------
    meshes: list, of Trimesh objects
    '''

    # randomly order the directory so if tests are running on a small
    # number of meshes for test speed we sample the whole test set eventually.
    file_names = np.random.permutation(os.listdir(dir_models))

    meshes = deque()
    for file_name in file_names:
        extension = trimesh.util.split_extension(file_name).lower()
        if extension in trimesh.available_formats():
            loaded = trimesh.util.make_sequence(get_mesh(file_name))
            for i in loaded:
                is_mesh = trimesh.util.is_instance_named(i, 'Trimesh')
                is_scene = trimesh.util.is_instance_named(i, 'Scene')
                if raise_error and not is_mesh and not is_scene:
                    raise ValueError('%s returned a non- Trimesh object!',
                                     file_name)
                if not is_mesh or (only_watertight and not i.is_watertight):
                    continue
                meshes.append(i)
        else:
            log.warning('%s has no loader, not running test on!',
                        file_name)
        if len(meshes) >= count:
            break
    return list(meshes)
Exemplo n.º 11
0
def get_meshes(count=np.inf, raise_error=False, only_watertight=True):
    """
    Get a list of meshes to test with.

    Arguments
    ----------
    count: int, approximate number of meshes you want
    raise_error: bool, if True raise a ValueError if a mesh
                 that should be loadable returns a non- Trimesh object.

    Returns
    ----------
    meshes: list, of Trimesh objects
    """
    # use deterministic file name order
    file_names = sorted(os.listdir(dir_models))

    meshes = []
    for file_name in file_names:
        extension = trimesh.util.split_extension(file_name).lower()
        if extension in trimesh.available_formats():
            loaded = trimesh.util.make_sequence(get_mesh(file_name))
            for m in loaded:
                is_mesh = trimesh.util.is_instance_named(m, 'Trimesh')
                is_scene = trimesh.util.is_instance_named(m, 'Scene')
                if raise_error and not is_mesh and not is_scene:
                    raise ValueError('%s returned a non- Trimesh object!',
                                     file_name)
                if not is_mesh or (only_watertight and not m.is_watertight):
                    continue
                meshes.append(m)
                yield m
        else:
            log.warning('%s has no loader, not running test on!', file_name)

        if len(meshes) >= count:
            break