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
18 } // end namespace io
\r
21 class IMeshManipulator;
\r
23 //! Meshloader capable of loading x meshes.
\r
24 class CXMeshFileLoader : public IMeshLoader
\r
29 CXMeshFileLoader(scene::ISceneManager* smgr);
\r
31 //! returns true if the file maybe is able to be loaded by this class
\r
32 //! based on the file extension (e.g. ".cob")
\r
33 bool isALoadableFileExtension(const io::path& filename) const override;
\r
35 //! creates/loads an animated mesh from the file.
\r
36 //! \return Pointer to the created mesh. Returns 0 if loading failed.
\r
37 //! If you no longer need the mesh, you should call IAnimatedMesh::drop().
\r
38 //! See IReferenceCounted::drop() for more information.
\r
39 IAnimatedMesh* createMesh(io::IReadFile* file) override;
\r
43 SXMesh() : MaxSkinWeightsPerVertex(0), MaxSkinWeightsPerFace(0), BoneCount(0),AttachedJointID(-1),HasSkinning(false), HasVertexColors(false) {}
\r
44 // this mesh contains triangulated texture data.
\r
45 // because in an .x file, faces can be made of more than 3
\r
46 // vertices, the indices data structure is triangulated during the
\r
47 // loading process. The IndexCountPerFace array is filled during
\r
48 // this triangulation process and stores how much indices belong to
\r
49 // every face. This data structure can be ignored, because all data
\r
50 // in this structure is triangulated.
\r
54 u32 MaxSkinWeightsPerVertex;
\r
55 u32 MaxSkinWeightsPerFace;
\r
58 core::array<u16> IndexCountPerFace; // default 3, but could be more
\r
60 core::array<scene::SSkinMeshBuffer*> Buffers;
\r
62 core::array<video::S3DVertex> Vertices;
\r
63 core::array<core::vector2df> TCoords2;
\r
65 core::array<u32> Indices;
\r
67 core::array<u32> FaceMaterialIndices; // index of material for each face
\r
69 core::array<video::SMaterial> Materials; // material array
\r
71 core::array<u32> WeightJoint;
\r
72 core::array<u32> WeightNum;
\r
74 s32 AttachedJointID;
\r
77 bool HasVertexColors;
\r
82 bool load(io::IReadFile* file);
\r
84 bool readFileIntoMemory(io::IReadFile* file);
\r
88 bool parseDataObject();
\r
90 bool parseDataObjectTemplate();
\r
92 bool parseDataObjectFrame(CSkinnedMesh::SJoint *parent);
\r
94 bool parseDataObjectTransformationMatrix(core::matrix4 &mat);
\r
96 bool parseDataObjectMesh(SXMesh &mesh);
\r
98 bool parseDataObjectSkinWeights(SXMesh &mesh);
\r
100 bool parseDataObjectSkinMeshHeader(SXMesh &mesh);
\r
102 bool parseDataObjectMeshNormals(SXMesh &mesh);
\r
104 bool parseDataObjectMeshTextureCoords(SXMesh &mesh);
\r
106 bool parseDataObjectMeshVertexColors(SXMesh &mesh);
\r
108 bool parseDataObjectMeshMaterialList(SXMesh &mesh);
\r
110 bool parseDataObjectAnimationSet();
\r
112 bool parseDataObjectAnimationTicksPerSecond();
\r
114 bool parseDataObjectAnimation();
\r
116 bool parseDataObjectAnimationKey(ISkinnedMesh::SJoint *joint);
\r
118 bool parseDataObjectTextureFilename(core::stringc& texturename);
\r
120 bool parseUnknownDataObject();
\r
122 //! places pointer to next begin of a token, and ignores comments
\r
123 void findNextNoneWhiteSpace();
\r
125 //! places pointer to next begin of a token, which must be a number,
\r
126 // and ignores comments
\r
127 void findNextNoneWhiteSpaceNumber();
\r
129 //! returns next parseable token. Returns empty string if no token there
\r
130 core::stringc getNextToken();
\r
132 //! reads header of dataobject including the opening brace.
\r
133 //! returns false if error happened, and writes name of object
\r
134 //! if there is one
\r
135 bool readHeadOfDataObject(core::stringc* outname=0);
\r
137 //! checks for closing curly brace, returns false if not there
\r
138 bool checkForClosingBrace();
\r
140 //! checks for one following semicolons, returns false if not there
\r
141 bool checkForOneFollowingSemicolons();
\r
143 //! checks for two following semicolons, returns false if they are not there
\r
144 bool checkForTwoFollowingSemicolons();
\r
146 //! reads a x file style string
\r
147 bool getNextTokenAsString(core::stringc& out);
\r
149 void readUntilEndOfLine();
\r
152 u32 readBinDWord();
\r
155 bool readVector2(core::vector2df& vec);
\r
156 bool readVector3(core::vector3df& vec);
\r
157 bool readMatrix(core::matrix4& mat);
\r
158 bool readRGB(video::SColor& color);
\r
159 bool readRGBA(video::SColor& color);
\r
161 CSkinnedMesh* AnimatedMesh;
\r
166 // counter for number arrays in binary format
\r
167 u32 BinaryNumCount;
\r
171 CSkinnedMesh::SJoint *CurFrame;
\r
173 core::array<SXMesh*> Meshes;
\r
181 } // end namespace scene
\r
182 } // end namespace irr
\r