trimesh.exchange.load module

Functions

available_formats()

Get a list of all available loaders

load(file_obj[, file_type, resolver])

Load a mesh or vectorized path into objects like

load_compressed(file_obj[, file_type, …])

Given a compressed archive load all the geometry that we can from it.

load_kwargs(*args, **kwargs)

Load geometry from a properly formatted dict or kwargs

load_remote(url, **kwargs)

Load a mesh at a remote URL into a local trimesh object.

mesh_formats()

Get a list of mesh formats

parse_file_args(file_obj, file_type[, resolver])

Given a file_obj and a file_type try to magically convert arguments to a file-like object and a lowercase string of file type.

trimesh.exchange.load.available_formats()

Get a list of all available loaders

Returns

loaders – Extensions of available loaders i.e. ‘stl’, ‘ply’, ‘dxf’, etc.

Return type

list

trimesh.exchange.load.load(file_obj, file_type=None, resolver=None, **kwargs)

Load a mesh or vectorized path into objects like Trimesh, Path2D, Path3D, Scene

Parameters
  • file_obj (str, or file- like object) – The source of the data to be loadeded

  • file_type (str) – What kind of file type do we have (eg: ‘stl’)

  • resolver (trimesh.visual.Resolver) – Object to load referenced assets like materials and textures

  • kwargs (dict) – Passed to geometry __init__

Returns

geometry – Loaded geometry as trimesh classes

Return type

Trimesh, Path2D, Path3D, Scene

trimesh.exchange.load.load_compressed(file_obj, file_type=None, resolver=None, mixed=False, **kwargs)

Given a compressed archive load all the geometry that we can from it.

Parameters
  • file_obj (open file-like object) – Containing compressed data

  • file_type (str) – Type of the archive file

  • mixed (bool) – If False, for archives containing both 2D and 3D data will only load the 3D data into the Scene.

Returns

scene – Geometry loaded in to a Scene object

Return type

trimesh.Scene

trimesh.exchange.load.load_kwargs(*args, **kwargs)

Load geometry from a properly formatted dict or kwargs

trimesh.exchange.load.load_remote(url, **kwargs)

Load a mesh at a remote URL into a local trimesh object.

This must be called explicitly rather than automatically from trimesh.load to ensure users don’t accidentally make network requests.

Parameters
  • url (string) – URL containing mesh file

  • **kwargs (passed to load) –

trimesh.exchange.load.mesh_formats()

Get a list of mesh formats

Returns

loaders – Extensions of available mesh loaders i.e. ‘stl’, ‘ply’, etc.

Return type

list

trimesh.exchange.load.parse_file_args(file_obj, file_type, resolver=None, **kwargs)

Given a file_obj and a file_type try to magically convert arguments to a file-like object and a lowercase string of file type.

Parameters
  • file_obj (str) –

    if string represents a file path, returns:

    file_obj: an ‘rb’ opened file object of the path file_type: the extension from the file path

    if string is NOT a path, but has JSON-like special characters:

    file_obj: the same string passed as file_obj file_type: set to ‘json’

    if string is a valid-looking URL

    file_obj: an open ‘rb’ file object with retrieved data file_type: from the extension

    if string is none of those:

    raise ValueError as we can’t do anything with input

    if file like object:

    ValueError will be raised if file_type is None file_obj: same as input file_type: same as input

    if other object: like a shapely.geometry.Polygon, etc:

    file_obj: same as input file_type: if None initially, set to the class name

    (in lower case), otherwise passed through

  • file_type (str) – type of file and handled according to above

Returns

  • file_obj (file-like object) – Contains data

  • file_type (str) – Lower case of the type of file (eg ‘stl’, ‘dae’, etc)

  • metadata (dict) – Any metadata gathered

  • opened (bool) – Did we open the file or not

  • resolver (trimesh.visual.Resolver) – Resolver to load other assets