CMSC23700 Common Code Library
Support code for CS23700 programming projects
Loading...
Searching...
No Matches
obj.hpp
Go to the documentation of this file.
1
9/*
10 * COPYRIGHT (c) 2017 John Reppy (http://cs.uchicago.edu/~jhr)
11 * All rights reserved.
12 */
13
14#ifndef _OBJ_HXX_
15#define _OBJ_HXX_
16
17#include "cs237.hpp"
18
19namespace OBJ {
20
23enum {
24 NoLight = 0,
25 Diffuse = 1,
26 Specular = 2
27 /* 3 Reflection on and Ray trace on */
28 /* 4 Transparency: Glass on
29 Reflection: Ray trace on */
30 /* 5 Reflection: Fresnel on and Ray trace on */
31 /* 6 Transparency: Refraction on
32 Reflection: Fresnel off and Ray trace on */
33 /* 7 Transparency: Refraction on
34 Reflection: Fresnel on and Ray trace on */
35 /* 8 Reflection on and Ray trace off */
36 /* 9 Transparency: Glass on
37 Reflection: Ray trace off */
38 /* 10 Casts shadows onto invisible surfaces */
39};
40
42enum {
45 MapComponent = 2
46};
47
49struct Material {
50 std::string name;
51 int illum;
56 glm::vec3 ambient;
57 glm::vec3 emissive;
58 glm::vec3 diffuse;
59 glm::vec3 specular;
60 float shininess;
61 std::string ambientMap;
62 std::string emissiveMap;
63 std::string diffuseMap;
64 std::string specularMap;
65 std::string normalMap;
66}; // struct Material
67
71struct Group {
72 std::string name;
74 uint32_t nVerts;
75 uint32_t nIndices;
76 glm::vec3 *verts;
77 glm::vec3 *norms;
78 glm::vec2 *txtCoords;
79 uint32_t *indices;
81}; // struct Group
82
84class Model {
85 public:
86
89 Model (std::string filename);
91
93 const cs237::AABBf_t &bounds () const { return this->_bbox; }
94
96 int numMaterials () const { return this->_materials.size(); }
98 const OBJ::Material & material (int i) const { return this->_materials[i]; }
99
101 int numGroups () const { return this->_groups.size(); }
103 const OBJ::Group & group (int i) const { return this->_groups[i]; }
105 std::vector<OBJ::Group>::const_iterator beginGroups () const { return this->_groups.begin(); }
107 std::vector<OBJ::Group>::const_iterator endGroups () const { return this->_groups.end(); }
108
109 private:
110 std::string _path;
111 std::string _mtlLibName;
112 cs237::AABBf_t _bbox;
113
114 std::vector<OBJ::Material> _materials;
115 std::vector<OBJ::Group> _groups;
116
117 // read a material library
118 bool readMaterial (std::string m);
119
120}; // class Model
121
122} // namespace OBJ
123
124#endif // !_OBJ_HXX_
A model from an OBJ file.
Definition obj.hpp:84
int numMaterials() const
the number of materials associated with this model
Definition obj.hpp:96
const OBJ::Material & material(int i) const
get a material
Definition obj.hpp:98
Model(std::string filename)
int numGroups() const
the number of groups in this model
Definition obj.hpp:101
std::vector< OBJ::Group >::const_iterator endGroups() const
terminator for looping over the groups in the model
Definition obj.hpp:107
const OBJ::Group & group(int i) const
get a group by index
Definition obj.hpp:103
std::vector< OBJ::Group >::const_iterator beginGroups() const
iterator for looping over the groups in the model
Definition obj.hpp:105
const cs237::AABBf_t & bounds() const
the model's axis-aligned bounding box
Definition obj.hpp:93
Definition obj.hpp:19
@ MapComponent
there is a map for the component
Definition obj.hpp:45
@ UniformComponent
there is a uniform value for the component
Definition obj.hpp:44
@ DefaultComponent
the component is not specified in the material
Definition obj.hpp:43
@ Specular
include specular highlights
Definition obj.hpp:26
@ Diffuse
ambient + diffuse
Definition obj.hpp:25
@ NoLight
just use color component
Definition obj.hpp:24
Definition obj.hpp:71
glm::vec2 * txtCoords
array of nVerts texture coordinates (or nullptr)
Definition obj.hpp:78
uint32_t nIndices
the number of indices (3 * number of triangles)
Definition obj.hpp:75
std::string name
name of this group
Definition obj.hpp:72
glm::vec3 * norms
array of nVerts normal vectors (or nullptr)
Definition obj.hpp:77
uint32_t * indices
Definition obj.hpp:79
glm::vec3 * verts
array of nVerts vertex coordinates
Definition obj.hpp:76
uint32_t nVerts
the number of vertices in this group.
Definition obj.hpp:74
int material
index to material for group (-1 for no material)
Definition obj.hpp:73
Structure that defines a material in a model.
Definition obj.hpp:49
std::string ambientMap
optional texture map for ambient
Definition obj.hpp:61
int ambientC
how is the ambient light specified?
Definition obj.hpp:52
int diffuseC
how is the diffuse light specified?
Definition obj.hpp:54
glm::vec3 ambient
uniform ambient component
Definition obj.hpp:56
std::string diffuseMap
optional texture map for diffuse lighting
Definition obj.hpp:63
int specularC
how is the specular light specified?
Definition obj.hpp:55
float shininess
uniform specular exponent
Definition obj.hpp:60
glm::vec3 specular
uniform specular component
Definition obj.hpp:59
glm::vec3 diffuse
uniform diffuse component
Definition obj.hpp:58
std::string normalMap
optional normal map for bump mapping
Definition obj.hpp:65
int illum
illumination mode (NoLight, etc.)
Definition obj.hpp:51
int emissiveC
how is the emissive light specified?
Definition obj.hpp:53
std::string specularMap
optional texture map for specular highlights
Definition obj.hpp:64
std::string name
name of material
Definition obj.hpp:50
glm::vec3 emissive
uniform emissive component
Definition obj.hpp:57
std::string emissiveMap
optional texture map for emissive lighting
Definition obj.hpp:62
Axis-Aligned Bounding Box parameterized over the scalar type.
Definition cs237-aabb.hpp:28