program transfera_mli_in_fisier_de_date_cu_tip_cunoscut;
uses crt;

type nod=record
      name:string[20];
      ambient:array [1..3] of real;
      difuse:array [1..3] of real;
      specular:array [1..3] of real;
      shininess:real;
      transparency:real;
      texture:string;
     end;
     fisier=file of nod;

var f:file of byte;
    b:byte;
    i,j:integer;
    sp,ok:boolean;
    fis:fisier;
    num1,num2:string;
    a:nod;
    st:string;

procedure init(var a:nod);
begin
a.ambient[1]:=0;
a.ambient[2]:=0;
a.ambient[3]:=0;
a.difuse[1]:=0;
a.difuse[2]:=0;
a.difuse[3]:=0;
a.specular[1]:=0;
a.specular[2]:=0;
a.specular[3]:=0;
a.shininess:=0;
a.transparency:=0;
a.name:='';
a.texture:='';
end;

begin
if paramcount=2 then
                begin
                num1:=paramstr(1);
                num2:=paramstr(2);
                end
                else
                begin
                writeln('   That program translates from the original .mli file to a file');
                writeln('which will be used by the 3ds<-->vrml filter');
                writeln('   The sintax is: transmli <input_name.ext> <output_name.ext>');
                writeln('Take care and remember the name of the file you''ll consider as output !!');
                halt;
                end;
{write('Input the name of the original Library of Materials ');
readln(num1);}
assign(f,num1);
reset(f);
{write('Input the name of the output file ');
readln(num2);}
assign(fis,num2);
rewrite(fis);

ok:=false;
repeat
read(f,b);
if (b=255) or (ok)
   then
   begin
   if not(ok) then read(f,b);
   ok:=false;
   if b=175
      then
      begin
      init(a);
      for i:=1 to 10 do
          read(f,b);
      st:='';
      repeat
      read(f,b);
      if b<>0 then st:=st+chr(b);
      until b=0;
      a.name:=st;

      for i:=1 to 21 do
          read(f,b);
      for i:=1 to 3 do
          begin
          read(f,b);
          a.ambient[i]:=b/255;
          end;

      for i:=1 to 21 do
          read(f,b);
      for i:=1 to 3 do
          begin
          read(f,b);
          a.difuse[i]:=b/255;
          end;

      for i:=1 to 21 do
          read(f,b);
      for i:=1 to 3 do
          begin
          read(f,b);
          a.specular[i]:=b/255;
          end;

       for i:=1 to 13 do
           read(f,b);
       a.shininess:=b/100;
       for j:=1 to 4 do
           begin
           for i:=1 to 14 do
               read(f,b);
           if j=2 then a.transparency:=b/100;
           end;
       for i:=1 to 22 do
           read(f,b);
       sp:=true;
       repeat
       {$i-}
       read(f,b);
       {$i+}
       if b=$a2
          then
          begin
          read(f,b);
          if b=$31
             then sp:=false;
          end;
       until (not(sp)) or (ioresult<>0) or (b=$ff);
       if b=$ff then ok:=true;
       if not(sp) then
       begin
         for i:=1 to 17 do
           read(f,b);
         st:='';
         repeat
          read(f,b);
          if b<>0 then st:=st+chr(b);
         until b=0;
       a.texture:=st;
       end
       else
       a.texture:='NONE';
       write(fis,a);
     end;
   end;
until eof(f);
close(f);
close(fis);
writeln('Done !');
end.