2
// This unit is part of the GLScene Engine https://github.com/glscene
5
Loader for FSRad OCT files.
8
16/10/08 - UweR - Compatibility fix for Delphi 2009
9
02/04/07 - DaStr - Added $I GLScene.inc
10
30/01/03 - Egg - Creation
19
uses Classes, GLVectorGeometry, GLVectorLists;
26
numTextures : Integer;
27
numLightmaps : Integer;
32
tv : TTexPoint; // texture coordinates
33
lv : TTexpoint; // lightmap coordinates
34
pos : TAffineVector; // vertex position
38
start : Integer; // first face vert in vertex array
39
num : Integer; // number of verts in the face
40
id : Integer; // texture index into the texture array
41
lid : Integer; // lightmap index into the lightmap array
47
id : Integer; // texture id
48
Name : array [0..63] of AnsiChar; // texture name
52
id : Integer; // lightmaps id
53
map : array [0..49151] of Byte; // 128 x 128 raw RGB data
55
POCTLightmap = ^TOCTLightmap;
58
pos : TAffineVector; // Position
59
color : TAffineVector; // Color (RGB)
60
intensity : Integer; // Intensity
65
TOCTFile = class (TObject)
69
Vertices : array of TOCTVertex;
70
Faces : array of TOCTFace;
71
Textures : array of TOCTTexture;
72
Lightmaps : array of TOCTLightmap;
73
Lights : array of TOCTLight;
74
PlayerPos : TAffineVector;
76
constructor Create; overload;
77
constructor Create(octStream : TStream); overload;
79
{ Saves content to stream in OCT format.
80
The Header is automatically prepared before streaming. }
81
procedure SaveToStream(aStream : TStream);
83
procedure AddTriangles(vertexCoords : TAffineVectorList;
84
texMapCoords : TAffineVectorList;
85
const textureName : String);
86
procedure AddLight(const lightPos : TAffineVector;
87
const lightColor : TVector;
88
lightIntensity : Integer);
92
// ------------------------------------------------------------------
93
// ------------------------------------------------------------------
94
// ------------------------------------------------------------------
96
// ------------------------------------------------------------------
97
// ------------------------------------------------------------------
98
// ------------------------------------------------------------------
100
uses SysUtils, GLMeshUtils;
103
// ------------------ TOCTFile ------------------
108
constructor TOCTFile.Create;
115
constructor TOCTFile.Create(octStream : TStream);
119
// Read in the header
120
octStream.Read(Header, SizeOf(Header));
122
// then the rest of the stuff
124
SetLength(Vertices, Header.numVerts);
125
octStream.Read(Vertices[0], Header.numVerts*SizeOf(TOCTVertex));
127
SetLength(Faces, Header.numFaces);
128
octStream.Read(Faces[0], Header.numFaces*SizeOf(TOCTFace));
130
SetLength(Textures, Header.numTextures);
131
octStream.Read(Textures[0], Header.numTextures*SizeOf(TOCTTexture));
133
SetLength(Lightmaps, Header.numLightmaps);
134
octStream.Read(Lightmaps[0], Header.numLightmaps*SizeOf(TOCTLightmap));
136
SetLength(Lights, Header.numLights);
137
octStream.Read(Lights[0], Header.numLights*SizeOf(TOCTLight));
139
octStream.Read(PlayerPos, SizeOf(PlayerPos))
144
procedure TOCTFile.SaveToStream(aStream : TStream);
146
with Header, aStream do begin
147
numVerts:=Length(Vertices);
148
numFaces:=Length(Faces);
149
numTextures:=Length(Textures);
150
numLightmaps:=Length(Lightmaps);
151
numLights:=Length(Lights);
153
Write(Header, SizeOf(Header));
154
Write(Vertices[0], numVerts*SizeOf(TOCTVertex));
155
Write(Faces[0], numFaces*SizeOf(TOCTFace));
156
Write(Textures[0], numTextures*SizeOf(TOCTTexture));
157
Write(Lightmaps[0], numLightmaps*SizeOf(TOCTLightmap));
158
Write(Lights[0], numLights*SizeOf(TOCTLight));
159
Write(PlayerPos, SizeOf(PlayerPos))
165
procedure TOCTFile.AddTriangles(vertexCoords : TAffineVectorList;
166
texMapCoords : TAffineVectorList;
167
const textureName : String);
170
baseIdx, texIdx : Integer;
172
Assert((texMapCoords=nil) or (texMapCoords.Count=vertexCoords.Count));
174
texIdx:=Length(Textures);
175
SetLength(Textures, texIdx+1);
176
Move(textureName[1], Textures[texIdx].Name[0], Length(textureName));
177
SetLength(Lightmaps, 1);
178
FillChar(Lightmaps[0].map[0], 128*3, 255);
180
baseIdx:=Length(Vertices);
181
SetLength(Vertices, baseIdx+vertexCoords.Count);
182
for i:=0 to vertexCoords.Count-1 do with Vertices[baseIdx+i] do begin
183
pos:=vertexCoords.List[i];
184
if Assigned(texMapCoords) then
185
tv:=PTexPoint(@texMapCoords.List[i])^;
188
SetLength(Faces, vertexCoords.Count div 3);
189
i:=0; while i<vertexCoords.Count do begin
190
with Faces[i div 3] do begin
194
p:=PlaneMake(vertexCoords[i],
195
CalcPlaneNormal(vertexCoords[i+0], vertexCoords[i+1], vertexCoords[i+0]));
203
procedure TOCTFile.AddLight(const lightPos : TAffineVector;
204
const lightColor : TVector;
205
lightIntensity : Integer);
210
SetLength(Lights, n+1);
211
with Lights[n] do begin
213
color:=PAffineVector(@lightColor)^;
214
intensity:=lightIntensity;