Main Page   Namespace List   Class Hierarchy   Alphabetical List   Data Structures   File List   Namespace Members   Data Fields   Globals  

ExCModel3DS.h

Go to the documentation of this file.
00001 /*
00002  * ExNihilo 3D Engine
00003  * 
00004  *  This program is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  This program is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU Library General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License
00015  *  along with this program; if not, write to the Free Software
00016  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00017  *
00018  * Please read AUTHORS file !!!
00019  * 
00020 
00021  *
00022  */
00023 
00024 #ifndef __EXCMODEL3DS_H__
00025 #define __EXCMODEL3DS_H__
00026 //--------------------------------
00027 // File to include
00028 //--------------------------------
00029 #include "ExDefine.h"
00030 #include "ExMath.h"
00031 #include "ExCModel.h"
00032 //--------------------------------
00033 //define relative to 3ds file format
00034 
00035 //>------ Primary Chunk, at the beginning of each file
00036 #define PRIMARY       0x4D4D
00037 //>------ Main Chunks
00038 #define OBJECTINFO    0x3D3D                            // This gives the version of the mesh and is found right before the material and object information
00039 #define EDITKEYFRAME  0xB000                            // This is the header for all of the key frame info
00040 #define FILEVERSION   0x0002
00041 //>------ common chunk
00042 #define INT_PERCENTAGE          0x0030
00043 #define PERCENTAGE                      0x0031
00044 //>------ sub defines of OBJECTINFO
00045 #define MATERIAL          0xAFFF                                // This stored the texture info
00046 #define OBJECT            0x4000                                // This stores the faces, vertices, etc...
00047 #define MESH_VERSION  0x3D3E
00048 #define MASTER_SCALE  0x0100
00049 
00050 //>------ sub defines of MATERIAL
00051 
00052 
00053 #define MATNAME                         0xA000                          // The material name                            TYPE:ascii
00054 #define MATAMBIENTCOLOR         0xA010                          // The material ambient color           TYPE:s
00055 #define MATDIFFUSE                      0xA020                          // The material diffuse color           TYPE:s
00056 #define MATSPECULAR                     0xA030                          // The material specular color          TYPE:s
00057 #define MATSHININESS            0xA040                          // The shininess                                        TYPE:s
00058 #define MATSHININESSSTR         0xA041                          // The shininess strenght                       TYPE:s
00059 #define MATTRANSPARENCY         0xA050
00060 #define MATTRANSFALLOFF         0xA052
00061 #define MATREFLECTBLUR          0xA053
00062 #define MATTWOSIDED                     0xA081
00063 #define MATTRANSPARENCYADD      0xA083
00064 #define MATSELFILUM                     0xA084
00065 #define MATWIREON                       0xA085
00066 #define MATWIRETHICKNESS        0xA087
00067 #define MATFACEMAP                      0xA088
00068 #define MATTRANSFALLOFFIN       0xA08A
00069 #define MATSOFTEN                       0xA08C
00070 #define MAT3DWIRETHICKNESS      0xA08E
00071 #define MATTYPE                         0xA100
00072 #define MATMAP                          0xA200                          // This is a header for a new material
00073 #define MATMAPFILE                      0xA300                          // This holds the file name of the texture
00074 #define MATMAPOPTION            0xA351                          
00075 #define MATMAPFILTERINGBLUR     0xA353          
00076 
00077 
00078 #define OBJECT_MESH   0x4100                            // This lets us know that we are reading a new object
00079 //>------ sub defines of OBJECT_MESH
00080 #define OBJECT_VERTICES     0x4110                      // The objects vertices
00081 #define OBJECT_FACES            0x4120                  // The objects faces
00082 #define OBJECT_MATERIAL         0x4130                  // This is found if the object has a material, either texture map or color
00083 #define OBJECT_UV                       0x4140                  // The UV texture coordinates
00084 #define OBJECT_SMOOTH_GROUP 0x4150
00085 #define OBJECT_MESH_MATRIX      0x4160
00086 
00087 struct tChunk
00088 {
00089         unsigned short int ID;                                  // The chunk's ID               
00090         unsigned int length;                                    // The length of the chunk
00091         unsigned int bytesRead;                                 // The amount of bytes read within that chunk
00092 };
00093 struct tFace
00094 {
00095         int vertIndex[3];                       // indicies for the verts that make up this triangle
00096         int coordIndex[3];                      // indicies for the tex coords to texture this face
00097 };
00098 struct tMaterialInfo
00099 {
00100         char  strName[255];                     // The texture name
00101         char  strFile[255];                     // The texture file name (If this is set it's a texture map)
00102         BYTE  color[3];                         // The color of the object (R, G, B)
00103         int   texureId;                         // the texture ID
00104         float uTile;                            // u tiling of texture  (Currently not used)
00105         float vTile;                            // v tiling of texture  (Currently not used)
00106         float uOffset;                      // u offset of texture      (Currently not used)
00107         float vOffset;                          // v offset of texture  (Currently not used)
00108 } ;
00109 struct t3DObject 
00110 {
00111         int  numOfVerts;                        // The number of verts in the model
00112         int  numOfFaces;                        // The number of faces in the model
00113         int  numTexVertex;                      // The number of texture coordinates
00114         int  materialID;                        // The texture ID to use, which is the index into our texture array
00115         bool bHasTexture;                       // This is TRUE if there is a texture map for this object
00116         char strName[255];                      // The name of the object
00117         std::string                     Material;                               
00118         std::vector<ExCVec3D>  Verts;   // The object's vertices
00119         std::vector<ExCVec3D>  Normals; // The object's normals
00120         std::vector<ExCVec2D>  TexVerts;        // The texture's UV coordinates
00121         std::vector<tFace>                Faces;        // The faces information of the object
00122 };
00123 //--------------------------------
00124 class ExCModel3DS : public ExCModel
00125 {
00126 protected:
00127 
00128 //--------------------------------
00129 // Variable
00130 //--------------------------------
00131         FILE                    *m_filePtr;
00132 //--------------------------------
00133 // Methode
00134 //--------------------------------
00135         void ReadObjectInfo(tChunk *chunk);
00136         void ReadObject(tChunk *chunk);
00137         void ReadObjectMaterial(tChunk *chunk);
00138 
00139         void ReadChunk(tChunk *chunk);
00140         void Skip(tChunk *chunk);
00141         
00142         void ReadVertices(t3DObject *pObject, tChunk *chunk);
00143         void ReadFace(t3DObject *pObject, tChunk *chunk);
00144         void ReadUVCoordinates(t3DObject *pObject, tChunk *chunk);
00145         void ReadObjectMaterial(t3DObject *pObject, tChunk *chunk);
00146 
00147         int numOfObjects;                                       // The number of objects in the model
00148         int numOfMaterials;                                     // The number of materials for the model
00149         std::vector<tMaterialInfo> m_VecMaterials;      // The list of material information (Textures and colors)
00150         std::vector<t3DObject> m_VecObject;                     // The object list for our model
00151 
00152         tChunk *m_CurrentChunk;
00153         tChunk *m_TempChunk;
00154         GLuint                                  m_ListId;
00155 
00156         float                   *m_VertexArray;                 //vertex Arrray
00157         unsigned int    *m_FaceArray;                   //Faces Array
00158         float                   *m_TextureArray;                //texture Arrray
00159         void BuildList(int Rendu);
00160         void BuildArray(int Rendu);
00161 public:
00162 //--------------------------------
00163 // Constructor // Destructor
00164 //--------------------------------
00165         ExCModel3DS(void);
00166         ~ExCModel3DS(void);
00167 //--------------------------------
00168 // Methode
00169 //--------------------------------
00170         void Draw(void);
00171         bool Load(std::string FileName);
00172 };
00173 #endif //__EXCMODEL3DS_H__

Generated on Tue Dec 10 18:20:04 2002 for ExNihilo by doxygen1.3-rc1