23 #ifndef __OBJIMPORTER__ 24 #define __OBJIMPORTER__ 33 namespace MeshImporter
36 #if _WIN32 //define something for Windows (32-bit and 64-bit, this part is common) 37 #pragma warning(disable:4996) 40 static void loadObjFile (
Mesh* mesh,
string filename) __attribute__ ((unused));
52 vector<Eigen::Vector4f> vert;
53 vector<Eigen::Vector3f> norm;
54 vector<Eigen::Vector2f> texCoord;
55 vector<Eigen::Vector4f> color;
56 vector<GLuint> elementsVertices;
57 vector<GLuint> elementsNormals;
58 vector<GLuint> elementsTexIDs;
62 cout <<
"Opening Wavefront obj file " << filename.c_str() << endl << endl;
65 ifstream in(filename.c_str(),ios::in);
68 cerr <<
"Cannot open " << filename.c_str() << endl; exit(1);
73 while(getline(in,line))
77 if(line.substr(0,2) ==
"v ")
80 istringstream s(line.substr(2));
82 s >> v[0]; s >> v[1]; s >> v[2]; v[3] = 1.0f;
85 if(s.rdbuf()->in_avail())
88 s >> c[0]; s >> c[1]; s >> c[2]; c[3] = 1.0f;
94 else if(line.substr(0,2) ==
"vn")
96 istringstream s(line.substr(3));
98 s >> vn[0]; s >> vn[1]; s >> vn[2];
103 else if(line.substr(0,2) ==
"vt")
105 istringstream s(line.substr(2));
107 s >> vt[0]; s >> vt[1];
108 texCoord.push_back(vt);
112 else if(line.substr(0,2) ==
"f ")
114 GLuint vertexID1, normalID1, textureID1;
115 istringstream s(line.substr(2));
119 elementsVertices.push_back(vertexID1-1);
127 elementsNormals.push_back(normalID1-1);
132 elementsTexIDs.push_back(textureID1-1);
137 elementsNormals.push_back(normalID1-1);
145 else if(line[0] ==
'#') { }
164 if (texCoord.size() > 0)
168 if (color.size() > 0)
172 if (elementsVertices.size() > 0)
void loadNormals(vector< Eigen::Vector3f > &norm)
Load normals (x,y,z) as a vertex attribute.
Definition: mesh.hpp:384
void loadColors(vector< Eigen::Vector4f > &clrs)
Load colors (r,g,b,a) as a vertex attribute.
Definition: mesh.hpp:438
Definition: bufferobject.hpp:34
static void loadObjFile(Mesh *mesh, string filename) __attribute__((unused))
Loads a mesh from an OBJ file.
Definition: objimporter.hpp:50
void errorCheckFunc(std::string file, int line, std::string message="")
GL error check method.
Definition: misc.hpp:53
void loadIndices(vector< GLuint > &ind)
Load indices into indices array.
Definition: mesh.hpp:448
void setDefaultAttribLocations(void)
Sets default attribute locations. vertex coords -> location 0 normals -> location 1 colors -> locatio...
Definition: mesh.hpp:474
void loadVertices(vector< Eigen::Vector4f > &vert)
Load vertices (x,y,z,w) and creates appropriate vertex attribute. The default attribute name is "in_P...
Definition: mesh.hpp:312
void loadTexCoords(vector< Eigen::Vector2f > &tex, bool normalize=false)
Load tex coords (u,v) as a vertex attribute. Optionally normalizes coords in range [0...
Definition: mesh.hpp:397
A common Mesh, usually containing triagles or points.
Definition: mesh.hpp:194