Function Reference: readObj

csg-toolkit: [varargout] = readObj (filename)
csg-toolkit: [varargout] = readObj (filename, "info")
csg-toolkit: v = readObj (…)
csg-toolkit: [v, f] = readObj (…)
csg-toolkit: [v, f, mtl] = readObj (…)
csg-toolkit: [v, f, vt, ft] = readObj (…)
csg-toolkit: [v, f, vt, ft, mtl] = readObj (…)
csg-toolkit: [v, f, vn, fn] = readObj (…)
csg-toolkit: [v, f, vn, fn, mtl] = readObj (…)
csg-toolkit: [v, f, vt, ft, vn, fn] = readObj (…)
csg-toolkit: [v, f, vt, ft, vn, fn, mtl] = readObj (…)

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 N×3 matrix with x,y,z point coordinates, where N is the number of vertices. If RGB color information is available, then it is an N×6 matrix including r,g,b values for each vertex.

f is an M×3 matrix with the indices of each corresponding vertex, where M is the number of faces.

vt is an N×2 matrix, where N is the number of texture coordinates.

ft is an M×3 matrix with the indices of each corresponding texture coordinates.

vn is an N×3 matrix with x,y,z normal coordinates, where N is the number of normals.

fn is an N×3 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.

See also: writeObj, renameObj

Source Code: readObj