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
5 #ifndef __C_OBJ_MESH_FILE_LOADER_H_INCLUDED__
\r
6 #define __C_OBJ_MESH_FILE_LOADER_H_INCLUDED__
\r
9 #include "IMeshLoader.h"
\r
10 #include "ISceneManager.h"
\r
11 #include "irrString.h"
\r
12 #include "SMeshBuffer.h"
\r
19 //! Meshloader capable of loading obj meshes.
\r
20 class COBJMeshFileLoader : public IMeshLoader
\r
25 COBJMeshFileLoader(scene::ISceneManager* smgr);
\r
28 virtual ~COBJMeshFileLoader();
\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
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
44 SObjMtl() : Meshbuffer(0), Bumpiness (1.0f), Illumination(0),
\r
45 RecalculateNormals(false)
\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
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
59 Meshbuffer = new SMeshBuffer();
\r
60 Meshbuffer->Material = o.Meshbuffer->Material;
\r
63 std::map<video::S3DVertex, int> VertMap;
\r
64 scene::SMeshBuffer *Meshbuffer;
\r
66 core::stringc Group;
\r
69 bool RecalculateNormals;
\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
83 // combination of goNextWord followed by copyWord
\r
84 const c8* goAndCopyNextWord(c8* outBuf, const c8* inBuf, u32 outBufLength, const c8* const pBufEnd);
\r
86 //! Find and return the material with the given name
\r
87 SObjMtl* findMtl(const core::stringc& mtlName, const core::stringc& grpName);
\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
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
105 scene::ISceneManager* SceneManager;
\r
107 core::array<SObjMtl*> Materials;
\r
110 } // end namespace scene
\r
111 } // end namespace irr
\r