diff options
Diffstat (limited to 'libraries/irrlicht-1.8.1/source/Irrlicht/COBJMeshFileLoader.h')
-rw-r--r-- | libraries/irrlicht-1.8.1/source/Irrlicht/COBJMeshFileLoader.h | 122 |
1 files changed, 122 insertions, 0 deletions
diff --git a/libraries/irrlicht-1.8.1/source/Irrlicht/COBJMeshFileLoader.h b/libraries/irrlicht-1.8.1/source/Irrlicht/COBJMeshFileLoader.h new file mode 100644 index 0000000..06e71d6 --- /dev/null +++ b/libraries/irrlicht-1.8.1/source/Irrlicht/COBJMeshFileLoader.h | |||
@@ -0,0 +1,122 @@ | |||
1 | // Copyright (C) 2002-2012 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_OBJ_MESH_FILE_LOADER_H_INCLUDED__ | ||
6 | #define __C_OBJ_MESH_FILE_LOADER_H_INCLUDED__ | ||
7 | |||
8 | #include "IMeshLoader.h" | ||
9 | #include "IFileSystem.h" | ||
10 | #include "ISceneManager.h" | ||
11 | #include "irrString.h" | ||
12 | #include "SMeshBuffer.h" | ||
13 | #include "irrMap.h" | ||
14 | |||
15 | namespace irr | ||
16 | { | ||
17 | namespace scene | ||
18 | { | ||
19 | |||
20 | //! Meshloader capable of loading obj meshes. | ||
21 | class COBJMeshFileLoader : public IMeshLoader | ||
22 | { | ||
23 | public: | ||
24 | |||
25 | //! Constructor | ||
26 | COBJMeshFileLoader(scene::ISceneManager* smgr, io::IFileSystem* fs); | ||
27 | |||
28 | //! destructor | ||
29 | virtual ~COBJMeshFileLoader(); | ||
30 | |||
31 | //! returns true if the file maybe is able to be loaded by this class | ||
32 | //! based on the file extension (e.g. ".obj") | ||
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 | struct SObjMtl | ||
44 | { | ||
45 | SObjMtl() : Meshbuffer(0), Bumpiness (1.0f), Illumination(0), | ||
46 | RecalculateNormals(false) | ||
47 | { | ||
48 | Meshbuffer = new SMeshBuffer(); | ||
49 | Meshbuffer->Material.Shininess = 0.0f; | ||
50 | Meshbuffer->Material.AmbientColor = video::SColorf(0.2f, 0.2f, 0.2f, 1.0f).toSColor(); | ||
51 | Meshbuffer->Material.DiffuseColor = video::SColorf(0.8f, 0.8f, 0.8f, 1.0f).toSColor(); | ||
52 | Meshbuffer->Material.SpecularColor = video::SColorf(1.0f, 1.0f, 1.0f, 1.0f).toSColor(); | ||
53 | } | ||
54 | |||
55 | SObjMtl(const SObjMtl& o) | ||
56 | : Name(o.Name), Group(o.Group), | ||
57 | Bumpiness(o.Bumpiness), Illumination(o.Illumination), | ||
58 | RecalculateNormals(false) | ||
59 | { | ||
60 | Meshbuffer = new SMeshBuffer(); | ||
61 | Meshbuffer->Material = o.Meshbuffer->Material; | ||
62 | } | ||
63 | |||
64 | core::map<video::S3DVertex, int> VertMap; | ||
65 | scene::SMeshBuffer *Meshbuffer; | ||
66 | core::stringc Name; | ||
67 | core::stringc Group; | ||
68 | f32 Bumpiness; | ||
69 | c8 Illumination; | ||
70 | bool RecalculateNormals; | ||
71 | }; | ||
72 | |||
73 | // helper method for material reading | ||
74 | const c8* readTextures(const c8* bufPtr, const c8* const bufEnd, SObjMtl* currMaterial, const io::path& relPath); | ||
75 | |||
76 | // returns a pointer to the first printable character available in the buffer | ||
77 | const c8* goFirstWord(const c8* buf, const c8* const bufEnd, bool acrossNewlines=true); | ||
78 | // returns a pointer to the first printable character after the first non-printable | ||
79 | const c8* goNextWord(const c8* buf, const c8* const bufEnd, bool acrossNewlines=true); | ||
80 | // returns a pointer to the next printable character after the first line break | ||
81 | const c8* goNextLine(const c8* buf, const c8* const bufEnd); | ||
82 | // copies the current word from the inBuf to the outBuf | ||
83 | u32 copyWord(c8* outBuf, const c8* inBuf, u32 outBufLength, const c8* const pBufEnd); | ||
84 | // copies the current line from the inBuf to the outBuf | ||
85 | core::stringc copyLine(const c8* inBuf, const c8* const bufEnd); | ||
86 | |||
87 | // combination of goNextWord followed by copyWord | ||
88 | const c8* goAndCopyNextWord(c8* outBuf, const c8* inBuf, u32 outBufLength, const c8* const pBufEnd); | ||
89 | |||
90 | //! Read the material from the given file | ||
91 | void readMTL(const c8* fileName, const io::path& relPath); | ||
92 | |||
93 | //! Find and return the material with the given name | ||
94 | SObjMtl* findMtl(const core::stringc& mtlName, const core::stringc& grpName); | ||
95 | |||
96 | //! Read RGB color | ||
97 | const c8* readColor(const c8* bufPtr, video::SColor& color, const c8* const pBufEnd); | ||
98 | //! Read 3d vector of floats | ||
99 | const c8* readVec3(const c8* bufPtr, core::vector3df& vec, const c8* const pBufEnd); | ||
100 | //! Read 2d vector of floats | ||
101 | const c8* readUV(const c8* bufPtr, core::vector2df& vec, const c8* const pBufEnd); | ||
102 | //! Read boolean value represented as 'on' or 'off' | ||
103 | const c8* readBool(const c8* bufPtr, bool& tf, const c8* const bufEnd); | ||
104 | |||
105 | // reads and convert to integer the vertex indices in a line of obj file's face statement | ||
106 | // -1 for the index if it doesn't exist | ||
107 | // indices are changed to 0-based index instead of 1-based from the obj file | ||
108 | bool retrieveVertexIndices(c8* vertexData, s32* idx, const c8* bufEnd, u32 vbsize, u32 vtsize, u32 vnsize); | ||
109 | |||
110 | void cleanUp(); | ||
111 | |||
112 | scene::ISceneManager* SceneManager; | ||
113 | io::IFileSystem* FileSystem; | ||
114 | |||
115 | core::array<SObjMtl*> Materials; | ||
116 | }; | ||
117 | |||
118 | } // end namespace scene | ||
119 | } // end namespace irr | ||
120 | |||
121 | #endif | ||
122 | |||