Function Reference: writeObj

csg-toolkit: writeObj (v, f, filename)
csg-toolkit: writeObj (v, f, vt, ft, filename)
csg-toolkit: writeObj (v, f, vn, fn, filename)
csg-toolkit: writeObj (v, f, vt, ft, vn, fn, filename)
csg-toolkit: writeObj (…, "info")
csg-toolkit: writeObj (…, "overwrite")
csg-toolkit: filename = writeObj (…)

This function saves a triangular 3D Mesh in a Wavefront OBJ file format according to its elements provided as input arguments.

The function typically takes 3, 5 or 7 input arguments. The last argument should be a char string referring to the filename of the OBJ file, whereas the first 2, 4, or 6 input arguments should be 2-dimensional matrices containing the elements of the triangular mesh in the following order:

v can be either an N×3 matrix with x,y,z vertex coordinates or an N×6 matrix containing the vertex coordinates and the r,g,b color information for each vertex in the range [0,1].

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

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

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

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

fn must be an N×3 matrix with the indices of each corresponding face normal.

When 5 input arguments are provided, the function will determine whether there is a texture coordinates matrix or a vertex normals matrix by the size of the second dimension of the matrix provided as the third input argument. The function can also take one or two additional optional arguments added after the aforementioned syntaxes to control its behavior. Use "info" as an optional input argument to display information about the saved 3D mesh. Use "overwrite" to overwrite existing file without asking back the user for confirmation.

The function can also return an output argument with the filename used for saving the mesh. This can be useful when prompting the user for a new filename when file already exists.

See also: readObj, renameObj

Source Code: writeObj