[8344] | 1 | /*! |
---|
| 2 | * @file md2Model.h |
---|
| 3 | * 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 | Surface Culling is fully implemented in md2 models: quake2 uses front face culling. |
---|
| 16 | */ |
---|
| 17 | |
---|
[8348] | 18 | #ifndef _MD3_DATA_H |
---|
[8344] | 19 | #define _MD3_DATA_H |
---|
| 20 | |
---|
| 21 | #include "base_object.h" |
---|
| 22 | |
---|
| 23 | #include "model.h" |
---|
| 24 | #include "material.h" |
---|
| 25 | #include "md_model_structure.h" |
---|
| 26 | |
---|
[8348] | 27 | |
---|
[8344] | 28 | //! These are the needed defines for the max values when loading .MD2 files |
---|
[8354] | 29 | #define MD3_IDENT (('4'<<24) + ('P'<<16) + ('D'<<8) + 'I') //!< the md2 identifier tag in the bin file |
---|
| 30 | #define MD3_VERSION 15 //!< the md2 version in the header |
---|
[8344] | 31 | #define MD2_MAX_TRIANGLES 4096 //!< maximal triangles count |
---|
| 32 | #define MD2_MAX_VERTICES 2048 //!< maximal vertices count |
---|
| 33 | #define MD2_MAX_TEXCOORDS 2048 //!< maximal tex coordinates |
---|
| 34 | #define MD2_MAX_FRAMES 512 //!< maximal frames |
---|
| 35 | #define MD2_MAX_SKINS 32 //!< maximal skins |
---|
| 36 | #define MD2_MAX_FRAMESIZE (MD2_MAX_VERTICES * 4 + 128) //!< maximal framesize |
---|
| 37 | |
---|
| 38 | #define NUM_VERTEX_NORMALS 162 //!< number of vertex normals |
---|
| 39 | #define SHADEDOT_QUANT 16 //!< shade dot quantity - no idea what it is |
---|
| 40 | |
---|
| 41 | //! This stores the speed of the animation between each key frame - currently conflicting with the animation framework |
---|
| 42 | #define kAnimationSpeed 12.0f //!< animation speed |
---|
| 43 | |
---|
| 44 | |
---|
[8351] | 45 | namespace md3 |
---|
| 46 | { |
---|
| 47 | |
---|
[8357] | 48 | class MD3BoneFrame; |
---|
| 49 | class MD3Mesh; |
---|
| 50 | |
---|
[8344] | 51 | //! This holds the header information that is read in at the beginning of the file: id software definition |
---|
[8353] | 52 | struct MD3Header |
---|
[8344] | 53 | { |
---|
| 54 | int ident; //!< This is used to identify the file |
---|
| 55 | int version; //!< The version number of the file (Must be 8) |
---|
| 56 | |
---|
[8353] | 57 | char filename[68]; //!< The filename of the model |
---|
[8344] | 58 | |
---|
[8353] | 59 | int boneFrameNum; //!< number of frames |
---|
| 60 | int tagNum; //!< number of tags |
---|
| 61 | int meshNum; //!< number of mesh |
---|
| 62 | int maxTexNum; //!< number of texture |
---|
[8354] | 63 | |
---|
[8353] | 64 | int boneFrameStart; //!< start of bone frames |
---|
| 65 | int tagStart; //!< start of the tag |
---|
| 66 | int meshStart; //!< mesh start |
---|
[8354] | 67 | |
---|
[8353] | 68 | int fileSize; //!< file size |
---|
[8344] | 69 | }; |
---|
| 70 | |
---|
| 71 | |
---|
| 72 | |
---|
| 73 | //! class to store the md2 data in |
---|
| 74 | class MD3Data : public BaseObject |
---|
| 75 | { |
---|
| 76 | public: |
---|
| 77 | MD3Data(const std::string& modelFileName, const std::string& skinFileName, float scale = 1.0f); |
---|
| 78 | virtual ~MD3Data(); |
---|
| 79 | |
---|
| 80 | |
---|
| 81 | private: |
---|
| 82 | bool loadModel(const std::string& fileName); |
---|
| 83 | bool loadSkin(const std::string& fileName = ""); |
---|
| 84 | |
---|
[8355] | 85 | int readHeader(FILE* pFile, int fileOffset); |
---|
| 86 | int readBoneFrames(FILE* pFile, int fileOffset); |
---|
| 87 | int readTags(FILE* pFile, int fileOffset); |
---|
| 88 | int readMeshes(FILE* pFile, int fileOffset); |
---|
[8344] | 89 | |
---|
[8346] | 90 | |
---|
[8344] | 91 | public: |
---|
| 92 | |
---|
[8357] | 93 | MD3Header* header; //!< the header file |
---|
[8344] | 94 | |
---|
[8357] | 95 | std::string filename; //!< the name of the file as recorded in the .md3 file |
---|
| 96 | std::string loadFilename; //!< filename of the actual file from which data was loaded |
---|
| 97 | |
---|
| 98 | int boneFrameNum; //!< number of anumation key fames in the models |
---|
| 99 | int tagNum; //!< number of tags |
---|
| 100 | int meshNum; //!< number of meshes |
---|
| 101 | |
---|
| 102 | int maxTextureNum; //!< maximum number of unique used in an md3 file |
---|
| 103 | int boneFrameStart; //!< starting position of bone frame data structures |
---|
| 104 | int tagStart; //!< starting position of tag-structures |
---|
| 105 | |
---|
| 106 | int meshStart; //!< starting position of mesh structures |
---|
| 107 | |
---|
| 108 | int fileSize; //!< file size |
---|
| 109 | |
---|
| 110 | |
---|
| 111 | MD3BoneFrame** boneFrames; //!< array of bone frames, contains the metadata (bounding box, tags,...) for each frame |
---|
[8372] | 112 | MD3Mesh** meshes; //!< array of meshes in the model. each containing the mesh for each of the animation |
---|
[8357] | 113 | |
---|
| 114 | int parentTagIndex; //!< tag index |
---|
| 115 | |
---|
| 116 | //MD3Model* parent; //!< reference to the MD3Model |
---|
| 117 | |
---|
| 118 | |
---|
[8344] | 119 | }; |
---|
| 120 | |
---|
| 121 | |
---|
[8351] | 122 | } |
---|
[8344] | 123 | |
---|
| 124 | |
---|
| 125 | |
---|
| 126 | #endif /* _MD3_DATA_H */ |
---|