trimesh.exchange.obj¶
- 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: str | Path | IO | BytesIO | StringIO | BinaryIO | TextIO | BufferedRandom | dict | None, resolver: Resolver | Mapping | None = None, group_material: bool = True, skip_materials: bool = False, maintain_order: bool = False, metadata: dict | None = None, split_objects: bool = False, split_groups: bool = False, **kwargs) dict¶
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 – Don’t load any materials.
maintain_order – Make the strongest attempt possible to not reorder faces or vertices which may result in visual artifacts and other odd behavior. The OBJ data structure is quite different than the “flat matching array” used by Trimesh and GLTF so this may not be completely possible.
split_objects – Whenever the loader encounters an o directive in the OBJ file, split the loaded result into a new Trimesh object.
split_groups – Whenever the loader encounters a g directive in the OBJ file, split the loaded result into a new Trimesh object.
- 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