Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

3ds.hh

Go to the documentation of this file.
00001 //3ds = threeds = tds
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;           // This is TRUE if there is a texture map for this object
00030     int  materialID;            // The texture ID to use, which is the index into our texture array
00031 
00032     //FIXME string and vertex???
00033     char strName[255]; // The name of the object
00034     vector<Vector> vertices; // The object's vertices pverts
00035     vector<Vector> normals; // The object's normals pnormals
00036     vector<Vector2d> uvs; // The texture's UV coordinates ptexverts
00037     vector<TexturedTriangle> faces; // The faces information of the object pfaces
00038 }
00039 
00040 struct Material {
00041     char  strName[255];         // The texture name
00042     char  strFile[255];         // The texture file name (If this is set it's a texture map)
00043     unsigned char color[3];     // The color of the object (R, G, B)
00044     int textureId;             // the texture ID
00045     /*  float uTile;                // u tiling of texture  (Currently not used)
00046     float vTile;                // v tiling of texture  (Currently not used)
00047     float uOffset;              // u offset of texture  (Currently not used)
00048     float vOffset;*/              // v offset of texture  (Currently not used)
00049 }
00050 
00051 struct Model3d 
00052 {
00053     vector<Material> materials; // The list of material information (Textures and colors)
00054     vector<Object3d> objects;   // The object list for our model
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     // This reads the object chunks
00067     void ProcessNextObjectChunk(t3DModel *pModel, t3DObject *pObject, tChunk *);
00068 
00069     // This reads the material chunks
00070     void ProcessNextMaterialChunk(t3DModel *pModel, tChunk *);
00071 
00072     // This reads the RGB value for the object's color
00073     void ReadColorChunk(tMaterialInfo *pMaterial, tChunk *pChunk);
00074 
00075     // This reads the objects vertices
00076     void ReadVertices(t3DObject *pObject, tChunk *);
00077 
00078     // This reads the objects face information
00079     void ReadVertexIndices(t3DObject *pObject, tChunk *);
00080 
00081     // This reads the texture coodinates of the object
00082     void ReadUVCoordinates(t3DObject *pObject, tChunk *);
00083 
00084     // This reads in the material name assigned to the object and sets the materialID
00085     void ReadObjectMaterial(t3DModel *pModel, t3DObject *pObject, tChunk *pPreviousChunk);
00086     
00087     // This computes the vertex normals for the object (used for lighting)
00088     void ComputeNormals(t3DModel *pModel);
00089 
00090     // This frees memory and closes the file
00091     void CleanUp();
00092     
00093     // The file pointer
00094     FILE *m_FilePointer;
00095     
00096     // These are used through the loading process to hold the chunk information
00097     tChunk *m_CurrentChunk;
00098     tChunk *m_TempChunk;
00099 }
00100 
00101 class tds {
00102 public: 
00103     tds(string& filename);
00104     ~tds();
00105     //fixme remove all of these
00106     //void loadObject(char *fileName);
00107     //void renderObject();
00108     //void setViewMode(int mode);
00109     //void toString();
00110     //UINT getTextureID(int i);
00111     
00112 private:
00113     UINT texture[MAX_TEXTURES]; // This holds the texture info, referenced by an ID
00114     
00115     CLoad3DS load3ds;           // This is 3DS class.  This should go in a good model class.
00116     Model3d model;              // This holds the 3D Model info that we load in
00117     //char objectName[256];
00118     
00119     //GLuint objectDL;
00120     //GLuint objectWireframeDL;
00121     
00122     //int textureType;
00123     //int viewMode;
00124     
00125     //void createTexture(UINT textureArray[], LPSTR strFileName, int textureID);
00126     //void createObjectDL(int type); // WIREFRAME | TEXTURE 
00127     //int setTextureType(LPSTR strFileName);
00128 };
00129 
00130 #endif 

Anoid NG © Michael Westergaard, Martin Stig Stissing, Ronni Michael Laursen, and Kristian Bisgaard Lassen