Details and Options
Unlike the native support for
"OBJ" files that
Import provides, ImportOBJ searches for and includes material information provided by neighboring material template library (MTL) files.
ImportOBJ uses the resource function
ImportMTL to parse MTL files into graphics directives.
The OBJ format is a human-readable ASCII text file.
ImportOBJ uses
Import to first load the data from
source as
"Text", then parses the text for any vertices, faces and so on.
source can be any of the forms supported by
Import.
If the
source file cannot be located, then ImportOBJ parses "
obj" as if it were OBJ data, similar to
ImportString["obj","OBJ"].
Elements supported by ImportOBJ include:
"Elements" | a list of supported element names |
"Text" | the raw text from the file including any comments |
"Data" | an Association of the data's key-value pairs |
"Dataset" | same as "Data" but viewed as a Dataset |
"GraphicsComplex" | a GraphicsComplex expression |
"Graphics3D" | (default) a Graphics3D expression with supported material data as directives |
The possible vertex information within "Data" includes:
"Vertices" | ordered list of vertices |
"VertexNormals" | ordered list of {x, y, z} triples that represent normal vectors |
"VertexTextures" | ordered list of vertices in the {u, v} coordinate system |
"Vertex" | {x, y, z} coordintes |
"Weight" | vertex weight (default 1) |
"Color" | vertex color (default Automatic) |
The possible geometric information within "Data" includes:
"Materials" | material properties as Graphics3D directives |
"Points" | list of Point primitives |
"Lines" | list of Line primitives |
"Faces" | list of Polygon primitives |
Similar to
GraphicsComplex, the geometric information uses integer-indices to label the vertex points where the indices match the ordering of the vertices.
Though the OBJ format can contain both polygonal objects as well as free-form objects, the intended use of ImportOBJ is to import only the polygonal components.
Extending the original format specification, vertex colors are supported by reading three additional numeric values after the three vertex coordinates, corresponding to the red, blue and green color channels, respectively.
The data groups each
Polygon with the imported material directives.
ImportOBJ uses the following options:
"BaseDirectory" | Automatic | the directory to search for material template library (MTL) files |
Possible settings for "BaseDirectory" are:
Automatic | use the directory where the OBJ file resides |
"path" | use the provided directory path |
Within the OBJ file, MTL files are specified as paths relative to the base directory.
Within the OBJ file, MTL files cannot contain spaces since spaces are used as a delimiter between multiple MTL files.
Multiple MTL files are allowed, separated by spaces, and all provided materials therein are concatenated.
If a verbose path is used for "BaseDirectory", then only the filename of the MTL file is used and appended to the base directory path.
Conventionally, a single MTL file is expected in the same directory as the OBJ file and uses the same filename but with the.mtl extension.
It is not guaranteed that the MTL files downloaded from the internet use relative paths for textures or match the
$PathnameSeparator for your operating system.
"BaseDirectory" exists to help with the inconsistent filepaths, but oftentimes the MTL file requires manual correcting of the paths.
If the base directory of the OBJ file cannot be determined then
Directory[] is used.