1 // Copyright (C) 2002-2012 Nikolaus Gebhardt
\r
2 // This file is part of the "Irrlicht Engine".
\r
3 // For conditions of distribution and use, see copyright notice in irrlicht.h
\r
5 #ifndef __C_X_MESH_FILE_LOADER_H_INCLUDED__
\r
6 #define __C_X_MESH_FILE_LOADER_H_INCLUDED__
\r
8 #include "IMeshLoader.h"
\r
9 #include "irrString.h"
\r
10 #include "CSkinnedMesh.h"
\r
19 } // end namespace io
\r
22 class IMeshManipulator;
\r
24 //! Meshloader capable of loading x meshes.
\r
25 class CXMeshFileLoader : public IMeshLoader
\r
30 CXMeshFileLoader(scene::ISceneManager* smgr, io::IFileSystem* fs);
\r
32 //! returns true if the file maybe is able to be loaded by this class
\r
33 //! based on the file extension (e.g. ".cob")
\r
34 bool isALoadableFileExtension(const io::path& filename) const override;
\r
36 //! creates/loads an animated mesh from the file.
\r
37 //! \return Pointer to the created mesh. Returns 0 if loading failed.
\r
38 //! If you no longer need the mesh, you should call IAnimatedMesh::drop().
\r
39 //! See IReferenceCounted::drop() for more information.
\r
40 IAnimatedMesh* createMesh(io::IReadFile* file) override;
\r
44 SXMesh() : MaxSkinWeightsPerVertex(0), MaxSkinWeightsPerFace(0), BoneCount(0),AttachedJointID(-1),HasSkinning(false), HasVertexColors(false) {}
\r
45 // this mesh contains triangulated texture data.
\r
46 // because in an .x file, faces can be made of more than 3
\r
47 // vertices, the indices data structure is triangulated during the
\r
48 // loading process. The IndexCountPerFace array is filled during
\r
49 // this triangulation process and stores how much indices belong to
\r
50 // every face. This data structure can be ignored, because all data
\r
51 // in this structure is triangulated.
\r
55 u32 MaxSkinWeightsPerVertex;
\r
56 u32 MaxSkinWeightsPerFace;
\r
59 core::array<u16> IndexCountPerFace; // default 3, but could be more
\r
61 core::array<scene::SSkinMeshBuffer*> Buffers;
\r
63 core::array<video::S3DVertex> Vertices;
\r
64 core::array<core::vector2df> TCoords2;
\r
66 core::array<u32> Indices;
\r
68 core::array<u32> FaceMaterialIndices; // index of material for each face
\r
70 core::array<video::SMaterial> Materials; // material array
\r
72 core::array<u32> WeightJoint;
\r
73 core::array<u32> WeightNum;
\r
75 s32 AttachedJointID;
\r
78 bool HasVertexColors;
\r
83 bool load(io::IReadFile* file);
\r
85 bool readFileIntoMemory(io::IReadFile* file);
\r
89 bool parseDataObject();
\r
91 bool parseDataObjectTemplate();
\r
93 bool parseDataObjectFrame(CSkinnedMesh::SJoint *parent);
\r
95 bool parseDataObjectTransformationMatrix(core::matrix4 &mat);
\r
97 bool parseDataObjectMesh(SXMesh &mesh);
\r
99 bool parseDataObjectSkinWeights(SXMesh &mesh);
\r
101 bool parseDataObjectSkinMeshHeader(SXMesh &mesh);
\r
103 bool parseDataObjectMeshNormals(SXMesh &mesh);
\r
105 bool parseDataObjectMeshTextureCoords(SXMesh &mesh);
\r
107 bool parseDataObjectMeshVertexColors(SXMesh &mesh);
\r
109 bool parseDataObjectMeshMaterialList(SXMesh &mesh);
\r
111 bool parseDataObjectAnimationSet();
\r
113 bool parseDataObjectAnimationTicksPerSecond();
\r
115 bool parseDataObjectAnimation();
\r
117 bool parseDataObjectAnimationKey(ISkinnedMesh::SJoint *joint);
\r
119 bool parseDataObjectTextureFilename(core::stringc& texturename);
\r
121 bool parseUnknownDataObject();
\r
123 //! places pointer to next begin of a token, and ignores comments
\r
124 void findNextNoneWhiteSpace();
\r
126 //! places pointer to next begin of a token, which must be a number,
\r
127 // and ignores comments
\r
128 void findNextNoneWhiteSpaceNumber();
\r
130 //! returns next parseable token. Returns empty string if no token there
\r
131 core::stringc getNextToken();
\r
133 //! reads header of dataobject including the opening brace.
\r
134 //! returns false if error happened, and writes name of object
\r
135 //! if there is one
\r
136 bool readHeadOfDataObject(core::stringc* outname=0);
\r
138 //! checks for closing curly brace, returns false if not there
\r
139 bool checkForClosingBrace();
\r
141 //! checks for one following semicolons, returns false if not there
\r
142 bool checkForOneFollowingSemicolons();
\r
144 //! checks for two following semicolons, returns false if they are not there
\r
145 bool checkForTwoFollowingSemicolons();
\r
147 //! reads a x file style string
\r
148 bool getNextTokenAsString(core::stringc& out);
\r
150 void readUntilEndOfLine();
\r
153 u32 readBinDWord();
\r
156 bool readVector2(core::vector2df& vec);
\r
157 bool readVector3(core::vector3df& vec);
\r
158 bool readMatrix(core::matrix4& mat);
\r
159 bool readRGB(video::SColor& color);
\r
160 bool readRGBA(video::SColor& color);
\r
162 CSkinnedMesh* AnimatedMesh;
\r
167 // counter for number arrays in binary format
\r
168 u32 BinaryNumCount;
\r
172 CSkinnedMesh::SJoint *CurFrame;
\r
174 core::array<SXMesh*> Meshes;
\r
182 } // end namespace scene
\r
183 } // end namespace irr
\r