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