Arty
load_obj.h
1 #ifndef LOAD_OBJ_H
2 #define LOAD_OBJ_H
3 
4 #include <vector>
5 #include <string>
6 #include <unordered_map>
7 
8 #include "float3.h"
9 #include "color.h"
10 #include "file_path.h"
11 
12 namespace obj {
13 
15 struct Index {
16  int v, n, t;
17 };
18 
19 struct Face {
20  static constexpr int max_indices = 8;
21  Index indices[max_indices];
23  int material;
24 };
25 
27 struct Group {
28  std::vector<Face> faces;
29 };
30 
32 struct Object {
33  std::vector<Group> groups;
34 };
35 
36 struct Material {
37  rgb ka;
38  rgb kd;
39  rgb ks;
40  rgb ke;
41  float ns;
42  float ni;
43  rgb tf;
44  float tr;
45  float d;
46  int illum;
47  std::string map_ka;
48  std::string map_kd;
49  std::string map_ks;
50  std::string map_ke;
51  std::string map_bump;
52  std::string map_d;
53 };
54 
55 struct File {
56  std::vector<Object> objects;
57  std::vector<float3> vertices;
58  std::vector<float3> normals;
59  std::vector<float2> texcoords;
60  std::vector<std::string> materials;
61  std::vector<std::string> mtl_libs;
62 };
63 
64 typedef std::unordered_map<std::string, Material> MaterialLib;
65 
66 } // namespace obj
67 
69 bool load_obj(const FilePath&, obj::File&);
71 bool load_mtl(const FilePath&, obj::MaterialLib&);
72 
73 #endif // LOAD_OBJ_H
Definition: load_obj.h:12
float ns
Specular index.
Definition: load_obj.h:41
std::vector< std::string > mtl_libs
List of MTL files referenced in the model.
Definition: load_obj.h:61
rgb tf
Transmittance.
Definition: load_obj.h:43
std::vector< std::string > materials
List of material names referenced in the model.
Definition: load_obj.h:60
rgb kd
Diffuse term.
Definition: load_obj.h:38
rgb ke
Emitting term.
Definition: load_obj.h:40
float d
Dissolve factor.
Definition: load_obj.h:45
std::string map_kd
Diffuse texture.
Definition: load_obj.h:48
A group of faces in the model.
Definition: load_obj.h:27
rgb ks
Specular term.
Definition: load_obj.h:39
Definition: load_obj.h:19
int illum
Illumination model.
Definition: load_obj.h:46
A reference to a vertex/normal/texture coord. of the model.
Definition: load_obj.h:15
Definition: load_obj.h:55
std::vector< Object > objects
List of objects in the model.
Definition: load_obj.h:56
std::string map_ka
Ambient texture.
Definition: load_obj.h:47
Definition: load_obj.h:36
Represents a path in the file system.
Definition: file_path.h:8
std::string map_ke
Emitting texture.
Definition: load_obj.h:50
std::string map_ks
Specular texture.
Definition: load_obj.h:49
int t
Vertex, normal and texture indices (0 means not present)
Definition: load_obj.h:16
std::vector< float3 > vertices
List of vertices in the model.
Definition: load_obj.h:57
int material
Index into the material names of the model.
Definition: load_obj.h:23
float tr
Transparency.
Definition: load_obj.h:44
std::vector< float2 > texcoords
List of texture coordinates in the model.
Definition: load_obj.h:59
int index_count
Number of indices in the face.
Definition: load_obj.h:22
float ni
Medium index.
Definition: load_obj.h:42
rgb ka
Ambient term.
Definition: load_obj.h:37
std::string map_bump
Bump mapping texture.
Definition: load_obj.h:51
std::vector< float3 > normals
List of normals in the model.
Definition: load_obj.h:58
Definition: color.h:9
std::string map_d
Dissolve texture.
Definition: load_obj.h:52
A object in the model, made of several groups.
Definition: load_obj.h:32