3dobj-renderer/include/obj.h

50 lines
906 B
C
Raw Normal View History

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