00001
00002
00003
00004
00005
00006
00007
00008 #ifndef __SP_MESHLOADER_X_H__
00009 #define __SP_MESHLOADER_X_H__
00010
00011
00012 #include "Base/spStandard.hpp"
00013
00014 #ifdef SP_COMPILE_WITH_MESHLOADER_X
00015
00016
00017 #include "Base/spInputOutputLog.hpp"
00018 #include "Base/spInputOutputFileSystem.hpp"
00019 #include "Base/spDimension.hpp"
00020 #include "RenderSystem/spTextureBase.hpp"
00021 #include "FileFormats/Mesh/spMeshLoader.hpp"
00022
00023 #include <vector>
00024 #include <string>
00025
00026
00027 namespace sp
00028 {
00029 namespace scene
00030 {
00031
00032
00033
00034
00036 class SP_EXPORT MeshLoaderX : public MeshLoader
00037 {
00038
00039 public:
00040
00041 MeshLoaderX();
00042 ~MeshLoaderX();
00043
00044 Mesh* loadMesh(const io::stringc &Filename, const io::stringc &TexturePath);
00045
00046 private:
00047
00048
00049
00050 enum ETemplateTypes
00051 {
00052 TEMPLATE_UNKNOWN,
00053
00054 TEMPLATE_ANIMATION,
00055 TEMPLATE_ANIMATIONKEY,
00056 TEMPLATE_ANIMATIONOPTIONS,
00057 TEMPLATE_ANIMATIONSET,
00058 TEMPLATE_BOOLEAN,
00059 TEMPLATE_BOOLEAN2D,
00060 TEMPLATE_COLORRGB,
00061 TEMPLATE_COLORRGBA,
00062 TEMPLATE_COORDS2D,
00063 TEMPLATE_FLOATKEYS,
00064 TEMPLATE_FRAME,
00065 TEMPLATE_FRAMETRANSFORMMATRIX,
00066 TEMPLATE_HEADER,
00067 TEMPLATE_INDEXEDCOLOR,
00068 TEMPLATE_MATERIAL,
00069 TEMPLATE_MATRIX4X4,
00070 TEMPLATE_MESH,
00071 TEMPLATE_MESHFACE,
00072 TEMPLATE_MESHFACEWRAPS,
00073 TEMPLATE_MESHMATERIALLIST,
00074 TEMPLATE_MESHNORMALS,
00075 TEMPLATE_MESHTEXTURECOORDS,
00076 TEMPLATE_MESHVERTEXCOLORS,
00077 TEMPLATE_QUATERNION,
00078 TEMPLATE_TEXTUREFILENAME,
00079 TEMPLATE_TIMEDFLOATKEYS,
00080 TEMPLATE_VECTOR,
00081 };
00082
00083 enum EMemberTypes
00084 {
00085 MEMBER_UNKNOWN,
00086
00087 MEMBER_ARRAY,
00088 MEMBER_BINARY,
00089 MEMBER_BINARY_RESOURCE,
00090 MEMBER_CHAR,
00091 MEMBER_CSTRING,
00092 MEMBER_DOUBLE,
00093 MEMBER_DWORD,
00094 MEMBER_FLOAT,
00095 MEMBER_SDWORD,
00096 MEMBER_STRING,
00097 MEMBER_SWORD,
00098 MEMBER_TEMPLATE,
00099 MEMBER_UCHAR,
00100 MEMBER_ULONGLONG,
00101 MEMBER_UNICODE,
00102 MEMBER_WORD,
00103 };
00104
00105 enum EAnimationKeyTypes
00106 {
00107 ANIMKEY_POSITION = 2,
00108 ANIMKEY_ROTATION = 0,
00109 ANIMKEY_SCALE = 1,
00110 };
00111
00112
00113
00114 struct STemplateX;
00115 struct SRegisteredTemplateX;
00116
00117 struct STemplateMemberX
00118 {
00119 STemplateMemberX(const EMemberTypes InitType = MEMBER_UNKNOWN);
00120 STemplateMemberX(STemplateX* InitTemplate);
00121 ~STemplateMemberX();
00122
00123
00124 EMemberTypes Type;
00125
00126 STemplateX* Template;
00127 std::vector<STemplateMemberX> ArrayList;
00128
00129 s32 ValInteger;
00130 f32 ValFloat;
00131 f64 ValDouble;
00132 io::stringc ValString;
00133 };
00134
00135 struct STemplateX
00136 {
00137 STemplateX();
00138 ~STemplateX();
00139
00140
00141 ETemplateTypes Type;
00142 io::stringc TypeName;
00143 io::stringc Name;
00144
00145 std::vector<STemplateMemberX> MemberList;
00146 std::vector<io::stringc> ReferenceList;
00147 };
00148
00149 struct SRegisteredTemplateMemberX
00150 {
00151 SRegisteredTemplateMemberX(const EMemberTypes InitType = MEMBER_UNKNOWN);
00152 SRegisteredTemplateMemberX(const EMemberTypes InitType, s32 InitArraySize);
00153 SRegisteredTemplateMemberX(SRegisteredTemplateX* InitTemplateMember);
00154 SRegisteredTemplateMemberX(SRegisteredTemplateX* InitTemplateMember, s32 InitArraySize);
00155 ~SRegisteredTemplateMemberX();
00156
00157
00158 EMemberTypes Type;
00159 SRegisteredTemplateMemberX* ArrayMember;
00160 SRegisteredTemplateX* TemplateMember;
00161 bool isArraySizeQualifier;
00162
00163
00164
00165 s32 ArraySize;
00166 };
00167
00168 struct SRegisteredTemplateX
00169 {
00170 SRegisteredTemplateX();
00171 ~SRegisteredTemplateX();
00172
00173
00174 void addMember(const EMemberTypes Type);
00175 void addMember(const EMemberTypes Type, s32 ArraySize);
00176 void addMember(SRegisteredTemplateX* TemplateMember);
00177 void addMember(SRegisteredTemplateX* TemplateMember, s32 ArraySize);
00178 void addArraySizeQualifier(const EMemberTypes Type);
00179
00180
00181 ETemplateTypes Type;
00182 io::stringc TypeName;
00183 bool acceptOtherMembers;
00184
00185 std::vector<SRegisteredTemplateMemberX*> MemberList;
00186 };
00187
00188 struct SMaterialX
00189 {
00190 video::color Diffuse, Specular, Emission;
00191 f32 Shininess;
00192 std::list<video::Texture*> TextureList;
00193 };
00194
00195
00196
00197 void clear();
00198
00199 bool readLineTxt();
00200 bool readLinePartTxt();
00201 void cropLineTxt(u32 CropEndPos);
00202 void cropLineTxt(u32 CropBeginPos, u32 CropEndPos);
00203 s32 findBreakTokenTxt() const;
00204
00205 bool readHeader();
00206 bool readMesh();
00207
00208 bool readNextTemplate(STemplateX* &Template);
00209
00210 bool readNextTemplateTxt(STemplateX* &Template);
00211 bool readTemplateMembersTxt(STemplateX* Template, SRegisteredTemplateX* RegisteredTemplate);
00212 bool readNextMemberTxt(STemplateMemberX* CurMember, SRegisteredTemplateMemberX* RegisteredMember, bool isArrayElement);
00213 bool checkLineForTemplateReferenceTxt();
00214 bool checkLineForTemplateTxt();
00215 void checkForTemplateDeclarationTxt();
00216
00217 bool readNextTemplateBin(STemplateX* Template);
00218 io::stringc readNextTokenBin() const;
00219
00220 bool examineTemplateMember(STemplateMemberX* Member);
00221 bool examineTemplate(STemplateX* Template);
00222
00223 void buildMesh();
00224
00225 io::stringc getLinesIndicate() const;
00226 void printErrorLI(const io::stringc &Message) const;
00227 void printWarningLI(const io::stringc &Message) const;
00228
00229 SRegisteredTemplateX* registerNewTemplate(const ETemplateTypes Type, const io::stringc &Name);
00230 void registerDefaultTemplates();
00231
00232 video::color getTemplateMemberColor(const STemplateMemberX &Member) const;
00233 SMaterialX getTemplateMemberMaterial(const STemplateX* Template) const;
00234 bool getTemplateMemberAnimationKey(const STemplateMemberX &Member, u32 VecSize, f32* Vec, s32 &Time) const;
00235
00236 #ifdef _DEBX_
00237 void _deb_PrintTemplateMember(STemplateMemberX &Member);
00238 void _deb_PrintTemplate(STemplateX* Template);
00239 #endif
00240
00241
00242
00243 io::stringc Line_, Trimed_;
00244
00245 u32 CurLineNr_;
00246
00247 bool isBinary_;
00248 bool isFloat64_;
00249 u32 FloatSize_;
00250
00251 STemplateX* CurTemplate_;
00252 u32 LastArraySize_;
00253
00254
00255 std::vector<SRegisteredTemplateX*> RegisteredTemplateList_;
00256 std::map<std::string, SRegisteredTemplateX*> RegisteredTemplateMap_;
00257
00258 std::map<std::string, SMaterialX> MaterialMap_;
00259
00260
00261 dim::matrix4f CurTransformation_;
00262
00263 scene::SkeletalAnimation* BoneAnim_;
00264 scene::AnimationJoint* CurAnimBone_;
00265
00266 std::map<std::string, scene::AnimationJoint*> AnimBoneMap_;
00267
00268 };
00269
00270
00271 }
00272
00273 }
00274
00275
00276 #endif
00277
00278 #endif
00279
00280
00281
00282