readObj
"info"
)This function reads a triangular 3D Mesh from Wavefront OBJ file and returns its elements into a variable number of output arguments.
When called with no output arguments readObj
displays info of the mesh. If called with a single output argument then only the vertices are returned. If only two output arguments are given then only the vertices and the faces of the mesh are returned. If four arguments are given, then vertex normals and face normals or texture coordinates and texture faces are returned, depending on which are present. If both sets are present, then readObj
returns only the texture coordinates and their corresponding faces. If six output arguments are given then all elements are returned as numerical array in the following order:
v is an matrix with x,y,z point coordinates, where is the number of vertices. If RGB color information is available, then it is an matrix including r,g,b values for each vertex.
f is an matrix with the indices of each corresponding vertex, where is the number of faces.
vt is an matrix, where is the number of texture coordinates.
ft is an matrix with the indices of each corresponding texture coordinates.
vn is an matrix with x,y,z normal coordinates, where is the number of normals.
fn is an matrix with the indices of each corresponding face normal.
If odd number of output arguments are provided, except for the case of a single argument, then the last output argument is used for returning the .mtl
filename, where material parameters are stored. Note that readObj
handles explicitly triangular mesh objects. If the OBJ file does not contain a proper triangular mesh, then an error message is returned.
Source Code: readObj