-
Notifications
You must be signed in to change notification settings - Fork 75
/
Copy pathsavevrml.m
54 lines (46 loc) · 1.3 KB
/
savevrml.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
function savevrml(node, face, elem, fname)
%
% savevrml(node,face,elem,fname)
%
% save a surface mesh to VRML 1.0 format
%
% author: Qianqian Fang, <q.fang at neu.edu>
% date: 2010/04/25
%
% input:
% node: input, surface node list, dimension (nn,3)
% face: input, surface face element list, dimension (be,3)
% elem: input, tetrahedral element list, dimension (ne,4)
% fname: output file name
%
% -- this function is part of iso2mesh toolbox (http://iso2mesh.sf.net)
%
if (nargin == 2)
fname = face;
face = [];
elem = [];
end
if (nargin == 3)
fname = elem;
elem = [];
end
fid = fopen(fname, 'wt');
if (fid == -1)
error('You do not have permission to save mesh files.');
end
fprintf(fid, '#VRML V1.0 ascii\n#Generated by iso2mesh (http://iso2mesh.sf.net)\n');
fprintf(fid, 'Separator {\nSwitch {\n\tDEF %s\n\tSeparator {\n', fname);
if (~isempty(node))
node = node(:, 1:3);
fprintf(fid, '\t\tCoordinate3 {\n\t\t\tpoint [\n');
fprintf(fid, '%.16f %.16f %.16f,\n', node');
fprintf(fid, '\t\t\t]\n\t\t}\n');
end
if (~isempty(face))
face = face(:, 1:3);
fprintf(fid, '\t\tIndexedFaceSet {\n\t\t\tcoordIndex [\n');
fprintf(fid, '%d %d %d -1\n', (face - 1)');
fprintf(fid, '\t\t\t]\n\t\t}\n');
end
fprintf(fid, '\t} # Separator\n}\n}\n');
fclose(fid);