function hgeo_copy_threejs(folder);

% Function hgeo_copy_threejs(folder);
% 
% copies the three.js library files to the
% actual directory, or, if input variable
% is given, into the indicated directory.
% 
% The copied files seem to get new time 
% stamps.
% 
% 
% (c) 2026 fabien van mook
% 
% 2026.08.20 release of this file within package "fvm-hgeo" under GNU GPLv3+

% This program is free software: you can redistribute it
% and/or modify it under the terms of the GNU General Public
% License as published by the Free Software Foundation, either
% version 3 of the License, or (at your option) any later
% version.
% 
% This program is distributed in the hope that it will be
% useful, but WITHOUT ANY WARRANTY; without even the implied
% warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
% PURPOSE. See the GNU General Public License for more
% details.
% 
% You can read the GNU General Public License on
% <https://www.gnu.org/copyleft/gpl.html>.


if (nargin < 1),
  folder = "";
else,
  if (length(folder) > 0),
    if (folder(end) != filesep),
      folder = [folder filesep];
    endif;
    mkdir(folder);
  endif;
endif;

% files = { <last_part_of_path>, <filename>; ...}:
%
files = {["20200827-threejs-r120-downloads" filesep "build" filesep], "three.js";
         ["20200827-threejs-r120-downloads" filesep "examples" filesep "js" filesep  "controls" filesep], "OrbitControls.js";
         ["20200827-threejs-r120-downloads" filesep "examples" filesep "js" filesep  "effects" filesep], "StereoEffect.js";
        };

for ifile = [1:size(files,1)],
  fn = [files{ifile,1} files{ifile,2}];
  found = 0;
  for ireldir = [1:4],
    reldir = repmat([".." filesep],1,ireldir);
    if isfile([reldir fn]),
      found = 1;
      break;
    endif;
  endfor;
  if (found),
    copyfile([reldir fn],[folder files{ifile,2}],"f");
    printf("hgeo_copy_threejs(): copied \"%s\" from directory \"%s\" to \"%s\".\n",files{ifile,2},[reldir files{ifile,1}],folder);
  else,
    warning("hgeo_copy_threejs(): cannot find threejs library file \"%s\".",files{ifile,2});
  endif;
endfor;

endfunction;
