1
// Copyright (C) 2002-2011 Nikolaus Gebhardt
2
// This file is part of the "Irrlicht Engine".
3
// For conditions of distribution and use, see copyright notice in irrlicht.h
5
#ifndef __C_OBJ_MESH_FILE_LOADER_H_INCLUDED__
6
#define __C_OBJ_MESH_FILE_LOADER_H_INCLUDED__
8
#include "IMeshLoader.h"
9
#include "IFileSystem.h"
10
#include "ISceneManager.h"
11
#include "irrString.h"
12
#include "SMeshBuffer.h"
20
//! Meshloader capable of loading obj meshes.
21
class COBJMeshFileLoader : public IMeshLoader
26
COBJMeshFileLoader(scene::ISceneManager* smgr, io::IFileSystem* fs);
29
virtual ~COBJMeshFileLoader();
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;
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);
45
SObjMtl() : Meshbuffer(0), Bumpiness (1.0f), Illumination(0),
46
RecalculateNormals(false)
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();
55
SObjMtl(const SObjMtl& o)
56
: Name(o.Name), Group(o.Group),
57
Bumpiness(o.Bumpiness), Illumination(o.Illumination),
58
RecalculateNormals(false)
60
Meshbuffer = new SMeshBuffer();
61
Meshbuffer->Material = o.Meshbuffer->Material;
64
core::map<video::S3DVertex, int> VertMap;
65
scene::SMeshBuffer *Meshbuffer;
70
bool RecalculateNormals;
73
// helper method for material reading
74
const c8* readTextures(const c8* bufPtr, const c8* const bufEnd, SObjMtl* currMaterial, const io::path& relPath);
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);
87
// combination of goNextWord followed by copyWord
88
const c8* goAndCopyNextWord(c8* outBuf, const c8* inBuf, u32 outBufLength, const c8* const pBufEnd);
90
//! Read the material from the given file
91
void readMTL(const c8* fileName, const io::path& relPath);
93
//! Find and return the material with the given name
94
SObjMtl* findMtl(const core::stringc& mtlName, const core::stringc& grpName);
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);
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);
112
scene::ISceneManager* SceneManager;
113
io::IFileSystem* FileSystem;
115
core::array<SObjMtl*> Materials;
118
} // end namespace scene
119
} // end namespace irr