00001 /* 00002 * Mesh loader B3D header 00003 * 00004 * This file is part of the "SoftPixel Engine" (Copyright (c) 2008 by Lukas Hermanns) 00005 * See "SoftPixelEngine.hpp" for license information. 00006 */ 00007 00008 #ifndef __SP_MESHLOADER_B3D_H__ 00009 #define __SP_MESHLOADER_B3D_H__ 00010 00011 00012 #include "Base/spStandard.hpp" 00013 00014 #ifdef SP_COMPILE_WITH_MESHLOADER_B3D 00015 00016 00017 #include "Base/spInputOutputLog.hpp" 00018 #include "Base/spInputOutputFileSystem.hpp" 00019 #include "Base/spDimension.hpp" 00020 #include "FileFormats/Mesh/spMeshLoader.hpp" 00021 00022 #include <vector> 00023 00024 00025 namespace sp 00026 { 00027 namespace scene 00028 { 00029 00030 00031 class SP_EXPORT MeshLoaderB3D : public MeshLoader 00032 { 00033 00034 public: 00035 00036 MeshLoaderB3D(); 00037 ~MeshLoaderB3D(); 00038 00039 Mesh* loadMesh(const io::stringc &Filename, const io::stringc &TexturePath); 00040 00041 private: 00042 00043 /* === Structures === */ 00044 00045 struct SBrushSurfaceB3D 00046 { 00047 s32 BrushID; 00048 video::MeshBuffer* Surface; 00049 }; 00050 00051 struct STextureSurfaceB3D 00052 { 00053 video::Texture* hTexture; 00054 dim::point2df Pos; 00055 dim::point2df Scale; 00056 bool isSphereMapping; 00057 }; 00058 00059 struct SSkeletonBoneB3D 00060 { 00061 // Constructor & destructor 00062 SSkeletonBoneB3D() 00063 : VerticesList(0), WeightsCount(0) 00064 { 00065 TabSize = 0; 00066 ParentBoneID = 0; 00067 Scale = 1.0f; 00068 } 00069 ~SSkeletonBoneB3D() 00070 { 00071 // Delete all memories 00072 MemoryManager::deleteBuffer(VerticesList); 00073 } 00074 00075 // General data 00076 s32 TabSize; // (later important to get the correct parnet bone) 00077 u32 ParentBoneID; 00078 io::stringc Name; 00079 00080 dim::vector3df Translation, Scale; 00081 dim::quaternion Quaternion; 00082 00083 // Bone vertex data 00084 struct SBoneVertexInfo 00085 { 00086 u32 Surface; 00087 u32 Index; 00088 f32 Weight; 00089 }; 00090 00091 SBoneVertexInfo* VerticesList; 00092 s32 WeightsCount; 00093 00094 // Bone keyframe data 00095 struct SBoneKeyframeInfo 00096 { 00097 SBoneKeyframeInfo() : Frame(0), Scale(1.0f) 00098 { 00099 } 00100 ~SBoneKeyframeInfo() 00101 { 00102 } 00103 00104 u32 Frame; 00105 00106 dim::vector3df Position; 00107 dim::vector3df Scale; 00108 dim::quaternion Rotation; 00109 }; 00110 00111 std::map<u32, SBoneKeyframeInfo> KeyframeList; 00112 }; 00113 00114 struct SVertexB3D 00115 { 00116 u32 SurfaceNr; 00117 video::MeshBuffer* Surface; 00118 u32 SurfVertexID; 00119 dim::vector3df Coord; 00120 dim::vector3df Normal; 00121 dim::point2df TexCoord; 00122 video::color Color; 00123 }; 00124 00125 struct SJointParent 00126 { 00127 AnimationJoint* Joint; 00128 u32 ParentID; 00129 }; 00130 00131 /* === Functions === */ 00132 00133 io::stringc readChunk(); 00134 void breakChunk(); 00135 s32 getChunkSize(); 00136 void readChunkBlock(io::stringc Tab = ""); 00137 00138 bool readChunkANIM(); 00139 bool readChunkKEYS(); 00140 bool readChunkTEXS(); 00141 bool readChunkBRUS(); 00142 bool readChunkVRTS(); 00143 bool readChunkTRIS(); 00144 bool readChunkMESH(); 00145 bool readChunkBONE(io::stringc &Tab); 00146 bool readChunkNODE(); 00147 00148 video::Texture* loadChunkTexture(io::stringc Filename); 00149 00150 void updateTexturing(); 00151 00152 void buildAnimation(); 00153 00154 bool loadModelData(); 00155 00156 /* === Members === */ 00157 00158 std::vector<STextureSurfaceB3D> TextureList_; 00159 std::vector<SBrushSurfaceB3D> BrushSurfaceList_; 00160 00161 std::vector<SSkeletonBoneB3D*> AnimBoneList_; 00162 00163 io::stringc CurName_; 00164 00165 dim::vector3df Position_, Scale_; 00166 dim::quaternion Quaternion_; 00167 00168 std::vector<s32> Stack_; 00169 s32 CurPos_; 00170 00171 // Building information 00172 00173 std::vector<SVertexB3D> VerticesList_; 00174 std::vector<s32> BrushTextureList_; 00175 00176 s32 CurBone_; 00177 s32 CurBrushID_; 00178 dim::matrix4f CurTransformation_, CurRotation_; 00179 00180 s32 AnimKeyframeCount_; 00181 f32 AnimFPS_; 00182 00183 }; 00184 00185 00186 } // /namespace scene 00187 00188 } // /namespace sp 00189 00190 00191 #endif 00192 00193 #endif 00194 00195 00196 00197 // ================================================================================