Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008 #ifndef __SP_MESHLOADER_MD2_H__
00009 #define __SP_MESHLOADER_MD2_H__
00010
00011
00012 #include "Base/spStandard.hpp"
00013
00014 #ifdef SP_COMPILE_WITH_MESHLOADER_MD2
00015
00016
00017 #include "Base/spInputOutputLog.hpp"
00018 #include "Base/spDimension.hpp"
00019 #include "RenderSystem/spTextureBase.hpp"
00020 #include "FileFormats/Mesh/spMeshLoader.hpp"
00021
00022 #include <vector>
00023 #include <string>
00024
00025
00026 namespace sp
00027 {
00028 namespace scene
00029 {
00030
00031
00032 enum EMD2AnimTypes
00033 {
00034 MD2ANIM_STAND = 0,
00035 MD2ANIM_RUN,
00036 MD2ANIM_ATTACK,
00037 MD2ANIM_PAIN_A,
00038 MD2ANIM_PAIN_B,
00039 MD2ANIM_PAIN_C,
00040 MD2ANIM_JUMP,
00041 MD2ANIM_FLIP,
00042 MD2ANIM_SALUTE,
00043 MD2ANIM_FALLBACK,
00044 MD2ANIM_WAVE,
00045 MD2ANIM_POINT,
00046 MD2ANIM_CROUCH_STAND,
00047 MD2ANIM_CROUCH_WALK,
00048 MD2ANIM_CROUCH_ATTACK,
00049 MD2ANIM_CROUCH_PAIN,
00050 MD2ANIM_CROUCH_DEATH,
00051 MD2ANIM_DEATH_FALLBACK,
00052 MD2ANIM_DEATH_FALLFORWARD,
00053 MD2ANIM_DEATH_FALLBACKSLOW,
00054 MD2ANIM_BOOM,
00055
00056 MD2ANIM_MAX_ANIMATIONS
00057 };
00058
00059
00060 class SP_EXPORT MeshLoaderMD2 : public MeshLoader
00061 {
00062
00063 public:
00064
00065 MeshLoaderMD2();
00066 ~MeshLoaderMD2();
00067
00068 Mesh* loadMesh(const io::stringc &Filename, const io::stringc &TexturePath);
00069
00070 static void getAnimationSeq(s32 Type, u32 &Start, u32 &End);
00071
00072 private:
00073
00074
00075
00076 static const s32 MD2_SHADEDOT_QUANT = 16;
00077 static const s32 MD2_VERTEX_NORMALS = 162;
00078
00079
00080
00081 struct SHeaderMD2
00082 {
00083 s32 ID;
00084 s32 Version;
00085
00086 s32 SkinWidth;
00087 s32 SkinHeight;
00088 s32 FrameSize;
00089
00090 s32 CountOfTextures;
00091 s32 CountOfVertices;
00092 s32 CountOfTexCoords;
00093 s32 CountOfTriangles;
00094 s32 CountOfCommands;
00095 s32 CountOfKeyframes;
00096
00097 s32 TextureOffset;
00098 s32 TexCoordOffset;
00099 s32 TriangleOffset;
00100 s32 KeyframeOffset;
00101 s32 CommandOffset;
00102 s32 EndOfFileOffset;
00103 };
00104
00105 struct SVertexMD2
00106 {
00107 dim::vector3d<u8> Vertex;
00108 u8 LightNormalIndex;
00109 };
00110
00111 struct SKeyFrameMD2
00112 {
00113 dim::vector3df Scale;
00114 dim::vector3df Translate;
00115 s8 Name[16];
00116 SVertexMD2 Vertices[1];
00117 };
00118
00119 struct STriangleMD2
00120 {
00121 s16 IndexVertex[3];
00122 s16 IndexTexCoord[3];
00123 };
00124
00125 struct SAnimationMD2
00126 {
00127 s32 FirstFrame;
00128 s32 LastFrame;
00129 s32 FPS;
00130 };
00131
00132 struct SAnimStateMD2
00133 {
00134 s32 StartFrame;
00135 s32 EndFrame;
00136 s32 FPS;
00137
00138 f32 CurTime;
00139 f32 OldTime;
00140 f32 Interpol;
00141
00142 s32 Type;
00143 s32 CurFrame;
00144 s32 NextFrame;
00145 };
00146
00147
00148
00149 bool loadModelData(io::stringc Filename);
00150 void buildAnimation();
00151 Mesh* buildModel();
00152
00153 void interpolate(dim::vector3df* CoordList, dim::vector3df* NormalList);
00154
00155
00156
00157 s32 KeyFramesCount_;
00158 s32 VerticesCount_;
00159 s32 CommandsCount_;
00160
00161 dim::vector3df* pVertices_;
00162 s32* pCommands_;
00163 u8* pLightNormals_;
00164
00165 SAnimStateMD2 Animation_;
00166 f32 Scale_;
00167
00168
00169
00170 static SAnimationMD2 AnimList_[21];
00171
00172 };
00173
00174
00175 }
00176
00177 }
00178
00179
00180 #endif
00181
00182 #endif
00183
00184
00185
00186