2
// This unit is part of the GLScene Engine https://github.com/glscene
5
TIN (Triangular Irregular Network) vector file format implementation.
7
08/04/13 - PW - Fixed a bug in VertArr: decremented element numbers by one
8
17/11/05 - PW - Added support for ascii TIN files with materials
9
05/06/03 - SG - Separated from GLVectorFileObjects.pas
20
GLVectorFileObjects, GLApplicationFileIO;
25
{ The TIN vector file (triangle irregular network).
26
It is a simple text format, with one triangle record per line, no materials,
27
no texturing (there may be more, but I never saw anything in this files).
28
This format is encountered in the DEM/DTED world and used in place of grids. }
29
TGLTINVectorFile = class(TGLVectorFile)
32
class function Capabilities : TGLDataFileCapabilities; override;
33
procedure LoadFromStream(aStream : TStream); override;
36
// ------------------------------------------------------------------
37
// ------------------------------------------------------------------
38
// ------------------------------------------------------------------
40
// ------------------------------------------------------------------
41
// ------------------------------------------------------------------
42
// ------------------------------------------------------------------
45
GLVectorGeometry, GLUtils, GLTypes;
47
// ------------------ TGLTINVectorFile ------------------
52
class function TGLTINVectorFile.Capabilities : TGLDataFileCapabilities;
59
procedure TGLTINVectorFile.LoadFromStream(aStream : TStream);
64
v1, v2, v3, n : TAffineVector;
68
Id_Mat, NVert, NTri : Integer;
70
VertArr : TGLPoint3DArray;
75
sl := TStringList.Create;
76
tl := TStringList.Create;
78
sl.LoadFromStream(aStream);
79
mesh := TGLMeshObject.CreateOwned(Owner.MeshObjects);
80
mesh.Mode := momTriangles;
81
if sl[0]<>'TIN' then // the file with single TIN described by vertices only
83
for i := 0 to sl.Count - 1 do
85
tl.CommaText := Copy(sl[i], 0, MaxInt);
89
SetVector(v1, GLUtils.StrToFloatDef(tl[0],0), GLUtils.StrToFloatDef(tl[1],0), GLUtils.StrToFloatDef(tl[2],0));
90
SetVector(v2, GLUtils.StrToFloatDef(tl[3],0), GLUtils.StrToFloatDef(tl[4],0), GLUtils.StrToFloatDef(tl[5],0));
91
SetVector(v3, GLUtils.StrToFloatDef(tl[6],0), GLUtils.StrToFloatDef(tl[7],0), GLUtils.StrToFloatDef(tl[8],0));
92
mesh.Vertices.Add(v1, v2, v3);
93
n := CalcPlaneNormal(v1, v2, v3);
94
mesh.Normals.Add(n, n, n);
98
else // the file with multiple TINs described by triangles and materials
99
while i < sl.Count - 1 do
102
tl.DelimitedText := sl[i];
103
if (tl.CommaText = 'BEGT') then // the beginning of new tin
106
Inc(i); tl.DelimitedText := sl[i];
107
if (tl[0] = 'ACTIVETIN') then
109
if (tl[0] = 'ID') then
110
Id_Tin := StrToInt(tl[1]);
111
if (tl[0] = 'TNAM') then
113
if (tl[0] = 'MAT') then
114
Id_Mat := StrToInt(tl[1]);
115
if (tl[0] = 'VERT') then
116
NVert := StrToInt(tl[1]);
118
SetLength(VertArr, NVert);
122
tl.DelimitedText := sl[i];
123
VertArr[j].X := StrToFloat(tl[0]);
124
VertArr[j].Y := StrToFloat(tl[1]);
125
VertArr[j].Z := StrToFloat(tl[2]);
128
Inc(i); tl.DelimitedText := sl[i];
129
NTri := StrToInt(tl[1]);
133
tl.DelimitedText := sl[i];
134
n1 := StrToInt(tl[0]); n2 := StrToInt(tl[1]); n3 := StrToInt(tl[2]);
135
SetVector(v1, VertArr[n1-1].X, VertArr[n1-1].Y, VertArr[n1-1].Z);
136
SetVector(v2, VertArr[n2-1].X, VertArr[n2-1].Y, VertArr[n2-1].Z);
137
SetVector(v3, VertArr[n3-1].X, VertArr[n3-1].Y, VertArr[n3-1].Z);
138
mesh.Vertices.Add(v1, v2, v3);
139
n := CalcPlaneNormal(v1, v2, v3);
140
mesh.Normals.Add(n, n, n);
142
Inc(i); tl.DelimitedText := sl[i]; //tl.DelimitedText = 'ENDT';
151
// ------------------------------------------------------------------
152
// ------------------------------------------------------------------
153
// ------------------------------------------------------------------
155
// ------------------------------------------------------------------
156
// ------------------------------------------------------------------
157
// ------------------------------------------------------------------
159
RegisterVectorFileFormat('tin', 'Triangular Irregular Network', TGLTINVectorFile);