~baltix/+junk/irrlicht-test

« back to all changes in this revision

Viewing changes to source/Irrlicht/C3DSMeshFileLoader.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
 
 
5
#ifndef __C_3DS_MESH_FILE_LOADER_H_INCLUDED__
 
6
#define __C_3DS_MESH_FILE_LOADER_H_INCLUDED__
 
7
 
 
8
#include "IMeshLoader.h"
 
9
#include "IFileSystem.h"
 
10
#include "ISceneManager.h"
 
11
#include "irrString.h"
 
12
#include "SMesh.h"
 
13
#include "matrix4.h"
 
14
 
 
15
namespace irr
 
16
{
 
17
namespace scene
 
18
{
 
19
 
 
20
//! Meshloader capable of loading 3ds meshes.
 
21
class C3DSMeshFileLoader : public IMeshLoader
 
22
{
 
23
public:
 
24
 
 
25
        //! Constructor
 
26
        C3DSMeshFileLoader(ISceneManager* smgr, io::IFileSystem* fs);
 
27
 
 
28
        //! destructor
 
29
        virtual ~C3DSMeshFileLoader();
 
30
 
 
31
        //! returns true if the file maybe is able to be loaded by this class
 
32
        //! based on the file extension (e.g. ".cob")
 
33
        virtual bool isALoadableFileExtension(const io::path& filename) const;
 
34
 
 
35
        //! creates/loads an animated mesh from the file.
 
36
        //! \return Pointer to the created mesh. Returns 0 if loading failed.
 
37
        //! If you no longer need the mesh, you should call IAnimatedMesh::drop().
 
38
        //! See IReferenceCounted::drop() for more information.
 
39
        virtual IAnimatedMesh* createMesh(io::IReadFile* file);
 
40
 
 
41
private:
 
42
 
 
43
        // byte-align structures
 
44
        #if defined(_MSC_VER) ||  defined(__BORLANDC__) || defined (__BCPLUSPLUS__)
 
45
        #       pragma pack( push, packing )
 
46
        #       pragma pack( 1 )
 
47
        #       define PACK_STRUCT
 
48
        #elif defined( __GNUC__ )
 
49
        #       define PACK_STRUCT      __attribute__((packed))
 
50
        #else
 
51
        #       error compiler not supported
 
52
        #endif
 
53
 
 
54
        struct ChunkHeader
 
55
        {
 
56
                u16 id;
 
57
                s32 length;
 
58
        } PACK_STRUCT;
 
59
 
 
60
        // Default alignment
 
61
        #if defined(_MSC_VER) ||  defined(__BORLANDC__) || defined (__BCPLUSPLUS__)
 
62
        #       pragma pack( pop, packing )
 
63
        #endif
 
64
 
 
65
        #undef PACK_STRUCT
 
66
 
 
67
 
 
68
        struct ChunkData
 
69
        {
 
70
                ChunkData() : read(0) {}
 
71
 
 
72
                ChunkHeader header;
 
73
                s32 read;
 
74
        };
 
75
 
 
76
        struct SCurrentMaterial
 
77
        {
 
78
                void clear() {
 
79
                        Material=video::SMaterial();
 
80
                        Name="";
 
81
                        Filename[0]="";
 
82
                        Filename[1]="";
 
83
                        Filename[2]="";
 
84
                        Filename[3]="";
 
85
                        Filename[4]="";
 
86
                        Strength[0]=0.f;
 
87
                        Strength[1]=0.f;
 
88
                        Strength[2]=0.f;
 
89
                        Strength[3]=0.f;
 
90
                        Strength[4]=0.f;
 
91
                }
 
92
 
 
93
                video::SMaterial Material;
 
94
                core::stringc Name;
 
95
                core::stringc Filename[5];
 
96
                f32 Strength[5];
 
97
        };
 
98
 
 
99
        struct SMaterialGroup
 
100
        {
 
101
                SMaterialGroup() : faceCount(0), faces(0) {};
 
102
 
 
103
                SMaterialGroup(const SMaterialGroup& o)
 
104
                {
 
105
                        *this = o;
 
106
                }
 
107
 
 
108
                ~SMaterialGroup()
 
109
                {
 
110
                        clear();
 
111
                }
 
112
 
 
113
                void clear()
 
114
                {
 
115
                        delete [] faces;
 
116
                        faces = 0;
 
117
                        faceCount = 0;
 
118
                }
 
119
 
 
120
                void operator =(const SMaterialGroup& o)
 
121
                {
 
122
                        MaterialName = o.MaterialName;
 
123
                        faceCount = o.faceCount;
 
124
                        faces = new u16[faceCount];
 
125
                        for (u32 i=0; i<faceCount; ++i)
 
126
                                faces[i] = o.faces[i];
 
127
                }
 
128
 
 
129
                core::stringc MaterialName;
 
130
                u16 faceCount;
 
131
                u16* faces;
 
132
        };
 
133
 
 
134
        bool readChunk(io::IReadFile* file, ChunkData* parent);
 
135
        bool readMaterialChunk(io::IReadFile* file, ChunkData* parent);
 
136
        bool readFrameChunk(io::IReadFile* file, ChunkData* parent);
 
137
        bool readTrackChunk(io::IReadFile* file, ChunkData& data,
 
138
                                IMeshBuffer* mb, const core::vector3df& pivot);
 
139
        bool readObjectChunk(io::IReadFile* file, ChunkData* parent);
 
140
        bool readPercentageChunk(io::IReadFile* file, ChunkData* chunk, f32& percentage);
 
141
        bool readColorChunk(io::IReadFile* file, ChunkData* chunk, video::SColor& out);
 
142
 
 
143
        void readChunkData(io::IReadFile* file, ChunkData& data);
 
144
        void readString(io::IReadFile* file, ChunkData& data, core::stringc& out);
 
145
        void readVertices(io::IReadFile* file, ChunkData& data);
 
146
        void readIndices(io::IReadFile* file, ChunkData& data);
 
147
        void readMaterialGroup(io::IReadFile* file, ChunkData& data);
 
148
        void readTextureCoords(io::IReadFile* file, ChunkData& data);
 
149
 
 
150
        void composeObject(io::IReadFile* file, const core::stringc& name);
 
151
        void loadMaterials(io::IReadFile* file);
 
152
        void cleanUp();
 
153
 
 
154
        scene::ISceneManager* SceneManager;
 
155
        io::IFileSystem* FileSystem;
 
156
 
 
157
        f32* Vertices;
 
158
        u16* Indices;
 
159
        u32* SmoothingGroups;
 
160
        core::array<u16> TempIndices;
 
161
        f32* TCoords;
 
162
        u16 CountVertices;
 
163
        u16 CountFaces; // = CountIndices/4
 
164
        u16 CountTCoords;
 
165
        core::array<SMaterialGroup> MaterialGroups;
 
166
 
 
167
        SCurrentMaterial CurrentMaterial;
 
168
        core::array<SCurrentMaterial> Materials;
 
169
        core::array<core::stringc> MeshBufferNames;
 
170
        core::matrix4 TransformationMatrix;
 
171
 
 
172
        SMesh* Mesh;
 
173
};
 
174
 
 
175
} // end namespace scene
 
176
} // end namespace irr
 
177
 
 
178
#endif
 
179