unit Loader; interface Uses OpenGl, SysUtils; type TCoord = Record X, Y, Z : glDouble; end; TFace = Record V1, V2, V3, V4 : Integer; end; Var Vertex : Array of TCoord; Face : Array of Tface; function transfo_string(var S : string) : String; function calcul_string_vertex ( S : string ) : TCoord; function calcul_string_face ( S : String ) : TFace; function charger_models (filename : String) : boolean; procedure affiche (a : Array of TCoord; i : integer ); implementation // Enleve les points d'une string en virgule function transfo_string(var S : string) : String; var i : integer; begin i := 1; while S[i] <> #0 do begin if S[i] = '.' then begin S[i] := ',' end; i := i+ 1; end; result := S; end; // Prends les coord des Vertex a partir d'une String function calcul_string_vertex ( S : string ) : TCoord; var i,coord : integer; tmp : string; begin tmp := ''; i := 3; coord := 0; while S[i] <> #0 do begin if S[i] = ' ' then begin if coord = 0 then result.x := StrToFloat (transfo_string(tmp)) else if coord = 1 then result.y := StrToFloat (transfo_string(tmp)); coord := coord + 1; tmp := ''; end else tmp := tmp + S[i]; i := i + 1; end; result.Z := StrToFloat (transfo_string(tmp)); end; // Prends les coord des Faces a partir d'une String function calcul_string_face ( S : String ) : TFace; var i,coord : integer; tmp : string; begin tmp := ''; i := 3; coord := 0; while S[i] <> #0 do begin if S[i] = ' ' then begin if coord = 0 then result.V1 := StrToInt (tmp) else if coord = 1 then result.V2 := StrToInt (tmp) else if coord = 2 then result.V3 := StrToInt (tmp) else result.V4 := StrToInt (tmp); coord := coord + 1; tmp := ''; end else tmp := tmp + S[i]; i := i + 1; end; result.V4 := StrToInt (tmp); end; // Charge les faces et les vertex dans leurs tableaux respectifs function charger_models (filename : String) : boolean; var f : TextFile; S,tmp : String; i,j : integer; begin if FileExists(filename) = false then result := false else begin AssignFile(f, filename); Reset(f); i := 0; j := 0; S := ''; tmp := ''; while not(eof(f)) do begin Readln(f, S); tmp := S; begin if S[1] = 'v' then begin i := i+1; SetLength(Vertex,Length(vertex) +1); Vertex[i].X := (calcul_string_vertex(tmp)).X; // voila les problemes se situent ici, les vertex ne prennent Vertex[i].Y := (calcul_string_vertex(tmp)).Y; // aucunes valeurs ils se remplissent qvec des (0,0,0) Vertex[i].Z := (calcul_string_vertex(tmp)).Z; tmp := ''; end; if S[1] = 'f' then begin j := j+1; SetLength(Face,Length(Face) +1); Face[j].V1 := calcul_string_face(tmp).V1; // idem Face[j].V2 := calcul_string_face(tmp).V2; Face[j].V3 := calcul_string_face(tmp).V3; Face[j].V4 := calcul_string_face(tmp).V4; tmp := ''; end; end; end; result := true; CloseFile(f); end; end; // Afficher les models procedure affiche (a : Array of TCoord; i : integer ); begin writeln(vertex[i].X); writeln(vertex[i].Y); writeln(vertex[i].Z); writeln(''); end; end.