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
4
// orginally written by Christian Stehno, modified by Nikolaus Gebhardt
6
#ifndef __C_OGRE_MESH_FILE_LOADER_H_INCLUDED__
7
#define __C_OGRE_MESH_FILE_LOADER_H_INCLUDED__
9
#include "IMeshLoader.h"
10
#include "IFileSystem.h"
11
#include "IVideoDriver.h"
12
#include "irrString.h"
14
#include "SMeshBuffer.h"
15
#include "SMeshBufferLightMap.h"
16
#include "IMeshManipulator.h"
18
#include "quaternion.h"
19
#include "CSkinnedMesh.h"
26
//! Meshloader capable of loading ogre meshes.
27
class COgreMeshFileLoader : public IMeshLoader
32
COgreMeshFileLoader(io::IFileSystem* fs, video::IVideoDriver* driver);
35
virtual ~COgreMeshFileLoader();
37
//! returns true if the file maybe is able to be loaded by this class
38
//! based on the file extension (e.g. ".cob")
39
virtual bool isALoadableFileExtension(const io::path& filename) const;
41
//! creates/loads an animated mesh from the file.
42
//! \return Pointer to the created mesh. Returns 0 if loading failed.
43
//! If you no longer need the mesh, you should call IAnimatedMesh::drop().
44
//! See IReferenceCounted::drop() for more information.
45
virtual IAnimatedMesh* createMesh(io::IReadFile* file);
49
// byte-align structures
50
#if defined(_MSC_VER) || defined(__BORLANDC__) || defined (__BCPLUSPLUS__)
51
# pragma pack( push, packing )
54
#elif defined( __GNUC__ )
55
# define PACK_STRUCT __attribute__((packed))
57
# error compiler not supported
67
#if defined(_MSC_VER) || defined(__BORLANDC__) || defined (__BCPLUSPLUS__)
68
# pragma pack( pop, packing )
76
ChunkData() : read(0) {}
84
core::array<core::stringc> Filename;
86
core::stringc CoordsType;
87
core::stringc MipMaps;
93
OgrePass() : AmbientTokenColor(false),
94
DiffuseTokenColor(false), SpecularTokenColor(false),
95
EmissiveTokenColor(false),
96
MaxLights(8), PointSize(1.0f), PointSprites(false),
97
PointSizeMin(0), PointSizeMax(0) {}
99
video::SMaterial Material;
101
bool AmbientTokenColor;
102
bool DiffuseTokenColor;
103
bool SpecularTokenColor;
104
bool EmissiveTokenColor;
114
OgreTechnique() : Name(""), LODIndex(0) {}
117
core::stringc Scheme;
119
core::array<OgrePass> Passes;
124
OgreMaterial() : Name(""), ReceiveShadows(true),
125
TransparencyCastsShadows(false) {}
129
bool TransparencyCastsShadows;
130
core::array<f32> LODDistances;
131
core::array<OgreTechnique> Techniques;
134
struct OgreVertexBuffer
136
OgreVertexBuffer() : BindIndex(0), VertexSize(0), Data(0) {}
140
core::array<f32> Data;
143
struct OgreVertexElement
155
core::array<OgreVertexElement> Elements;
156
core::array<OgreVertexBuffer> Buffers;
157
core::array<core::vector3df> Vertices;
158
core::array<core::vector3df> Normals;
159
core::array<s32> Colors;
160
core::array<core::vector2df> TexCoords;
163
struct OgreTextureAlias
165
OgreTextureAlias() {};
166
OgreTextureAlias(const core::stringc& a, const core::stringc& b) : Texture(a), Alias(b) {};
167
core::stringc Texture;
171
struct OgreBoneAssignment
180
core::stringc Material;
182
core::array<s32> Indices;
183
OgreGeometry Geometry;
185
core::array<OgreTextureAlias> TextureAliases;
186
core::array<OgreBoneAssignment> BoneAssignments;
192
bool SkeletalAnimation;
193
OgreGeometry Geometry;
194
core::array<OgreSubMesh> SubMeshes;
195
core::array<OgreBoneAssignment> BoneAssignments;
196
core::vector3df BBoxMinEdge;
197
core::vector3df BBoxMaxEdge;
204
core::vector3df Position;
205
core::quaternion Orientation;
206
core::vector3df Scale;
215
core::vector3df Position;
216
core::quaternion Orientation;
217
core::vector3df Scale;
224
core::array<OgreKeyframe> Keyframes;
229
core::array<OgreBone> Bones;
230
core::array<OgreAnimation> Animations;
233
bool readChunk(io::IReadFile* file);
234
bool readObjectChunk(io::IReadFile* file, ChunkData& parent, OgreMesh& mesh);
235
bool readGeometry(io::IReadFile* file, ChunkData& parent, OgreGeometry& geometry);
236
bool readVertexDeclaration(io::IReadFile* file, ChunkData& parent, OgreGeometry& geometry);
237
bool readVertexBuffer(io::IReadFile* file, ChunkData& parent, OgreGeometry& geometry);
238
bool readSubMesh(io::IReadFile* file, ChunkData& parent, OgreSubMesh& subMesh);
240
void readChunkData(io::IReadFile* file, ChunkData& data);
241
void readString(io::IReadFile* file, ChunkData& data, core::stringc& out);
242
void readBool(io::IReadFile* file, ChunkData& data, bool& out);
243
void readInt(io::IReadFile* file, ChunkData& data, s32* out, u32 num=1);
244
void readShort(io::IReadFile* file, ChunkData& data, u16* out, u32 num=1);
245
void readFloat(io::IReadFile* file, ChunkData& data, f32* out, u32 num=1);
246
void readVector(io::IReadFile* file, ChunkData& data, core::vector3df& out);
247
void readQuaternion(io::IReadFile* file, ChunkData& data, core::quaternion& out);
249
void composeMeshBufferMaterial(scene::IMeshBuffer* mb, const core::stringc& materialName);
250
scene::SMeshBuffer* composeMeshBuffer(const core::array<s32>& indices, const OgreGeometry& geom);
251
scene::SMeshBufferLightMap* composeMeshBufferLightMap(const core::array<s32>& indices, const OgreGeometry& geom);
252
scene::IMeshBuffer* composeMeshBufferSkinned(scene::CSkinnedMesh& mesh, const core::array<s32>& indices, const OgreGeometry& geom);
253
void composeObject(void);
254
bool readColor(io::IReadFile* meshFile, video::SColor& col);
255
void getMaterialToken(io::IReadFile* file, core::stringc& token, bool noNewLine=false);
256
void readTechnique(io::IReadFile* meshFile, OgreMaterial& mat);
257
void readPass(io::IReadFile* file, OgreTechnique& technique);
258
void loadMaterials(io::IReadFile* file);
259
bool loadSkeleton(io::IReadFile* meshFile, const core::stringc& name);
262
io::IFileSystem* FileSystem;
263
video::IVideoDriver* Driver;
265
core::stringc Version;
267
core::array<OgreMesh> Meshes;
268
io::path CurrentlyLoadingFromPath;
270
core::array<OgreMaterial> Materials;
271
OgreSkeleton Skeleton;
277
} // end namespace scene
278
} // end namespace irr