Keos3DSLoader.h

Go to the documentation of this file.
00001 /*
00002  * This source file is part of KEOS (Free 3D Engine)
00003  * For the latest info, see http://www.keosengine.org/
00004  * E-mails : thierry.vouriot@keosengine.org, yeri@keosengine.org
00005  *
00006  * This program is free software; you can redistribute it and/or modify it under
00007  * the terms of the GNU Lesser General Public License as published by the Free Software
00008  * Foundation; either version 2 of the License, or (at your option) any later
00009  * version.
00010  *
00011  * This program is distributed in the hope that it will be useful, but WITHOUT
00012  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00013  * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU Lesser General Public License along with
00016  * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
00017  * Place - Suite 330, Boston, MA 02111-1307, USA, or go to
00018  * http://www.gnu.org/copyleft/lesser.txt.
00019  *
00020  */
00021 #ifndef KEOS_3DSLOADER_H
00022 #define KEOS_3DSLOADER_H
00023 
00024 #include "KeosPrerequisites.h"
00025 #include "KeosLoader.h"
00026 #include "KeosMesh.h"
00027 
00028 namespace Keos
00029 {
00030   //-----------------------------------------------------------------------
00033   class C3DSLoader : public ILoader<CMesh>
00034   {
00035   public :
00036 
00037     C3DSLoader();
00038 
00043     virtual CMesh* LoadFromFile(const String& strFilename);
00044 
00045   private :
00046 
00048 #define CHUNK_PRIMARY       0x4D4D
00049 
00051 #define CHUNK_OBJECTINFO  0x3D3D // This gives the version of the mesh and is found right before the material and object information
00052 #define CHUNK_VERSION   0x0002 // This gives the version of the .3ds file
00053 #define CHUNK_EDITKEYFRAME  0xB000 // This is the header for all of the key frame info
00054 
00056 #define CHUNK_MATERIAL   0xAFFF // This stored the texture info
00057 #define CHUNK_OBJECT   0x4000 // This stores the faces, vertices, etc...
00058 
00060 #define CHUNK_MATNAME   0xA000 // This holds the material name
00061 #define CHUNK_MATDIFFUSE  0xA020 // This holds the color of the object/material
00062 #define CHUNK_MATMAP   0xA200 // This is a header for a new material
00063 #define CHUNK_MATMAPFILE  0xA300 // This holds the file name of the texture
00064 
00065 #define CHUNK_OBJECT_MESH  0x4100 // This lets us know that we are reading a new object
00066 
00068 #define CHUNK_OBJECT_VERTICES   0x4110 // The objects vertices
00069 #define CHUNK_OBJECT_FACES  0x4120 // The objects faces
00070 #define CHUNK_OBJECT_MATERIAL 0x4130 // This is found if the object has a material, either texture map or color
00071 #define CHUNK_OBJECT_UV   0x4140 // The UV texture coordinates
00072 
00073 #include <pshpack1.h>
00074 
00076     struct TChunk
00077     {
00078       unsigned short int ID; // The chunk's ID
00079       unsigned int length; // The length of the chunk
00080       size_t bytesRead;  // The amount of bytes read within that chunk
00081     };
00082 
00084     struct TGeom
00085     {
00086       TIndexList Indicies;
00087       int materialID;  // Index in the CMesh material list
00088     };
00089 
00090     // This holds a face with its materialID
00091     struct TFace
00092     {
00093       uint vertIndex[3]; // 3 Sides of a triangle make a face.
00094       int materialID;  // Index in the CMesh material list
00095     };
00096 
00097 #include <poppack.h>
00098 
00101     size_t GetString(char *);
00102 
00105     void ReadChunk(TChunk *);
00106 
00109     void ProcessNextChunk(CMesh *pMesh, TChunk *);
00110 
00113     void ProcessNextObjectChunk(CMesh *pMesh, char* strObjectName, TChunk *);
00114 
00117     void ProcessNextMaterialChunk(CMesh *pMesh, TChunk *);
00118 
00121     void ReadColorChunk(CMaterial *pMaterial, TChunk *pChunk);
00122 
00125     void ReadVertices(TChunk *);
00126 
00129     void ReadVertexIndices(TChunk *);
00130 
00133     void ReadUVCoordinates(TChunk *);
00134 
00137     void ReadObjectMaterial(CMesh *pMesh, TChunk *pPreviousChunk);
00138 
00141     void CleanUp();
00142 
00143     // These are used through the loading process to hold the chunk information
00144     TChunk *m_CurrentChunk;
00145     TChunk *m_TempChunk;
00146 
00148     FILE *m_FilePointer;
00149 
00151     std::vector<TFace> m_Faces;
00153     int m_nNumVerts;
00155     TVector3F  *m_pVertices;
00157     int m_nNumTexVertex;
00159     TVector2F  *m_pTexCoords;
00160 
00162     ushort m_nObjectWithMultMaterial;
00163   };
00164 } // namespace Keos
00165 
00166 #endif // KEOS_3DSLOADER_H

Generated on Fri Mar 9 14:29:01 2007 for Keos by  doxygen 1.5.1-p1