File Exchange

image thumbnail

Save Wavefront .OBJ files (simple or colour)

version 1.0.3 (5.32 KB) by J. Benjamin Kacerovsky
Saves triangulated mesh objects as wavefront .obj files, optionally with user-defined face or vertex colours.

11 Downloads

Updated 01 May 2020

View License

Saves triangulated meshes (FV struct, such as the output from the built-in isosurface function) as .obj files, together with the corresponding .mtl files in the current working directory.

obj_write saves the input mesh as a simple wavefront .obj file, optionally with an .mtl-file defining a single white material. No additional inputs or settings are required, only the FV struct and filename to be saved.

obj_write_color and obj_write_RGB provide options for saving coloured .obj file. The two functions differ in the way facevertex colour input is defined.

Colour information can be passed to the obj_writer_color function as an Nx1 array, in the same way, 'FaceVertexCData' would be defined as input for a patch object. Values will be mapped to a user-defined colormap (default='jet') to define face-colors of the .obj object.

Colour information can be passed to the obj_writer_RGB function as an Nx3 array of RGB value triplets.

N can be equal to the number of faces (1 colour/face) or vertices, in which case face colour will be defined as the average colour of the 3 face-vertices.

Each face colour is saved as a new material in the .obj file (in the current version Ka=Kd=Ks). To limit the number of materials in each object a binning parameter is defined (RGB_bins).

Object transparency can be optionally defined (default=1 for a solid object).

rotateVertices is a useful small function to rotate points defined by xyz coordinates around each axis by user-specified angles.

Cite As

J. Benjamin Kacerovsky (2020). Save Wavefront .OBJ files (simple or colour) (https://www.mathworks.com/matlabcentral/fileexchange/72906-save-wavefront-obj-files-simple-or-colour), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (0)

Updates

1.0.3

updated the description

1.0.2

added obj_writer. A simpler script that just saves a .obj file (without colours). obj_writer requires fewer input parameters (only FV and filename) and should be easier to use if colours are not required

1.0.1

comments updated

MATLAB Release Compatibility
Created with R2019b
Compatible with any release
Platform Compatibility
Windows macOS Linux
Tags Add Tags