// Copyright (C) 2002-2007 Nikolaus Gebhardt // This file is part of the "Irrlicht Engine". // For conditions of distribution and use, see copyright notice in irrlicht.h #ifndef __C_X_MESH_FILE_LOADER_H_INCLUDED__ #define __C_X_MESH_FILE_LOADER_H_INCLUDED__ #include "IMeshLoader.h" #include "IReadFile.h" #include "irrString.h" #include "CSkinnedMesh.h" namespace irr { namespace scene { class IMeshManipulator; //! Meshloader capable of loading x meshes. class CXMeshFileLoader : public IMeshLoader { public: //! Constructor CXMeshFileLoader(scene::ISceneManager* smgr); //! destructor virtual ~CXMeshFileLoader(); //! returns true if the file maybe is able to be loaded by this class //! based on the file extension (e.g. ".cob") virtual bool isALoadableFileExtension(const c8* fileName); //! creates/loads an animated mesh from the file. //! \return Pointer to the created mesh. Returns 0 if loading failed. //! If you no longer need the mesh, you should call IAnimatedMesh::drop(). //! See IUnknown::drop() for more information. virtual IAnimatedMesh* createMesh(irr::io::IReadFile* file); struct SXTemplateMaterial { core::stringc Name; // template name from Xfile video::SMaterial Material; // material }; struct SXMesh { // this mesh contains triangulated texture data. // because in an .x file, faces can be made of more than 3 // vertices, the indices data structure is triangulated during the // loading process. The IndexCountPerFace array is filled during // this triangulation process and stores how much indices belong to // every face. This data structure can be ignored, because all data // in this structure is triangulated. core::stringc Name; core::array< s32 > IndexCountPerFace; // default 3, but could be more core::array Buffers; core::array Vertices; core::array Indices; core::array FaceIndices; // index of material for each face core::array Materials; // material array }; private: bool load(); bool readFileIntoMemory(); 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(); 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(); //! places pointer to next begin of a token, and ignores comments void findNextNoneWhiteSpace(); //! places pointer to next begin of a token, which must be a number, // and ignores comments void findNextNoneWhiteSpaceNumber(); //! returns next parseable token. Returns empty string if no token there core::stringc getNextToken(); //! reads header of dataobject including the opening brace. //! returns false if error happened, and writes name of object //! if there is one bool readHeadOfDataObject(core::stringc* outname=0); //! checks for one following semicolons, returns false if they are not there bool checkForOneFollowingSemicolons(); //! checks for two following semicolons, returns false if they are not there bool checkForTwoFollowingSemicolons(); //! reads a x file style string bool getNextTokenAsString(core::stringc& out); void readUntilEndOfLine(); core::stringc stripPathFromString(core::stringc string, bool returnPath); u16 readBinWord(); u32 readBinDWord(); s32 readInt(); f32 readFloat(); bool readVector2(core::vector2df& vec); bool readVector3(core::vector3df& vec); bool readRGB(video::SColorf& color); bool readRGBA(video::SColorf& color); bool readRGB(video::SColor& color); bool readRGBA(video::SColor& color); ISceneManager* SceneManager; core::array *Buffers; core::array *AllJoints; CSkinnedMesh* AnimatedMesh; io::IReadFile* file; s32 MajorVersion; s32 MinorVersion; bool binary; s32 binaryNumCount; c8* Buffer; s32 Size; c8 FloatSize; const c8* P; c8* End; bool ErrorHappened; CSkinnedMesh::SJoint *CurFrame; core::array Meshes; core::array TemplateMaterials; }; } // end namespace scene } // end namespace irr #endif