function material(arg)
%MATERIAL Material reflectance mode.
%   MATERIAL controls the surface reflectance properties of SURFACE 
%   and PATCH objects.  SURFACE and PATCH objects are created by 
%   the functions SURF, MESH, PCOLOR, FILL, and FILL3. 
%
%   MATERIAL SHINY makes the objects shiny.
%   MATERIAL DULL makes the objects dull.
%   MATERIAL METAL makes the objects metalic.
% 
%   MATERIAL([ka kd ks]) sets the ambient/diffuse/specular strength
%   of the objects.
% 
%   MATERIAL([ka kd ks n]) sets the ambient/diffuse/specular strength
%   and specular exponent of the objects.
% 
%   MATERIAL([ka kd ks n sc]) sets the ambient/diffuse/specular strength,
%   specular exponent and specular color reflectance of the objects.
% 
%   MATERIAL DEFAULT sets the ambient/diffuse/specular strength,
%   specular exponent and specular color reflectance of the objects 
%   to their defaults.
%
%   See also LIGHT, LIGHTING
 
%   Copyright (c) 1984-98 by The MathWorks, Inc.
%   $Revision: 1.8 $  $Date: 1997/11/21 23:33:55 $

if (nargin ~= 1)
    error('Materials are shiny, dull, metal, default, or a vector');
else
    isurf = [findobj(gca,'type','surface'); findobj(gca,'type','patch')];

    if strcmp(class(arg), 'char')

      if strcmp(arg, 'shiny')
        ka = 0.3; kd = 0.6; ks = 0.9; n = 20; sc = 1.0;
      elseif strcmp(arg,'dull')
        ka = 0.3; kd = 0.8; ks = 0.0; n = 10; sc = 1.0;
      elseif strcmp(arg,'metal')
        ka = 0.3; kd = 0.3; ks = 1.0; n = 25; sc = 0.5;
      elseif strcmp(arg,'default')
        ka = 'default'; kd = 'default'; ks = 'default'; n = 'default'; sc = 'default';
      else
        error('Materials are shiny, dull, metal, or default');
      end
      set(isurf,'AmbientStrength', ka, 'DiffuseStrength', kd, 'SpecularStrength', ks, ...
                 'SpecularExponent', n, 'SpecularColorReflectance', sc)

    elseif strcmp(class(arg), 'double')

      sz = size(arg);
      if length(sz) ~= 2
        error('The material vector must be of size 1x3, 1x4, or 1x5');
      elseif sz(1) ~= 1
        error('The material vector must be of size 1x3, 1x4, or 1x5');
      elseif sz(2) < 3 | sz(2) > 5
        error('The material vector must be of size 1x3, 1x4, or 1x5');
      elseif sz(2) == 3
        set(isurf,'AmbientStrength', arg(1), 'DiffuseStrength', arg(2), 'SpecularStrength', arg(3))
      elseif sz(2) == 4
        set(isurf,'AmbientStrength', arg(1), 'DiffuseStrength', arg(2), 'SpecularStrength', arg(3),...
                  'SpecularExponent', arg(4))
      elseif sz(2) == 5
        set(isurf,'AmbientStrength', arg(1), 'DiffuseStrength', arg(2), 'SpecularStrength', arg(3),...
                  'SpecularExponent', arg(4), 'SpecularColorReflectance', arg(5))
      end
      

    else
      error('Materials are shiny, dull, metal or a vector');
    end
end
