00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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;
00079 unsigned int length;
00080 size_t bytesRead;
00081 };
00082
00084 struct TGeom
00085 {
00086 TIndexList Indicies;
00087 int materialID;
00088 };
00089
00090
00091 struct TFace
00092 {
00093 uint vertIndex[3];
00094 int materialID;
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
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 }
00165
00166 #endif // KEOS_3DSLOADER_H