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

3dsloader.hh

Go to the documentation of this file.
00001 #ifndef _tdsloader_hh
00002 #define _tdsloader_hh
00003 
00004 #include "tdstypes.hh"
00005 
00006 //>------ Primary Chunk, at the beginning of each file
00007 #define PRIMARY       0x4D4D
00008 
00009 //>------ Main Chunks
00010 #define OBJECTINFO    0x3D3D                // This gives the version of the mesh and is found right before the material and object information
00011 #define VERSION       0x0002                // This gives the version of the .3ds file
00012 #define EDITKEYFRAME  0xB000                // This is the header for all of the key frame info
00013 
00014 //>------ sub defines of OBJECTINFO
00015 #define MATERIAL      0xAFFF                // This stored the texture info
00016 #define OBJECT        0x4000                // This stores the faces, vertices, etc...
00017 
00018 //>------ sub defines of MATERIAL
00019 #define MATNAME       0xA000                // This holds the material name
00020 #define MATDIFFUSE    0xA020                // This holds the color of the object/material
00021 #define MATMAP        0xA200                // This is a header for a new material
00022 #define MATMAPFILE    0xA300                // This holds the file name of the texture
00023 
00024 #define OBJECT_MESH   0x4100                // This lets us know that we are reading a new object
00025 
00026 //>------ sub defines of OBJECT_MESH
00027 #define OBJECT_VERTICES     0x4110          // The objects vertices
00028 #define OBJECT_FACES        0x4120          // The objects faces
00029 #define OBJECT_MATERIAL     0x4130          // This is found if the object has a material, either texture map or color
00030 #define OBJECT_UV           0x4140          // The UV texture coordinates
00031 
00032 
00033 // Here is our structure for our 3DS indicies (since .3DS stores 4 unsigned shorts)
00034 struct tIndices {                           
00035 
00036     unsigned short a, b, c, bVisible;       // This will hold point1, 2, and 3 index's into the vertex array plus a visible flag
00037 };
00038 
00039 // This holds the chunk info
00040 struct tChunk
00041 {
00042     unsigned short int ID;          // The chunk's ID       
00043     unsigned int length;            // The length of the chunk
00044     unsigned int bytesRead;         // The amount of bytes read within that chunk
00045 };
00046 
00047 // This class handles all of the loading code
00048 class CLoad3DS {
00049     
00050     public:
00051         CLoad3DS();                             // This inits the data members
00052 
00053         // This is the function that you call to load the 3DS
00054         bool import3DS(t3DModel *pModel, char *strFileName);
00055 
00056     private:
00057         // This reads in a string and saves it in the char array passed in
00058         int getString(char *);
00059 
00060         // This reads the next chunk
00061         void readChunk(tChunk *);
00062 
00063         // This reads the next large chunk
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 #endif
00102 

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