]> git.lizzy.rs Git - irrlicht.git/blob - source/Irrlicht/COBJMeshFileLoader.h
Reduce IrrCompileConfig usage to files that actually need it
[irrlicht.git] / source / Irrlicht / COBJMeshFileLoader.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 #ifndef __C_OBJ_MESH_FILE_LOADER_H_INCLUDED__\r
6 #define __C_OBJ_MESH_FILE_LOADER_H_INCLUDED__\r
7 \r
8 #include <map>\r
9 #include "IMeshLoader.h"\r
10 #include "IFileSystem.h"\r
11 #include "ISceneManager.h"\r
12 #include "irrString.h"\r
13 #include "SMeshBuffer.h"\r
14 \r
15 namespace irr\r
16 {\r
17 namespace scene\r
18 {\r
19 \r
20 //! Meshloader capable of loading obj meshes.\r
21 class COBJMeshFileLoader : public IMeshLoader\r
22 {\r
23 public:\r
24 \r
25         //! Constructor\r
26         COBJMeshFileLoader(scene::ISceneManager* smgr, io::IFileSystem* fs);\r
27 \r
28         //! destructor\r
29         virtual ~COBJMeshFileLoader();\r
30 \r
31         //! returns true if the file maybe is able to be loaded by this class\r
32         //! based on the file extension (e.g. ".obj")\r
33         bool isALoadableFileExtension(const io::path& filename) const override;\r
34 \r
35         //! creates/loads an animated mesh from the file.\r
36         //! \return Pointer to the created mesh. Returns 0 if loading failed.\r
37         //! If you no longer need the mesh, you should call IAnimatedMesh::drop().\r
38         //! See IReferenceCounted::drop() for more information.\r
39         IAnimatedMesh* createMesh(io::IReadFile* file) override;\r
40 \r
41 private:\r
42 \r
43         struct SObjMtl\r
44         {\r
45                 SObjMtl() : Meshbuffer(0), Bumpiness (1.0f), Illumination(0),\r
46                         RecalculateNormals(false)\r
47                 {\r
48                         Meshbuffer = new SMeshBuffer();\r
49                         Meshbuffer->Material.Shininess = 0.0f;\r
50                         Meshbuffer->Material.AmbientColor = video::SColorf(0.2f, 0.2f, 0.2f, 1.0f).toSColor();\r
51                         Meshbuffer->Material.DiffuseColor = video::SColorf(0.8f, 0.8f, 0.8f, 1.0f).toSColor();\r
52                         Meshbuffer->Material.SpecularColor = video::SColorf(1.0f, 1.0f, 1.0f, 1.0f).toSColor();\r
53                 }\r
54 \r
55                 SObjMtl(const SObjMtl& o)\r
56                         : Name(o.Name), Group(o.Group),\r
57                         Bumpiness(o.Bumpiness), Illumination(o.Illumination),\r
58                         RecalculateNormals(false)\r
59                 {\r
60                         Meshbuffer = new SMeshBuffer();\r
61                         Meshbuffer->Material = o.Meshbuffer->Material;\r
62                 }\r
63 \r
64                 std::map<video::S3DVertex, int> VertMap;\r
65                 scene::SMeshBuffer *Meshbuffer;\r
66                 core::stringc Name;\r
67                 core::stringc Group;\r
68                 f32 Bumpiness;\r
69                 c8 Illumination;\r
70                 bool RecalculateNormals;\r
71         };\r
72 \r
73         // returns a pointer to the first printable character available in the buffer\r
74         const c8* goFirstWord(const c8* buf, const c8* const bufEnd, bool acrossNewlines=true);\r
75         // returns a pointer to the first printable character after the first non-printable\r
76         const c8* goNextWord(const c8* buf, const c8* const bufEnd, bool acrossNewlines=true);\r
77         // returns a pointer to the next printable character after the first line break\r
78         const c8* goNextLine(const c8* buf, const c8* const bufEnd);\r
79         // copies the current word from the inBuf to the outBuf\r
80         u32 copyWord(c8* outBuf, const c8* inBuf, u32 outBufLength, const c8* const pBufEnd);\r
81         // copies the current line from the inBuf to the outBuf\r
82         core::stringc copyLine(const c8* inBuf, const c8* const bufEnd);\r
83 \r
84         // combination of goNextWord followed by copyWord\r
85         const c8* goAndCopyNextWord(c8* outBuf, const c8* inBuf, u32 outBufLength, const c8* const pBufEnd);\r
86 \r
87         //! Find and return the material with the given name\r
88         SObjMtl* findMtl(const core::stringc& mtlName, const core::stringc& grpName);\r
89 \r
90         //! Read RGB color\r
91         const c8* readColor(const c8* bufPtr, video::SColor& color, const c8* const pBufEnd);\r
92         //! Read 3d vector of floats\r
93         const c8* readVec3(const c8* bufPtr, core::vector3df& vec, const c8* const pBufEnd);\r
94         //! Read 2d vector of floats\r
95         const c8* readUV(const c8* bufPtr, core::vector2df& vec, const c8* const pBufEnd);\r
96         //! Read boolean value represented as 'on' or 'off'\r
97         const c8* readBool(const c8* bufPtr, bool& tf, const c8* const bufEnd);\r
98 \r
99         // reads and convert to integer the vertex indices in a line of obj file's face statement\r
100         // -1 for the index if it doesn't exist\r
101         // indices are changed to 0-based index instead of 1-based from the obj file\r
102         bool retrieveVertexIndices(c8* vertexData, s32* idx, const c8* bufEnd, u32 vbsize, u32 vtsize, u32 vnsize);\r
103 \r
104         void cleanUp();\r
105 \r
106         scene::ISceneManager* SceneManager;\r
107         io::IFileSystem* FileSystem;\r
108 \r
109         core::array<SObjMtl*> Materials;\r
110 };\r
111 \r
112 } // end namespace scene\r
113 } // end namespace irr\r
114 \r
115 #endif\r
116 \r