Home > matGeom > meshes3d > writeMesh.m

writeMesh

PURPOSE ^

Write 3D mesh data by inferring format from file name.

SYNOPSIS ^

function writeMesh(fileName, vertices, faces, varargin)

DESCRIPTION ^

 Write 3D mesh data by inferring format from file name.

   writeMesh(FNAME, V, F)

   writeMesh(FNAME, MESH)

   Example
   writeMesh

   See also
     meshes3d, readMesh, writeMesh_off, writeMesh_ply, writeMesh_stl

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function writeMesh(fileName, vertices, faces, varargin)
0002 % Write 3D mesh data by inferring format from file name.
0003 %
0004 %   writeMesh(FNAME, V, F)
0005 %
0006 %   writeMesh(FNAME, MESH)
0007 %
0008 %   Example
0009 %   writeMesh
0010 %
0011 %   See also
0012 %     meshes3d, readMesh, writeMesh_off, writeMesh_ply, writeMesh_stl
0013 %
0014 
0015 % ------
0016 % Author: David Legland
0017 % e-mail: david.legland@inrae.fr
0018 % INRAE - BIA Research Unit - BIBS Platform (Nantes)
0019 % Created: 2020-11-20,    using Matlab 9.8.0.1323502 (R2020a)
0020 % Copyright 2020 INRAE.
0021 
0022 % check inputs
0023 if ~ischar(fileName)
0024     error('First argument must contain the name of the file');
0025 end
0026 
0027 % optionnaly parses data
0028 if isstruct(vertices)
0029     if nargin > 2
0030         varargin = [{faces} varargin{:}];
0031     end
0032     faces = vertices.faces;
0033     vertices = vertices.vertices;
0034 end
0035 
0036 [~, ~, ext] = fileparts(fileName);
0037 switch lower(ext)
0038     case '.off'
0039         writeMesh_off(fileName, vertices, faces);
0040     case '.ply'
0041         writeMesh_ply(fileName, vertices, faces, varargin{:});
0042     case '.stl'
0043         writeMesh_stl(fileName, vertices, faces, varargin{:});
0044     otherwise
0045         error('Unrecognized file format for rezading mesh: %s', ext);
0046 end

Generated on Wed 16-Feb-2022 15:10:47 by m2html © 2003-2019