1 ## Copyright (C) 2002 Etienne Grossmann <etienne@egdn.net>
3 ## This program is free software; you can redistribute it and/or modify it under
4 ## the terms of the GNU General Public License as published by the Free Software
5 ## Foundation; either version 3 of the License, or (at your option) any later
8 ## This program is distributed in the hope that it will be useful, but WITHOUT
9 ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 ## You should have received a copy of the GNU General Public License along with
14 ## this program; if not, see <http://www.gnu.org/licenses/>.
16 ## save_vrml(outname,[options],s1,...) - Save vrml code
18 ## Makes a vrml2 file from strings of vrml code. A "background" node is
26 ## - "outname" should not contain the substring ".wrl" anywhere else
28 ## - "outname" should only contain the character ">" as ">>" at the
29 ## beginning , to indicate append rather than overwriting the
32 function save_vrml(outname, varargin)
37 if ! ischar(outname) ,
38 error "save_vrml wants a string as first arg"
41 if strcmp(outname(1:2),">>"),
44 outname = strrep(outname,">","");
46 outname = strrep(outname,".wrl",''); # No suffix.
48 fname = sprintf("%s.wrl",outname); # Add suffix.
49 bg_col = [0.4 0.4 0.7];
52 l_ambientIntensity = 0.5 ;
53 l_direction = [0.57735 -0.57735 0.57735] ;
55 bg_node = sprintf (["Background {\n",...
56 " skyColor %8.3g %8.3g %8.3g\n",...
61 lightstr = sprintf (["PointLight {\n",\
62 " intensity %8.3g\n",\
63 " ambientIntensity %8.3g\n",\
64 " direction %8.3g %8.3g %8.3g\n",\
66 l_intensity, l_ambientIntensity, l_direction);
69 # Read eventual options
73 args = nargin; # nargin is now a function
77 if strcmp (tmp, "nobg"),
79 elseif strcmp (tmp, "nolight"),
81 else # Reached non-options
85 # while n++ < ninit, va_arg (); end
92 bg_node = [bg_node, lightstr];
94 if findstr(outname,"/"),
95 outname = outname(max(findstr(outname,"/"))+1:size(outname,2)) ;
98 if append, fid = fopen(fname,"at"); # Saving.
99 else fid = fopen(fname,"wt");
102 if fid == -1 , error(sprintf("save_vrml : unable to open %s",fname)); end
105 fprintf(fid,"#VRML V2.0 utf8 \n# %s , created by save_vrml.m on %s \n%s",
106 fname,datestr(now),bg_node);
108 while i <= length (varargin) ,
110 if verbose, printf ("save_vrml : %i'th string\n",i); end
112 fprintf (fid,"%s", varargin{i}) ;