Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008 #ifndef __SP_MESHLOADER_3DS_H__
00009 #define __SP_MESHLOADER_3DS_H__
00010
00011
00012 #include "Base/spStandard.hpp"
00013
00014 #ifdef SP_COMPILE_WITH_MESHLOADER_3DS
00015
00016
00017 #include "Base/spInputOutput.hpp"
00018 #include "Base/spDimension.hpp"
00019 #include "FileFormats/Mesh/spMeshLoader.hpp"
00020
00021 #include <vector>
00022
00023
00024 namespace sp
00025 {
00026 namespace scene
00027 {
00028
00029
00030 class SP_EXPORT MeshLoader3DS : public MeshLoader
00031 {
00032
00033 public:
00034
00035 MeshLoader3DS();
00036 ~MeshLoader3DS();
00037
00038 Mesh* loadMesh(const io::stringc &Filename, const io::stringc &TexturePath);
00039
00040 private:
00041
00042
00043
00044 enum EMesh3DSChunks
00045 {
00046 CHUNK_MAGICNUMBER = 0x4D4D,
00047 CHUNK_VERSION = 0x0002,
00048
00049 CHUNK_COLOR_F32 = 0x0010,
00050 CHUNK_COLOR_U8 = 0x0011,
00051
00052 CHUNK_EDIT = 0x3D3D,
00053 CHUNK_EDIT_OBJECT = 0x4000,
00054 CHUNK_OBJECT_MESH = 0x4100,
00055 CHUNK_MESH_VERTICES = 0x4110,
00056 CHUNK_MESH_TRIANGLES = 0x4120,
00057 CHUNK_MESH_MATERIAL = 0x4130,
00058 CHUNK_MESH_TEXCOORDS = 0x4140,
00059 CHUNK_MESH_MATRIX = 0x4160,
00060
00061 CHUNK_EDIT_MATERIAL = 0xAFFF,
00062 CHUNK_MATERIAL_NAME = 0xA000,
00063 CHUNK_MATERIAL_DIFFUSE = 0xA020,
00064 CHUNK_MATERIAL_SHADING = 0xA100,
00065 CHUNK_MATERIAL_COLORMAP = 0xA200,
00066 CHUNK_TEXTURE_FILE = 0xA300,
00067
00068 CHUNK_KEYFRAME = 0xB000,
00069 CHUNK_KEYFRAME_CURTIME = 0xB009,
00070 CHUNK_KEYFRAME_TRACK = 0xB002,
00071 CHUNK_TRACK_BONENAME = 0xB010,
00072 CHUNK_TRACK_PIVOTPOINT = 0xB013,
00073 CHUNK_TRACK_BOUNDBOX = 0xB014,
00074 CHUNK_TRACK_BONEPOS = 0xB020,
00075 CHUNK_TRACK_BONEROT = 0xB021,
00076 CHUNK_TRACK_BONESCL = 0xB022,
00077 CHUNK_TRACK_NODE_ID = 0xB030,
00078 };
00079
00080
00081
00082 struct SChunk3DS
00083 {
00084 u16 ID;
00085 u32 Length, Readed;
00086 };
00087
00088 struct SMaterial3DS
00089 {
00090 io::stringc Name;
00091 io::stringc TextureFilename;
00092 video::color Diffuse;
00093 };
00094
00095 struct SMaterialGroup3DS
00096 {
00097 io::stringc Name;
00098 std::vector<u16> TriangleEnum;
00099 };
00100
00101 struct SObjectGroup3DS
00102 {
00103 Mesh* Object;
00104 dim::matrix4f Transformation;
00105
00106 std::vector<dim::vector3df> VertexList;
00107 std::vector<dim::point2df> TexCoordList;
00108 std::vector<SMeshTriangle3D> TriangleList;
00109
00110 std::vector<SMaterialGroup3DS> MaterialGroupList;
00111 };
00112
00113 struct SJoint3DS
00114 {
00115 s16 NodeID;
00116 io::stringc Name;
00117 s16 ParentJointID;
00118 Mesh* Object;
00119 std::vector<dim::vector3df> PositionList;
00120 std::vector<dim::quaternion> RotationList;
00121 std::vector<dim::vector3df> ScaleList;
00122 };
00123
00124
00125
00126 template <typename T> T readValue()
00127 {
00128 CurChunk_->Readed += sizeof(T);
00129 return File_->readValue<T>();
00130 }
00131 template <typename T> void readStream(T* Buffer, u32 Count)
00132 {
00133 CurChunk_->Readed += sizeof(T) * Count;
00134 File_->readBuffer(Buffer, sizeof(T), Count);
00135 }
00136
00137
00138
00139 void readChunk(SChunk3DS* Chunk);
00140 void readChunk();
00141 void ignore(u32 ByteCount);
00142
00143 io::stringc readString();
00144 video::color readColor();
00145
00146 bool readHeader();
00147 bool readNextChunk(SChunk3DS* PrevChunk);
00148
00149 bool readMeshVertices();
00150 bool readMeshTriangles();
00151 bool readMeshMaterial();
00152 bool readMeshTexCoords();
00153 bool readMeshMatrix();
00154
00155 bool readTrackPosition();
00156 bool readTrackRotation();
00157 bool readTrackScale();
00158
00159 void addNewMesh();
00160
00161 void buildMesh(const SObjectGroup3DS &ObjectGroup);
00162
00163
00164
00165 SChunk3DS* CurChunk_;
00166
00167 Mesh* RootMesh_;
00168
00169 std::vector<SObjectGroup3DS> ObjectGroupList_;
00170 SObjectGroup3DS* CurObjGroup_;
00171
00172 std::vector<SJoint3DS> JointList_;
00173 SJoint3DS* CurJoint_;
00174
00175 std::vector<SMaterial3DS> MaterialList_;
00176
00177 };
00178
00179
00180 }
00181
00182 }
00183
00184
00185 #endif
00186
00187 #endif
00188
00189
00190
00191