2007-05-20 11:03:49 -07:00
|
|
|
// Copyright (C) 2002-2007 Nikolaus Gebhardt
|
|
|
|
// This file is part of the "Irrlicht Engine".
|
|
|
|
// For conditions of distribution and use, see copyright notice in irrlicht.h
|
|
|
|
|
|
|
|
#ifndef __C_OBJ_MESH_FILE_LOADER_H_INCLUDED__
|
|
|
|
#define __C_OBJ_MESH_FILE_LOADER_H_INCLUDED__
|
|
|
|
|
|
|
|
#include "IMeshLoader.h"
|
|
|
|
#include "IFileSystem.h"
|
|
|
|
#include "IVideoDriver.h"
|
|
|
|
#include "irrString.h"
|
|
|
|
#include "SMeshBuffer.h"
|
|
|
|
|
|
|
|
namespace irr
|
|
|
|
{
|
|
|
|
namespace scene
|
|
|
|
{
|
|
|
|
|
2007-09-19 07:08:28 -07:00
|
|
|
//! Meshloader capable of loading obj meshes.
|
2007-05-20 11:03:49 -07:00
|
|
|
class COBJMeshFileLoader : public IMeshLoader
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
//! Constructor
|
|
|
|
COBJMeshFileLoader(io::IFileSystem* fs, video::IVideoDriver* driver);
|
|
|
|
|
|
|
|
//! destructor
|
|
|
|
virtual ~COBJMeshFileLoader();
|
|
|
|
|
|
|
|
//! returns true if the file maybe is able to be loaded by this class
|
2007-09-19 07:08:28 -07:00
|
|
|
//! based on the file extension (e.g. ".obj")
|
2007-09-16 16:41:55 -07:00
|
|
|
virtual bool isALoadableFileExtension(const c8* fileName) const;
|
2007-05-20 11:03:49 -07:00
|
|
|
|
|
|
|
//! creates/loads an animated mesh from the file.
|
|
|
|
//! \return Pointer to the created mesh. Returns 0 if loading failed.
|
|
|
|
//! If you no longer need the mesh, you should call IAnimatedMesh::drop().
|
2007-09-06 23:11:47 -07:00
|
|
|
//! See IReferenceCounted::drop() for more information.
|
2007-09-19 07:08:28 -07:00
|
|
|
virtual IAnimatedMesh* createMesh(io::IReadFile* file);
|
2007-05-20 11:03:49 -07:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
struct SObjMtl
|
|
|
|
{
|
2008-01-13 16:23:02 -08:00
|
|
|
SObjMtl() : Meshbuffer(0), Illumination(0) {
|
2007-09-19 07:08:28 -07:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2008-01-13 16:23:02 -08:00
|
|
|
SObjMtl(SObjMtl& o) : Meshbuffer(o.Meshbuffer), Name(o.Name), Illumination(o.Illumination) { o.Meshbuffer->grab(); }
|
2007-09-19 07:08:28 -07:00
|
|
|
|
|
|
|
scene::SMeshBuffer *Meshbuffer;
|
2008-01-13 16:23:02 -08:00
|
|
|
core::stringc Name;
|
|
|
|
c8 Illumination;
|
2007-05-20 11:03:49 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
// returns a pointer to the first printable character available in the buffer
|
2008-01-13 16:23:02 -08:00
|
|
|
const c8* goFirstWord(const c8* buf, const c8* const bufEnd);
|
2007-05-20 11:03:49 -07:00
|
|
|
// returns a pointer to the first printable character after the first non-printable
|
2008-01-13 16:23:02 -08:00
|
|
|
const c8* goNextWord(const c8* buf, const c8* const bufEnd);
|
2007-05-20 11:03:49 -07:00
|
|
|
// returns a pointer to the next printable character after the first line break
|
2008-01-13 16:23:02 -08:00
|
|
|
const c8* goNextLine(const c8* buf, const c8* const bufEnd);
|
2007-05-20 11:03:49 -07:00
|
|
|
// copies the current word from the inBuf to the outBuf
|
|
|
|
u32 copyWord(c8* outBuf, const c8* inBuf, u32 outBufLength, const c8* const pBufEnd);
|
|
|
|
// copies the current line from the inBuf to the outBuf
|
2008-01-13 16:23:02 -08:00
|
|
|
core::stringc copyLine(const c8* inBuf, const c8* const bufEnd);
|
2007-05-20 11:03:49 -07:00
|
|
|
// combination of goNextWord followed by copyWord
|
|
|
|
const c8* goAndCopyNextWord(c8* outBuf, const c8* inBuf, u32 outBufLength, const c8* const pBufEnd);
|
|
|
|
|
2007-08-13 16:28:44 -07:00
|
|
|
//! Read the material from the given file
|
2008-01-13 16:23:02 -08:00
|
|
|
void readMTL(const c8* fileName, core::stringc relPath);
|
2007-08-13 16:28:44 -07:00
|
|
|
//! Find and return the material with the given name
|
2008-01-13 16:23:02 -08:00
|
|
|
SObjMtl * findMtl(const c8* mtlName);
|
2007-08-13 16:28:44 -07:00
|
|
|
|
2007-05-20 11:03:49 -07:00
|
|
|
//! Read RGB color
|
2008-01-13 16:23:02 -08:00
|
|
|
const c8* readColor(const c8* bufPtr, video::SColor& color, const c8* const pBufEnd);
|
2007-05-20 11:03:49 -07:00
|
|
|
//! Read 3d vector of floats
|
2008-01-13 16:23:02 -08:00
|
|
|
const c8* readVec3(const c8* bufPtr, core::vector3df& vec, const c8* const pBufEnd);
|
2007-05-20 11:03:49 -07:00
|
|
|
//! Read 2d vector of floats
|
2008-01-13 16:23:02 -08:00
|
|
|
const c8* readVec2(const c8* bufPtr, core::vector2df& vec, const c8* const pBufEnd);
|
2007-05-20 11:03:49 -07:00
|
|
|
//! Read boolean value represented as 'on' or 'off'
|
2008-01-13 16:23:02 -08:00
|
|
|
const c8* readBool(const c8* bufPtr, bool& tf, const c8* const bufEnd);
|
2007-05-20 11:03:49 -07:00
|
|
|
|
|
|
|
// reads and convert to integer the vertex indices in a line of obj file's face statement
|
|
|
|
// -1 for the index if it doesn't exist
|
|
|
|
// indices are changed to 0-based index instead of 1-based from the obj file
|
2008-01-13 16:23:02 -08:00
|
|
|
bool retrieveVertexIndices(c8* vertexData, s32* idx, const c8* bufEnd, u32 vbsize, u32 vtsize, u32 vnsize);
|
2007-05-20 11:03:49 -07:00
|
|
|
|
|
|
|
void cleanUp();
|
|
|
|
|
|
|
|
io::IFileSystem* FileSystem;
|
|
|
|
video::IVideoDriver* Driver;
|
|
|
|
|
2008-01-20 16:24:28 -08:00
|
|
|
core::array<SObjMtl*> Materials;
|
2007-05-20 11:03:49 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
} // end namespace scene
|
|
|
|
} // end namespace irr
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|