]> git.lizzy.rs Git - irrlicht.git/blob - source/Irrlicht/CXMeshFileLoader.h
cfedfd04be9b049420fea9a16ffb300597cac510
[irrlicht.git] / source / Irrlicht / CXMeshFileLoader.h
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
4 \r
5 #ifndef __C_X_MESH_FILE_LOADER_H_INCLUDED__\r
6 #define __C_X_MESH_FILE_LOADER_H_INCLUDED__\r
7 \r
8 #include "IMeshLoader.h"\r
9 #include "irrString.h"\r
10 #include "CSkinnedMesh.h"\r
11 \r
12 \r
13 namespace irr\r
14 {\r
15 namespace io\r
16 {\r
17         class IFileSystem;\r
18         class IReadFile;\r
19 } // end namespace io\r
20 namespace scene\r
21 {\r
22 class IMeshManipulator;\r
23 \r
24 //! Meshloader capable of loading x meshes.\r
25 class CXMeshFileLoader : public IMeshLoader\r
26 {\r
27 public:\r
28 \r
29         //! Constructor\r
30         CXMeshFileLoader(scene::ISceneManager* smgr, io::IFileSystem* fs);\r
31 \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
35 \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
41 \r
42         struct SXMesh\r
43         {\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
52 \r
53                 core::stringc Name;\r
54 \r
55                 u32 MaxSkinWeightsPerVertex;\r
56                 u32 MaxSkinWeightsPerFace;\r
57                 u32 BoneCount;\r
58 \r
59                 core::array<u16> IndexCountPerFace; // default 3, but could be more\r
60 \r
61                 core::array<scene::SSkinMeshBuffer*> Buffers;\r
62 \r
63                 core::array<video::S3DVertex> Vertices;\r
64                 core::array<core::vector2df> TCoords2;\r
65 \r
66                 core::array<u32> Indices;\r
67 \r
68                 core::array<u32> FaceMaterialIndices; // index of material for each face\r
69 \r
70                 core::array<video::SMaterial> Materials; // material array\r
71 \r
72                 core::array<u32> WeightJoint;\r
73                 core::array<u32> WeightNum;\r
74 \r
75                 s32 AttachedJointID;\r
76 \r
77                 bool HasSkinning;\r
78                 bool HasVertexColors;\r
79         };\r
80 \r
81 private:\r
82 \r
83         bool load(io::IReadFile* file);\r
84 \r
85         bool readFileIntoMemory(io::IReadFile* file);\r
86 \r
87         bool parseFile();\r
88 \r
89         bool parseDataObject();\r
90 \r
91         bool parseDataObjectTemplate();\r
92 \r
93         bool parseDataObjectFrame(CSkinnedMesh::SJoint *parent);\r
94 \r
95         bool parseDataObjectTransformationMatrix(core::matrix4 &mat);\r
96 \r
97         bool parseDataObjectMesh(SXMesh &mesh);\r
98 \r
99         bool parseDataObjectSkinWeights(SXMesh &mesh);\r
100 \r
101         bool parseDataObjectSkinMeshHeader(SXMesh &mesh);\r
102 \r
103         bool parseDataObjectMeshNormals(SXMesh &mesh);\r
104 \r
105         bool parseDataObjectMeshTextureCoords(SXMesh &mesh);\r
106 \r
107         bool parseDataObjectMeshVertexColors(SXMesh &mesh);\r
108 \r
109         bool parseDataObjectMeshMaterialList(SXMesh &mesh);\r
110 \r
111         bool parseDataObjectAnimationSet();\r
112 \r
113         bool parseDataObjectAnimationTicksPerSecond();\r
114 \r
115         bool parseDataObjectAnimation();\r
116 \r
117         bool parseDataObjectAnimationKey(ISkinnedMesh::SJoint *joint);\r
118 \r
119         bool parseDataObjectTextureFilename(core::stringc& texturename);\r
120 \r
121         bool parseUnknownDataObject();\r
122 \r
123         //! places pointer to next begin of a token, and ignores comments\r
124         void findNextNoneWhiteSpace();\r
125 \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
129 \r
130         //! returns next parseable token. Returns empty string if no token there\r
131         core::stringc getNextToken();\r
132 \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
137 \r
138         //! checks for closing curly brace, returns false if not there\r
139         bool checkForClosingBrace();\r
140 \r
141         //! checks for one following semicolons, returns false if not there\r
142         bool checkForOneFollowingSemicolons();\r
143 \r
144         //! checks for two following semicolons, returns false if they are not there\r
145         bool checkForTwoFollowingSemicolons();\r
146 \r
147         //! reads a x file style string\r
148         bool getNextTokenAsString(core::stringc& out);\r
149 \r
150         void readUntilEndOfLine();\r
151 \r
152         u16 readBinWord();\r
153         u32 readBinDWord();\r
154         u32 readInt();\r
155         f32 readFloat();\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
161 \r
162         CSkinnedMesh* AnimatedMesh;\r
163 \r
164         c8* Buffer;\r
165         const c8* P;\r
166         c8* End;\r
167         // counter for number arrays in binary format\r
168         u32 BinaryNumCount;\r
169         u32 Line;\r
170         io::path FilePath;\r
171 \r
172         CSkinnedMesh::SJoint *CurFrame;\r
173 \r
174         core::array<SXMesh*> Meshes;\r
175 \r
176         u32 MajorVersion;\r
177         u32 MinorVersion;\r
178         bool BinaryFormat;\r
179         c8 FloatSize;\r
180 };\r
181 \r
182 } // end namespace scene\r
183 } // end namespace irr\r
184 \r
185 #endif\r