Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/md2_loader/src/lib/graphics/importer/md2Model.h @ 4075

Last change on this file since 4075 was 4075, checked in by patrick, 19 years ago

orxonox/braches/md2_loader: started implementing loader/model classes

File size: 4.5 KB
Line 
1/*!
2    \file md2Model.h
3    \brief Definition of an MD2 Model, a model format invented by ID Software.
4       
5        We are deeply thankfull for all the wunderfull things id software made for us gamers!
6
7        The md2 file format is structured in a very simple way: it contains animations which are made out of
8        frames (so called keyframes). Each frame is a complete draweable model in a specific position.
9        A frame is a collection of vertex and its compagnions (normals, texture coordinates).
10       
11        A typical model has about 200 frames, the maximum frame count is fixed by MD2_MAX_FRAMES to currently
12        512 frames. The maximal vetices count is set to 2048 verteces, not enough?
13        You just have to change the MD2_MAX_* values if it doesn't fit your purposes...
14*/
15
16#ifndef _MD2MODEL_H
17#define _MD2MODEL_H
18
19#include "abstract_model.h"
20
21
22//! These are the needed defines for the max values when loading .MD2 files
23#define MD2_MAX_TRIANGLES               4096
24#define MD2_MAX_VERTICES                2048
25#define MD2_MAX_TEXCOORDS               2048
26#define MD2_MAX_FRAMES                  512
27#define MD2_MAX_SKINS                   32
28#define MD2_MAX_FRAMESIZE               (MD2_MAX_VERTICES * 4 + 128)
29
30//! This stores the speed of the animation between each key frame - currently conflicting with the animation framework
31#define kAnimationSpeed                 5.0f
32
33//! This holds the header information that is read in at the beginning of the file: id software definition
34struct tMd2Header
35{ 
36   int ident;                                   //!< This is used to identify the file
37   int version;                                 //!< The version number of the file (Must be 8)
38   
39   int skinWidth;                               //!< The skin width in pixels
40   int skinHeight;                              //!< The skin height in pixels
41   int frameSize;                               //!< The size in bytes the frames are
42   
43   int numSkins;                                //!< The number of skins associated with the model
44   int numVertices;                             //!< The number of vertices (constant for each frame)
45   int numTexCoords;                    //!< The number of texture coordinates
46   int numTriangles;                    //!< The number of faces (polygons)
47   int numGlCommands;                   //!< The number of gl commands
48   int numFrames;                               //!< The number of animation frames
49   
50   int offsetSkins;                             //!< The offset in the file for the skin data
51   int offsetTexCoords;                 //!< The offset in the file for the texture data
52   int offsetTriangles;                 //!< The offset in the file for the face data
53   int offsetFrames;                    //!< The offset in the file for the frames data
54   int offsetGlCommands;                //!< The offset in the file for the gl commands data
55   int offsetEnd;                               //!< The end of the file offset
56};
57
58
59//! This is used to store the vertices that are read in for the current frame directly from the file (compressed)
60struct tMd2AliasTriangle
61{
62   byte vertex[3];
63   byte lightNormalIndex;
64};
65
66//! This stores the normals and vertices for the frames (uncompressed)
67struct tMd2Triangle
68{
69   float vertex[3];
70   float normal[3];
71};
72
73//! This stores the indices into the vertex and texture coordinate arrays
74struct tMd2Face
75{
76   short vertexIndices[3];
77   short textureIndices[3];
78};
79
80//! This stores UV coordinates
81struct tMd2TexCoord
82{
83   short u, v;
84};
85
86//! This stores the animation scale, translation and name information for a frame, plus verts
87struct tMd2AliasFrame
88{
89   float scale[3];
90   float translate[3];
91   char name[16];
92   tMd2AliasTriangle aliasVertices[1];
93};
94
95//! This stores the frames vertices after they have been transformed
96struct tMd2Frame
97{
98   char strName[16];
99   tMd2Triangle *pVertices;
100};
101
102//! This stores a skin name
103typedef char tMd2Skin[64];
104
105//! This is a MD2 Model class
106class MD2Model : public AbstractModel {
107
108public:
109  MD2Model();
110  virtual ~MD2Model();
111 
112  bool loadModel(const char* filename);
113  bool loadSkin(const char* filename);
114 
115  void drawModel(float time);
116  void drawFrame(int frame);
117 
118  void setAnim(int type);
119  void scaleModel(float s);
120 
121private:
122  void animate(float time);
123  void processLightning();
124  void interpolate(CVector3* vertlist);
125  void renderFrame();
126};
127
128//! A class that handles all of the loading code
129class MD2Loader {
130
131public:
132  MD2Loader();
133  virtual ~MD2Loader();
134 
135  bool importMD2(t3DModel *pModel, char *strFileName, char *strTexture);
136
137private:
138  void readMD2Data();
139  void parseAnimations(t3DModel *pModel);
140  void convertDataStructures(t3DModel *pModel);
141  void computeNormals(t3DModel *pModel);
142  void cleanUp();
143 
144  FILE *m_FilePointer; 
145  tMd2Header m_Header;                                      //!< The header data
146  tMd2Skin *m_pSkins;                                           //!< The skin data
147  tMd2TexCoord *m_pTexCoords;                           //!< The texture coordinates
148  tMd2Face *m_pTriangles;                                       //!< Face index information
149  tMd2Frame *m_pFrames;                                     //!< The frames of animation (vertices)
150};
151
152
153#endif /* _MD2MODEL_H */
Note: See TracBrowser for help on using the repository browser.