2
// This unit is part of the GLScene Engine https://github.com/glscene
5
Quake2 MD2 vector file format implementation.
8
28/08/10 - Yar - Bugfix for FPC 2.5.1 (Thanks Predator)
9
31/03/07 - DaStr - Added $I GLScene.inc
10
05/06/03 - SG - Separated from GLVectorFileObjects.pas
21
GLVectorFileObjects, GLApplicationFileIO,
27
{ The MD2 vector file (Quake2 actor file).
28
Stores a set of "frames" describing the different postures of the actor,
29
it may be animated by TGLActor. The "Skin" must be loaded indepentendly
30
(the whole mesh uses a single texture bitmap).
31
Based on code by Roger Cao. }
32
TGLMD2VectorFile = class(TGLVectorFile)
35
class function Capabilities : TGLDataFileCapabilities; override;
36
procedure LoadFromStream(aStream : TStream); override;
39
// ------------------------------------------------------------------
40
// ------------------------------------------------------------------
41
// ------------------------------------------------------------------
43
// ------------------------------------------------------------------
44
// ------------------------------------------------------------------
45
// ------------------------------------------------------------------
51
// ------------------ TGLMD2VectorFile ------------------
56
class function TGLMD2VectorFile.Capabilities : TGLDataFileCapabilities;
63
procedure TGLMD2VectorFile.LoadFromStream(aStream : TStream);
67
mesh : TMorphableMeshObject;
68
faceGroup : TFGIndexTexCoordList;
69
morphTarget : TMeshMorphTarget;
71
MD2File:=TFileMD2.Create;
72
MD2File.LoadFromStream(aStream);
75
mesh:=TMorphableMeshObject.CreateOwned(Owner.MeshObjects);
76
with mesh, MD2File do begin
78
faceGroup:=TFGIndexTexCoordList.CreateOwned(FaceGroups);
79
with faceGroup do begin
81
VertexIndices.Capacity:=iTriangles*3;
82
TexCoords.Capacity:=iTriangles*3;
84
for i:=0 to iTriangles-1 do with IndexList[i] do begin
90
// retrieve frames data (morph targets)
91
for i:=0 to iFrames-1 do begin
92
morphTarget:=TMeshMorphTarget.CreateOwned(MorphTargets);
93
with morphTarget do begin
94
Name:='Frame'+IntToStr(i);
95
Vertices.Capacity:=iVertices;
96
for j:=0 to iVertices-1 do
97
Vertices.Add(VertexList[i][j]);
98
BuildNormals(faceGroup.VertexIndices, momTriangles);
102
if GetOwner is TGLActor then with TGLActor(GetOwner).Animations do begin
104
with MD2File do for i:=0 to frameNames.Count-1 do with Add do begin
107
StartFrame:=Integer(frameNames.Objects[i]);
108
if i<frameNames.Count-1 then
109
EndFrame:=Integer(frameNames.Objects[i+1])-1
110
else EndFrame:=iFrames-1;
113
if mesh.MorphTargets.Count>0 then
120
// ------------------------------------------------------------------
121
// ------------------------------------------------------------------
122
// ------------------------------------------------------------------
124
// ------------------------------------------------------------------
125
// ------------------------------------------------------------------
126
// ------------------------------------------------------------------
128
RegisterVectorFileFormat('md2', 'Quake II model files', TGLMD2VectorFile);