0001 function savevrml(node,face,elem,fname)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019 if(nargin==2)
0020 fname=face;
0021 face=[];
0022 elem=[];
0023 end
0024
0025 if(nargin==3)
0026 fname=elem;
0027 elem=[];
0028 end
0029
0030 fid=fopen(fname,'wt');
0031 if(fid==-1)
0032 error('You do not have permission to save mesh files.');
0033 end
0034
0035 fprintf(fid,'#VRML V1.0 ascii\n#Generated by iso2mesh (http://iso2mesh.sf.net)\n');
0036 fprintf(fid,'Separator {\nSwitch {\n\tDEF %s\n\tSeparator {\n',fname);
0037
0038 if(~isempty(node))
0039 node=node(:,1:3);
0040 fprintf(fid,'\t\tCoordinate3 {\n\t\t\tpoint [\n');
0041 fprintf(fid,'%.16f %.16f %.16f,\n',node');
0042 fprintf(fid,'\t\t\t]\n\t\t}\n');
0043 end
0044
0045 if(~isempty(face))
0046 face=face(:,1:3);
0047 fprintf(fid,'\t\tIndexedFaceSet {\n\t\t\tcoordIndex [\n');
0048 fprintf(fid,'%d %d %d -1\n',(face-1)');
0049 fprintf(fid,'\t\t\t]\n\t\t}\n');
0050 end
0051
0052 fprintf(fid,'\t} # Separator\n}\n}\n');
0053
0054 fclose(fid);