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