00001
00002
00003
00004
00005
00006
00007
00008
00009 #pragma once
00010
00011
00012 #include <vector>
00013 #include <string>
00014
00015
00016
00017 typedef unsigned int uint;
00018 typedef unsigned char byte;
00019
00020 enum LShading {sWireframe, sFlat, sGouraud, sPhong, sMetal};
00021
00022 enum LOptimizationLevel {oNone, oSimple, oFull};
00023
00024
00025 struct LChunk;
00026 struct LTri;
00027
00028
00029
00030 struct LVector4
00031 {
00032 float x;
00033 float y;
00034 float z;
00035 float w;
00036 };
00037
00038 struct LVector3
00039 {
00040 float x;
00041 float y;
00042 float z;
00043 };
00044
00045 struct LVector2
00046 {
00047 float x;
00048 float y;
00049 };
00050
00051 struct LColor3
00052 {
00053 float r;
00054 float g;
00055 float b;
00056 };
00057
00058
00059
00060 struct LTriangle
00061 {
00062 unsigned short a;
00063 unsigned short b;
00064 unsigned short c;
00065 };
00066
00067 struct LMatrix4
00068 {
00069 float _11, _12, _13, _14;
00070 float _21, _22, _23, _24;
00071 float _31, _32, _33, _34;
00072 float _41, _42, _43, _44;
00073 };
00074
00075 struct LTriangle2
00076 {
00077 LVector4 vertices[3];
00078 LVector3 vertexNormals[3];
00079 LVector2 textureCoords[3];
00080 LVector3 faceNormal;
00081 uint materialId;
00082 };
00083
00084
00085 struct LMap
00086 {
00087
00088 float strength;
00089
00090 char mapName[255];
00091 float uScale;
00092 float vScale;
00093 float uOffset;
00094 float vOffset;
00095 float angle;
00096 };
00097
00098
00099
00100 class LObject
00101 {
00102 public:
00103
00104 LObject();
00105
00106 virtual ~LObject();
00107
00108 virtual const std::string& GetName();
00109
00110
00111
00112
00113
00114 virtual void SetName(const std::string& value);
00115
00116 bool IsObject(const std::string &name);
00117 protected:
00118
00119 std::string m_name;
00120 };
00121
00122
00123
00124 class LMaterial : public LObject
00125 {
00126 public:
00127
00128 LMaterial();
00129
00130 virtual ~LMaterial();
00131
00132 uint GetID();
00133
00134 LMap& GetTextureMap1();
00135
00136 LMap& GetTextureMap2();
00137
00138 LMap& GetOpacityMap();
00139
00140 LMap& GetSpecularMap();
00141
00142 LMap& GetBumpMap();
00143
00144 LMap& GetReflectionMap();
00145
00146 LColor3 GetAmbientColor();
00147
00148 LColor3 GetDiffuseColor();
00149
00150 LColor3 GetSpecularColor();
00151
00152 float GetShininess();
00153
00154 float GetTransparency();
00155
00156 LShading GetShadingType();
00157
00158
00159
00160
00161
00162 void SetID(uint value);
00163
00164 void SetAmbientColor(const LColor3 &color);
00165
00166 void SetDiffuseColor(const LColor3 &color);
00167
00168 void SetSpecularColor(const LColor3 &color);
00169
00170 void SetShininess(float value);
00171
00172 void SetTransparency(float value);
00173
00174 void SetShadingType(LShading shading);
00175 protected:
00176
00177 int m_id;
00178
00179 LMap m_texMap1;
00180
00181 LMap m_texMap2;
00182
00183 LMap m_opacMap;
00184
00185 LMap m_reflMap;
00186
00187 LMap m_bumpMap;
00188
00189 LMap m_specMap;
00190
00191 LColor3 m_ambient;
00192
00193 LColor3 m_diffuse;
00194
00195 LColor3 m_specular;
00196
00197 float m_shininess;
00198
00199 float m_transparency;
00200
00201 LShading m_shading;
00202 };
00203
00204
00205
00206 class LMesh : public LObject
00207 {
00208 public:
00209
00210 LMesh();
00211
00212 virtual ~LMesh();
00213
00214 void Clear();
00215
00216 uint GetVertexCount();
00217
00218 void SetVertexArraySize(uint value);
00219
00220 uint GetTriangleCount();
00221
00222 void SetTriangleArraySize(uint value);
00223
00224 const LVector4& GetVertex(uint index);
00225
00226 const LVector3& GetNormal(uint index);
00227
00228 const LVector2& GetUV(uint index);
00229
00230 const LVector3& GetTangent(uint index);
00231
00232 const LVector3& GetBinormal(uint index);
00233
00234 void SetVertex(const LVector4 &vec, uint index);
00235
00236 void SetNormal(const LVector3 &vec, uint index);
00237
00238 void SetUV(const LVector2 &vec, uint index);
00239
00240 void SetTangent(const LVector3 &vec, uint index);
00241
00242 void SetBinormal(const LVector3 &vec, uint index);
00243
00244 const LTriangle& GetTriangle(uint index);
00245
00246 LTriangle2 GetTriangle2(uint index);
00247
00248 LMatrix4 GetMatrix();
00249
00250 void SetMatrix(LMatrix4 m);
00251
00252 void Optimize(LOptimizationLevel value);
00253
00254 void SetTri(const LTri &tri, uint index);
00255
00256 LTri& GetTri(uint index);
00257
00258 uint GetMaterial(uint index);
00259
00260 uint AddMaterial(uint id);
00261
00262 uint GetMaterialCount();
00263 protected:
00264
00265 std::vector<LVector4> m_vertices;
00266 std::vector<LVector3> m_normals;
00267 std::vector<LVector3> m_binormals;
00268 std::vector<LVector3> m_tangents;
00269 std::vector<LVector2> m_uv;
00270
00271
00272 std::vector<LTriangle> m_triangles;
00273
00274
00275 std::vector<LTri> m_tris;
00276
00277
00278 LMatrix4 m_matrix;
00279
00280
00281 std::vector<uint> m_materials;
00282
00283
00284 void CalcNormals(bool useSmoothingGroups);
00285
00286 void CalcTextureSpace();
00287
00288 void TransformVertices();
00289 };
00290
00291
00292
00293 class LLight : public LObject
00294 {
00295 public:
00296
00297 LLight();
00298
00299 virtual ~LLight();
00300
00301 void Clear();
00302
00303 void SetPosition(LVector3 vec);
00304
00305 LVector3 GetPosition();
00306
00307 void SetColor(LColor3 color);
00308
00309 LColor3 GetColor();
00310
00311 void SetSpotlight(bool value);
00312
00313 bool GetSpotlight();
00314
00315 void SetTarget(LVector3 target);
00316
00317 LVector3 GetTarget();
00318
00319 void SetHotspot(float value);
00320
00321 float GetHotspot();
00322
00323 void SetFalloff(float value);
00324
00325 float GetFalloff();
00326 protected:
00327 LVector3 m_pos;
00328 LColor3 m_color;
00329 bool m_spotlight;
00330 LVector3 m_target;
00331 float m_hotspot;
00332 float m_falloff;
00333 };
00334
00335
00336
00337 class LImporter
00338 {
00339 public:
00340
00341 LImporter();
00342
00343 virtual ~LImporter();
00344
00345 virtual bool LoadFile(const char *filename) = 0;
00346
00347 uint GetMeshCount();
00348
00349 uint GetLightCount();
00350
00351 uint GetMaterialCount();
00352
00353 LMesh& GetMesh(uint index);
00354
00355 LLight& GetLight(uint index);
00356
00357 LMaterial& GetMaterial(uint index);
00358
00359 LMaterial* FindMaterial(const std::string &name);
00360
00361
00362 LMesh* FindMesh(const std::string &name);
00363
00364 LLight* FindLight(const std::string &name);
00365
00366 void SetOptimizationLevel(LOptimizationLevel value);
00367
00368 LOptimizationLevel GetOptimizationLevel();
00369 protected:
00370
00371 std::vector<LLight> m_lights;
00372
00373 std::vector<LMesh> m_meshes;
00374
00375 std::vector<LMaterial> m_materials;
00376
00377 LOptimizationLevel m_optLevel;
00378
00379 virtual void Clear();
00380 };
00381
00382
00383 class L3DS : public LImporter
00384 {
00385 public:
00386
00387 L3DS();
00388
00389 L3DS(const char *filename);
00390
00391 virtual ~L3DS();
00392
00393 virtual bool LoadFile(const char *filename);
00394 protected:
00395
00396 char m_objName[100];
00397
00398 bool m_eof;
00399
00400 unsigned char *m_buffer;
00401
00402 uint m_bufferSize;
00403
00404 uint m_pos;
00405
00406
00407 short ReadShort();
00408
00409 int ReadInt();
00410
00411 char ReadChar();
00412
00413 float ReadFloat();
00414
00415 byte ReadByte();
00416
00417 int ReadASCIIZ(char *buf, int max_count);
00418
00419 void Seek(int offset, int origin);
00420
00421 uint Pos();
00422
00423
00424 LChunk ReadChunk();
00425
00426 bool FindChunk(LChunk &target, const LChunk &parent);
00427
00428 void SkipChunk(const LChunk &chunk);
00429
00430 void GotoChunk(const LChunk &chunk);
00431
00432
00433 LColor3 ReadColor(const LChunk &chunk);
00434
00435 float ReadPercentage(const LChunk &chunk);
00436
00437 bool Read3DS();
00438
00439 void ReadLight(const LChunk &parent);
00440
00441 void ReadMesh(const LChunk &parent);
00442
00443 void ReadFaceList(const LChunk &chunk, LMesh &mesh);
00444
00445 void ReadMaterial(const LChunk &parent);
00446
00447 void ReadMap(const LChunk &chunk, LMap& map);
00448
00449 void ReadKeyframeData(const LChunk &parent);
00450
00451 long ReadKeyheader();
00452 };
00453
00454