-
Notifications
You must be signed in to change notification settings - Fork 0
/
OBJLoader.h
92 lines (73 loc) · 1.65 KB
/
OBJLoader.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#ifndef _OBJLOADER_H_
#define _OBJLOADER_H_
/*
* OBJLoader.h
*
* An OBJ model loader.
*
* Coded by Joseph A. Marrero. 12/22/06
* http://www.l33tprogramer.com/
*/
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include "Math/Vertex.h"
using namespace std;
using namespace MATH;
class COBJLoader
{
public:
typedef struct tagOBJVertex {
float x; float y; float z;
} OBJVertex;
typedef struct tagOBJTextureCoord {
float u; float v;
} OBJTextureCoord;
typedef struct tagOBJNormal {
float nx; float ny; float nz;
} OBJNormal;
typedef struct tagOBJGroup {
string groupName;
vector<CompleteVertex> mesh;
} OBJGroup;
protected:
typedef enum tagElement {
ELM_VERTEX,
ELM_TEXTURECOORD,
ELM_NORMAL,
ELM_FACE,
ELM_GROUP,
ELM_OTHER
} Element;
void setElement( char *token );
void addVertex( );
void addTextureCoord( );
void addNormal( );
void addFace( );
void addGroup( );
public:
explicit COBJLoader( char *filename, bool verbose = false );
explicit COBJLoader( string &filename, bool verbose = false );
~COBJLoader( );
bool load( );
void clear( );
vector<OBJGroup> &getMesh( );
vector<OBJGroup> getMesh( ) const;
protected:
void addDefaultGroup( );
ifstream m_File;
vector<OBJVertex> m_Vertices;
vector<OBJTextureCoord> m_TextureCoords;
vector<OBJNormal> m_Normals;
map<string, vector<CompleteVertex> *> m_GroupMap;
vector<OBJGroup> m_Groups;
Element m_CurrentElement;
string m_CurrentGroup;
bool m_bVerboseOutput;
};
inline vector<COBJLoader::OBJGroup> &COBJLoader::getMesh( )
{ return m_Groups; }
inline vector<COBJLoader::OBJGroup> COBJLoader::getMesh( ) const
{ return m_Groups; }
#endif