trimesh.exchange.obj module

trimesh.exchange.obj.export_obj(mesh, include_normals=None, include_color=True, include_texture=True, return_texture=False, write_texture=True, resolver=None, digits=8, mtl_name=None, header='https://github.com/mikedh/trimesh')

Export a mesh as a Wavefront OBJ file. TODO: scenes with textured meshes

Parameters:
  • mesh (trimesh.Trimesh) – Mesh to be exported

  • include_normals (Optional[bool]) – Include vertex normals in export. If None will only be included if vertex normals are in cache.

  • include_color (bool) – Include vertex color in export

  • include_texture (bool) – Include vt texture in file text

  • return_texture (bool) – If True, return a dict with texture files

  • write_texture (bool) – If True and a writable resolver is passed write the referenced texture files with resolver

  • resolver (None or trimesh.resolvers.Resolver) – Resolver which can write referenced text objects

  • digits (int) – Number of digits to include for floating point

  • mtl_name (None or str) – If passed, the file name of the MTL file.

  • header (str or None) – Header string for top of file or None for no header.

Returns:

  • export (str) – OBJ format output

  • texture (dict) – Contains files that need to be saved in the same directory as the exported mesh: {file name : bytes}

trimesh.exchange.obj.load_obj(file_obj, resolver=None, group_material=True, skip_materials=False, maintain_order=False, **kwargs)

Load a Wavefront OBJ file into kwargs for a trimesh.Scene object.

Parameters:
  • file_obj (file like object) – Contains OBJ data

  • resolver (trimesh.visual.resolvers.Resolver) – Allow assets such as referenced textures and material files to be loaded

  • group_material (bool) – Group faces that share the same material into the same mesh.

  • skip_materials (bool) – Don’t load any materials.

  • maintain_order (bool or None) – Do not reorder faces or vertices which may result in visual artifacts.

Returns:

kwargs – Keyword arguments which can be loaded by trimesh.exchange.load.load_kwargs into a trimesh.Scene

Return type:

dict

trimesh.exchange.obj.parse_mtl(mtl, resolver=None)

Parse a loaded MTL file.

Parameters:
  • mtl (str or bytes) – Data from an MTL file

  • resolver (trimesh.Resolver) – Fetch assets by name from file system, web, or other

Returns:

mtllibs – Each dict has keys: newmtl, map_Kd, Kd

Return type:

list of dict