~baltix/+junk/irrlicht-test

« back to all changes in this revision

Viewing changes to source/Irrlicht/COgreMeshFileLoader.h

  • Committer: Mantas Kriaučiūnas
  • Date: 2011-07-18 13:06:25 UTC
  • Revision ID: mantas@akl.lt-20110718130625-c5pvifp61e7kj1ol
Included whole irrlicht SVN libraries to work around launchpad recipe issue with quilt, see https://answers.launchpad.net/launchpad/+question/165193

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
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
 
 
21
namespace irr
 
22
{
 
23
namespace scene
 
24
{
 
25
 
 
26
//! Meshloader capable of loading ogre meshes.
 
27
class COgreMeshFileLoader : public IMeshLoader
 
28
{
 
29
public:
 
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
 
 
47
private:
 
48
 
 
49
        // byte-align structures
 
50
        #if defined(_MSC_VER) ||  defined(__BORLANDC__) || defined (__BCPLUSPLUS__)
 
51
        #       pragma pack( push, packing )
 
52
        #       pragma pack( 1 )
 
53
        #       define PACK_STRUCT
 
54
        #elif defined( __GNUC__ )
 
55
        #       define PACK_STRUCT      __attribute__((packed))
 
56
        #else
 
57
        #       error compiler not supported
 
58
        #endif
 
59
 
 
60
        struct ChunkHeader
 
61
        {
 
62
                u16 id;
 
63
                u32 length;
 
64
        } PACK_STRUCT;
 
65
 
 
66
        // Default alignment
 
67
        #if defined(_MSC_VER) ||  defined(__BORLANDC__) || defined (__BCPLUSPLUS__)
 
68
        #       pragma pack( pop, packing )
 
69
        #endif
 
70
 
 
71
        #undef PACK_STRUCT
 
72
 
 
73
 
 
74
        struct ChunkData
 
75
        {
 
76
                ChunkData() : read(0) {}
 
77
 
 
78
                ChunkHeader header;
 
79
                u32 read;
 
80
        };
 
81
 
 
82
        struct OgreTexture
 
83
        {
 
84
                core::array<core::stringc> Filename;
 
85
                core::stringc Alias;
 
86
                core::stringc CoordsType;
 
87
                core::stringc MipMaps;
 
88
                core::stringc Alpha;
 
89
        };
 
90
 
 
91
        struct OgrePass
 
92
        {
 
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) {}
 
98
 
 
99
                video::SMaterial Material;
 
100
                OgreTexture Texture;
 
101
                bool AmbientTokenColor;
 
102
                bool DiffuseTokenColor;
 
103
                bool SpecularTokenColor;
 
104
                bool EmissiveTokenColor;
 
105
                u32 MaxLights;
 
106
                f32 PointSize;
 
107
                bool PointSprites;
 
108
                u32 PointSizeMin;
 
109
                u32 PointSizeMax;
 
110
        };
 
111
 
 
112
        struct OgreTechnique
 
113
        {
 
114
                OgreTechnique() : Name(""), LODIndex(0) {}
 
115
 
 
116
                core::stringc Name;
 
117
                core::stringc Scheme;
 
118
                u16 LODIndex;
 
119
                core::array<OgrePass> Passes;
 
120
        };
 
121
 
 
122
        struct OgreMaterial
 
123
        {
 
124
                OgreMaterial() : Name(""), ReceiveShadows(true),
 
125
                        TransparencyCastsShadows(false) {}
 
126
 
 
127
                core::stringc Name;
 
128
                bool ReceiveShadows;
 
129
                bool TransparencyCastsShadows;
 
130
                core::array<f32> LODDistances;
 
131
                core::array<OgreTechnique> Techniques;
 
132
        };
 
133
 
 
134
        struct OgreVertexBuffer
 
135
        {
 
136
                OgreVertexBuffer() : BindIndex(0), VertexSize(0), Data(0) {}
 
137
 
 
138
                u16 BindIndex;
 
139
                u16 VertexSize;
 
140
                core::array<f32> Data;
 
141
        };
 
142
 
 
143
        struct OgreVertexElement
 
144
        {
 
145
                u16 Source,
 
146
                Type,
 
147
                Semantic,
 
148
                Offset,
 
149
                Index;
 
150
        };
 
151
 
 
152
        struct OgreGeometry
 
153
        {
 
154
                s32 NumVertex;
 
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;
 
161
        };
 
162
 
 
163
        struct OgreTextureAlias
 
164
        {
 
165
                OgreTextureAlias() {};
 
166
                OgreTextureAlias(const core::stringc& a, const core::stringc& b) : Texture(a), Alias(b) {};
 
167
                core::stringc Texture;
 
168
                core::stringc Alias;
 
169
        };
 
170
 
 
171
        struct OgreBoneAssignment
 
172
        {
 
173
                s32 VertexID;
 
174
                u16 BoneID;
 
175
                f32 Weight;
 
176
        };
 
177
 
 
178
        struct OgreSubMesh
 
179
        {
 
180
                core::stringc Material;
 
181
                bool SharedVertices;
 
182
                core::array<s32> Indices;
 
183
                OgreGeometry Geometry;
 
184
                u16 Operation;
 
185
                core::array<OgreTextureAlias> TextureAliases;
 
186
                core::array<OgreBoneAssignment> BoneAssignments;
 
187
                bool Indices32Bit;
 
188
        };
 
189
 
 
190
        struct OgreMesh
 
191
        {
 
192
                bool SkeletalAnimation;
 
193
                OgreGeometry Geometry;
 
194
                core::array<OgreSubMesh> SubMeshes;
 
195
                core::array<OgreBoneAssignment> BoneAssignments;
 
196
                core::vector3df BBoxMinEdge;
 
197
                core::vector3df BBoxMaxEdge;
 
198
                f32 BBoxRadius;
 
199
        };
 
200
 
 
201
        struct OgreBone
 
202
        {
 
203
                core::stringc Name;
 
204
                core::vector3df Position;
 
205
                core::quaternion Orientation;
 
206
                core::vector3df Scale;
 
207
                u16 Handle;
 
208
                u16 Parent;
 
209
        };
 
210
 
 
211
        struct OgreKeyframe
 
212
        {
 
213
                u16 BoneID;
 
214
                f32 Time;
 
215
                core::vector3df Position;
 
216
                core::quaternion Orientation;
 
217
                core::vector3df Scale;
 
218
        };
 
219
 
 
220
        struct OgreAnimation
 
221
        {
 
222
                core::stringc Name;
 
223
                f32 Length;
 
224
                core::array<OgreKeyframe> Keyframes;
 
225
        };
 
226
 
 
227
        struct OgreSkeleton
 
228
        {
 
229
                core::array<OgreBone> Bones;
 
230
                core::array<OgreAnimation> Animations;
 
231
        };
 
232
 
 
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);
 
239
 
 
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);
 
248
 
 
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);
 
260
        void clearMeshes();
 
261
 
 
262
        io::IFileSystem* FileSystem;
 
263
        video::IVideoDriver* Driver;
 
264
 
 
265
        core::stringc Version;
 
266
        bool SwapEndian;
 
267
        core::array<OgreMesh> Meshes;
 
268
        io::path CurrentlyLoadingFromPath;
 
269
 
 
270
        core::array<OgreMaterial> Materials;
 
271
        OgreSkeleton Skeleton;
 
272
 
 
273
        IMesh* Mesh;
 
274
        u32 NumUV;
 
275
};
 
276
 
 
277
} // end namespace scene
 
278
} // end namespace irr
 
279
 
 
280
#endif
 
281