m3sh.hds.Mesh.

from_OBJ#

classmethod Mesh.from_OBJ(filename, *args, quiet=False)#

Read mesh from Wavefront OBJ file.

Added in version 1.1.0.

Read mesh combinatorics (face definitions) and vertex coordinates from an OBJ file. Additional data, like vertex normals, is read only on request, see the example below.

Parameters:
filenamestr

Name of OBJ file.

*args

Variable number of arguments of type str.

quietbool, optional

Suppress console output if True.

Returns:
meshMesh

Mesh instance. Reading fails if mesh combinatorics do not represent an orientable manifold surface mesh.

data

A corresponding data block of type ndarray as requested via args. If a data block could not be read, None is returned in its place.

Warning

This method cannot read multiple meshes from a single file! If the file defines multiples meshes they are interpreted as the connected components of a single mesh.

See also

m3sh.obj.read

Low-level read function, can read non-manifold data.

Notes

By default filename (without suffix) is used as the name of the created mesh instance. If the OBJ file defines an object name it is used instead.

Examples

Vertex normals or texture coordinates stored in an OBJ file can be read via

>>> mesh, vecs, uvs = Mesh.from_OBJ(filename, 'vn', 'vt')

Additional return values (in this case vertex normals and texture coordinates) are returned in the same order as they are presented in the argument list args. If the requested data is not stored in the file a None value is returned in its place.