write_obj

Write mesh data to OBJ format mesh file

Contents

Syntax

write_obj(filename,face,vertex)

Description

filename: string, file to read.
face    : double array, nf x 3 array specifying the connectivity of the mesh.
vertex  : double array, nv x 3 array specifying the position of the vertices.
color   : double array, nv x 3 or nf x 3 array specifying the color of the vertices or faces.

Example

write_obj('cube.obj',face,vertex);

Contribution

Author : Meng Bin
History: 2014/03/05 file created
Revised: 2014/03/07 by Meng Bin, Block write to enhance writing speed
Revised: 2014/03/17 by Meng Bin, modify doc format
Copyright 2014 Computational Geometry Group
Department of Mathematics, CUHK
http://www.math.cuhk.edu.hk/~lmlui
function write_obj(filename,face,vertex)

fid = fopen(filename,'w');
if( fid==-1 )
    error('Can''t open the file.');
end

%write logo
fprintf (fid, '#Generated by geometric processing package.\n');

%write vertex
fprintf (fid, 'v %.6f %.6f %.6f\n',vertex');

%write face
fprintf (fid, 'f %d %d %d\n',face');
% for i = 1:nface
%     fprintf (fid, '%s ','f');
%     for j = 1:nvert_face
%         fprintf (fid, '%d ',face(i,j)-1);
%     end
%     fprintf (fid, '\n');
% end

fclose(fid);