Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/branches/md2_loader: fixed some compile errors, altered some variable names, automake now works and did update Makefile.in :)

File size: 4.6 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#include "base_object.h"
21#include "stdincl.h"
22
23
24//! These are the needed defines for the max values when loading .MD2 files
25#define MD2_MAX_TRIANGLES               4096
26#define MD2_MAX_VERTICES                2048
27#define MD2_MAX_TEXCOORDS               2048
28#define MD2_MAX_FRAMES                  512
29#define MD2_MAX_SKINS                   32
30#define MD2_MAX_FRAMESIZE               (MD2_MAX_VERTICES * 4 + 128)
31
32//! This stores the speed of the animation between each key frame - currently conflicting with the animation framework
33#define kAnimationSpeed                 5.0f
34
35//! This holds the header information that is read in at the beginning of the file: id software definition
36struct tMd2Header
37{ 
38   int ident;                                   //!< This is used to identify the file
39   int version;                                 //!< The version number of the file (Must be 8)
40   
41   int skinWidth;                               //!< The skin width in pixels
42   int skinHeight;                              //!< The skin height in pixels
43   int frameSize;                               //!< The size in bytes the frames are
44   
45   int numSkins;                                //!< The number of skins associated with the model
46   int numVertices;                             //!< The number of vertices (constant for each frame)
47   int numTexCoords;                    //!< The number of texture coordinates
48   int numTriangles;                    //!< The number of faces (polygons)
49   int numGlCommands;                   //!< The number of gl commands
50   int numFrames;                               //!< The number of animation frames
51   
52   int offsetSkins;                             //!< The offset in the file for the skin data
53   int offsetTexCoords;                 //!< The offset in the file for the texture data
54   int offsetTriangles;                 //!< The offset in the file for the face data
55   int offsetFrames;                    //!< The offset in the file for the frames data
56   int offsetGlCommands;                //!< The offset in the file for the gl commands data
57   int offsetEnd;                               //!< The end of the file offset
58};
59
60
61//! This is used to store the vertices that are read in for the current frame directly from the file (compressed)
62struct tMd2AliasTriangle
63{
64   byte vertex[3];
65   byte lightNormalIndex;
66};
67
68//! This stores the normals and vertices for the frames (uncompressed)
69struct tMd2Triangle
70{
71   float vertex[3];
72   float normal[3];
73};
74
75//! This stores the indices into the vertex and texture coordinate arrays
76struct tMd2Face
77{
78   short vertexIndices[3];
79   short textureIndices[3];
80};
81
82//! This stores UV coordinates
83struct tMd2TexCoord
84{
85   short u, v;
86};
87
88//! This stores the animation scale, translation and name information for a frame, plus verts
89struct tMd2AliasFrame
90{
91   float scale[3];
92   float translate[3];
93   char name[16];
94   tMd2AliasTriangle aliasVertices[1];
95};
96
97//! This stores the frames vertices after they have been transformed
98struct tMd2Frame
99{
100   char strName[16];
101   tMd2Triangle *pVertices;
102};
103
104//! This stores a skin name
105typedef char tMd2Skin[64];
106
107//! This is a MD2 Model class
108class MD2Model : public AbstractModel {
109
110public:
111  MD2Model();
112  virtual ~MD2Model();
113 
114  bool loadModel(const char* filename);
115  bool loadSkin(const char* filename);
116 
117  void drawModel(float time);
118  void drawFrame(int frame);
119 
120  void setAnim(int type);
121  void scaleModel(float s);
122 
123private:
124  void animate(float time);
125  void processLightning();
126  void interpolate(CVector3* vertlist);
127  void renderFrame();
128};
129
130//! A class that handles all of the loading code
131class MD2Loader : public BaseObject {
132
133public:
134  MD2Loader();
135  virtual ~MD2Loader();
136 
137  bool importMD2(t3DModel *pModel, char *strFileName, char *strTexture);
138
139private:
140  void readMD2Data();
141  void parseAnimations(t3DModel *pModel);
142  void convertDataStructures(t3DModel *pModel);
143  void computeNormals(t3DModel *pModel);
144  void cleanUp();
145 
146  FILE *pFile; 
147  tMd2Header header;                                        //!< The header data
148  tMd2Skin *pSkins;                                             //!< The skin data
149  tMd2TexCoord *pTexCoords;                             //!< The texture coordinates
150  tMd2Face *pTriangles;                                 //!< Face index information
151  tMd2Frame *pFrames;                                       //!< The frames of animation (vertices)
152};
153
154
155#endif /* _MD2MODEL_H */
Note: See TracBrowser for help on using the repository browser.