CMSC23700 Common Code Library
Support code for CS23700 programming projects
obj.hxx
Go to the documentation of this file.
1 
9 /*
10  * COPYRIGHT (c) 2015 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.hxx"
18 #include <vector>
19 
20 namespace OBJ {
21 
24 enum {
25  NoLight = 0,
26  Diffuse = 1,
27  Specular = 2
28 };
29 
31 struct Material {
32  std::string name;
33  int illum;
37  float shininess;
38  std::string ambientMap;
39  std::string diffuseMap;
40  std::string specularMap;
41  std::string normalMap;
42 };
43 
45 struct Group {
46  std::string name;
47  int material;
48  uint32_t nVerts;
49  uint32_t nIndices;
53  uint32_t *indices;
54 };
56 
58 class Model {
59  public:
60 
63  Model (std::string filename);
64  ~Model ();
65 
67  const cs237::AABBf &BBox () const { return this->_bbox; }
68 
70  int NumMaterials () const { return this->_materials.size(); }
72  const OBJ::Material & Material (int i) const { return this->_materials[i]; }
73 
75  int NumGroups () const { return this->_groups.size(); }
77  const OBJ::Group & Group (int i) const { return this->_groups[i]; }
79  std::vector<OBJ::Group>::const_iterator beginGroups () const { return this->_groups.begin(); }
81  std::vector<OBJ::Group>::const_iterator endGroups () const { return this->_groups.end(); }
82 
83  private:
84  std::string _path;
85  std::string _mtlLibName;
86  cs237::AABBf _bbox;
87 
88  std::vector<OBJ::Material> _materials;
89  std::vector<OBJ::Group> _groups;
90 
91  // read a material library
92  bool readMaterial (std::string m);
93 
94 };
95 
96 }; // namespace OBJ
97 
98 #endif // !_OBJ_HXX_
uint32_t nIndices
the number of indices (3 * number of triangles)
Definition: obj.hxx:49
just use color component
Definition: obj.hxx:25
std::vector< OBJ::Group >::const_iterator beginGroups() const
iterator for looping over the groups in the module
Definition: obj.hxx:79
const OBJ::Material & Material(int i) const
get a material
Definition: obj.hxx:72
int material
index to material for group (-1 for no material)
Definition: obj.hxx:47
std::string normalMap
optional normal map for bump mapping
Definition: obj.hxx:41
int NumMaterials() const
the number of materials associated with this model
Definition: obj.hxx:70
cs237::vec2f * txtCoords
array of nVerts texture coordinates (or nullptr)
Definition: obj.hxx:52
std::string specularMap
optional texture map for specular highlights
Definition: obj.hxx:40
float shininess
specular exponent
Definition: obj.hxx:37
const OBJ::Group & Group(int i) const
get a group by index
Definition: obj.hxx:77
uint32_t nVerts
the number of vertices in this group.
Definition: obj.hxx:48
cs237::color3f ambient
ambient component
Definition: obj.hxx:34
std::string name
name of material
Definition: obj.hxx:32
Axis-Aligned Bounding Box.
Definition: cs237-aabb.hxx:24
Structure that defines a material in a model.
Definition: obj.hxx:31
std::string diffuseMap
optional texture map for diffuse lighting
Definition: obj.hxx:39
Definition: obj.hxx:20
A model from an OBJ file.
Definition: obj.hxx:58
uint32_t * indices
Definition: obj.hxx:53
std::string ambientMap
optional texture map for ambient
Definition: obj.hxx:38
template class for three-element vectors
Definition: cs237-types.hxx:26
A mesh that corresponds to a group in the obj file.
Definition: obj.hxx:45
include specular highlights
Definition: obj.hxx:27
template class for two-element vectors
Definition: cs237-types.hxx:25
cs237::color3f specular
specular component
Definition: obj.hxx:36
std::vector< OBJ::Group >::const_iterator endGroups() const
terminator for looping over the groups in the module
Definition: obj.hxx:81
ambient + diffuse
Definition: obj.hxx:26
Definition: cs237-color.hxx:57
int NumGroups() const
the number of groups in this model
Definition: obj.hxx:75
Model(std::string filename)
const cs237::AABBf & BBox() const
the model's axis-aligned bounding box
Definition: obj.hxx:67
std::string name
name of this group */
Definition: obj.hxx:46
cs237::vec3f * verts
array of nVerts texture coordinates (or nullptr)
Definition: obj.hxx:50
int illum
illumination mode (NoLight, etc.)
Definition: obj.hxx:33
cs237::vec3f * norms
array of nVerts texture coordinates (or nullptr)
Definition: obj.hxx:51
cs237::color3f diffuse
diffuse component
Definition: obj.hxx:35