mElite  1.0
An Elite clone based on TextElite by Jan-Philipp Kappmeier and Melanie Schmidt.
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
ObjectLoader3ds.h
Go to the documentation of this file.
1 
8 #ifndef _C3DS_OBJECT_H_
9 #define _C3DS_OBJECT_H_
10 
11 #include<stdio.h>
12 #include<vector>
13 
18 struct stChunk {
19  stChunk() : id(0), length(0), bytesRead(0) {}
20  unsigned short id; // unsigned added
21  size_t length;
22  size_t bytesRead;
23 };
24 
29 struct stVertex {
30  stVertex() : x(0), y(0), z(0) {}
31  float x, y, z;
32 };
33 
38 struct stFace {
39  stFace() : matId(0) { indices[0] = indices[1] = indices[2] = 0; }
40  unsigned int indices[3];
42  int matId;
43 };
44 
49 struct stFileFace {
50  stFileFace() : vis(0) { indices[0] = indices[1] = indices[2] = 0; }
51  unsigned short indices[3], vis;
52 };
53 
58 struct stColor {
59  stColor() : r(0), g(0), b(0) {}
60  unsigned char r, g, b;
61 };
62 
68 struct stTexCoord {
69  stTexCoord() : tu(0), tv(0) {}
70  float tu, tv;
71 };
72 
78 struct stMaterial {
79  stMaterial() { name[0] = 0; textureName[0] = 0; }
80  char name[256];
84  char textureName[256];
85 };
86 
91 struct stMesh {
94 
95  char name[256];
96 
100 
101  unsigned int totalFaces;
102  unsigned int totalVertices;
103  unsigned int totalTexCoords;
104 };
105 
115 public:
116  ObjectLoader3ds();
118 
119  // load a file
120  bool LoadModel(const char *fileName);
121 
122  // deals with reading chunk headers.
123  void ReadSubChunk(FILE *fp, stChunk *pChunk);
124  void MoveToNextChunk(FILE *fp, stChunk *pChunk);
125  size_t GetNextString(FILE *fp, char *str);
126  void ReadChunk(FILE *fp, stChunk *pChunk);
127 
128  // read different sections out of the file like vertex
129  // positions, tex coords, faces, etc.
130  void ReadMaterials(FILE *fp, stChunk *pChunk);
131  void ReadDiffuse(FILE *fp, stChunk *pChunk);
132  void ReadAmbient(FILE *fp, stChunk *pChunk);
133  void ReadSpecular(FILE *fp, stChunk *pChunk);
134  void ReadMeshMaterials(FILE *fp, stChunk *pChunk);
135  void ReadFaces(FILE *fp, stChunk *pChunk);
136  void ReadVertices(FILE *fp, stChunk *pChunk);
137  void ReadTexCoords(FILE *fp, stChunk *pChunk);
138 
139  void shutdown();
140 
141  // List of mesh objects if there are more than 1,
142  // list of materials, and counters for each.
143  std::vector<stMesh> meshList;
144  std::vector<stMaterial> materialList;
147 };
148 
149 #endif