]> Creatis software - CreaPhase.git/blob - octave_packages/vrml-1.0.13/vrml_material.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / vrml-1.0.13 / vrml_material.m
1 ## Copyright (C) 2002 Etienne Grossmann <etienne@egdn.net>
2 ##
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
6 ## version.
7 ##
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
11 ## details.
12 ##
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/>.
15
16 ##  s = vrml_material (dc,ec,tr) - Returns a "material" vrml node
17 ##
18 ## dc : 3x1 : diffuseColor
19 ## ec : 3x1 : emissiveColor
20 ##   or 1x1 : use dc as emissiveColor if ec is true.             Default = 0
21 ## tr : 1x1 : transparency                                       Default = 0
22
23 function s = vrml_material (dc, ec, tran,DEF)
24
25 if nargin < 1, dc = [0.3 0.4 0.9] ; # Default color
26 elseif prod (size (dc)) != 3,
27   error ("dc should have length 3 (it is %i x %i)",size (dc));
28 end
29
30 emit = 1;
31
32 if nargin < 2, ec = 0; end
33 if nargin < 3, tran = 0; end
34 if nargin < 4, DEF = ""; end
35
36 if prod (size (ec)) == 1 && !isnan (ec) , emit = ec ; ec = dc ; end
37 if isnan (tran)
38   tran = 0;
39 end
40
41 if emit && !isnan (ec)
42   se = sprintf ("              emissiveColor %8.3g %8.3g %8.3g\n",ec);
43 else
44   se = "";
45 end
46 if ! isnan (tran) && tran
47   st = sprintf ("              transparency %8.3g\n",tran);
48 else
49   st = "";
50 end
51
52 if isempty (DEF), sd = "";
53 else              sd = ["DEF ",DEF];
54 end
55
56 s = sprintf (["            material ",sd," Material {\n",\
57               se,st,\
58               "              diffuseColor  %8.3g %8.3g %8.3g \n",\
59               "          }\n"],\
60              dc);
61 endfunction
62