#ifndef __C_OBJ_MESH_FILE_LOADER_H_INCLUDED__
#define __C_OBJ_MESH_FILE_LOADER_H_INCLUDED__
#include "IMeshLoader.h"
#include "IFileSystem.h"
#include "ISceneManager.h"
#include "irrString.h"
#include "SMeshBuffer.h"
#include "irrMap.h"
namespace irr
{
namespace scene
{
class COBJMeshFileLoader : public IMeshLoader
{
public:
COBJMeshFileLoader(scene::ISceneManager* smgr, io::IFileSystem* fs);
virtual ~COBJMeshFileLoader();
virtual bool isALoadableFileExtension(const io::path& filename) const;
virtual IAnimatedMesh* createMesh(io::IReadFile* file);
private:
struct SObjMtl
{
SObjMtl() : Meshbuffer(0), Bumpiness (1.0f), Illumination(0),
RecalculateNormals(false)
{
Meshbuffer = new SMeshBuffer();
Meshbuffer->Material.Shininess = 0.0f;
Meshbuffer->Material.AmbientColor = video::SColorf(0.2f, 0.2f, 0.2f, 1.0f).toSColor();
Meshbuffer->Material.DiffuseColor = video::SColorf(0.8f, 0.8f, 0.8f, 1.0f).toSColor();
Meshbuffer->Material.SpecularColor = video::SColorf(1.0f, 1.0f, 1.0f, 1.0f).toSColor();
}
SObjMtl(const SObjMtl& o)
: Name(o.Name), Group(o.Group),
Bumpiness(o.Bumpiness), Illumination(o.Illumination),
RecalculateNormals(false)
{
Meshbuffer = new SMeshBuffer();
Meshbuffer->Material = o.Meshbuffer->Material;
}
core::map<video::S3DVertex, int> VertMap;
scene::SMeshBuffer *Meshbuffer;
core::stringc Name;
core::stringc Group;
f32 Bumpiness;
c8 Illumination;
bool RecalculateNormals;
};
const c8* readTextures(const c8* bufPtr, const c8* const bufEnd, SObjMtl* currMaterial, const io::path& relPath);
const c8* goFirstWord(const c8* buf, const c8* const bufEnd, bool acrossNewlines=true);
const c8* goNextWord(const c8* buf, const c8* const bufEnd, bool acrossNewlines=true);
const c8* goNextLine(const c8* buf, const c8* const bufEnd);
u32 copyWord(c8* outBuf, const c8* inBuf, u32 outBufLength, const c8* const pBufEnd);
core::stringc copyLine(const c8* inBuf, const c8* const bufEnd);
const c8* goAndCopyNextWord(c8* outBuf, const c8* inBuf, u32 outBufLength, const c8* const pBufEnd);
void readMTL(const c8* fileName, const io::path& relPath);
SObjMtl* findMtl(const core::stringc& mtlName, const core::stringc& grpName);
const c8* readColor(const c8* bufPtr, video::SColor& color, const c8* const pBufEnd);
const c8* readVec3(const c8* bufPtr, core::vector3df& vec, const c8* const pBufEnd);
const c8* readUV(const c8* bufPtr, core::vector2df& vec, const c8* const pBufEnd);
const c8* readBool(const c8* bufPtr, bool& tf, const c8* const bufEnd);
bool retrieveVertexIndices(c8* vertexData, s32* idx, const c8* bufEnd, u32 vbsize, u32 vtsize, u32 vnsize);
void cleanUp();
scene::ISceneManager* SceneManager;
io::IFileSystem* FileSystem;
core::array<SObjMtl*> Materials;
};
}
}
#endif