#ifndef __C_X_MESH_FILE_LOADER_H_INCLUDED__
#define __C_X_MESH_FILE_LOADER_H_INCLUDED__
#include "IMeshLoader.h"
#include "irrString.h"
#include "CSkinnedMesh.h"
namespace irr
{
namespace io
{
class IFileSystem;
class IReadFile;
}
namespace scene
{
class IMeshManipulator;
class CXMeshFileLoader : public IMeshLoader
{
public:
CXMeshFileLoader(scene::ISceneManager* smgr, io::IFileSystem* fs);
virtual bool isALoadableFileExtension(const io::path& filename) const;
virtual IAnimatedMesh* createMesh(io::IReadFile* file);
struct SXTemplateMaterial
{
core::stringc Name;
video::SMaterial Material;
};
struct SXMesh
{
SXMesh() : MaxSkinWeightsPerVertex(0), MaxSkinWeightsPerFace(0), BoneCount(0),AttachedJointID(-1),HasSkinning(false), HasVertexColors(false) {}
core::stringc Name;
u32 MaxSkinWeightsPerVertex;
u32 MaxSkinWeightsPerFace;
u32 BoneCount;
core::array<u16> IndexCountPerFace;
core::array<scene::SSkinMeshBuffer*> Buffers;
core::array<video::S3DVertex> Vertices;
core::array<core::vector2df> TCoords2;
core::array<u32> Indices;
core::array<u32> FaceMaterialIndices;
core::array<video::SMaterial> Materials;
core::array<u32> WeightJoint;
core::array<u32> WeightNum;
s32 AttachedJointID;
bool HasSkinning;
bool HasVertexColors;
};
private:
bool load(io::IReadFile* file);
bool readFileIntoMemory(io::IReadFile* file);
bool parseFile();
bool parseDataObject();
bool parseDataObjectTemplate();
bool parseDataObjectFrame(CSkinnedMesh::SJoint *parent);
bool parseDataObjectTransformationMatrix(core::matrix4 &mat);
bool parseDataObjectMesh(SXMesh &mesh);
bool parseDataObjectSkinWeights(SXMesh &mesh);
bool parseDataObjectSkinMeshHeader(SXMesh &mesh);
bool parseDataObjectMeshNormals(SXMesh &mesh);
bool parseDataObjectMeshTextureCoords(SXMesh &mesh);
bool parseDataObjectMeshVertexColors(SXMesh &mesh);
bool parseDataObjectMeshMaterialList(SXMesh &mesh);
bool parseDataObjectMaterial(video::SMaterial& material);
bool parseDataObjectAnimationSet();
bool parseDataObjectAnimation();
bool parseDataObjectAnimationKey(ISkinnedMesh::SJoint *joint);
bool parseDataObjectTextureFilename(core::stringc& texturename);
bool parseUnknownDataObject();
void findNextNoneWhiteSpace();
void findNextNoneWhiteSpaceNumber();
core::stringc getNextToken();
bool readHeadOfDataObject(core::stringc* outname=0);
bool checkForClosingBrace();
bool checkForOneFollowingSemicolons();
bool checkForTwoFollowingSemicolons();
bool getNextTokenAsString(core::stringc& out);
void readUntilEndOfLine();
u16 readBinWord();
u32 readBinDWord();
u32 readInt();
f32 readFloat();
bool readVector2(core::vector2df& vec);
bool readVector3(core::vector3df& vec);
bool readMatrix(core::matrix4& mat);
bool readRGB(video::SColor& color);
bool readRGBA(video::SColor& color);
ISceneManager* SceneManager;
io::IFileSystem* FileSystem;
core::array<CSkinnedMesh::SJoint*> *AllJoints;
CSkinnedMesh* AnimatedMesh;
c8* Buffer;
const c8* P;
c8* End;
u32 BinaryNumCount;
u32 Line;
io::path FilePath;
CSkinnedMesh::SJoint *CurFrame;
core::array<SXMesh*> Meshes;
core::array<SXTemplateMaterial> TemplateMaterials;
u32 MajorVersion;
u32 MinorVersion;
bool BinaryFormat;
c8 FloatSize;
};
}
}
#endif