[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 | |
---|
[8724] | 27 | #include <map> |
---|
[8348] | 28 | |
---|
[8724] | 29 | |
---|
[8344] | 30 | //! These are the needed defines for the max values when loading .MD2 files |
---|
[8426] | 31 | #define MD3_IDENT (('3'<<24) + ('P'<<16) + ('D'<<8) + 'I') //!< the md3 identifier tag in the bin file |
---|
[8354] | 32 | #define MD3_VERSION 15 //!< the md2 version in the header |
---|
[8344] | 33 | |
---|
| 34 | |
---|
| 35 | |
---|
[8351] | 36 | namespace md3 |
---|
| 37 | { |
---|
| 38 | |
---|
[8357] | 39 | class MD3BoneFrame; |
---|
| 40 | class MD3Mesh; |
---|
[8724] | 41 | class MD3Normal; |
---|
| 42 | class MD3Animation; |
---|
[8357] | 43 | |
---|
[8724] | 44 | //! This holds the header information that is read in at the beginning of the file: id software definition |
---|
| 45 | typedef struct MD3Header |
---|
| 46 | { |
---|
| 47 | int ident; //!< This is used to identify the file |
---|
| 48 | int version; //!< The version number of the file (Must be 8) |
---|
[8344] | 49 | |
---|
[8724] | 50 | char filename[68]; //!< The filename of the model |
---|
[8344] | 51 | |
---|
[8724] | 52 | int boneFrameNum; //!< number of frames |
---|
| 53 | int tagNum; //!< number of tags |
---|
| 54 | int meshNum; //!< number of mesh |
---|
| 55 | int maxTexNum; //!< number of texture |
---|
[8354] | 56 | |
---|
[8724] | 57 | int boneFrameStart; //!< start of bone frames |
---|
| 58 | int tagStart; //!< start of the tag |
---|
| 59 | int meshStart; //!< mesh start |
---|
[8354] | 60 | |
---|
[8724] | 61 | int fileSize; //!< file size |
---|
| 62 | }; |
---|
[8344] | 63 | |
---|
[8724] | 64 | //!< holding the informations about the current animation state |
---|
| 65 | typedef struct MD3AnimationState |
---|
| 66 | { |
---|
| 67 | int currentFrame; //!< currently rendered animation key frame of this model. Every part has its own current frame! |
---|
| 68 | int nextFrame; //!< next animation key frame of the model. |
---|
| 69 | float interpolationFraction; //!< interpolation position between currentFrame and nextFrame [0,1] |
---|
| 70 | }; |
---|
[8344] | 71 | |
---|
[8724] | 72 | //! class to store the md2 data in |
---|
| 73 | class MD3Data : public BaseObject |
---|
| 74 | { |
---|
| 75 | public: |
---|
| 76 | MD3Data(const std::string& modelFileName, const std::string& skinFileName, float scale = 1.0f); |
---|
| 77 | virtual ~MD3Data(); |
---|
[8344] | 78 | |
---|
[8724] | 79 | void addLinkedModel(int tagIndex, MD3Data* child); |
---|
| 80 | int getTagIndexByName(std::string name); |
---|
[8344] | 81 | |
---|
[8724] | 82 | private: |
---|
| 83 | bool loadModel(const std::string& fileName); |
---|
| 84 | bool loadSkin(const std::string& fileName = ""); |
---|
[8344] | 85 | |
---|
[8724] | 86 | void init(); |
---|
[8344] | 87 | |
---|
[8724] | 88 | int readHeader(FILE* pFile, int fileOffset); |
---|
| 89 | int readBoneFrames(FILE* pFile, int fileOffset); |
---|
| 90 | int readTags(FILE* pFile, int fileOffset); |
---|
| 91 | int readMeshes(FILE* pFile, int fileOffset); |
---|
[8346] | 92 | |
---|
[8375] | 93 | |
---|
[8724] | 94 | int readMeshTriangles(FILE* pFile, int fileOffset, int mesh); |
---|
| 95 | int readMeshTextures(FILE* pFile, int fileOffset, int mesh); |
---|
| 96 | int readMeshTexVecs(FILE* pFile, int fileOffset, int mesh); |
---|
| 97 | int readMeshVertices(FILE* pFile, int fileOffset, int mesh); |
---|
[8344] | 98 | |
---|
| 99 | |
---|
[8724] | 100 | public: |
---|
[8357] | 101 | |
---|
[8724] | 102 | MD3Header* header; //!< the header file |
---|
[8357] | 103 | |
---|
[8724] | 104 | std::map<int, MD3Data*> sortedMap; //!< map |
---|
| 105 | int parentTagIndex; //!< the tag index of the parent model |
---|
| 106 | MD3Data* parent; //!< the parent model |
---|
[8357] | 107 | |
---|
[8724] | 108 | std::string filename; //!< the name of the file as recorded in the .md3 file |
---|
[8357] | 109 | |
---|
[8724] | 110 | MD3AnimationState animationState; //!< the animation state of this model |
---|
[8357] | 111 | |
---|
[8724] | 112 | MD3BoneFrame** boneFrames; //!< array of bone frames, contains the metadata (bounding box, tags,...) for each frame |
---|
| 113 | MD3Mesh** meshes; //!< array of meshes in the model. each containing the mesh for each of the animation |
---|
[8357] | 114 | |
---|
[8724] | 115 | MD3BoneFrame* tmpBoneFrame; //!< a temporary bone frame |
---|
| 116 | sVec3D** tmpMesh; //!< a temporary mesh frame |
---|
| 117 | MD3Normal** tmpNormal; //!< a temporary normals frame |
---|
| 118 | float** tmpMatrix; //!< a temporary matrix |
---|
[8357] | 119 | |
---|
| 120 | |
---|
[8724] | 121 | /* the animation part */ |
---|
| 122 | MD3Animation* animation; //!< animation |
---|
| 123 | int op; //!< the current operation |
---|
| 124 | int upperBound; //!< the upper bound |
---|
| 125 | bool bInterpolate; //!< interpolate the frames |
---|
| 126 | }; |
---|
[8357] | 127 | |
---|
| 128 | |
---|
[8351] | 129 | } |
---|
[8344] | 130 | |
---|
| 131 | |
---|
| 132 | |
---|
| 133 | #endif /* _MD3_DATA_H */ |
---|