aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/irrlicht-1.8/source/Irrlicht/CXMeshFileLoader.h
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/CXMeshFileLoader.h198
1 files changed, 198 insertions, 0 deletions
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/CXMeshFileLoader.h b/libraries/irrlicht-1.8/source/Irrlicht/CXMeshFileLoader.h
new file mode 100644
index 0000000..67fb041
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/CXMeshFileLoader.h
@@ -0,0 +1,198 @@
1// Copyright (C) 2002-2012 Nikolaus Gebhardt
2// This file is part of the "Irrlicht Engine".
3// For conditions of distribution and use, see copyright notice in irrlicht.h
4
5#ifndef __C_X_MESH_FILE_LOADER_H_INCLUDED__
6#define __C_X_MESH_FILE_LOADER_H_INCLUDED__
7
8#include "IMeshLoader.h"
9#include "irrString.h"
10#include "CSkinnedMesh.h"
11
12
13namespace irr
14{
15namespace io
16{
17 class IFileSystem;
18 class IReadFile;
19} // end namespace io
20namespace scene
21{
22class IMeshManipulator;
23
24//! Meshloader capable of loading x meshes.
25class CXMeshFileLoader : public IMeshLoader
26{
27public:
28
29 //! Constructor
30 CXMeshFileLoader(scene::ISceneManager* smgr, io::IFileSystem* fs);
31
32 //! returns true if the file maybe is able to be loaded by this class
33 //! based on the file extension (e.g. ".cob")
34 virtual bool isALoadableFileExtension(const io::path& filename) const;
35
36 //! creates/loads an animated mesh from the file.
37 //! \return Pointer to the created mesh. Returns 0 if loading failed.
38 //! If you no longer need the mesh, you should call IAnimatedMesh::drop().
39 //! See IReferenceCounted::drop() for more information.
40 virtual IAnimatedMesh* createMesh(io::IReadFile* file);
41
42 struct SXTemplateMaterial
43 {
44 core::stringc Name; // template name from Xfile
45 video::SMaterial Material; // material
46 };
47
48 struct SXMesh
49 {
50 SXMesh() : MaxSkinWeightsPerVertex(0), MaxSkinWeightsPerFace(0), BoneCount(0),AttachedJointID(-1),HasSkinning(false), HasVertexColors(false) {}
51 // this mesh contains triangulated texture data.
52 // because in an .x file, faces can be made of more than 3
53 // vertices, the indices data structure is triangulated during the
54 // loading process. The IndexCountPerFace array is filled during
55 // this triangulation process and stores how much indices belong to
56 // every face. This data structure can be ignored, because all data
57 // in this structure is triangulated.
58
59 core::stringc Name;
60
61 u32 MaxSkinWeightsPerVertex;
62 u32 MaxSkinWeightsPerFace;
63 u32 BoneCount;
64
65 core::array<u16> IndexCountPerFace; // default 3, but could be more
66
67 core::array<scene::SSkinMeshBuffer*> Buffers;
68
69 core::array<video::S3DVertex> Vertices;
70 core::array<core::vector2df> TCoords2;
71
72 core::array<u32> Indices;
73
74 core::array<u32> FaceMaterialIndices; // index of material for each face
75
76 core::array<video::SMaterial> Materials; // material array
77
78 core::array<u32> WeightJoint;
79 core::array<u32> WeightNum;
80
81 s32 AttachedJointID;
82
83 bool HasSkinning;
84 bool HasVertexColors;
85 };
86
87private:
88
89 bool load(io::IReadFile* file);
90
91 bool readFileIntoMemory(io::IReadFile* file);
92
93 bool parseFile();
94
95 bool parseDataObject();
96
97 bool parseDataObjectTemplate();
98
99 bool parseDataObjectFrame(CSkinnedMesh::SJoint *parent);
100
101 bool parseDataObjectTransformationMatrix(core::matrix4 &mat);
102
103 bool parseDataObjectMesh(SXMesh &mesh);
104
105 bool parseDataObjectSkinWeights(SXMesh &mesh);
106
107 bool parseDataObjectSkinMeshHeader(SXMesh &mesh);
108
109 bool parseDataObjectMeshNormals(SXMesh &mesh);
110
111 bool parseDataObjectMeshTextureCoords(SXMesh &mesh);
112
113 bool parseDataObjectMeshVertexColors(SXMesh &mesh);
114
115 bool parseDataObjectMeshMaterialList(SXMesh &mesh);
116
117 bool parseDataObjectMaterial(video::SMaterial& material);
118
119 bool parseDataObjectAnimationSet();
120
121 bool parseDataObjectAnimation();
122
123 bool parseDataObjectAnimationKey(ISkinnedMesh::SJoint *joint);
124
125 bool parseDataObjectTextureFilename(core::stringc& texturename);
126
127 bool parseUnknownDataObject();
128
129 //! places pointer to next begin of a token, and ignores comments
130 void findNextNoneWhiteSpace();
131
132 //! places pointer to next begin of a token, which must be a number,
133 // and ignores comments
134 void findNextNoneWhiteSpaceNumber();
135
136 //! returns next parseable token. Returns empty string if no token there
137 core::stringc getNextToken();
138
139 //! reads header of dataobject including the opening brace.
140 //! returns false if error happened, and writes name of object
141 //! if there is one
142 bool readHeadOfDataObject(core::stringc* outname=0);
143
144 //! checks for closing curly brace, returns false if not there
145 bool checkForClosingBrace();
146
147 //! checks for one following semicolons, returns false if not there
148 bool checkForOneFollowingSemicolons();
149
150 //! checks for two following semicolons, returns false if they are not there
151 bool checkForTwoFollowingSemicolons();
152
153 //! reads a x file style string
154 bool getNextTokenAsString(core::stringc& out);
155
156 void readUntilEndOfLine();
157
158 u16 readBinWord();
159 u32 readBinDWord();
160 u32 readInt();
161 f32 readFloat();
162 bool readVector2(core::vector2df& vec);
163 bool readVector3(core::vector3df& vec);
164 bool readMatrix(core::matrix4& mat);
165 bool readRGB(video::SColor& color);
166 bool readRGBA(video::SColor& color);
167
168 ISceneManager* SceneManager;
169 io::IFileSystem* FileSystem;
170
171 core::array<CSkinnedMesh::SJoint*> *AllJoints;
172
173 CSkinnedMesh* AnimatedMesh;
174
175 c8* Buffer;
176 const c8* P;
177 c8* End;
178 // counter for number arrays in binary format
179 u32 BinaryNumCount;
180 u32 Line;
181 io::path FilePath;
182
183 CSkinnedMesh::SJoint *CurFrame;
184
185 core::array<SXMesh*> Meshes;
186
187 core::array<SXTemplateMaterial> TemplateMaterials;
188
189 u32 MajorVersion;
190 u32 MinorVersion;
191 bool BinaryFormat;
192 c8 FloatSize;
193};
194
195} // end namespace scene
196} // end namespace irr
197
198#endif