type
TVektor = record
x, y, z: real;
end;
TDreieck = record
n: TVektor; // n ist Normalvektor
p: array[1..3] of TVektor; //p hat Koordinaten von 3 Eckpunkten
end;
Var
Dreiecke:Array of TDreieck;
function ReadNumber(const s:string; var i:integer):real;
var
j:integer;
begin
j:=i;
while s[j]<>' ' do
dec(j);
result:=StrToFloat(Copy(s,j+1,i-j));
while s[j]=' ' do
dec(j);
i:=j;
end;
procedure TForm1.Button2Click(Sender: TObject);
const
s1='facet normal';
s2='vertex';
s3='endsolid';
var
s:string;
//i:integer;
j:integer;
L:integer;
List:TStrings;
Line:integer;
data:TDreieck;
begin
Dreiecke:=nil;
List:=TStringList.Create;
List.LoadFromFile(OpenDialog1.FileName);
Line:=1;
while (Copy(Trim(List[Line]),1,Length(s3))<>s3) do
begin
s:=Trim(List[Line]);
L:=Length(s);
if (Copy(s,1,Length(s1))=s1) then
begin
data.n.z:=ReadNumber(s,L);
data.n.y:=ReadNumber(s,L);
data.n.x:=ReadNumber(s,L);
inc(Line);
while (Copy(s,1,Length(s2))<>s2) do inc(Line);
for j:=1 to 3 do begin
data.p[j].z:=ReadNumber(s,L);
data.p[j].y:=ReadNumber(s,L);
data.p[j].x:=ReadNumber(s,L);
inc(line);
end;
SetLength(Dreiecke,Length(Dreiecke)+1);
Dreiecke[High(dreiecke)]:=data;
end
else inc(Line);
end;
end;