00001
00002
00003 #ifndef _tds_hh_
00004 #define _tds_hh_
00005
00006 #include <GL/gl.h>
00007 #include <vector>
00008 #include "vector.hh"
00009 #include "asc.hh"
00010
00011 #define TEXTURE_BMP 0
00012 #define TEXTURE_TGA 1 // not available
00013 #define TEXTURE_JPG 2 // not available
00014 #define TEXTURE_GIF 3 // not available
00015
00016 #define WIREFRAME 0
00017 #define TEXTURE 1
00018
00019 struct TexturedTriangle : public Triangle {
00020 int TA, TB, TC;
00021 TexturedTriangle(int a, int b, int c, int ta, int tb, int tc) : Triangle(a,b,c), TA(ta), TB(tb), TC(tc) {}
00022 };
00023
00024 struct Vector2d {
00025 double x,y;
00026 }
00027
00028 struct Object3d {
00029 bool bHasTexture;
00030 int materialID;
00031
00032
00033 char strName[255];
00034 vector<Vector> vertices;
00035 vector<Vector> normals;
00036 vector<Vector2d> uvs;
00037 vector<TexturedTriangle> faces;
00038 }
00039
00040 struct Material {
00041 char strName[255];
00042 char strFile[255];
00043 unsigned char color[3];
00044 int textureId;
00045
00046
00047
00048
00049 }
00050
00051 struct Model3d
00052 {
00053 vector<Material> materials;
00054 vector<Object3d> objects;
00055 };
00056
00057 class tdsloader {
00058 public:
00059 tdsloader();
00060 bool Import3DS(Model3d *model, char *strFileName);
00061 private:
00062 int GetString(char *);
00063 void ReadChunk(tChunk *);
00064 void ProcessNextChunk(t3DModel *pModel, tChunk *);
00065
00066
00067 void ProcessNextObjectChunk(t3DModel *pModel, t3DObject *pObject, tChunk *);
00068
00069
00070 void ProcessNextMaterialChunk(t3DModel *pModel, tChunk *);
00071
00072
00073 void ReadColorChunk(tMaterialInfo *pMaterial, tChunk *pChunk);
00074
00075
00076 void ReadVertices(t3DObject *pObject, tChunk *);
00077
00078
00079 void ReadVertexIndices(t3DObject *pObject, tChunk *);
00080
00081
00082 void ReadUVCoordinates(t3DObject *pObject, tChunk *);
00083
00084
00085 void ReadObjectMaterial(t3DModel *pModel, t3DObject *pObject, tChunk *pPreviousChunk);
00086
00087
00088 void ComputeNormals(t3DModel *pModel);
00089
00090
00091 void CleanUp();
00092
00093
00094 FILE *m_FilePointer;
00095
00096
00097 tChunk *m_CurrentChunk;
00098 tChunk *m_TempChunk;
00099 }
00100
00101 class tds {
00102 public:
00103 tds(string& filename);
00104 ~tds();
00105
00106
00107
00108
00109
00110
00111
00112 private:
00113 UINT texture[MAX_TEXTURES];
00114
00115 CLoad3DS load3ds;
00116 Model3d model;
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128 };
00129
00130 #endif