49 lines
906 B
C++
49 lines
906 B
C++
// not good at using namespaces, bear with me
|
|
|
|
#include <vector>
|
|
#include <string>
|
|
using namespace std;
|
|
|
|
// struct to hold vertex position
|
|
struct Vertex {
|
|
float pos[3];
|
|
};
|
|
|
|
// struct to hold normal vectors
|
|
struct Normal {
|
|
float dir[3];
|
|
};
|
|
|
|
// struct to hold material information
|
|
struct Material {
|
|
int idx;
|
|
string name;
|
|
float ambient[4];
|
|
float specular[4];
|
|
float diffuse[4];
|
|
};
|
|
|
|
// meta struct for each individual face, pointers to its set of
|
|
// vertices, normals and material structs
|
|
struct Face {
|
|
vector<Vertex*> vertices;
|
|
vector<Normal*> normals;
|
|
Material* mtl;
|
|
};
|
|
|
|
// class to load and handle .obj and .mtl parsing and face data construction
|
|
class ObjectLoader
|
|
{
|
|
public:
|
|
void load_obj(string filename);
|
|
void load_mtl(string filename);
|
|
|
|
vector<Face> faces;
|
|
|
|
protected:
|
|
Material* get_mtl_ptr(string mtl_name);
|
|
|
|
vector<Vertex> vertices;
|
|
vector<Normal> normals;
|
|
vector<Material> mtls;
|
|
};
|