1
// Copyright (C) 2002-2011 Nikolaus Gebhardt
2
// This file is part of the "Irrlicht Engine".
3
// For conditions of distribution and use, see copyright notice in irrlicht.h
5
#ifndef __C_X_MESH_FILE_LOADER_H_INCLUDED__
6
#define __C_X_MESH_FILE_LOADER_H_INCLUDED__
8
#include "IMeshLoader.h"
10
#include "CSkinnedMesh.h"
22
class IMeshManipulator;
24
//! Meshloader capable of loading x meshes.
25
class CXMeshFileLoader : public IMeshLoader
30
CXMeshFileLoader(scene::ISceneManager* smgr, io::IFileSystem* fs);
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;
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);
42
struct SXTemplateMaterial
44
core::stringc Name; // template name from Xfile
45
video::SMaterial Material; // material
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.
61
u32 MaxSkinWeightsPerVertex;
62
u32 MaxSkinWeightsPerFace;
65
core::array<u16> IndexCountPerFace; // default 3, but could be more
67
core::array<scene::SSkinMeshBuffer*> Buffers;
69
core::array<video::S3DVertex> Vertices;
70
core::array<core::vector2df> TCoords2;
72
core::array<u32> Indices;
74
core::array<u32> FaceMaterialIndices; // index of material for each face
76
core::array<video::SMaterial> Materials; // material array
78
core::array<u32> WeightJoint;
79
core::array<u32> WeightNum;
89
bool load(io::IReadFile* file);
91
bool readFileIntoMemory(io::IReadFile* file);
95
bool parseDataObject();
97
bool parseDataObjectTemplate();
99
bool parseDataObjectFrame(CSkinnedMesh::SJoint *parent);
101
bool parseDataObjectTransformationMatrix(core::matrix4 &mat);
103
bool parseDataObjectMesh(SXMesh &mesh);
105
bool parseDataObjectSkinWeights(SXMesh &mesh);
107
bool parseDataObjectSkinMeshHeader(SXMesh &mesh);
109
bool parseDataObjectMeshNormals(SXMesh &mesh);
111
bool parseDataObjectMeshTextureCoords(SXMesh &mesh);
113
bool parseDataObjectMeshVertexColors(SXMesh &mesh);
115
bool parseDataObjectMeshMaterialList(SXMesh &mesh);
117
bool parseDataObjectMaterial(video::SMaterial& material);
119
bool parseDataObjectAnimationSet();
121
bool parseDataObjectAnimation();
123
bool parseDataObjectAnimationKey(ISkinnedMesh::SJoint *joint);
125
bool parseDataObjectTextureFilename(core::stringc& texturename);
127
bool parseUnknownDataObject();
129
//! places pointer to next begin of a token, and ignores comments
130
void findNextNoneWhiteSpace();
132
//! places pointer to next begin of a token, which must be a number,
133
// and ignores comments
134
void findNextNoneWhiteSpaceNumber();
136
//! returns next parseable token. Returns empty string if no token there
137
core::stringc getNextToken();
139
//! reads header of dataobject including the opening brace.
140
//! returns false if error happened, and writes name of object
142
bool readHeadOfDataObject(core::stringc* outname=0);
144
//! checks for closing curly brace, returns false if not there
145
bool checkForClosingBrace();
147
//! checks for one following semicolons, returns false if not there
148
bool checkForOneFollowingSemicolons();
150
//! checks for two following semicolons, returns false if they are not there
151
bool checkForTwoFollowingSemicolons();
153
//! reads a x file style string
154
bool getNextTokenAsString(core::stringc& out);
156
void readUntilEndOfLine();
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);
168
ISceneManager* SceneManager;
169
io::IFileSystem* FileSystem;
171
core::array<CSkinnedMesh::SJoint*> *AllJoints;
173
CSkinnedMesh* AnimatedMesh;
178
// counter for number arrays in binary format
183
CSkinnedMesh::SJoint *CurFrame;
185
core::array<SXMesh*> Meshes;
187
core::array<SXTemplateMaterial> TemplateMaterials;
195
} // end namespace scene
196
} // end namespace irr