aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/irrlicht-1.8/source/Irrlicht/COgreMeshFileLoader.h
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/irrlicht-1.8/source/Irrlicht/COgreMeshFileLoader.h')
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/COgreMeshFileLoader.h269
1 files changed, 269 insertions, 0 deletions
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/COgreMeshFileLoader.h b/libraries/irrlicht-1.8/source/Irrlicht/COgreMeshFileLoader.h
new file mode 100644
index 0000000..8179285
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/COgreMeshFileLoader.h
@@ -0,0 +1,269 @@
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// orginally written by Christian Stehno, modified by Nikolaus Gebhardt
5
6#ifndef __C_OGRE_MESH_FILE_LOADER_H_INCLUDED__
7#define __C_OGRE_MESH_FILE_LOADER_H_INCLUDED__
8
9#include "IMeshLoader.h"
10#include "IFileSystem.h"
11#include "IVideoDriver.h"
12#include "irrString.h"
13#include "SMesh.h"
14#include "SMeshBuffer.h"
15#include "SMeshBufferLightMap.h"
16#include "IMeshManipulator.h"
17#include "matrix4.h"
18#include "quaternion.h"
19#include "CSkinnedMesh.h"
20
21namespace irr
22{
23namespace scene
24{
25
26//! Meshloader capable of loading ogre meshes.
27class COgreMeshFileLoader : public IMeshLoader
28{
29public:
30
31 //! Constructor
32 COgreMeshFileLoader(io::IFileSystem* fs, video::IVideoDriver* driver);
33
34 //! destructor
35 virtual ~COgreMeshFileLoader();
36
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;
40
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);
46
47private:
48
49// byte-align structures
50#include "irrpack.h"
51
52 struct ChunkHeader
53 {
54 u16 id;
55 u32 length;
56 } PACK_STRUCT;
57
58// Default alignment
59#include "irrunpack.h"
60
61
62 struct ChunkData
63 {
64 ChunkData() : read(0) {}
65
66 ChunkHeader header;
67 u32 read;
68 };
69
70 struct OgreTexture
71 {
72 core::array<core::stringc> Filename;
73 core::stringc Alias;
74 core::stringc CoordsType;
75 core::stringc MipMaps;
76 core::stringc Alpha;
77 };
78
79 struct OgrePass
80 {
81 OgrePass() : AmbientTokenColor(false),
82 DiffuseTokenColor(false), SpecularTokenColor(false),
83 EmissiveTokenColor(false),
84 MaxLights(8), PointSize(1.0f), PointSprites(false),
85 PointSizeMin(0), PointSizeMax(0) {}
86
87 video::SMaterial Material;
88 OgreTexture Texture;
89 bool AmbientTokenColor;
90 bool DiffuseTokenColor;
91 bool SpecularTokenColor;
92 bool EmissiveTokenColor;
93 u32 MaxLights;
94 f32 PointSize;
95 bool PointSprites;
96 u32 PointSizeMin;
97 u32 PointSizeMax;
98 };
99
100 struct OgreTechnique
101 {
102 OgreTechnique() : Name(""), LODIndex(0) {}
103
104 core::stringc Name;
105 core::stringc Scheme;
106 u16 LODIndex;
107 core::array<OgrePass> Passes;
108 };
109
110 struct OgreMaterial
111 {
112 OgreMaterial() : Name(""), ReceiveShadows(true),
113 TransparencyCastsShadows(false) {}
114
115 core::stringc Name;
116 bool ReceiveShadows;
117 bool TransparencyCastsShadows;
118 core::array<f32> LODDistances;
119 core::array<OgreTechnique> Techniques;
120 };
121
122 struct OgreVertexBuffer
123 {
124 OgreVertexBuffer() : BindIndex(0), VertexSize(0), Data(0) {}
125
126 u16 BindIndex;
127 u16 VertexSize;
128 core::array<f32> Data;
129 };
130
131 struct OgreVertexElement
132 {
133 u16 Source,
134 Type,
135 Semantic,
136 Offset,
137 Index;
138 };
139
140 struct OgreGeometry
141 {
142 s32 NumVertex;
143 core::array<OgreVertexElement> Elements;
144 core::array<OgreVertexBuffer> Buffers;
145 core::array<core::vector3df> Vertices;
146 core::array<core::vector3df> Normals;
147 core::array<s32> Colors;
148 core::array<core::vector2df> TexCoords;
149 };
150
151 struct OgreTextureAlias
152 {
153 OgreTextureAlias() {};
154 OgreTextureAlias(const core::stringc& a, const core::stringc& b) : Texture(a), Alias(b) {};
155 core::stringc Texture;
156 core::stringc Alias;
157 };
158
159 struct OgreBoneAssignment
160 {
161 s32 VertexID;
162 u16 BoneID;
163 f32 Weight;
164 };
165
166 struct OgreSubMesh
167 {
168 core::stringc Material;
169 bool SharedVertices;
170 core::array<s32> Indices;
171 OgreGeometry Geometry;
172 u16 Operation;
173 core::array<OgreTextureAlias> TextureAliases;
174 core::array<OgreBoneAssignment> BoneAssignments;
175 bool Indices32Bit;
176 };
177
178 struct OgreMesh
179 {
180 bool SkeletalAnimation;
181 OgreGeometry Geometry;
182 core::array<OgreSubMesh> SubMeshes;
183 core::array<OgreBoneAssignment> BoneAssignments;
184 core::vector3df BBoxMinEdge;
185 core::vector3df BBoxMaxEdge;
186 f32 BBoxRadius;
187 };
188
189 struct OgreBone
190 {
191 core::stringc Name;
192 core::vector3df Position;
193 core::quaternion Orientation;
194 core::vector3df Scale;
195 u16 Handle;
196 u16 Parent;
197 };
198
199 struct OgreKeyframe
200 {
201 u16 BoneID;
202 f32 Time;
203 core::vector3df Position;
204 core::quaternion Orientation;
205 core::vector3df Scale;
206 };
207
208 struct OgreAnimation
209 {
210 core::stringc Name;
211 f32 Length;
212 core::array<OgreKeyframe> Keyframes;
213 };
214
215 struct OgreSkeleton
216 {
217 core::array<OgreBone> Bones;
218 core::array<OgreAnimation> Animations;
219 };
220
221 bool readChunk(io::IReadFile* file);
222 bool readObjectChunk(io::IReadFile* file, ChunkData& parent, OgreMesh& mesh);
223 bool readGeometry(io::IReadFile* file, ChunkData& parent, OgreGeometry& geometry);
224 bool readVertexDeclaration(io::IReadFile* file, ChunkData& parent, OgreGeometry& geometry);
225 bool readVertexBuffer(io::IReadFile* file, ChunkData& parent, OgreGeometry& geometry);
226 bool readSubMesh(io::IReadFile* file, ChunkData& parent, OgreSubMesh& subMesh);
227
228 void readChunkData(io::IReadFile* file, ChunkData& data);
229 void readString(io::IReadFile* file, ChunkData& data, core::stringc& out);
230 void readBool(io::IReadFile* file, ChunkData& data, bool& out);
231 void readInt(io::IReadFile* file, ChunkData& data, s32* out, u32 num=1);
232 void readShort(io::IReadFile* file, ChunkData& data, u16* out, u32 num=1);
233 void readFloat(io::IReadFile* file, ChunkData& data, f32* out, u32 num=1);
234 void readVector(io::IReadFile* file, ChunkData& data, core::vector3df& out);
235 void readQuaternion(io::IReadFile* file, ChunkData& data, core::quaternion& out);
236
237 void composeMeshBufferMaterial(scene::IMeshBuffer* mb, const core::stringc& materialName);
238 scene::SMeshBuffer* composeMeshBuffer(const core::array<s32>& indices, const OgreGeometry& geom);
239 scene::SMeshBufferLightMap* composeMeshBufferLightMap(const core::array<s32>& indices, const OgreGeometry& geom);
240 scene::IMeshBuffer* composeMeshBufferSkinned(scene::CSkinnedMesh& mesh, const core::array<s32>& indices, const OgreGeometry& geom);
241 void composeObject(void);
242 bool readColor(io::IReadFile* meshFile, video::SColor& col);
243 void getMaterialToken(io::IReadFile* file, core::stringc& token, bool noNewLine=false);
244 void readTechnique(io::IReadFile* meshFile, OgreMaterial& mat);
245 void readPass(io::IReadFile* file, OgreTechnique& technique);
246 void loadMaterials(io::IReadFile* file);
247 bool loadSkeleton(io::IReadFile* meshFile, const core::stringc& name);
248 void clearMeshes();
249
250 io::IFileSystem* FileSystem;
251 video::IVideoDriver* Driver;
252
253 core::stringc Version;
254 bool SwapEndian;
255 core::array<OgreMesh> Meshes;
256 io::path CurrentlyLoadingFromPath;
257
258 core::array<OgreMaterial> Materials;
259 OgreSkeleton Skeleton;
260
261 IMesh* Mesh;
262 u32 NumUV;
263};
264
265} // end namespace scene
266} // end namespace irr
267
268#endif
269