]> git.lizzy.rs Git - irrlicht.git/blob - source/Irrlicht/CMY3DMeshFileLoader.h
Merging r6075 through r6106 from trunk to ogl-es branch.
[irrlicht.git] / source / Irrlicht / CMY3DMeshFileLoader.h
1 // Copyright (C) 2002-2012 Nikolaus Gebhardt\r
2 // This file is part of the "Irrlicht Engine".\r
3 // For conditions of distribution and use, see copyright notice in irrlicht.h\r
4 //\r
5 // This file was originally written by ZDimitor.\r
6 // I (Nikolaus Gebhardt) did some few changes to this:\r
7 // - replaced logging calls to their os:: counterparts\r
8 // - removed some logging calls\r
9 // - removed setTexture path and replaced it with the directory of the mesh\r
10 // - added EAMT_MY3D file type\r
11 // - fixed a memory leak when decompressing RLE data.\r
12 // - cleaned multi character constant problems with gcc\r
13 // - removed octree child scene node generation because irrlicht is now able to draw\r
14 //   scene nodes with transparent and sold materials in them at the same time. (see changes.txt)\r
15 // Thanks a lot to ZDimitor for his work on this and that he gave me\r
16 // his permission to add it into Irrlicht.\r
17 \r
18 //--------------------------------------------------------------------------------\r
19 // This tool created by ZDimitor everyone can use it as wants\r
20 //--------------------------------------------------------------------------------\r
21 \r
22 #ifndef __CMY3D_MESH_FILE_LOADER_H_INCLUDED__\r
23 #define __CMY3D_MESH_FILE_LOADER_H_INCLUDED__\r
24 \r
25 \r
26 #ifdef _MSC_VER\r
27 #pragma once\r
28 #endif\r
29 \r
30 \r
31 #include "IMeshLoader.h"\r
32 #include "SMesh.h"\r
33 #include "SMeshBufferLightMap.h"\r
34 #include "IFileSystem.h"\r
35 #include "IVideoDriver.h"\r
36 #include "irrString.h"\r
37 #include "ISceneManager.h"\r
38 \r
39 namespace irr\r
40 {\r
41 namespace scene\r
42 {\r
43 \r
44 // byte-align structures\r
45 #include "irrpack.h"\r
46 \r
47 struct SMyColor\r
48 {   SMyColor () {;}\r
49     SMyColor (s32 __R, s32 __G, s32 __B, s32 __A)\r
50         : R(__R), G(__G), B(__B), A(__A) {}\r
51     s32 R, G, B, A;\r
52 } PACK_STRUCT;\r
53 \r
54 // material header\r
55 struct SMyMaterialHeader\r
56 {   c8  Name[256];           // material name\r
57     u32 Index;\r
58     SMyColor AmbientColor;\r
59     SMyColor DiffuseColor;\r
60     SMyColor EmissiveColor;\r
61     SMyColor SpecularColor;\r
62     f32 Shininess;\r
63     f32 Transparency;\r
64     u32 TextureCount;        // texture count\r
65 } PACK_STRUCT;\r
66 \r
67 // Default alignment\r
68 #include "irrunpack.h"\r
69 \r
70 class CMY3DMeshFileLoader : public IMeshLoader\r
71 {\r
72 public:\r
73         CMY3DMeshFileLoader(ISceneManager *scmgr, io::IFileSystem* fs);\r
74         virtual ~CMY3DMeshFileLoader();\r
75 \r
76         virtual bool isALoadableFileExtension(const io::path& filename) const _IRR_OVERRIDE_;\r
77 \r
78         virtual IAnimatedMesh* createMesh(io::IReadFile* file) _IRR_OVERRIDE_;\r
79 \r
80         //! getting access to the nodes (with transparent material), creating\r
81         //! while loading .my3d file\r
82         const core::array<ISceneNode*>& getChildNodes() const;\r
83 \r
84 private:\r
85 \r
86         video::ITexture* readEmbeddedLightmap(io::IReadFile* file, char* namebuf);\r
87 \r
88         scene::ISceneManager* SceneManager;\r
89         io::IFileSystem* FileSystem;\r
90 \r
91         struct SMyMaterialEntry\r
92         {\r
93                 SMyMaterialEntry ()\r
94                 : Texture1FileName("null"), Texture2FileName("null"),\r
95                 Texture1(0), Texture2(0), MaterialType(video::EMT_SOLID) {\r
96                         Header.Name[0] = 0;\r
97                 }\r
98 \r
99                 SMyMaterialHeader Header;\r
100                 core::stringc Texture1FileName;\r
101                 core::stringc Texture2FileName;\r
102                 video::ITexture *Texture1;\r
103                 video::ITexture *Texture2;\r
104                 video::E_MATERIAL_TYPE MaterialType;\r
105         };\r
106 \r
107         struct SMyMeshBufferEntry\r
108         {\r
109                 SMyMeshBufferEntry() : MaterialIndex(-1), MeshBuffer(0) {}\r
110                 SMyMeshBufferEntry(s32 mi, SMeshBufferLightMap* mb)\r
111                         : MaterialIndex(mi), MeshBuffer(mb) {}\r
112 \r
113                 s32 MaterialIndex;\r
114                 SMeshBufferLightMap* MeshBuffer;\r
115         };\r
116 \r
117         SMyMaterialEntry*    getMaterialEntryByIndex     (u32 matInd);\r
118         SMeshBufferLightMap* getMeshBufferByMaterialIndex(u32 matInd);\r
119 \r
120         core::array<SMyMaterialEntry>   MaterialEntry;\r
121         core::array<SMyMeshBufferEntry> MeshBufferEntry;\r
122 \r
123         core::array<ISceneNode*> ChildNodes;\r
124 };\r
125 \r
126 \r
127 } // end namespace scene\r
128 } // end namespace irr\r
129 \r
130 \r
131 #endif // __CMY3D_MESH_FILE_LOADER_H_INCLUDED__\r