home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Virtual Reality Homebrewer's Handbook
/
vr.iso
/
vroom
/
3d_2_nff.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
1996-03-19
|
5KB
|
171 lines
program threed_2_nff;
uses dos;
function file_exists(filename : string) : boolean;
var dirinfo : searchrec;
begin
findfirst(filename,anyfile,dirinfo);
file_exists:=(doserror=0);
end;
var input_file, output_file, my_pal : string;
in_f, out_f, col_f : text;
ch : char;
gourard,ok : boolean;
n1,n2,n3,c,c2, failed : integer;
x,y,z, bright : real;
colour : byte;
r,g,b : array[0..15] of real;
procedure write_colours;
var r1,g1,b1 : integer;
begin
r1:=round(15*bright*r[colour]);
g1:=round(15*bright*g[colour]);
b1:=round(15*bright*b[colour]);
write(out_f,'0x');
case r1 of
0..9 : write(out_f,r1);
10 : write(out_f,'a');
11 : write(out_f,'b');
12 : write(out_f,'c');
13 : write(out_f,'d');
14 : write(out_f,'e');
15 : write(out_f,'f');
end;
case g1 of
0..9 : write(out_f,g1);
10 : write(out_f,'a');
11 : write(out_f,'b');
12 : write(out_f,'c');
13 : write(out_f,'d');
14 : write(out_f,'e');
15 : write(out_f,'f');
end;
case b1 of
0..9 : writeln(out_f,b1);
10 : writeln(out_f,'a');
11 : writeln(out_f,'b');
12 : writeln(out_f,'c');
13 : writeln(out_f,'d');
14 : writeln(out_f,'e');
15 : writeln(out_f,'f');
end;
end;
begin
failed:=0;
write('3D Input File : ');
readln(input_file);
if not(file_exists(input_file)) then
begin
writeln;
writeln('Error! File does not exist');
halt;
end;
writeln;
write('NFF Output File : ');
readln(output_file);
writeln;
write('Gourard shaded ? : ');
readln(ch);
if ((ch='Y')or(ch='y')) then gourard:=true else gourard:=false;
write('Default colours ? : ');
readln(ch);
if ((ch='n')or(ch='N')) then
begin
write('Palette name : ');
readln(my_pal);
end
else
my_pal:='def.col';
if not(file_exists(my_pal)) then
begin
writeln;
writeln('Error! Palette does not exist');
halt;
end;
assign(col_f,my_pal);
reset(col_f);
for c:=0 to 15 do readln(col_f,r[c], g[c], b[c]);
close(col_f);
writeln('Checking ',input_file);
assign(in_f,input_file);
reset(in_f);
readln(in_f,n1); {Number of vertices}
for c:=1 to n1 do readln(in_f,x,y,z); {Transfer vertices}
readln(in_f,n1);
if n1<>0 then {Check digit}
begin
writeln('Error - failed check digit on input file');
halt;
end;
readln(in_f,n1); {Number of faces}
for c:=1 to n1 do
begin
readln(in_f,colour,bright);
readln(in_f,n2); {Number of points}
if n2<3 then inc(failed);
for c2:=1 to n2 do read(in_f,n3);
readln(in_f);
readln(in_f,n2);
if n2<>0 then
begin
writeln('Error - failed check digit on input file');
halt;
end;
end;
readln(in_f,n1);
if n1<>0 then
begin
writeln('Error - failed check digit on input file');
halt;
end;
close(in_f);
if failed>0 then writeln(failed,' points or lines found which will not be converted');
writeln;
writeln('Starting conversion');
assign(in_f,input_file);
reset(in_f);
assign(out_f,output_file);
rewrite(out_f);
writeln(out_f,'nff'); {Header}
writeln(out_f,'version 2.0');
writeln(out_f,input_file); {Object Name}
readln(in_f,n1); {Number of vertices}
writeln(out_f,n1);
for c:=1 to n1 do {Transfer vertices}
begin
readln(in_f,x,y,z);
write(out_f,x,' ',y,' ',z,' ');
if gourard then writeln(out_f,'N') else writeln(out_f);
end;
readln(in_f,n1); {Check digit}
readln(in_f,n1); {Number of faces}
writeln(out_f,n1-failed);
for c:=1 to n1 do
begin
readln(in_f,colour,bright);
readln(in_f,n2); {Number of points}
if n2>2 then ok:=true else ok:=false;
if ok then write(out_f,n2,' ');
for c2:=1 to n2 do
begin
read(in_f,n3); {Transfer points}
if ok then write(out_f,n3-1,' ');
end;
readln(in_f);
if ok then write_colours;
readln(in_f,n2); {Check digit}
end;
readln(in_f,n1); {Check digit}
close(in_f);
close(out_f);
writeln('Conversion completed');
end.