unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, GLScene, GLMisc, GLVectorFileObjects, GLWin32Viewer, GLFileSTL,
Menus, ComCtrls, StdCtrls, ExtCtrls, GLTexture, GLObjects, GLHUDObjects;
type
TVektor =
record
x, y, z: real;
end;
TDreieck =
record
n: TVektor;
p:
array[1..3]
of TVektor;
end;
.
.
.
Var
Form1: TForm1;
Dreiecke:
array of TDreieck;
.
.
.
//PROCEDURE TMain.Test; <--bekomme ich Fehlermeldun
FUNCTION FindLine(
const s:
string; raiseerr:boolean):boolean;
var
line:integer;
list:TStrings;
begin
while (line<list.count)
and (Copy(Trim(list[line]),1,Length(s))<>s)
do inc(line);
if line<list.count
then result:=true
else if not raiseerr
then result:=false
else raise Exception.Create(s+'
nicht gefunden.');
end;
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 ReadLine(
var v:TVektor);
var s:
string; i:integer; list:TStrings; line:integer;
begin
s:=Trim(list[line]);
i:=Length(s);
v.z:=ReadNumber(s,i);
v.y:=ReadNumber(s,i);
v.x:=ReadNumber(s,i);
inc(line);
end;
PROCEDURE ReadRecord;
const recline='
vertex';
var i:integer; data:TDreieck;
begin
ReadLine(data.n);
for i:=1
to 3
do begin
FindLine(recline,true);
ReadLine(data.p[i]);
end;
SetLength(Dreiecke,Length(Dreiecke)+1);
Dreiecke[High(dreiecke)]:=data;
end;
// var f:TextFile; i,j:integer; // nur zur Kontrolle benutzt
PROCEDURE CopyDreiecke(tofile:boolean);
var list:TStrings;
FUNCTION ToStr(v:real):
String;
begin
result:=FloatToStrF(v,ffExponent,7,3)+'
';
if result[1]<>'
-'
then result:='
'+result;
end;
PROCEDURE AddVector(
const v:TVektor);
type TxVector=Array[0..2]
of real;
var s:
string; i:integer; list:TStrings;
begin
for i:=0
to High(TxVector)
do s:=s+ToStr(TxVector(v)[i]);
list.Add(s);
end;
var i,j:integer;
begin
list:=TStringList.Create;
try
try
if Length(Dreiecke)=0
then
raise Exception.Create('
Dreiecke ist leer.');
for i:=0
to High(Dreiecke)
do
with Dreiecke[i]
do begin
AddVector(n);
for j:=Low(p)
to High(p)
do AddVector(p[j]);
list.Add('
');
end;
if tofile
then list.SaveToFile(ExtractFilePath(ParamStr(0))+'
Log.txt');
//else Clipboard.AsText:=List.Text;
ShowMessage('
fertig.');
except
On E:
Exception do ShowMessage(E.
Message);
end;
finally
list.free;
end;
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
CopyDreiecke(true);
end;
procedure TForm1.Button2Click(Sender: TObject);
const
recstart='
facet normal';
recline='
vertex';
var list:TStrings; line:integer; data:TDreieck;
begin
Dreiecke:=nil;
list:=TStringList.Create;
try
try
//list.text:=Clipboard.AsText;
List.LoadFromFile(OpenDialog1.FileName);
line:=0;
while FindLine(recstart,false)
do ReadRecord;
except
On E:
Exception do begin
ShowMessage(E.
Message);
Dreiecke:=nil;
end;
end;
finally
list.free;
end;
end;
end.